@Override public int update(String statement) { return session.update(statement); }
@Override public int update(String statement, Object parameter) { return session.update(statement, parameter); }
public int update(String statement, Object parameters) { String updateStatement = dbSqlSessionFactory.mapStatement(statement); return getSqlSession().update(updateStatement, parameters); }
/** * 执行 SQL 更新 * * @param updateWrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句) */ public boolean update(Wrapper<T> updateWrapper) { Map<String, Object> map = new HashMap<>(2); map.put(Constants.ENTITY, this); map.put(Constants.WRAPPER, updateWrapper); // update SqlSession sqlSession = sqlSession(); try { return SqlHelper.retBool(sqlSession.update(sqlStatement(SqlMethod.UPDATE), map)); } finally { closeSqlSession(sqlSession); } }
@Transactional @Override public boolean update(String sql, Object... args) { SqlSession sqlSession = sqlSession(); try { return SqlHelper.retBool(sqlSession.update(UPDATE, sqlMap(sql, args))); }finally { closeSqlSession(sqlSession); } }
protected void flushUpdates() { for (Entity updatedObject : updatedObjects) { String updateStatement = dbSqlSessionFactory.getUpdateStatement(updatedObject); updateStatement = dbSqlSessionFactory.mapStatement(updateStatement); if (updateStatement == null) { throw new ActivitiException("no update statement for " + updatedObject.getClass() + " in the ibatis mapping files"); } log.debug("updating: {}", updatedObject); int updatedRecords = sqlSession.update(updateStatement, updatedObject); if (updatedRecords == 0) { throw new ActivitiOptimisticLockingException(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(); }
/** * 更新(字段选择更新) */ public boolean updateById() { Assert.isFalse(StringUtils.checkValNull(pkVal()), "updateById primaryKey is null."); // updateById Map<String, Object> map = new HashMap<>(1); map.put(Constants.ENTITY, this); SqlSession sqlSession = sqlSession(); try { return SqlHelper.retBool(sqlSession.update(sqlStatement(SqlMethod.UPDATE_BY_ID), map)); } finally { closeSqlSession(sqlSession); } }
@Transactional(rollbackFor = Exception.class) @Override public boolean updateBatchById(Collection<T> entityList, int batchSize) { Assert.notEmpty(entityList, "error: entityList must not be empty"); String sqlStatement = sqlStatement(SqlMethod.UPDATE_BY_ID); try (SqlSession batchSqlSession = sqlSessionBatch()) { int i = 0; for (T anEntityList : entityList) { MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>(); param.put(Constants.ENTITY, anEntityList); batchSqlSession.update(sqlStatement, param); if (i >= 1 && i % batchSize == 0) { batchSqlSession.flushStatements(); } i++; } batchSqlSession.flushStatements(); } return true; }
@Override public int update(String statement) { return sqlSessionProxy.update(statement); }
@Override public int update(String statement) { return sqlSessionProxy.update(statement); }
@Override public int update(String statement, Object parameter) { return sqlSessionProxy.update(statement, parameter); }
@Transactional(rollbackFor = Exception.class) @Override public boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize) { Assert.notEmpty(entityList, "error: entityList must not be empty"); Class<?> cls = currentModelClass(); TableInfo tableInfo = TableInfoHelper.getTableInfo(cls); Assert.notNull(tableInfo, "error: can not execute. because can not find cache of TableInfo for entity!"); String keyProperty = tableInfo.getKeyProperty(); Assert.notEmpty(keyProperty, "error: can not execute. because can not find column for id from entity!"); try (SqlSession batchSqlSession = sqlSessionBatch()) { int i = 0; for (T entity : entityList) { Object idVal = ReflectionKit.getMethodValue(cls, entity, keyProperty); if (StringUtils.checkValNull(idVal) || Objects.isNull(getById((Serializable) idVal))) { batchSqlSession.insert(sqlStatement(SqlMethod.INSERT_ONE), entity); } else { MapperMethod.ParamMap<T> param = new MapperMethod.ParamMap<>(); param.put(Constants.ENTITY, entity); batchSqlSession.update(sqlStatement(SqlMethod.UPDATE_BY_ID), param); } // 不知道以后会不会有人说更新失败了还要执行插入 😂😂😂 if (i >= 1 && i % batchSize == 0) { batchSqlSession.flushStatements(); } i++; } batchSqlSession.flushStatements(); } return true; }
result = rowCountResult(sqlSession.update(command.getName(), param)); break;
sqlSession -> when(sqlSession.update(randomStatement)).thenReturn(randomInt), dbSession -> dbSession.update(randomStatement), sqlSession -> { verify(sqlSession).update(randomStatement); return randomInt; }); verifyDelegation( sqlSession -> when(sqlSession.update(randomStatement, randomParameter)).thenReturn(randomInt), dbSession -> dbSession.update(randomStatement, randomParameter), sqlSession -> { verify(sqlSessionMock).update(randomStatement, randomParameter); return randomInt; });
@Override public int executeUpdate(String updateStatement, Object parameter) { updateStatement = dbSqlSessionFactory.mapStatement(updateStatement); return sqlSession.update(updateStatement, parameter); }
@Override public int executeUpdate(String updateStatement, Object parameter) { updateStatement = dbSqlSessionFactory.mapStatement(updateStatement); return sqlSession.update(updateStatement, parameter); }
@Override public int executeNonEmptyUpdateStmt(String updateStmt, Object parameter) { updateStmt = dbSqlSessionFactory.mapStatement(updateStmt); //if mapped statement is empty, which can happens for some databases, we have no need to execute it MappedStatement mappedStatement = sqlSession.getConfiguration().getMappedStatement(updateStmt); if (mappedStatement.getBoundSql(parameter).getSql().isEmpty()) return 0; return sqlSession.update(updateStmt, parameter); }
@Override public int executeNonEmptyUpdateStmt(String updateStmt, Object parameter) { updateStmt = dbSqlSessionFactory.mapStatement(updateStmt); //if mapped statement is empty, which can happens for some databases, we have no need to execute it MappedStatement mappedStatement = sqlSession.getConfiguration().getMappedStatement(updateStmt); if (mappedStatement.getBoundSql(parameter).getSql().isEmpty()) return 0; return sqlSession.update(updateStmt, parameter); }
public void lock(String statement, Object parameter) { // do not perform locking if H2 database is used. H2 uses table level locks // by default which may cause deadlocks if the deploy command needs to get a new // Id using the DbIdGenerator while performing a deployment. if (!DbSqlSessionFactory.H2.equals(dbSqlSessionFactory.getDatabaseType())) { String mappedStatement = dbSqlSessionFactory.mapStatement(statement); if (!Context.getProcessEngineConfiguration().isJdbcBatchProcessing()) { sqlSession.update(mappedStatement, parameter); } else { sqlSession.selectList(mappedStatement, parameter); } } }
public void lock(String statement, Object parameter) { // do not perform locking if H2 database is used. H2 uses table level locks // by default which may cause deadlocks if the deploy command needs to get a new // Id using the DbIdGenerator while performing a deployment. if (!DbSqlSessionFactory.H2.equals(dbSqlSessionFactory.getDatabaseType())) { String mappedStatement = dbSqlSessionFactory.mapStatement(statement); if (!Context.getProcessEngineConfiguration().isJdbcBatchProcessing()) { sqlSession.update(mappedStatement, parameter); } else { sqlSession.selectList(mappedStatement, parameter); } } }