/** * Executes a {@link BulkDeleteOperation}, 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 the {@link EntityDependencyOrder}. */ public void delete(String statement, Object parameter, Class<? extends Entity> entityClass) { if (!bulkDeleteOperations.containsKey(entityClass)) { bulkDeleteOperations.put(entityClass, new ArrayList<BulkDeleteOperation>(1)); } bulkDeleteOperations.get(entityClass).add(new BulkDeleteOperation(dbSqlSessionFactory.mapStatement(statement), parameter)); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public List selectListWithRawParameter(String statement, Object parameter, boolean useCache) { statement = dbSqlSessionFactory.mapStatement(statement); List loadedObjects = sqlSession.selectList(statement, parameter); if (useCache) { return cacheLoadOrStore(loadedObjects); } else { return loadedObjects; } }
public Object selectOne(String statement, Object parameter) { statement = dbSqlSessionFactory.mapStatement(statement); Object result = sqlSession.selectOne(statement, parameter); if (result instanceof Entity) { Entity loadedObject = (Entity) result; result = cacheLoadOrStore(loadedObject); } return result; }
public int update(String statement, Object parameters) { String updateStatement = dbSqlSessionFactory.mapStatement(statement); return getSqlSession().update(updateStatement, parameters); }
protected void flushRegularInsert(Entity entity, Class<? extends Entity> clazz) { String insertStatement = dbSqlSessionFactory.getInsertStatement(entity); insertStatement = dbSqlSessionFactory.mapStatement(insertStatement); if (insertStatement == null) { throw new FlowableException("no insert statement for " + entity.getClass() + " in the ibatis mapping files"); } LOGGER.debug("inserting: {}", entity); sqlSession.insert(insertStatement, entity); // See https://activiti.atlassian.net/browse/ACT-1290 if (entity instanceof HasRevision) { incrementRevision(entity); } }
protected void flushBulkInsert(Collection<Entity> entities, Class<? extends Entity> clazz) { String insertStatement = dbSqlSessionFactory.getBulkInsertStatement(clazz); insertStatement = dbSqlSessionFactory.mapStatement(insertStatement); if (insertStatement == null) { throw new FlowableException("no insert statement for " + entities.iterator().next().getClass() + " in the ibatis mapping files"); } Iterator<Entity> entityIterator = entities.iterator(); Boolean hasRevision = null; while (entityIterator.hasNext()) { List<Entity> subList = new ArrayList<>(); int index = 0; while (entityIterator.hasNext() && index < dbSqlSessionFactory.getMaxNrOfStatementsInBulkInsert()) { Entity entity = entityIterator.next(); subList.add(entity); if (hasRevision == null) { hasRevision = entity instanceof HasRevision; } index++; } sqlSession.insert(insertStatement, subList); } if (hasRevision != null && hasRevision) { entityIterator = entities.iterator(); while (entityIterator.hasNext()) { incrementRevision(entityIterator.next()); } } }
protected void flushUpdates() { for (Entity updatedObject : updatedObjects) { String updateStatement = dbSqlSessionFactory.getUpdateStatement(updatedObject); updateStatement = dbSqlSessionFactory.mapStatement(updateStatement); if (updateStatement == null) { throw new FlowableException("no update statement for " + updatedObject.getClass() + " in the ibatis mapping files"); } LOGGER.debug("updating: {}", updatedObject); int updatedRecords = sqlSession.update(updateStatement, updatedObject); if (updatedRecords == 0) { throw new FlowableOptimisticLockingException(updatedObject + " was updated by another transaction concurrently"); } // See https://activiti.atlassian.net/browse/ACT-1290 if (updatedObject instanceof HasRevision) { ((HasRevision) updatedObject).setRevision(((HasRevision) updatedObject).getRevisionNext()); } } updatedObjects.clear(); }
protected void flushDeleteEntities(Class<? extends Entity> entityClass, Collection<Entity> entitiesToDelete) { for (Entity entity : entitiesToDelete) { String deleteStatement = dbSqlSessionFactory.getDeleteStatement(entity.getClass()); deleteStatement = dbSqlSessionFactory.mapStatement(deleteStatement); if (deleteStatement == null) { throw new FlowableException("no delete statement for " + entity.getClass() + " in the ibatis mapping files"); } // It only makes sense to check for optimistic locking exceptions // for objects that actually have a revision if (entity instanceof HasRevision) { int nrOfRowsDeleted = sqlSession.delete(deleteStatement, entity); if (nrOfRowsDeleted == 0) { throw new FlowableOptimisticLockingException(entity + " was updated by another transaction concurrently"); } } else { sqlSession.delete(deleteStatement, entity); } } }
@SuppressWarnings("unchecked") public <T extends Entity> T selectById(Class<T> entityClass, String id, boolean useCache) { T entity = null; if (useCache) { entity = entityCache.findInCache(entityClass, id); if (entity != null) { return entity; } } String selectStatement = dbSqlSessionFactory.getSelectStatement(entityClass); selectStatement = dbSqlSessionFactory.mapStatement(selectStatement); entity = (T) sqlSession.selectOne(selectStatement, id); if (entity == null) { return null; } entityCache.put(entity, true); // true -> store state so we can see later if it is updated later on return entity; }