poolmanresultset.java
来自「Java Database connection pool」· Java 代码 · 共 1,658 行 · 第 1/4 页
JAVA
1,658 行
java.sql.Timestamp t = (java.sql.Timestamp) getObject(colName); DateFormat df = DateFormat.getInstance(); df.setCalendar(cal); java.util.Date newDate = df.parse(t.toString()); return new java.sql.Timestamp(newDate.getTime()); } catch (NullPointerException ne) { } catch (java.text.ParseException pe) { pe.printStackTrace(); } return null; } public int getType() throws SQLException { return this.scrollableType; } /** @deprecated */ public InputStream getUnicodeStream(int colIndex) throws SQLException { try { return (InputStream) getObject(colIndex); } catch (NullPointerException ne) { } return null; } /** @deprecated */ public InputStream getUnicodeStream(String colName) throws SQLException { try { return (InputStream) getObject(colName); } catch (NullPointerException ne) { } return null; } public SQLWarning getWarnings() throws SQLException { return null; } public void insertRow() throws SQLException { // insert new data into the database com.codestudio.sql.Result result = (com.codestudio.sql.Result) insertRow.get(0); StringBuffer SQL = new StringBuffer("INSERT INTO "); SQL.append(result.tableName); SQL.append(" VALUES("); for (int i = 0; i < insertRow.size(); i++) { com.codestudio.sql.Result newResult = (com.codestudio.sql.Result) insertRow.get(i); if (newResult.colValue instanceof java.lang.String) { SQL.append("'"); SQL.append(newResult.colValue.toString()); SQL.append("'"); } else if (newResult.type == java.sql.Types.NULL) { SQL.append("null"); } else { SQL.append(newResult.colValue.toString()); } // if we are not on the alst elment, then add a comma to the statement if (i != (insertRow.size() - 1)) SQL.append(","); } SQL.append(")"); com.codestudio.sql.PoolManStatement smarts = (com.codestudio.sql.PoolManStatement) statement; Connection con = smarts.getConnection(); Statement stm = con.createStatement(); stm.execute(SQL.toString()); // update this ResultSet rowlist.add(new ArrayList(insertRow)); this.insertedIndexes.add(new Integer(pos)); // clear row moveToCurrentRow(); composeInsertRow(); // 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 boolean isAfterLast() throws SQLException { // this method cannot be called if currently on the insert row assertNotInserting(); if (this.scrollableType == TYPE_FORWARD_ONLY) throw new SQLException("Invalid method call for this ResultSet type TYPE_FORWARD_ONLY"); if (pos > rowlist.size()) return true; return false; } public boolean isBeforeFirst() throws SQLException { // this method cannot be called if currently on the insert row assertNotInserting(); if (this.scrollableType == TYPE_FORWARD_ONLY) throw new SQLException("Invalid method call for ResultSet type TYPE_FORWARD_ONLY"); if (pos == 0) return true; return false; } public boolean isFirst() throws SQLException { // this method cannot be called if currently on the insert row assertNotInserting(); if (this.scrollableType == TYPE_FORWARD_ONLY) throw new SQLException("Invalid method call for ResultSet type TYPE_FORWARD_ONLY"); if (pos == 1) return true; return false; } public boolean isLast() throws SQLException { // this method cannot be called if currently on the insert row assertNotInserting(); if (this.scrollableType == TYPE_FORWARD_ONLY) throw new SQLException("Invalid method call for ResultSet type TYPE_FORWARD_ONLY"); if (pos == rowlist.size()) return true; return false; } public boolean last() throws SQLException { if (this.scrollableType == TYPE_FORWARD_ONLY) throw new SQLException("Invalid method call for ResultSet type TYPE_FORWARD_ONLY"); clearUpdates(); this.pos = rowlist.size(); return true; } /** * If currently on the insert row, this method will move the cursor back * to an active row -- either the row the cursor was on before moving to the * insert row or the row that the cursor was moved to while handling the * insert row. If not on the insert row, this method has no effect. */ public void moveToCurrentRow() throws SQLException { if (this.concurType == CONCUR_READ_ONLY) throw new SQLException("ResultSet not updatable"); onInsertRow = false; } /** * After invoking this method, all updates and gets will be invoked * on the insert row rather than the current row. The current row will * be remembered, however, and can be recovered by invoking <code> * moveToCurrentRow()</code>. */ public void moveToInsertRow() throws SQLException { if (this.concurType == CONCUR_READ_ONLY) throw new SQLException("ResultSet not updatable"); if (insertRow == null) throw new SQLException("Unable to create insert row, incomplete metadata from driver"); onInsertRow = true; } public boolean next() throws SQLException { this.pos++; clearUpdates(); if (pos > rowlist.size()) return false; return true; } public boolean previous() throws SQLException { if (this.scrollableType == TYPE_FORWARD_ONLY) throw new SQLException("Operation not permitted when ResultSet is TYPE_FORWARD_ONLY"); this.pos--; clearUpdates(); if (pos < 1) { beforeFirst(); return false; } return true; } public void refreshRow() throws SQLException { // this method cannot be called if currently on the insert row assertNotInserting(); if (this.scrollableType == TYPE_FORWARD_ONLY) throw new SQLException("Operation not permitted when ResultSet is TYPE_FORWARD_ONLY"); if (this.scrollableType == TYPE_SCROLL_INSENSITIVE) return; invokeRowRefresh(); } private void invokeRowRefresh() throws SQLException { clearUpdates(); // get the results again from the database by re-executing the statement // and replacing the ArrayList row at rowlist(pos-1). ResultSet res = null; Statement s = null; try { PoolManStatement smarts = (PoolManStatement) this.statement; Connection con = smarts.getConnection(); s = ((PoolManStatement) con.createStatement()).getNativeStatement(); res = s.executeQuery(smarts.getSQL()); ResultSetMetaData rmeta = PoolManResultSetMetaData.getCopy(res.getMetaData()); //## MC int curpos = 0; int cols = rmeta.getColumnCount(); while (res.next()) { curpos++; if (curpos == pos) { ArrayList row = new ArrayList(1); for (int i = 1; i < cols; i++) { String tableName = null; try { tableName = rmeta.getTableName(i); if (tableName.trim().length() < 1) tableName = null; } catch (Exception te) { tableName = null; } if (null == tableName) tableName = smarts.fabricateTableName(smarts.getSQL(), i); Result result = new Result(tableName, rmeta.getColumnLabel(i), res.getObject(i), rmeta.getColumnType(i)); row.add(result); } rowlist.set(pos - 1, row); } } } catch (SQLException e) { throw e; } finally { if (null != res) try { JDBCPool.closeResources(s, res); } catch (Exception ee) { } } } public boolean relative(int rows) throws SQLException { if (this.scrollableType == TYPE_FORWARD_ONLY) throw new SQLException("Operation Not permitted when ResultSet is TYPE_FORWARD_ONLY"); if ((pos == 0) || (pos > rowlist.size())) throw new SQLException("Operation not permitted when cursor is not on a valid row: " + " Cursor was either before the first or after the last row"); clearUpdates(); this.pos = pos + rows; if (pos < 1) { beforeFirst(); return false; } if (pos > rowlist.size()) { afterLast(); return false; } return true; } public boolean rowDeleted() throws SQLException { // this method cannot be called if currently on the insert row assertNotInserting(); if (this.concurType == CONCUR_READ_ONLY) { throw new SQLException("Illegal Operation when ResultSet is CONCUR_READ_ONLY"); } if (null == rowlist.get(pos - 1)) return true; return false; } public boolean rowInserted() throws SQLException { // this method cannot be called if currently on the insert row assertNotInserting(); if (this.concurType == CONCUR_READ_ONLY) { throw new SQLException("Illegal Operation when ResultSet is CONCUR_READ_ONLY"); } for (int n = 0; n < insertedIndexes.size(); n++) { Integer i = (Integer) insertedIndexes.get(n); if (i.intValue() == pos) return true; } return false; } public boolean rowUpdated() throws SQLException { // this method cannot be called if currently on the insert row assertNotInserting(); if (this.concurType == CONCUR_READ_ONLY) { throw new SQLException("Illegal Operation when ResultSet is CONCUR_READ_ONLY"); } for (int n = 0; n < updatedIndexes.size(); n++) { Integer i = (Integer) updatedIndexes.get(n); if (i.intValue() == pos) return true; } return false; } public void setFetchDirection(int direction) throws SQLException { if (this.scrollableType == TYPE_FORWARD_ONLY) throw new SQLException("Operation Not permitted when ResultSet is TYPE_FORWARD_ONLY"); this.fetchDirection = direction; } public void setFetchSize(int rows) throws SQLException { this.fetchSize = rows; } public void updateAsciiStream(int colIndex, InputStream x, 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 updateAsciiStream(String colName, InputStream x, 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 updateBigDecimal(int colIndex, BigDecimal x) 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.NUMERIC) || (r.type == java.sql.Types.DECIMAL)) 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.add((colIndex - 1), new Result(r.tableName, r.colName, x, r.type)); else updatedResults.add(new Result(r.tableName, r.colName, x, r.type)); } public void updateBigDecimal(String colName, BigDecimal x) throws SQLException { updateBigDecimal(findColumn(colName), x); } public void updateBinaryStream(int colIndex, InputStream x, 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 updateBinaryStream(String colName, InputStream x, 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 updateBoolean(int colIndex, boolean x) 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.BIT) 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 Boolean(x), r.type)); else updatedResults.add(new Result(r.tableName, r.colName, new Boolean(x), r.type)); } public void updateBoolean(String colName, boolean x) throws SQLException { updateBoolean(findColumn(colName), x); } public void updateByte(int colIndex, byte x) throws SQLException { // current row
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?