@Test public void testUpdateJustId() throws Exception { StatementExecutor<JustId, Integer> se = new StatementExecutor<JustId, Integer>(databaseType, new TableInfo<JustId, Integer>(connectionSource, null, JustId.class), null); JustId justId = new JustId(); justId.id = 1; assertEquals(0, se.update(null, justId, null)); }
public int update(DatabaseConnection databaseConnection, T data, ObjectCache objectCache) throws SQLException { try { if (argFieldTypes.length <= 1) { return 0; } Object[] args = getFieldObjects(data); Object newVersion = null; if (versionFieldType != null) { newVersion = versionFieldType.extractJavaFieldValue(data); newVersion = versionFieldType.moveToNextValue(newVersion); args[versionFieldTypeIndex] = versionFieldType.convertJavaFieldToSqlArgValue(newVersion); } int rowC = databaseConnection.update(statement, args, argFieldTypes); if (rowC > 0) { if (newVersion != null) { versionFieldType.assignField(data, newVersion, false, null); } if (objectCache != null) { Object id = idField.extractJavaFieldValue(data); T cachedData = objectCache.get(clazz, id); if (cachedData != null && cachedData != data) { for (FieldType fieldType : tableInfo.getFieldTypes()) { if (fieldType != idField) { fieldType.assignField(cachedData, fieldType.extractJavaFieldValue(data), false, objectCache); } } } } } logger.debug("update data with statement '{}' and {} args, changed {} rows", statement, args.length, rowC); if (args.length > 0) { logger.trace("update arguments: {}", (Object) args); } return rowC; } catch (SQLException e) { throw SqlExceptionUtil.create("Unable to run update stmt on object " + data + ": " + statement, e); } }
MappedUpdate extends BaseMappedStatement<T, ID> { public int update(DatabaseConnection databaseConnection, T data, ObjectCache objectCache) throws SQLException { try { if (argFieldTypes.length <= 1) { return 0; } Object[] args = getFieldObjects(data); Object newVersion = null; if (versionFieldType != null) { newVersion = versionFieldType.extractJavaFieldValue(data); newVersion = versionFieldType.moveToNextValue(newVersion); args[versionFieldTypeIndex] = versionFieldType.convertJavaFieldToSqlArgValue(newVersion); } int rowC = databaseConnection.update(statement, args, argFieldTypes); if (rowC > 0) { if (newVersion != null) { versionFieldType.assignField(data, newVersion, false, null); } if (objectCache != null) { Object id = idField.extractJavaFieldValue(data); T cachedData = objectCache.get(clazz, id); if (cachedData != null && cachedData != data) { for (FieldType fieldType : tableInfo.getFieldTypes()) { if (fieldType != idField) { fieldType.assignField(cachedData, fieldType.extractJavaFieldValue(data), false, objectCache); } } } } } logger.debug("update data with statement '{}' and {} args, changed {} rows", statement, args.length, rowC); if (args.length > 0) { logger.trace("update arguments: {}", (Object) args); } return rowC; } catch (SQLException e) { throw SqlExceptionUtil.create("Unable to run update stmt on object " + data + ": " + statement, e); } } }
MappedUpdate extends BaseMappedStatement<T, ID> { public int update(DatabaseConnection databaseConnection, T data, ObjectCache objectCache) throws SQLException { try { if (argFieldTypes.length <= 1) { return 0; } Object[] args = getFieldObjects(data); Object newVersion = null; if (versionFieldType != null) { newVersion = versionFieldType.extractJavaFieldValue(data); newVersion = versionFieldType.moveToNextValue(newVersion); args[versionFieldTypeIndex] = versionFieldType.convertJavaFieldToSqlArgValue(newVersion); } int rowC = databaseConnection.update(statement, args, argFieldTypes); if (rowC > 0) { if (newVersion != null) { versionFieldType.assignField(data, newVersion, false, null); } if (objectCache != null) { Object id = idField.extractJavaFieldValue(data); T cachedData = objectCache.get(clazz, id); if (cachedData != null && cachedData != data) { for (FieldType fieldType : tableInfo.getFieldTypes()) { if (fieldType != idField) { fieldType.assignField(cachedData, fieldType.extractJavaFieldValue(data), false, objectCache); } } } } } logger.debug("update data with statement '{}' and {} args, changed {} rows", statement, args.length, rowC); if (args.length > 0) { logger.trace("update arguments: {}", (Object) args); } return rowC; } catch (SQLException e) { throw SqlExceptionUtil.create("Unable to run update stmt on object " + data + ": " + statement, e); } } private  MappedUpdate(TableInfo<T, ID> tableInfo, String statement, FieldType[] argFieldTypes,
			FieldType versionFieldType, int versionFieldTypeIndex); }
