poolmanresultset.java
来自「Java Database connection pool」· Java 代码 · 共 1,658 行 · 第 1/4 页
JAVA
1,658 行
ArrayList row = getTrueRow(); // test for type and colname validity boolean valid = false; Result r = (Result) row.get(colIndex - 1); if (r.type == java.sql.Types.TINYINT) valid = true; // add to the ArrayList of updates for this row if (!valid) throw new SQLException("Update Error: Check column name and argument type"); else if (onInsertRow) row.set((colIndex - 1), new Result(r.tableName, r.colName, new Byte(x), r.type)); else updatedResults.add(new Result(r.tableName, r.colName, new Byte(x), r.type)); } public void updateByte(String colName, byte x) throws SQLException { updateByte(findColumn(colName), x); } public void updateBytes(int colIndex, byte[] x) throws SQLException { throw new UnsupportedOperationException("PoolMan doesn't support this method, use native ResultSet " + "(configurable in your poolman.xml) or execute the query using the " + "native Statement returned from PoolManStatement.getNativeStatement() " + "if your underlying driver supports it"); } public void updateBytes(String colName, byte[] x) throws SQLException { throw new UnsupportedOperationException("PoolMan doesn't support this method, use native ResultSet " + "(configurable in your poolman.xml) or execute the query using the " + "native Statement returned from PoolManStatement.getNativeStatement() " + "if your underlying driver supports it"); } public void updateCharacterStream(int colIndex, Reader reader, int length) throws SQLException { throw new UnsupportedOperationException("PoolMan doesn't support this method, use native ResultSet " + "(configurable in your poolman.xml) or execute the query using the " + "native Statement returned from PoolManStatement.getNativeStatement() " + "if your underlying driver supports it"); } public void updateCharacterStream(String colName, Reader reader, int length) throws SQLException { throw new UnsupportedOperationException("PoolMan doesn't support this method, use native ResultSet " + "(configurable in your poolman.xml) or execute the query using the " + "native Statement returned from PoolManStatement.getNativeStatement() " + "if your underlying driver supports it"); } public void updateDate(int colIndex, java.sql.Date d) throws SQLException { // current row ArrayList row = getTrueRow(); // test for type and colname validity boolean valid = false; Result r = (Result) row.get(colIndex - 1); if (r.type == java.sql.Types.DATE) valid = true; // add to the ArrayList of updates for this row if (!valid) throw new SQLException("Update Error: Check column name and argument type"); else if (onInsertRow) row.set((colIndex - 1), new Result(r.tableName, r.colName, d, r.type)); else updatedResults.add(new Result(r.tableName, r.colName, d, r.type)); } public void updateDate(String colName, java.sql.Date d) throws SQLException { updateDate(findColumn(colName), d); } public void updateDouble(int colIndex, double d) throws SQLException { // current row ArrayList row = getTrueRow(); // test for type and colname validity boolean valid = false; Result r = (Result) row.get(colIndex - 1); if (r.type == java.sql.Types.DOUBLE) valid = true; // add to the ArrayList of updates for this row if (!valid) throw new SQLException("Update Error: Check column name and argument type"); else if (onInsertRow) row.set((colIndex - 1), new Result(r.tableName, r.colName, new Double(d), r.type)); else updatedResults.add(new Result(r.tableName, r.colName, new Double(d), r.type)); } public void updateDouble(String colName, double d) throws SQLException { updateDouble(findColumn(colName), d); } public void updateFloat(int colIndex, float f) throws SQLException { // current row ArrayList row = getTrueRow(); // test for type and colname validity boolean valid = false; Result r = (Result) row.get(colIndex - 1); if (r.type == java.sql.Types.FLOAT) valid = true; // add to the ArrayList of updates for this row if (!valid) throw new SQLException("Update Error: Check column name and argument type"); else if (onInsertRow) row.set((colIndex - 1), new Result(r.tableName, r.colName, new Float(f), r.type)); else updatedResults.add(new Result(r.tableName, r.colName, new Float(f), r.type)); } public void updateFloat(String colName, float f) throws SQLException { updateFloat(findColumn(colName), f); } public void updateInt(int colIndex, int i) throws SQLException { // current row ArrayList row = getTrueRow(); // test for type and colname validity boolean valid = false; Result r = (Result) row.get(colIndex - 1); if (r.type == java.sql.Types.INTEGER) valid = true; if (!valid) throw new SQLException("UpdateInt Error: Check column name and argument type"); else if (onInsertRow) row.set((colIndex - 1), new Result(r.tableName, r.colName, new Integer(i), r.type)); else updatedResults.add(new Result(r.tableName, r.colName, new Integer(i), r.type)); } public void updateInt(String colName, int i) throws SQLException { updateInt(findColumn(colName), i); } public void updateLong(int colIndex, long l) throws SQLException { // current row ArrayList row = getTrueRow(); // test for type and colname validity boolean valid = false; Result r = (Result) row.get(colIndex - 1); if (r.type == java.sql.Types.BIGINT || r.type == java.sql.Types.INTEGER || r.type == java.sql.Types.SMALLINT || r.type == java.sql.Types.REAL || r.type == java.sql.Types.FLOAT || r.type == java.sql.Types.DOUBLE || r.type == java.sql.Types.DECIMAL || r.type == java.sql.Types.NUMERIC) valid = true; // add to the ArrayList of updates for this row if (!valid) throw new SQLException("Update Error: Check column name and argument type"); else if (onInsertRow) row.set((colIndex - 1), new Result(r.tableName, r.colName, new Long(l), r.type)); else updatedResults.add(new Result(r.tableName, r.colName, new Long(l), r.type)); } public void updateLong(String colName, long l) throws SQLException { updateLong(findColumn(colName), l); } public void updateNull(int colIndex) throws SQLException { // current row ArrayList row = getTrueRow(); // current column Result r = (Result) row.get(colIndex - 1); // add to the ArrayList of updates for this row if (onInsertRow) row.set((colIndex - 1), new Result(r.tableName, r.colName, null, r.type)); else updatedResults.add(new Result(r.tableName, r.colName, null, r.type)); } public void updateNull(String colName) throws SQLException { updateNull(findColumn(colName)); } public void updateObject(int colIndex, Object o) throws SQLException { // current row ArrayList row = getTrueRow(); Result r = (Result) row.get(colIndex - 1); // add to the ArrayList of updates for this row if (onInsertRow) row.set((colIndex - 1), new Result(r.tableName, r.colName, o, r.type)); else updatedResults.add(new Result(r.tableName, r.colName, o, r.type)); } public void updateObject(int colIndex, Object o, int scale) throws SQLException { updateObject(colIndex, o); } public void updateObject(String colName, Object o) throws SQLException { updateObject(findColumn(colName), o); } public void updateObject(String colName, Object o, int scale) throws SQLException { updateObject(findColumn(colName), o); } /** * Update the row with the new Result objects in updatedResults. * Also update the database and the SQLCache. */ public void updateRow() throws SQLException { // update the database ArrayList row = (ArrayList) rowlist.get(pos - 1); for (int i = 0; i < updatedResults.size(); i++) { // get the new Result and the corresponding old Result to be replaced com.codestudio.sql.Result newResult = (com.codestudio.sql.Result) updatedResults.get(i); com.codestudio.sql.Result oldResult = null; for (int n = 0; n < row.size(); n++) { com.codestudio.sql.Result r = (com.codestudio.sql.Result) row.get(n); if (r.colName.equalsIgnoreCase(newResult.colName)) oldResult = r; } String SQL; if (newResult.colValue instanceof java.lang.String) { SQL = "UPDATE " + newResult.tableName + " SET " + newResult.colName + " = '" + newResult.colValue.toString() + "' " + "WHERE " + oldResult.colName + " = '" + oldResult.colValue.toString() + "'"; } else if (newResult.type == java.sql.Types.NULL) { SQL = "UPDATE " + newResult.tableName + " SET " + newResult.colName + " = null " + " WHERE " + oldResult.colName + " = " + oldResult.colValue.toString(); } else { SQL = "UPDATE " + newResult.tableName + " SET " + newResult.colName + " = " + newResult.colValue.toString() + " WHERE " + oldResult.colName + " = " + oldResult.colValue.toString(); } com.codestudio.sql.PoolManStatement smarts = (com.codestudio.sql.PoolManStatement) statement; Connection con = smarts.getConnection(); Statement stm = con.createStatement(); stm.execute(SQL); } // update this ResultSet updatedIndexes.add(new Integer(pos)); invokeRowRefresh(); // update the SQLCache if there is one (no effect if cache is disabled) PoolManStatement sst = (PoolManStatement) this.statement; JDBCPool pool = (JDBCPool) sst.getPool(); pool.refreshCache(); } public void updateShort(int colIndex, short s) throws SQLException { // current row ArrayList row = getTrueRow(); // test for type and colname validity boolean valid = false; Result r = (Result) row.get(colIndex - 1); if (r.type == java.sql.Types.SMALLINT || r.type == java.sql.Types.TINYINT || r.type == java.sql.Types.INTEGER) valid = true; // add to the ArrayList of updates for this row if (!valid) throw new SQLException("Update Error: Check column name and argument type"); else if (onInsertRow) row.set((colIndex - 1), new Result(r.tableName, r.colName, new Short(s), r.type)); else updatedResults.add(new Result(r.tableName, r.colName, new Short(s), r.type)); } public void updateShort(String colName, short s) throws SQLException { updateShort(findColumn(colName), s); } public void updateString(int colIndex, String s) throws SQLException { boolean valid = false; // current row ArrayList row = getTrueRow(); // test for type and colname validity Result r = (Result) row.get(colIndex - 1); if ((r.type == java.sql.Types.CHAR) || (r.type == java.sql.Types.VARCHAR) || (r.type == java.sql.Types.LONGVARCHAR)) valid = true; // add to the ArrayList of updates for this row if (!valid) throw new SQLException("Update Error: Check column name and argument type"); else if (onInsertRow) row.set((colIndex - 1), new Result(r.tableName, r.colName, s, r.type)); else updatedResults.add(new Result(r.tableName, r.colName, s, r.type)); } public void updateString(String colName, String s) throws SQLException { updateString(findColumn(colName), s); } public void updateTime(int colIndex, Time t) throws SQLException { boolean valid = false; // current row ArrayList row = getTrueRow(); // test for type and colname validity Result r = (Result) row.get(colIndex - 1); if (r.type == java.sql.Types.TIME) valid = true; // add to the ArrayList of updates for this row if (!valid) throw new SQLException("Update Error: Check column name and argument type"); else if (onInsertRow) row.set((colIndex - 1), new Result(r.tableName, r.colName, t, r.type)); else updatedResults.add(new Result(r.tableName, r.colName, t, r.type)); } public void updateTime(String colName, Time t) throws SQLException { updateTime(findColumn(colName), t); } public void updateTimestamp(int colIndex, Timestamp t) throws SQLException { boolean valid = false; // current row ArrayList row = getTrueRow(); // test for type and colname validity Result r = (Result) row.get(colIndex - 1); if (r.type == java.sql.Types.TIMESTAMP) valid = true; // add to the ArrayList of updates for this row if (!valid) throw new SQLException("Update Error: Check column name and argument type"); else if (onInsertRow) row.set((colIndex - 1), new Result(r.tableName, r.colName, t, r.type)); else updatedResults.add(new Result(r.tableName, r.colName, t, r.type)); } public void updateTimestamp(String colName, Timestamp t) throws SQLException { updateTimestamp(findColumn(colName), t); } public boolean wasNull() throws SQLException { if (getObject(lastColIndex) == null) return true; return false; } private void clearUpdates() { this.updatedResults.clear(); if (this.insertRow != null) this.insertRow.clear(); } private void composeInsertRow() { try { ResultSetMetaData meta = PoolManResultSetMetaData.getCopy(getMetaData()); //## MC this.insertRow = new ArrayList(); for (int n = 1; n <= meta.getColumnCount(); n++) { String tableName = null; try { tableName = meta.getTableName(n); if (tableName.trim().length() < 1) tableName = null; } catch (Exception te) { tableName = null; } if (tableName == null) { PoolManStatement ps = (PoolManStatement) this.statement; tableName = ps.fabricateTableName(ps.getSQL(), n); } insertRow.add((n - 1), new Result(tableName, meta.getColumnName(n), null, meta.getColumnType(n))); } } catch (SQLException se) { this.insertRow = null; } } private void assertNotInserting() throws SQLException { if (onInsertRow) throw new SQLException("Operation not permitted while cursor is on the insert row"); } private ArrayList getTrueRow() { if (onInsertRow) return insertRow; else return (ArrayList) rowlist.get(pos - 1); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?