List of usage examples for org.springframework.jdbc JdbcUpdateAffectedIncorrectNumberOfRowsException JdbcUpdateAffectedIncorrectNumberOfRowsException
public JdbcUpdateAffectedIncorrectNumberOfRowsException(String sql, int expected, int actual)
From source file:org.dcache.chimera.H2FsSqlDriver.java
@Override long createTagInode(int uid, int gid, int mode) { final String CREATE_TAG_INODE_WITHOUT_VALUE = "INSERT INTO t_tags_inodes (imode, inlink, iuid, igid, isize, " + "ictime, iatime, imtime, ivalue) VALUES (?,1,?,?,0,?,?,?,NULL)"; Timestamp now = new Timestamp(System.currentTimeMillis()); KeyHolder keyHolder = new GeneratedKeyHolder(); int rc = _jdbc.update(con -> { PreparedStatement ps = con.prepareStatement(CREATE_TAG_INODE_WITHOUT_VALUE, Statement.RETURN_GENERATED_KEYS); ps.setInt(1, mode | UnixPermission.S_IFREG); ps.setInt(2, uid);/*from w w w. ja v a 2 s. c o m*/ ps.setInt(3, gid); ps.setTimestamp(4, now); ps.setTimestamp(5, now); ps.setTimestamp(6, now); return ps; }, keyHolder); if (rc != 1) { throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(CREATE_TAG_INODE_WITHOUT_VALUE, 1, rc); } /* H2 uses weird names for the column with the auto-generated key, so we cannot use the code * in the base class. */ return (Long) keyHolder.getKey(); }
From source file:org.dcache.chimera.H2FsSqlDriver.java
@Override long createTagInode(int uid, int gid, int mode, byte[] value) { final String CREATE_TAG_INODE_WITH_VALUE = "INSERT INTO t_tags_inodes (imode, inlink, iuid, igid, isize, " + "ictime, iatime, imtime, ivalue) VALUES (?,1,?,?,?,?,?,?,?)"; Timestamp now = new Timestamp(System.currentTimeMillis()); KeyHolder keyHolder = new GeneratedKeyHolder(); int rc = _jdbc.update(con -> { PreparedStatement ps = con.prepareStatement(CREATE_TAG_INODE_WITH_VALUE, Statement.RETURN_GENERATED_KEYS); ps.setInt(1, mode | UnixPermission.S_IFREG); ps.setInt(2, uid);//from w ww. j a v a 2 s .co m ps.setInt(3, gid); ps.setLong(4, value.length); ps.setTimestamp(5, now); ps.setTimestamp(6, now); ps.setTimestamp(7, now); ps.setBinaryStream(8, new ByteArrayInputStream(value), value.length); return ps; }, keyHolder); if (rc != 1) { throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(CREATE_TAG_INODE_WITH_VALUE, 1, rc); } /* H2 uses weird names for the column with the auto-generated key, so we cannot use the code * in the base class. */ return (Long) keyHolder.getKey(); }
From source file:cz.jirutka.spring.data.jdbc.BaseJdbcRepository.java
@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"); }//from w w w . j a v a 2 s . c o m 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); }
From source file:com.alibaba.cobar.client.CobarSqlMapClientTemplate.java
@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);// ww w .jav a2 s. c o m } }
From source file:com.haiegoo.framework.ibatis.SqlMapClientMasterSlaveTemplate.java
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);// w ww .java2 s . com } }
From source file:org.dcache.chimera.FsSqlDriver.java
void remove(FsInode inode) { if (inode.isDirectory()) { removeTag(inode);/* w w w. j ava2 s .c om*/ } /* Updating the inode effectively blocks anybody else from changing it and thus also from * adding more links. */ _jdbc.update("UPDATE t_inodes SET inlink=0 WHERE inumber=?", inode.ino()); /* Remove all hard-links. */ List<Long> parents = _jdbc.queryForList("SELECT iparent FROM t_dirs WHERE ichild=?", Long.class, inode.ino()); for (Long parent : parents) { decNlink(new FsInode(inode.getFs(), parent)); } int n = _jdbc.update("DELETE FROM t_dirs WHERE ichild=?", inode.ino()); if (n != parents.size()) { throw new JdbcUpdateAffectedIncorrectNumberOfRowsException("DELETE FROM t_dirs WHERE ichild=?", parents.size(), n); } removeInodeIfUnlinked(inode); }
From source file:com.haiegoo.framework.ibatis.SqlMapClientMasterSlaveTemplate.java
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);//from w w w .ja v a 2 s .c o m } }
From source file:org.dcache.chimera.FsSqlDriver.java
/** * Move/rename inode from source in srcDir to dest in destDir. The reference counts * of srcDir and destDir are updated.//from w w w . j a v a 2 s . c o m * * @param srcDir * @param source * @param destDir * @param dest * @param inode * @return true if moved, false if source did not exist */ boolean rename(FsInode inode, FsInode srcDir, String source, FsInode destDir, String dest) { String moveLink = "UPDATE t_dirs SET iparent=?, iname=? WHERE iparent=? AND iname=? AND ichild=?"; int n = _jdbc.update(moveLink, ps -> { ps.setLong(1, destDir.ino()); ps.setString(2, dest); ps.setLong(3, srcDir.ino()); ps.setString(4, source); ps.setLong(5, inode.ino()); }); if (n == 0) { return false; } if (n > 1) { throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(moveLink, 1, n); } if (!srcDir.equals(destDir)) { incNlink(destDir); decNlink(srcDir); } else { incNlink(srcDir, 0); } return true; }
From source file:com.alibaba.cobar.client.CobarSqlMapClientTemplate.java
@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);//from ww w .j a va 2 s . c o m } }
From source file:org.dcache.chimera.FsSqlDriver.java
/** * * creates a new id for a tag and stores it into t_tags_inodes table. * * @param uid// w ww. ja va 2 s . c om * @param gid * @param mode * @return */ long createTagInode(int uid, int gid, int mode) { final String CREATE_TAG_INODE_WITHOUT_VALUE = "INSERT INTO t_tags_inodes (imode, inlink, iuid, igid, isize, " + "ictime, iatime, imtime, ivalue) VALUES (?,1,?,?,0,?,?,?,NULL)"; Timestamp now = new Timestamp(System.currentTimeMillis()); KeyHolder keyHolder = new GeneratedKeyHolder(); int rc = _jdbc.update(con -> { PreparedStatement ps = con.prepareStatement(CREATE_TAG_INODE_WITHOUT_VALUE, Statement.RETURN_GENERATED_KEYS); ps.setInt(1, mode | UnixPermission.S_IFREG); ps.setInt(2, uid); ps.setInt(3, gid); ps.setTimestamp(4, now); ps.setTimestamp(5, now); ps.setTimestamp(6, now); return ps; }, keyHolder); if (rc != 1) { throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(CREATE_TAG_INODE_WITHOUT_VALUE, 1, rc); } return (Long) keyHolder.getKeys().get("itagid"); }