MappedUpdate extends BaseMappedStatement<T, ID> { public int update(DatabaseConnection databaseConnection, T data, ObjectCache objectCache) throws SQLException { try { if (argFieldTypes.length <= 1) { return 0; } Object[] args = getFieldObjects(data); Object newVersion = null; if (versionFieldType != null) { newVersion = versionFieldType.extractJavaFieldValue(data); newVersion = versionFieldType.moveToNextValue(newVersion); args[versionFieldTypeIndex] = versionFieldType.convertJavaFieldToSqlArgValue(newVersion); } int rowC = databaseConnection.update(statement, args, argFieldTypes); if (rowC > 0) { if (newVersion != null) { versionFieldType.assignField(data, newVersion, false, null); } if (objectCache != null) { Object id = idField.extractJavaFieldValue(data); T cachedData = objectCache.get(clazz, id); if (cachedData != null && cachedData != data) { for (FieldType fieldType : tableInfo.getFieldTypes()) { if (fieldType != idField) { fieldType.assignField(cachedData, fieldType.extractJavaFieldValue(data), false, objectCache); } } } } } logger.debug("update data with statement '{}' and {} args, changed {} rows", statement, args.length, rowC); if (args.length > 0) { logger.trace("update arguments: {}", (Object) args); } return rowC; } catch (SQLException e) { throw SqlExceptionUtil.create("Unable to run update stmt on object " + data + ": " + statement, e); } } private  MappedUpdate(TableInfo<T, ID> tableInfo, String statement, FieldType[] argFieldTypes,
			FieldType versionFieldType, int versionFieldTypeIndex); static MappedUpdate<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo); int update(DatabaseConnection databaseConnection, T data, ObjectCache objectCache); }
MappedUpdate extends BaseMappedStatement<T, ID> { public int update(DatabaseConnection databaseConnection, T data, ObjectCache objectCache) throws SQLException { try { if (argFieldTypes.length <= 1) { return 0; } Object[] args = getFieldObjects(data); Object newVersion = null; if (versionFieldType != null) { newVersion = versionFieldType.extractJavaFieldValue(data); newVersion = versionFieldType.moveToNextValue(newVersion); args[versionFieldTypeIndex] = versionFieldType.convertJavaFieldToSqlArgValue(newVersion); } int rowC = databaseConnection.update(statement, args, argFieldTypes); if (rowC > 0) { if (newVersion != null) { versionFieldType.assignField(data, newVersion, false, null); } if (objectCache != null) { Object id = idField.extractJavaFieldValue(data); T cachedData = objectCache.get(clazz, id); if (cachedData != null && cachedData != data) { for (FieldType fieldType : tableInfo.getFieldTypes()) { if (fieldType != idField) { fieldType.assignField(cachedData, fieldType.extractJavaFieldValue(data), false, objectCache); } } } } } logger.debug("update data with statement '{}' and {} args, changed {} rows", statement, args.length, rowC); if (args.length > 0) { logger.trace("update arguments: {}", (Object) args); } return rowC; } catch (SQLException e) { throw SqlExceptionUtil.create("Unable to run update stmt on object " + data + ": " + statement, e); } } private  MappedUpdate(TableInfo<T, ID> tableInfo, String statement, FieldType[] argFieldTypes,
			FieldType versionFieldType, int versionFieldTypeIndex); static MappedUpdate<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo); int update(DatabaseConnection databaseConnection, T data, ObjectCache objectCache);  }