Class SQLExpressionFactory


  • public class SQLExpressionFactory
    extends Object
    Factory for creating SQL expressions/literals. These are typically called when we are building up an SQL statement and we want to impose conditions using the fields of a class, and values for the field.
    • Constructor Detail

      • SQLExpressionFactory

        public SQLExpressionFactory​(RDBMSStoreManager storeMgr)
        Constructor for an SQLExpressionFactory. Also loads up the defined SQL methods [extension-point: "org.datanucleus.store.rdbms.sql_method"] and caches the keys. Also loads up the defined SQL operations [extension-point: "org.datanucleus.store.rdbms.sql_operation"] and caches the keys.
        Parameters:
        storeMgr - RDBMS Manager
    • Method Detail

      • newExpression

        public SQLExpression newExpression​(SQLStatement stmt,
                                           SQLTable sqlTbl,
                                           JavaTypeMapping mapping)
        Factory for an expression representing a mapping on a table.
        Parameters:
        stmt - The statement
        sqlTbl - The table
        mapping - The mapping
        Returns:
        The expression
      • newExpression

        public SQLExpression newExpression​(SQLStatement stmt,
                                           SQLTable sqlTbl,
                                           JavaTypeMapping mapping,
                                           JavaTypeMapping parentMapping)
        Factory for an expression representing a mapping on a table.
        Parameters:
        stmt - The statement
        sqlTbl - The table
        mapping - The mapping
        parentMapping - Optional parent mapping of this mapping (e.g when handling an implementation of an interface)
        Returns:
        The expression
      • newLiteral

        public SQLExpression newLiteral​(SQLStatement stmt,
                                        JavaTypeMapping mapping,
                                        Object value)
        Factory for a literal representing a value. To create a NullLiteral pass in a null mapping.
        Parameters:
        stmt - The statement
        mapping - The mapping
        value - The value
        Returns:
        The literal
      • newLiteralParameter

        public SQLExpression newLiteralParameter​(SQLStatement stmt,
                                                 JavaTypeMapping mapping,
                                                 Object value,
                                                 String paramName)
        Factory for a literal as an input parameter. If the mapping (type of parameter) is not known at this point then put in null and it will return a ParameterLiteral.
        Parameters:
        stmt - The statement
        mapping - The mapping
        value - Value of the literal (if known)
        paramName - The parameter name
        Returns:
        The literal
      • replaceParameterLiteral

        public SQLExpression replaceParameterLiteral​(ParameterLiteral paramLit,
                                                     SQLExpression comparisonExpr)
        Convenience method to replace the provided ParameterLiteral with a "parameter-based" literal using the supplied mapping (generated before its type was known).
        Parameters:
        paramLit - The parameter literal
        comparisonExpr - Expression we compare against
        Returns:
        The replacement expression
      • invokeMethod

        public SQLExpression invokeMethod​(SQLStatement stmt,
                                          String className,
                                          String methodName,
                                          SQLExpression expr,
                                          List args)
        Accessor for the result of an SQLMethod call on the supplied expression with the supplied args. Throws a NucleusException is the method is not supported.
        Parameters:
        stmt - SQLStatement that this relates to
        className - Class we are invoking the method on
        methodName - Name of the method
        expr - The expression we invoke the method on
        args - Any arguments to the method call
        Returns:
        The result
      • isMethodRegistered

        public boolean isMethodRegistered​(String className,
                                          String methodName)
      • registerMethod

        public void registerMethod​(String className,
                                   String methodName,
                                   SQLMethod method)
        Method to allow a user to register an SQLMethod at runtime without utilising the plugin mechanism. Will throw a NucleusUserException if this class+method already has an SQLMethod defined.
        Parameters:
        className - Class name (or null if "static")
        methodName - Name of the method/function
        method - The SQLMethod to invoke when this method is encountered
      • getMethod

        protected SQLMethod getMethod​(String className,
                                      String methodName,
                                      List args)
        Accessor for the method defined by the class/method names and supplied args. Throws a NucleusException is the method is not supported. Note that if the class name passed in is not for a listed class with that method defined then will check all remaining defined methods for a superclass.
        Parameters:
        className - Class we are invoking the method on
        methodName - Name of the method
        args - Any arguments to the method call (ignored currently) TODO Check the arguments
        Returns:
        The method
      • invokeOperation

        public SQLExpression invokeOperation​(String name,
                                             SQLExpression expr,
                                             SQLExpression expr2)
        Accessor for the result of an SQLOperation call on the supplied expression with the supplied args. Throws a NucleusException is the method is not supported.
        Parameters:
        name - Operation to be invoked
        expr - The first expression to perform the operation on
        expr2 - The second expression to perform the operation on
        Returns:
        The result
        Throws:
        UnsupportedOperationException - if the operation is not specified
      • getMappingForType

        public JavaTypeMapping getMappingForType​(Class cls,
                                                 boolean useCached)
        Accessor for a mapping to use in a query expression.
        Parameters:
        cls - The class that the mapping should represent.
        useCached - Whether to use any cached mapping (if available)
        Returns:
        The mapping