本文整理汇总了Java中org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException类的典型用法代码示例。如果您正苦于以下问题:Java JdbcUpdateAffectedIncorrectNumberOfRowsException类的具体用法?Java JdbcUpdateAffectedIncorrectNumberOfRowsException怎么用?Java JdbcUpdateAffectedIncorrectNumberOfRowsException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JdbcUpdateAffectedIncorrectNumberOfRowsException类属于org.springframework.jdbc包,在下文中一共展示了JdbcUpdateAffectedIncorrectNumberOfRowsException类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException; //导入依赖的package包/类
@Override
public <S extends T> S update(S entity) {
Map<String, Object> columns = preUpdate(entity, columns(entity));
List<Object> idValues = removeIdColumns(columns); // modifies the
// columns list!
String updateQuery = sqlGenerator.update(table, columns);
if (idValues.contains(null)) {
throw new IllegalArgumentException("Entity's ID contains null values");
}
for (int i = 0; i < table.getPkColumns().size(); i++) {
columns.put(table.getPkColumns().get(i), idValues.get(i));
}
Object[] queryParams = columns.values().toArray();
int rowsAffected = jdbcOps.update(updateQuery, queryParams);
if (rowsAffected < 1) {
throw new NoRecordUpdatedException(table.getTableName(), idValues.toArray());
}
if (rowsAffected > 1) {
throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(updateQuery, 1, rowsAffected);
}
return postUpdate(entity);
}
示例2: update
import org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException; //导入依赖的package包/类
public <S extends T> S update(final S entity) {
Map<String, Object> columns = preUpdate(entity, columns(entity));
List<Object> idValues = removeIdColumns(columns); // modifies the columns list!
String sql = sqlGenerator.update(table, columns);
if (idValues.contains(null)) {
throw new IllegalArgumentException("Entity's ID contains null values");
}
for (int i = 0; i < table.getPkColumns().size(); i++) {
columns.put(table.getPkColumns().get(i), idValues.get(i));
}
Object[] queryParams = columns.values().toArray();
int rowsAffected = jdbcTemplate.update(sql, queryParams);
if (rowsAffected < 1) {
throw new NoRecordUpdatedException(table.getTableName(), idValues.toArray());
}
if (rowsAffected > 1) {
throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(sql, 1, rowsAffected);
}
return postUpdate(entity);
}
示例3: testOverMaxRows
import org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException; //导入依赖的package包/类
@Test
public void testOverMaxRows() throws SQLException {
given(preparedStatement.executeUpdate()).willReturn(8);
given(connection.prepareStatement(UPDATE)).willReturn(preparedStatement);
MaxRowsUpdater pc = new MaxRowsUpdater();
thrown.expect(JdbcUpdateAffectedIncorrectNumberOfRowsException.class);
pc.run();
}
示例4: testNotRequiredRows
import org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException; //导入依赖的package包/类
@Test
public void testNotRequiredRows() throws SQLException {
given(preparedStatement.executeUpdate()).willReturn(2);
given(connection.prepareStatement(UPDATE)).willReturn(preparedStatement);
thrown.expect(JdbcUpdateAffectedIncorrectNumberOfRowsException.class);
RequiredRowsUpdater pc = new RequiredRowsUpdater();
pc.run();
}
示例5: update
import org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException; //导入依赖的package包/类
public void update(String statementName, Object parameterObject, int requiredRowsAffected)
throws DataAccessException {
int actualRowsAffected = update(statementName, parameterObject);
if (actualRowsAffected != requiredRowsAffected) {
throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(
statementName, requiredRowsAffected, actualRowsAffected);
}
}
示例6: delete
import org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException; //导入依赖的package包/类
public void delete(String statementName, Object parameterObject, int requiredRowsAffected)
throws DataAccessException {
int actualRowsAffected = delete(statementName, parameterObject);
if (actualRowsAffected != requiredRowsAffected) {
throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(
statementName, requiredRowsAffected, actualRowsAffected);
}
}
示例7: testUpdateWithRequiredRowsAffectedAndInvalidRowCount
import org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException; //导入依赖的package包/类
@Test
public void testUpdateWithRequiredRowsAffectedAndInvalidRowCount() throws SQLException {
TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
given(template.executor.update("myStatement", "myParameter")).willReturn(20);
try {
template.update("myStatement", "myParameter", 10);
fail("Should have thrown JdbcUpdateAffectedIncorrectNumberOfRowsException");
}
catch (JdbcUpdateAffectedIncorrectNumberOfRowsException ex) {
// expected
assertEquals(10, ex.getExpectedRowsAffected());
assertEquals(20, ex.getActualRowsAffected());
}
}
示例8: testDeleteWithRequiredRowsAffectedAndInvalidRowCount
import org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException; //导入依赖的package包/类
@Test
public void testDeleteWithRequiredRowsAffectedAndInvalidRowCount() throws SQLException {
TestSqlMapClientTemplate template = new TestSqlMapClientTemplate();
given(template.executor.delete("myStatement", "myParameter")).willReturn(20);
try {
template.delete("myStatement", "myParameter", 10);
fail("Should have thrown JdbcUpdateAffectedIncorrectNumberOfRowsException");
}
catch (JdbcUpdateAffectedIncorrectNumberOfRowsException ex) {
// expected
assertEquals(10, ex.getExpectedRowsAffected());
assertEquals(20, ex.getActualRowsAffected());
}
}
示例9: delete
import org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException; //导入依赖的package包/类
@Override
public void delete(final String statementName, final Object parameterObject,
int requiredRowsAffected) throws DataAccessException {
Integer rowAffected = this.delete(statementName, parameterObject);
if (rowAffected != requiredRowsAffected) {
throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(statementName,
requiredRowsAffected, rowAffected);
}
}
示例10: update
import org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException; //导入依赖的package包/类
@Override
public void update(String statementName, Object parameterObject, int requiredRowsAffected)
throws DataAccessException {
int rowAffected = this.update(statementName, parameterObject);
if (rowAffected != requiredRowsAffected) {
throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(statementName,
requiredRowsAffected, rowAffected);
}
}
示例11: checkRowsAffected
import org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException; //导入依赖的package包/类
/**
* Check the given number of affected rows against the
* specified maximum number or required number.
* @param rowsAffected the number of affected rows
* @throws JdbcUpdateAffectedIncorrectNumberOfRowsException
* if the actually affected rows are out of bounds
* @see #setMaxRowsAffected
* @see #setRequiredRowsAffected
*/
protected void checkRowsAffected(int rowsAffected) throws JdbcUpdateAffectedIncorrectNumberOfRowsException {
if (this.maxRowsAffected > 0 && rowsAffected > this.maxRowsAffected) {
throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(getSql(), this.maxRowsAffected, rowsAffected);
}
if (this.requiredRowsAffected > 0 && rowsAffected != this.requiredRowsAffected) {
throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(getSql(), this.requiredRowsAffected, rowsAffected);
}
}