Package org.sqlproc.engine.impl
Class SqlProcessContext
- java.lang.Object
-
- org.sqlproc.engine.impl.SqlProcessContext
-
- All Implemented Interfaces:
SqlRuntimeContext
public class SqlProcessContext extends Object implements SqlRuntimeContext
The crate (design pattern) for all input parameters for theSqlMetaStatement.process(org.sqlproc.engine.impl.SqlMetaStatement.Type, Object, SqlControl, SqlEngine)
Also can work as a context for a dynamic ANSI SQL query generation. This processing is based on the contractSqlMetaElement.process(SqlProcessContext)
.- Author:
- Vladimir Hudec
-
-
Field Summary
Fields Modifier and Type Field Description private Object
dynamicInputValues
The SQL statement dynamic parameters.private Set<String>
oppositeNames
Unset features in the runtime.private SqlControl
sqlControl
The compound parameters controlling the META SQL execution.private SqlEngine
sqlEngine
The primary SQL Processor class for the META SQL execution.private SqlMetaSqlFragment.Type
sqlFragmentType
The type of the META SQL fragment.private SqlMetaStatement.Type
sqlStatementType
The SQL command type.
-
Constructor Summary
Constructors Constructor Description SqlProcessContext(SqlMetaStatement.Type sqlStatementType, Object dynamicInputValues, SqlControl sqlControl, SqlEngine sqlEngine)
Creates a new instance.SqlProcessContext(SqlProcessContext ctx, Object dynamicInputValues, SqlControl sqlControl)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
checkAttribute(Object bean, String attrName)
Checks the attribute getter method existence.boolean
checkMethod(Class<?> clazz, String methodName, Class<?>... args)
Checks the class method existence.boolean
checkMethod(Object bean, String methodName, Object... args)
Checks the bean method existence.Object
getAttribute(Object bean, String attrName)
Returns the value of the specified simple attribute of the specified bean.Class<?>[]
getAttributeParameterizedTypes(Class<?> clazz, String attrName)
Returns the Java parameterized type info for the attribute, if there is one.Class<?>
getAttributeType(Class<?> clazz, String attrName)
Returns the Java type info for the attribute, if there is one.Object
getDynamicInputValues()
Returns the SQL statement dynamic parameters.Class<?>
getEnumToClass(Class<?> clazz)
Returns the bean enumeration type.Object
getEnumToValue(Object bean)
Returns the bean enumeration value.String
getFeature(String name)
Convenient method to obtain a String feature based on the name.String
getFeature(SqlFeature feature)
Convenient method to obtain a String feature based on the name.String
getFeature(SqlFeature feature, String specName)
Convenient method to obtain a String feature based on the name.Integer
getFeatureAsInt(SqlFeature feature)
Convenient method to obtain an Integer feature based on the name.Object
getFeatureAsObject(SqlFeature feature)
Convenient method to obtain an Object feature based on the name.String[]
getFeatures(String name)
Convenient method to obtain a String array features based on the name.BeanUtilsPlugin.GetterType
getGetterType(Class<?> clazz, String attrName)
Returns the attribute getter method types, if there is one.BeanUtilsPlugin.GetterType
getGetterType(Object bean, String attrName)
Returns the attribute getter method types, if there is one.Object
getInstance(Class<?> clazz)
Returns the new class instanceMap<String,Class<?>>
getMoreResultClasses()
Returns the compound parameters controlling the META SQL execution.(package private) List<SqlOrder>
getOrder()
Returns the list of ordering directives.(package private) SqlOrder.Order
getOrder(int orderIndex)
Convenient method to obtain the ordering directive based on the index.(package private) int
getOrderIndex(String orderId)
Convenient method to obtain the index of the ordering directive.SqlPluginFactory
getPluginFactory()
Returns the factory responsible for the SQL Processor plugins.protected Object
getRawFeature(String name)
Convenient method to obtain a feature based on the name.protected Object
getRawFeature(SqlFeature feature)
Convenient method to obtain a feature based on the name.(package private) SqlMetaStatement.Type
getSqlStatementType()
Returns the SQL command type.Object
getStaticInputValues()
Returns the SQL statement static parameters.SqlTypeFactory
getTypeFactory()
Returns the factory responsible for the META types construction.Object
getValueToEnum(Class<?> objClass, Object val)
Returns the enumeration instance for the enumeration valueprivate void
initFeatures()
Initialize the optional features.Object
invokeMethod(Class<?> clazz, String methodName, Object... args)
Invokes the class method with the specified name and parameters.Object
invokeMethod(Object bean, String methodName, Object... args)
Invokes the bean method with the specified name and parameters.boolean
isFeature(SqlFeature feature)
Convenient method to obtain a boolean feature based on the name.boolean
isInSetOrInsert()
Returns the indicator the SET or VALUES fragment of META SQL is in processvoid
setAttribute(Object bean, String attrName, Object attrValue)
Sets the value of the specified simple attribute of the specified bean.void
setSqlFragmentType(SqlMetaSqlFragment.Type sqlFragmentType)
Sets the type of the META SQL fragment.boolean
simpleSetAttribute(Object bean, String attrName, Object attrValue, Class<?>... attrTypes)
Sets the value of the specified simple attribute of the specified bean, if there is one.String
toString()
For debug purposes.
-
-
-
Field Detail
-
sqlStatementType
private SqlMetaStatement.Type sqlStatementType
The SQL command type.
-
dynamicInputValues
private Object dynamicInputValues
The SQL statement dynamic parameters.
-
sqlControl
private SqlControl sqlControl
The compound parameters controlling the META SQL execution.
-
sqlEngine
private SqlEngine sqlEngine
The primary SQL Processor class for the META SQL execution.
-
sqlFragmentType
private SqlMetaSqlFragment.Type sqlFragmentType
The type of the META SQL fragment.
-
-
Constructor Detail
-
SqlProcessContext
SqlProcessContext(SqlMetaStatement.Type sqlStatementType, Object dynamicInputValues, SqlControl sqlControl, SqlEngine sqlEngine)
Creates a new instance.- Parameters:
sqlStatementType
- the type of the SQL commanddynamicInputValues
- the dynamic input parameterssqlControl
- the compound parameters controlling the META SQL executionsqlEngine
- the primary SQL Processor class for the META SQL execution
-
SqlProcessContext
SqlProcessContext(SqlProcessContext ctx, Object dynamicInputValues, SqlControl sqlControl)
Creates a new instance.- Parameters:
ctx
- the crate for all input parameters and the context of processingdynamicInputValues
- the dynamic input parameterssqlControl
- the compound parameters controlling the META SQL execution
-
-
Method Detail
-
initFeatures
private void initFeatures()
Initialize the optional features.
-
getSqlStatementType
SqlMetaStatement.Type getSqlStatementType()
Returns the SQL command type.- Returns:
- the SQL command type
-
getDynamicInputValues
public Object getDynamicInputValues()
Returns the SQL statement dynamic parameters.- Returns:
- the SQL statement dynamic parameters
-
getStaticInputValues
public Object getStaticInputValues()
Returns the SQL statement static parameters.- Returns:
- the SQL statement static parameters
-
getMoreResultClasses
public Map<String,Class<?>> getMoreResultClasses()
Returns the compound parameters controlling the META SQL execution.- Returns:
- the compound parameters controlling the META SQL execution
-
setSqlFragmentType
public void setSqlFragmentType(SqlMetaSqlFragment.Type sqlFragmentType)
Sets the type of the META SQL fragment.- Parameters:
sqlFragmentType
- the type of the META SQL fragment
-
isInSetOrInsert
public boolean isInSetOrInsert()
Returns the indicator the SET or VALUES fragment of META SQL is in process- Returns:
- the indicator the SET or VALUES fragment of META SQL is in process
-
getFeature
public String getFeature(String name)
Convenient method to obtain a String feature based on the name.- Specified by:
getFeature
in interfaceSqlRuntimeContext
- Parameters:
name
- name of the feature- Returns:
- value of the feature
-
getFeature
public String getFeature(SqlFeature feature)
Convenient method to obtain a String feature based on the name.- Specified by:
getFeature
in interfaceSqlRuntimeContext
- Parameters:
feature
- the feature- Returns:
- value of the feature
-
getFeature
public String getFeature(SqlFeature feature, String specName)
Convenient method to obtain a String feature based on the name.- Specified by:
getFeature
in interfaceSqlRuntimeContext
- Parameters:
feature
- the featurespecName
- the specific name- Returns:
- value of the feature
-
getFeatures
public String[] getFeatures(String name)
Convenient method to obtain a String array features based on the name.- Specified by:
getFeatures
in interfaceSqlRuntimeContext
- Parameters:
name
- the feature- Returns:
- the array of the feature values
-
isFeature
public boolean isFeature(SqlFeature feature)
Convenient method to obtain a boolean feature based on the name.- Specified by:
isFeature
in interfaceSqlRuntimeContext
- Parameters:
feature
- the feature- Returns:
- value of the feature
-
getFeatureAsInt
public Integer getFeatureAsInt(SqlFeature feature)
Convenient method to obtain an Integer feature based on the name.- Specified by:
getFeatureAsInt
in interfaceSqlRuntimeContext
- Parameters:
feature
- the feature- Returns:
- value of the feature
-
getFeatureAsObject
public Object getFeatureAsObject(SqlFeature feature)
Convenient method to obtain an Object feature based on the name.- Specified by:
getFeatureAsObject
in interfaceSqlRuntimeContext
- Parameters:
feature
- the feature- Returns:
- value of the feature
-
getRawFeature
protected Object getRawFeature(SqlFeature feature)
Convenient method to obtain a feature based on the name.- Parameters:
feature
- the feature- Returns:
- value of the feature
-
getRawFeature
protected Object getRawFeature(String name)
Convenient method to obtain a feature based on the name.- Parameters:
name
- name of the feature- Returns:
- value of the feature
-
getOrder
List<SqlOrder> getOrder()
Returns the list of ordering directives.- Returns:
- the list of ordering directives
-
getOrderIndex
int getOrderIndex(String orderId)
Convenient method to obtain the index of the ordering directive.- Parameters:
orderId
- the order number- Returns:
- the index of the ordering directive
-
getOrder
SqlOrder.Order getOrder(int orderIndex)
Convenient method to obtain the ordering directive based on the index.- Parameters:
orderIndex
- the index of the ordering rule- Returns:
- the ordering directive
-
getTypeFactory
public SqlTypeFactory getTypeFactory()
Returns the factory responsible for the META types construction.- Specified by:
getTypeFactory
in interfaceSqlRuntimeContext
- Returns:
- the factory for the META types construction
-
getPluginFactory
public SqlPluginFactory getPluginFactory()
Returns the factory responsible for the SQL Processor plugins.- Specified by:
getPluginFactory
in interfaceSqlRuntimeContext
- Returns:
- the factory for the SQL Processor plugins
-
getInstance
public Object getInstance(Class<?> clazz)
Returns the new class instance- Specified by:
getInstance
in interfaceSqlRuntimeContext
- Parameters:
clazz
- the class to be constructed- Returns:
- the new class instance. Null in the case of any error.
-
getAttributeType
public Class<?> getAttributeType(Class<?> clazz, String attrName)
Returns the Java type info for the attribute, if there is one.- Specified by:
getAttributeType
in interfaceSqlRuntimeContext
- Parameters:
clazz
- the class for which the attribute type is requestedattrName
- the name of the attribute which type is requested- Returns:
- the object that represents the Java type info. Null in the case there's no such attribute.
-
getAttributeParameterizedTypes
public Class<?>[] getAttributeParameterizedTypes(Class<?> clazz, String attrName)
Returns the Java parameterized type info for the attribute, if there is one.- Specified by:
getAttributeParameterizedTypes
in interfaceSqlRuntimeContext
- Parameters:
clazz
- the class for which the attribute type is requestedattrName
- the name of the attribute which type is requested- Returns:
- the object that represents the Java parameterized type info. Null in the case there's no such attribute.
-
getGetterType
public BeanUtilsPlugin.GetterType getGetterType(Class<?> clazz, String attrName)
Returns the attribute getter method types, if there is one.- Specified by:
getGetterType
in interfaceSqlRuntimeContext
- Parameters:
clazz
- the class for which the getter is requestedattrName
- the name of the attribute which getter is requested- Returns:
- The method that should be used to read the property value. Null in the case there's no such attribute's getter.
-
getGetterType
public BeanUtilsPlugin.GetterType getGetterType(Object bean, String attrName)
Returns the attribute getter method types, if there is one.- Specified by:
getGetterType
in interfaceSqlRuntimeContext
- Parameters:
bean
- the bean for which the getter is requestedattrName
- the name of the attribute which getter is requested- Returns:
- The getter method types that should be used to read the property value. Null in the case there's no such attribute's getter.
-
checkAttribute
public boolean checkAttribute(Object bean, String attrName)
Checks the attribute getter method existence.- Specified by:
checkAttribute
in interfaceSqlRuntimeContext
- Parameters:
bean
- the bean for which the getter is checkedattrName
- the name of the attribute which getter is checked- Returns:
- True if there's the attribute getter method
-
getAttribute
public Object getAttribute(Object bean, String attrName)
Returns the value of the specified simple attribute of the specified bean.- Specified by:
getAttribute
in interfaceSqlRuntimeContext
- Parameters:
bean
- the bean for which the attribute value is requestedattrName
- the name of the attribute which value is requested- Returns:
- the attribute value
-
simpleSetAttribute
public boolean simpleSetAttribute(Object bean, String attrName, Object attrValue, Class<?>... attrTypes)
Sets the value of the specified simple attribute of the specified bean, if there is one.- Specified by:
simpleSetAttribute
in interfaceSqlRuntimeContext
- Parameters:
bean
- the bean for which the attribute value is to be modifiedattrName
- the name of the attribute to be modifiedattrValue
- the value to which the attribute should be setattrTypes
- the possible attribute types- Returns:
- True if the attribute was successfully modified
-
setAttribute
public void setAttribute(Object bean, String attrName, Object attrValue)
Sets the value of the specified simple attribute of the specified bean.- Specified by:
setAttribute
in interfaceSqlRuntimeContext
- Parameters:
bean
- the bean for which the attribute value is to be modifiedattrName
- the name of the attribute to be modifiedattrValue
- the value to which the attribute should be set
-
checkMethod
public boolean checkMethod(Class<?> clazz, String methodName, Class<?>... args)
Checks the class method existence.- Specified by:
checkMethod
in interfaceSqlRuntimeContext
- Parameters:
clazz
- the class for which the method existence is checkedmethodName
- the name of the method to be checkedargs
- the method parameters types- Returns:
- True if there's such a method
-
checkMethod
public boolean checkMethod(Object bean, String methodName, Object... args)
Checks the bean method existence.- Specified by:
checkMethod
in interfaceSqlRuntimeContext
- Parameters:
bean
- the bean for which the method existence is checkedmethodName
- the name of the method to be checkedargs
- the method parameters- Returns:
- True if there's such a method
-
invokeMethod
public Object invokeMethod(Class<?> clazz, String methodName, Object... args)
Invokes the class method with the specified name and parameters. The method can be a static one.- Specified by:
invokeMethod
in interfaceSqlRuntimeContext
- Parameters:
clazz
- the class which method is going to be invokedmethodName
- the requested method nameargs
- the method parameters- Returns:
- the result of the method invocation
-
invokeMethod
public Object invokeMethod(Object bean, String methodName, Object... args)
Invokes the bean method with the specified name and parameters.- Specified by:
invokeMethod
in interfaceSqlRuntimeContext
- Parameters:
bean
- the bean which method is going to be invokedmethodName
- the requested method nameargs
- the method parameters- Returns:
- the result of the method invocation
-
getEnumToValue
public Object getEnumToValue(Object bean)
Returns the bean enumeration value.- Specified by:
getEnumToValue
in interfaceSqlRuntimeContext
- Parameters:
bean
- the bean of the enumeration type- Returns:
- the enumeration value. Null in the case of any error.
-
getEnumToClass
public Class<?> getEnumToClass(Class<?> clazz)
Returns the bean enumeration type.- Specified by:
getEnumToClass
in interfaceSqlRuntimeContext
- Parameters:
clazz
- the class of the enumeration type- Returns:
- the enumeration type. Null in the case of any error.
-
getValueToEnum
public Object getValueToEnum(Class<?> objClass, Object val)
Returns the enumeration instance for the enumeration value- Specified by:
getValueToEnum
in interfaceSqlRuntimeContext
- Parameters:
objClass
- the class of the enumeration typeval
- the enumeration value- Returns:
- the enumeration instance. Null in the case of any error.
-
-