Class DbSqlSession
- java.lang.Object
-
- org.activiti.engine.impl.db.DbSqlSession
-
- All Implemented Interfaces:
Session
- Direct Known Subclasses:
ProfilingDbSqlSession
public class DbSqlSession extends Object implements Session
-
-
Field Summary
Fields Modifier and Type Field Description protected static List<ActivitiVersion>ACTIVITI_VERSIONSprotected Map<Class<? extends Entity>,List<BulkDeleteOperation>>bulkDeleteOperationsprotected StringconnectionMetadataDefaultCatalogprotected StringconnectionMetadataDefaultSchemaprotected DbSqlSessionFactorydbSqlSessionFactoryprotected Map<Class<? extends Entity>,Map<String,Entity>>deletedObjectsprotected EntityCacheentityCacheprotected Map<Class<? extends Entity>,Map<String,Entity>>insertedObjectsstatic String[]JDBC_METADATA_TABLE_TYPESprotected static StringLAST_V5_VERSIONprotected org.apache.ibatis.session.SqlSessionsqlSessionprotected List<Entity>updatedObjects
-
Constructor Summary
Constructors Constructor Description DbSqlSession(DbSqlSessionFactory dbSqlSessionFactory, EntityCache entityCache)DbSqlSession(DbSqlSessionFactory dbSqlSessionFactory, EntityCache entityCache, Connection connection, String catalog, String schema)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected StringaddMissingComponent(String missingComponents, String component)protected StringaddSqlStatementPiece(String sqlStatement, String line)protected ListcacheLoadOrStore(List<Object> loadedObjects)protected EntitycacheLoadOrStore(Entity entity)Returns the object in the cache.voidclose()protected voidcollectChildExecutionsForInsertion(List<Entity> result, Map<String,List<ExecutionEntity>> parentToChildrenMapping, Set<String> handledExecutionIds, String parentId, boolean parentBeforeChildExecution)voidcommit()DeploymentQueryImplcreateDeploymentQuery()ExecutionQueryImplcreateExecutionQuery()HistoricActivityInstanceQueryImplcreateHistoricActivityInstanceQuery()HistoricDetailQueryImplcreateHistoricDetailQuery()HistoricProcessInstanceQueryImplcreateHistoricProcessInstanceQuery()HistoricTaskInstanceQueryImplcreateHistoricTaskInstanceQuery()HistoricVariableInstanceQueryImplcreateHistoricVariableInstanceQuery()JobQueryImplcreateJobQuery()ModelQueryImplcreateModelQueryImpl()ProcessDefinitionQueryImplcreateProcessDefinitionQuery()ProcessInstanceQueryImplcreateProcessInstanceQuery()TaskQueryImplcreateTaskQuery()voiddbSchemaCheckVersion()voiddbSchemaCreate()protected voiddbSchemaCreateEngine()protected voiddbSchemaCreateHistory()voiddbSchemaDrop()voiddbSchemaPrune()StringdbSchemaUpdate()protected voiddbSchemaUpgrade(String component, int currentDatabaseVersionsIndex)protected voiddebugFlush()voiddelete(String statement, Object parameter, Class<? extends Entity> entityClass)Executes aBulkDeleteOperation, with the sql in the statement parameter.voiddelete(Entity entity)voiddetermineUpdatedObjects()voidexecuteMandatorySchemaResource(String operation, String component)voidexecuteSchemaResource(String operation, String component, String resourceName, boolean isOptional)protected intfindMatchingVersionIndex(String dbVersion)Returns the index in the list ofACTIVITI_VERSIONSmatching the provided string version.voidflush()protected voidflushBulkDeletes(Class<? extends Entity> entityClass)protected voidflushBulkInsert(Collection<Entity> entities, Class<? extends Entity> clazz)protected voidflushDeleteEntities(Class<? extends Entity> entityClass, Collection<Entity> entitiesToDelete)protected voidflushDeletes()protected voidflushInsertEntities(Class<? extends Entity> entityClass, Collection<Entity> entitiesToInsert)protected voidflushInserts()protected voidflushRegularInsert(Entity entity, Class<? extends Entity> clazz)protected voidflushUpdates()<T> TgetCustomMapper(Class<T> type)DbSqlSessionFactorygetDbSqlSessionFactory()protected StringgetDbVersion()StringgetResourceForDbOperation(String directory, String operation, String component)org.apache.ibatis.session.SqlSessiongetSqlSession()protected voidincrementRevision(Entity insertedObject)voidinsert(Entity entity)booleanisEngineTablePresent()booleanisEntityInserted(Entity entity)booleanisEntityToBeDeleted(Entity entity)booleanisHistoryTablePresent()protected booleanisMissingTablesException(Exception e)booleanisMysql()booleanisOracle()booleanisTablePresent(String tableName)protected Collection<Entity>orderExecutionEntities(Map<String,Entity> executionEntities, boolean parentBeforeChildExecution)voidperformSchemaOperationsProcessEngineBuild()voidperformSchemaOperationsProcessEngineClose()protected StringprependDatabaseTablePrefix(String tableName)protected StringreadNextTrimmedLine(BufferedReader reader)protected voidremoveUnnecessaryOperations()Clears all deleted and inserted objects from the cache, and removes inserts and deletes that cancel each other.voidrollback()<T extends Entity>
TselectById(Class<T> entityClass, String id)<T extends Entity>
TselectById(Class<T> entityClass, String id, boolean useCache)ListselectList(String statement)ListselectList(String statement, Object parameter)ListselectList(String statement, Object parameter, boolean useCache)ListselectList(String statement, Object parameter, int firstResult, int maxResults)ListselectList(String statement, Object parameter, int firstResult, int maxResults, boolean useCache)ListselectList(String statement, Object parameter, Page page)ListselectList(String statement, Object parameter, Page page, boolean useCache)ListselectList(String statement, ListQueryParameterObject parameter)ListselectList(String statement, ListQueryParameterObject parameter, boolean useCache)ListselectList(String statement, ListQueryParameterObject parameter, Page page)ListselectList(String statement, ListQueryParameterObject parameter, Page page, boolean useCache)ListselectListWithRawParameter(String statement, Object parameter, int firstResult, int maxResults)ListselectListWithRawParameter(String statement, Object parameter, int firstResult, int maxResults, boolean useCache)ListselectListWithRawParameterWithoutFilter(String statement, Object parameter, int firstResult, int maxResults)ObjectselectOne(String statement, Object parameter)intupdate(String statement, Object parameters)voidupdate(Entity entity)protected StringupdateDdlForMySqlVersionLowerThan56(String ddlStatements)MySQL is funny when it comes to timestamps and dates.
-
-
-
Field Detail
-
LAST_V5_VERSION
protected static final String LAST_V5_VERSION
- See Also:
- Constant Field Values
-
ACTIVITI_VERSIONS
protected static final List<ActivitiVersion> ACTIVITI_VERSIONS
-
sqlSession
protected org.apache.ibatis.session.SqlSession sqlSession
-
dbSqlSessionFactory
protected DbSqlSessionFactory dbSqlSessionFactory
-
entityCache
protected EntityCache entityCache
-
bulkDeleteOperations
protected Map<Class<? extends Entity>,List<BulkDeleteOperation>> bulkDeleteOperations
-
connectionMetadataDefaultCatalog
protected String connectionMetadataDefaultCatalog
-
connectionMetadataDefaultSchema
protected String connectionMetadataDefaultSchema
-
JDBC_METADATA_TABLE_TYPES
public static String[] JDBC_METADATA_TABLE_TYPES
-
-
Constructor Detail
-
DbSqlSession
public DbSqlSession(DbSqlSessionFactory dbSqlSessionFactory, EntityCache entityCache)
-
DbSqlSession
public DbSqlSession(DbSqlSessionFactory dbSqlSessionFactory, EntityCache entityCache, Connection connection, String catalog, String schema)
-
-
Method Detail
-
insert
public void insert(Entity entity)
-
update
public void update(Entity entity)
-
delete
public void delete(String statement, Object parameter, Class<? extends Entity> entityClass)
Executes aBulkDeleteOperation, with the sql in the statement parameter. The passed class determines when this operation will be executed: it will be executed when the particular class has passed in theEntityDependencyOrder.
-
delete
public void delete(Entity entity)
-
selectList
public List selectList(String statement, ListQueryParameterObject parameter, Page page)
-
selectList
public List selectList(String statement, ListQueryParameterObject parameter, Page page, boolean useCache)
-
selectList
public List selectList(String statement, Object parameter, int firstResult, int maxResults)
-
selectList
public List selectList(String statement, Object parameter, int firstResult, int maxResults, boolean useCache)
-
selectList
public List selectList(String statement, ListQueryParameterObject parameter)
-
selectList
public List selectList(String statement, ListQueryParameterObject parameter, boolean useCache)
-
selectListWithRawParameter
public List selectListWithRawParameter(String statement, Object parameter, int firstResult, int maxResults)
-
selectListWithRawParameter
public List selectListWithRawParameter(String statement, Object parameter, int firstResult, int maxResults, boolean useCache)
-
selectListWithRawParameterWithoutFilter
public List selectListWithRawParameterWithoutFilter(String statement, Object parameter, int firstResult, int maxResults)
-
selectById
public <T extends Entity> T selectById(Class<T> entityClass, String id, boolean useCache)
-
cacheLoadOrStore
protected Entity cacheLoadOrStore(Entity entity)
Returns the object in the cache. If this object was loaded before, then the original object is returned (the cached version is more recent). If this is the first time this object is loaded, then the loadedObject is added to the cache.
-
removeUnnecessaryOperations
protected void removeUnnecessaryOperations()
Clears all deleted and inserted objects from the cache, and removes inserts and deletes that cancel each other.Also removes deletes with duplicate ids.
-
determineUpdatedObjects
public void determineUpdatedObjects()
-
debugFlush
protected void debugFlush()
-
isEntityInserted
public boolean isEntityInserted(Entity entity)
-
isEntityToBeDeleted
public boolean isEntityToBeDeleted(Entity entity)
-
flushInserts
protected void flushInserts()
-
flushInsertEntities
protected void flushInsertEntities(Class<? extends Entity> entityClass, Collection<Entity> entitiesToInsert)
-
orderExecutionEntities
protected Collection<Entity> orderExecutionEntities(Map<String,Entity> executionEntities, boolean parentBeforeChildExecution)
-
collectChildExecutionsForInsertion
protected void collectChildExecutionsForInsertion(List<Entity> result, Map<String,List<ExecutionEntity>> parentToChildrenMapping, Set<String> handledExecutionIds, String parentId, boolean parentBeforeChildExecution)
-
flushBulkInsert
protected void flushBulkInsert(Collection<Entity> entities, Class<? extends Entity> clazz)
-
incrementRevision
protected void incrementRevision(Entity insertedObject)
-
flushUpdates
protected void flushUpdates()
-
flushDeletes
protected void flushDeletes()
-
flushDeleteEntities
protected void flushDeleteEntities(Class<? extends Entity> entityClass, Collection<Entity> entitiesToDelete)
-
commit
public void commit()
-
rollback
public void rollback()
-
dbSchemaCheckVersion
public void dbSchemaCheckVersion()
-
addMissingComponent
protected String addMissingComponent(String missingComponents, String component)
-
getDbVersion
protected String getDbVersion()
-
dbSchemaCreate
public void dbSchemaCreate()
-
dbSchemaCreateHistory
protected void dbSchemaCreateHistory()
-
dbSchemaCreateEngine
protected void dbSchemaCreateEngine()
-
dbSchemaDrop
public void dbSchemaDrop()
-
dbSchemaPrune
public void dbSchemaPrune()
-
executeMandatorySchemaResource
public void executeMandatorySchemaResource(String operation, String component)
-
dbSchemaUpdate
public String dbSchemaUpdate()
-
findMatchingVersionIndex
protected int findMatchingVersionIndex(String dbVersion)
Returns the index in the list ofACTIVITI_VERSIONSmatching the provided string version. Returns -1 if no match can be found.
-
isEngineTablePresent
public boolean isEngineTablePresent()
-
isHistoryTablePresent
public boolean isHistoryTablePresent()
-
isTablePresent
public boolean isTablePresent(String tableName)
-
dbSchemaUpgrade
protected void dbSchemaUpgrade(String component, int currentDatabaseVersionsIndex)
-
getResourceForDbOperation
public String getResourceForDbOperation(String directory, String operation, String component)
-
executeSchemaResource
public void executeSchemaResource(String operation, String component, String resourceName, boolean isOptional)
-
updateDdlForMySqlVersionLowerThan56
protected String updateDdlForMySqlVersionLowerThan56(String ddlStatements)
MySQL is funny when it comes to timestamps and dates.More specifically, for a DDL statement like 'MYCOLUMN timestamp(3)': - MySQL 5.6.4+ has support for timestamps/dates with millisecond (or smaller) precision. The DDL above works and the data in the table will have millisecond precision - MySQL < 5.5.3 allows the DDL statement, but ignores it. The DDL above works but the data won't have millisecond precision - MySQL 5.5.3 < [version] < 5.6.4 gives and exception when using the DDL above.
Also, the 5.5 and 5.6 branches of MySQL are both actively developed and patched.
Hence, when doing auto-upgrade/creation of the Activiti tables, the default MySQL DDL file is used and all timestamps/datetimes are converted to not use the millisecond precision by string replacement done in the method below.
If using the DDL files directly (which is a sane choice in production env.), there is a distinction between MySQL version < 5.6.
-
readNextTrimmedLine
protected String readNextTrimmedLine(BufferedReader reader) throws IOException
- Throws:
IOException
-
isMissingTablesException
protected boolean isMissingTablesException(Exception e)
-
performSchemaOperationsProcessEngineBuild
public void performSchemaOperationsProcessEngineBuild()
-
performSchemaOperationsProcessEngineClose
public void performSchemaOperationsProcessEngineClose()
-
getCustomMapper
public <T> T getCustomMapper(Class<T> type)
-
isMysql
public boolean isMysql()
-
isOracle
public boolean isOracle()
-
createDeploymentQuery
public DeploymentQueryImpl createDeploymentQuery()
-
createModelQueryImpl
public ModelQueryImpl createModelQueryImpl()
-
createProcessDefinitionQuery
public ProcessDefinitionQueryImpl createProcessDefinitionQuery()
-
createProcessInstanceQuery
public ProcessInstanceQueryImpl createProcessInstanceQuery()
-
createExecutionQuery
public ExecutionQueryImpl createExecutionQuery()
-
createTaskQuery
public TaskQueryImpl createTaskQuery()
-
createJobQuery
public JobQueryImpl createJobQuery()
-
createHistoricProcessInstanceQuery
public HistoricProcessInstanceQueryImpl createHistoricProcessInstanceQuery()
-
createHistoricActivityInstanceQuery
public HistoricActivityInstanceQueryImpl createHistoricActivityInstanceQuery()
-
createHistoricTaskInstanceQuery
public HistoricTaskInstanceQueryImpl createHistoricTaskInstanceQuery()
-
createHistoricDetailQuery
public HistoricDetailQueryImpl createHistoricDetailQuery()
-
createHistoricVariableInstanceQuery
public HistoricVariableInstanceQueryImpl createHistoricVariableInstanceQuery()
-
getSqlSession
public org.apache.ibatis.session.SqlSession getSqlSession()
-
getDbSqlSessionFactory
public DbSqlSessionFactory getDbSqlSessionFactory()
-
-