当前位置: 首页>>代码示例>>Java>>正文


Java JdbcUpdateAffectedIncorrectNumberOfRowsException类代码示例

本文整理汇总了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);
}
 
开发者ID:rubasace,项目名称:spring-data-jdbc,代码行数:29,代码来源:BaseJdbcRepository.java

示例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);
}
 
开发者ID:nickevin,项目名称:Qihua,代码行数:28,代码来源:JdbcRepository.java

示例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();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:SqlUpdateTests.java

示例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();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:SqlUpdateTests.java

示例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);
	}
}
 
开发者ID:otsecbsol,项目名称:linkbinder,代码行数:10,代码来源:SqlMapClientTemplate.java

示例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);
	}
}
 
开发者ID:otsecbsol,项目名称:linkbinder,代码行数:10,代码来源:SqlMapClientTemplate.java

示例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());
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:15,代码来源:SqlMapClientTests.java

示例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());
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:15,代码来源:SqlMapClientTests.java

示例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);
    }
}
 
开发者ID:alibaba,项目名称:cobarclient,代码行数:10,代码来源:CobarSqlMapClientTemplate.java

示例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);
    }
}
 
开发者ID:alibaba,项目名称:cobarclient,代码行数:10,代码来源:CobarSqlMapClientTemplate.java

示例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);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:SqlUpdate.java


注:本文中的org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。