Package org.datanucleus.store.rdbms.sql.method

Examples of org.datanucleus.store.rdbms.sql.method.SQLMethod


    public SQLExpression invokeMethod(SQLStatement stmt, String className, String methodName,
            SQLExpression expr, List args)
    {
        // Try to find an existing instance of the required SQLMethod
        String classMethodKey = (className != null ? (className + "_" + methodName) : methodName);
        SQLMethod method = methodByClassMethodName.get(classMethodKey);
        if (method != null)
        {
            // Reuse method, setting statement for this usage
            synchronized (method) // Only permit sole usage at any time
            {
                method.setStatement(stmt);
                return method.getExpression(expr, args);
            }
        }

        // No existing instance so try a datastore-dependent key
        String datastoreId = storeMgr.getDatastoreAdapter().getVendorID();
        String key = getSQLMethodKey(datastoreId, className, methodName);
        String sqlMethodClassName = methodClassByDatastoreMethodName.get(key);
        if (sqlMethodClassName == null)
        {
            // No datastore-dependent method, so try a datastore-independent key
            key = getSQLMethodKey(null, className, methodName);
            sqlMethodClassName = methodClassByDatastoreMethodName.get(key);
            if (sqlMethodClassName == null)
            {
                if (className != null)
                {
                    throw new NucleusUserException(LOCALISER.msg("060008", methodName, className));
                }
                else
                {
                    throw new NucleusUserException(LOCALISER.msg("060009", methodName));
                }
            }
        }

        // Use SQLMethod().getExpression(SQLExpression, args)
        try
        {
            method = (SQLMethod)stmt.getClassLoaderResolver().classForName(sqlMethodClassName).newInstance();
            synchronized (method) // Only permit sole usage at any time
            {
                method.setStatement(stmt);

                // Cache the method in case its used later
                methodByClassMethodName.put(classMethodKey, method);

                return method.getExpression(expr, args);
            }
        }
        catch (ClassNotResolvedException cnre)
        {
            throw new NucleusUserException(LOCALISER.msg("060010", sqlMethodClassName));
View Full Code Here

TOP

Related Classes of org.datanucleus.store.rdbms.sql.method.SQLMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.