Class SQLExpressionFactory
- java.lang.Object
-
- org.datanucleus.store.rdbms.sql.expression.SQLExpressionFactory
-
public class SQLExpressionFactory extends java.lang.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
SQLExpressionFactory.MethodKey
-
Field Summary
Fields Modifier and Type Field Description (package private) org.datanucleus.ClassLoaderResolver
clr
private static java.lang.Class[]
EXPR_CREATION_ARG_TYPES
(package private) java.util.Map<java.lang.String,java.lang.Class<? extends SQLExpression>>
expressionClassByMappingName
Cache of expression class, keyed by the mapping class name.private static java.lang.Class[]
LIT_CREATION_ARG_TYPES
(package private) java.util.Map<java.lang.String,java.lang.Class<? extends SQLExpression>>
literalClassByMappingName
Cache of literal class, keyed by the mapping class name.(package private) java.util.Map<java.lang.Class,JavaTypeMapping>
mappingByClass
Map of JavaTypeMapping for use in query expressions, keyed by the type being represented.(package private) java.util.Set<SQLExpressionFactory.MethodKey>
pluginSqlMethodsKeysSupported
Keys of SQLMethods that are supported.(package private) java.util.Set<java.lang.String>
pluginSqlOperationKeysSupported
Keys of SQLOperations that are supported.(package private) java.util.Map<SQLExpressionFactory.MethodKey,SQLMethod>
sqlMethodsByKey
Cache of SQLMethod instances, keyed by their class+method[+datastore] name.(package private) java.util.Map<java.lang.String,SQLOperation>
sqlOperationsByName
Cache of SQLOperation instances, keyed by their name.(package private) RDBMSStoreManager
storeMgr
-
Constructor Summary
Constructors Constructor Description SQLExpressionFactory(RDBMSStoreManager storeMgr)
Constructor for an SQLExpressionFactory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JavaTypeMapping
getMappingForType(java.lang.Class cls)
JavaTypeMapping
getMappingForType(java.lang.Class cls, boolean useCached)
Accessor for a mapping to use in a query expression.protected SQLMethod
getMethod(java.lang.String className, java.lang.String methodName, java.util.List args)
Accessor for the method defined by the class/method names and supplied args.private SQLExpressionFactory.MethodKey
getSQLMethodKey(java.lang.String datastoreName, java.lang.String className, java.lang.String methodName)
Convenience method to return the key for the SQL method.private java.lang.String
getSQLOperationKey(java.lang.String datastoreName, java.lang.String name)
Convenience method to return the key for the SQL operation.SQLExpression
invokeMethod(SQLStatement stmt, java.lang.String className, java.lang.String methodName, SQLExpression expr, java.util.List<SQLExpression> args)
Accessor for the result of an SQLMethod call on the supplied expression with the supplied args.SQLExpression
invokeOperation(java.lang.String name, SQLExpression expr, SQLExpression expr2)
Accessor for the result of an SQLOperation call on the supplied expression with the supplied args.boolean
isMethodRegistered(java.lang.String className, java.lang.String methodName)
SQLExpression
newExpression(SQLStatement stmt, SQLTable sqlTbl, JavaTypeMapping mapping)
Factory for an expression representing a mapping on a table.SQLExpression
newExpression(SQLStatement stmt, SQLTable sqlTbl, JavaTypeMapping mapping, JavaTypeMapping parentMapping)
Factory for an expression representing a mapping on a table.SQLExpression
newLiteral(SQLStatement stmt, JavaTypeMapping mapping, java.lang.Object value)
Factory for a literal representing a value.SQLExpression
newLiteralParameter(SQLStatement stmt, JavaTypeMapping mapping, java.lang.Object value, java.lang.String paramName)
Factory for a literal as an input parameter.void
registerMethod(java.lang.String className, java.lang.String methodName, SQLMethod method)
Method to allow a user to register an SQLMethod at runtime without utilising the plugin mechanism.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).
-
-
-
Field Detail
-
EXPR_CREATION_ARG_TYPES
private static final java.lang.Class[] EXPR_CREATION_ARG_TYPES
-
LIT_CREATION_ARG_TYPES
private static final java.lang.Class[] LIT_CREATION_ARG_TYPES
-
storeMgr
RDBMSStoreManager storeMgr
-
clr
org.datanucleus.ClassLoaderResolver clr
-
expressionClassByMappingName
java.util.Map<java.lang.String,java.lang.Class<? extends SQLExpression>> expressionClassByMappingName
Cache of expression class, keyed by the mapping class name.
-
literalClassByMappingName
java.util.Map<java.lang.String,java.lang.Class<? extends SQLExpression>> literalClassByMappingName
Cache of literal class, keyed by the mapping class name.
-
pluginSqlMethodsKeysSupported
java.util.Set<SQLExpressionFactory.MethodKey> pluginSqlMethodsKeysSupported
Keys of SQLMethods that are supported.
-
sqlMethodsByKey
java.util.Map<SQLExpressionFactory.MethodKey,SQLMethod> sqlMethodsByKey
Cache of SQLMethod instances, keyed by their class+method[+datastore] name.
-
pluginSqlOperationKeysSupported
java.util.Set<java.lang.String> pluginSqlOperationKeysSupported
Keys of SQLOperations that are supported.
-
sqlOperationsByName
java.util.Map<java.lang.String,SQLOperation> sqlOperationsByName
Cache of SQLOperation instances, keyed by their name.
-
mappingByClass
java.util.Map<java.lang.Class,JavaTypeMapping> mappingByClass
Map of JavaTypeMapping for use in query expressions, keyed by the type being represented.
-
-
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 statementsqlTbl
- The tablemapping
- 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 statementsqlTbl
- The tablemapping
- The mappingparentMapping
- 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, java.lang.Object value)
Factory for a literal representing a value. To create a NullLiteral pass in a null mapping.- Parameters:
stmt
- The statementmapping
- The mappingvalue
- The value- Returns:
- The literal
-
newLiteralParameter
public SQLExpression newLiteralParameter(SQLStatement stmt, JavaTypeMapping mapping, java.lang.Object value, java.lang.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 statementmapping
- The mappingvalue
- 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 literalcomparisonExpr
- Expression we compare against- Returns:
- The replacement expression
-
invokeMethod
public SQLExpression invokeMethod(SQLStatement stmt, java.lang.String className, java.lang.String methodName, SQLExpression expr, java.util.List<SQLExpression> 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 toclassName
- Class we are invoking the method onmethodName
- Name of the methodexpr
- The expression we invoke the method onargs
- Any arguments to the method call- Returns:
- The result
-
isMethodRegistered
public boolean isMethodRegistered(java.lang.String className, java.lang.String methodName)
-
registerMethod
public void registerMethod(java.lang.String className, java.lang.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/functionmethod
- The SQLMethod to invoke when this method is encountered
-
getMethod
protected SQLMethod getMethod(java.lang.String className, java.lang.String methodName, java.util.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 onmethodName
- Name of the methodargs
- Any arguments to the method call (ignored currently) TODO Check the arguments- Returns:
- The method
-
getSQLMethodKey
private SQLExpressionFactory.MethodKey getSQLMethodKey(java.lang.String datastoreName, java.lang.String className, java.lang.String methodName)
Convenience method to return the key for the SQL method. Returns a string like{datastore}#{class}.{method}
if the class is defined, and{datastore}#{method}
if the class is not defined (function).- Parameters:
datastoreName
- Vendor id of the RDBMS datastoreclassName
- Name of the class that we are invoking on (null if static).methodName
- Method to be invoked- Returns:
- Key for the SQLMethod
-
invokeOperation
public SQLExpression invokeOperation(java.lang.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 invokedexpr
- The first expression to perform the operation onexpr2
- The second expression to perform the operation on- Returns:
- The result
- Throws:
java.lang.UnsupportedOperationException
- if the operation is not specified
-
getSQLOperationKey
private java.lang.String getSQLOperationKey(java.lang.String datastoreName, java.lang.String name)
Convenience method to return the key for the SQL operation. Returns a string like{datastore}#{operation}
.- Parameters:
datastoreName
- Vendor id of the RDBMS datastorename
- Operation to be invoked- Returns:
- Key for the SQLOperation
-
getMappingForType
public JavaTypeMapping getMappingForType(java.lang.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
-
getMappingForType
public JavaTypeMapping getMappingForType(java.lang.Class cls)
-
-