📄 updatableresultset.java
字号:
int index = ((Integer) this.primaryKeyIndicies.get(0)).intValue(); if (!this.doingUpdates && !this.onInsertRow) { dataFrom = (byte[]) rowToRefresh.getColumnValue(index); } else { dataFrom = updateInsertStmt.getBytesRepresentation(index); // Primary keys not set? if (updateInsertStmt.isNull(index) || (dataFrom.length == 0)) { dataFrom = (byte[]) rowToRefresh.getColumnValue(index); } else { dataFrom = stripBinaryPrefix(dataFrom); } } this.refresher.setBytesNoEscape(1, dataFrom); } else { for (int i = 0; i < numKeys; i++) { byte[] dataFrom = null; int index = ((Integer) this.primaryKeyIndicies.get(i)) .intValue(); if (!this.doingUpdates && !this.onInsertRow) { dataFrom = (byte[]) rowToRefresh.getColumnValue(index); } else { dataFrom = updateInsertStmt.getBytesRepresentation(index); // Primary keys not set? if (updateInsertStmt.isNull(index) || (dataFrom.length == 0)) { dataFrom = (byte[]) rowToRefresh.getColumnValue(index); } else { dataFrom = stripBinaryPrefix(dataFrom); } } this.refresher.setBytesNoEscape(i + 1, dataFrom); } } java.sql.ResultSet rs = null; try { rs = this.refresher.executeQuery(); int numCols = rs.getMetaData().getColumnCount(); if (rs.next()) { for (int i = 0; i < numCols; i++) { byte[] val = rs.getBytes(i + 1); if ((val == null) || rs.wasNull()) { rowToRefresh.setColumnValue(i, null); } else { rowToRefresh.setColumnValue(i, rs.getBytes(i + 1)); } } } else { throw SQLError.createSQLException(Messages .getString("UpdatableResultSet.12"), //$NON-NLS-1$ SQLError.SQL_STATE_GENERAL_ERROR); //$NON-NLS-1$ } } finally { if (rs != null) { try { rs.close(); } catch (SQLException ex) { ; // ignore } } } } /** * JDBC 2.0 * * <p> * Moves a relative number of rows, either positive or negative. Attempting * to move beyond the first/last row in the result set positions the cursor * before/after the the first/last row. Calling relative(0) is valid, but * does not change the cursor position. * </p> * * <p> * Note: Calling relative(1) is different than calling next() since is makes * sense to call next() when there is no current row, for example, when the * cursor is positioned before the first row or after the last row of the * result set. * </p> * * @param rows * DOCUMENT ME! * * @return true if on a row, false otherwise. * * @exception SQLException * if a database-access error occurs, or there is no current * row, or result set type is TYPE_FORWARD_ONLY. */ public synchronized boolean relative(int rows) throws SQLException { return super.relative(rows); } private void resetInserter() throws SQLException { this.inserter.clearParameters(); for (int i = 0; i < this.fields.length; i++) { this.inserter.setNull(i + 1, 0); } } /** * JDBC 2.0 Determine if this row has been deleted. A deleted row may leave * a visible "hole" in a result set. This method can be used to detect holes * in a result set. The value returned depends on whether or not the result * set can detect deletions. * * @return true if deleted and deletes are detected * * @exception SQLException * if a database-access error occurs * @throws NotImplemented * DOCUMENT ME! * * @see DatabaseMetaData#deletesAreDetected */ public synchronized boolean rowDeleted() throws SQLException { throw SQLError.notImplemented(); } /** * JDBC 2.0 Determine if the current row has been inserted. The value * returned depends on whether or not the result set can detect visible * inserts. * * @return true if inserted and inserts are detected * * @exception SQLException * if a database-access error occurs * @throws NotImplemented * DOCUMENT ME! * * @see DatabaseMetaData#insertsAreDetected */ public synchronized boolean rowInserted() throws SQLException { throw SQLError.notImplemented(); } /** * JDBC 2.0 Determine if the current row has been updated. The value * returned depends on whether or not the result set can detect updates. * * @return true if the row has been visibly updated by the owner or another, * and updates are detected * * @exception SQLException * if a database-access error occurs * @throws NotImplemented * DOCUMENT ME! * * @see DatabaseMetaData#updatesAreDetected */ public synchronized boolean rowUpdated() throws SQLException { throw SQLError.notImplemented(); } /** * Sets the concurrency type of this result set * * @param concurrencyFlag * the type of concurrency that this ResultSet should support. */ protected void setResultSetConcurrency(int concurrencyFlag) { super.setResultSetConcurrency(concurrencyFlag); // // FIXME: Issue warning when asked for updateable result set, but result // set is not // updatable // // if ((concurrencyFlag == CONCUR_UPDATABLE) && !isUpdatable()) { // java.sql.SQLWarning warning = new java.sql.SQLWarning( // NotUpdatable.NOT_UPDATEABLE_MESSAGE); // } } private byte[] stripBinaryPrefix(byte[] dataFrom) { return StringUtils.stripEnclosure(dataFrom, "_binary'", "'"); } /** * Reset UPDATE prepared statement to value in current row. This_Row MUST * point to current, valid row. * * @throws SQLException * DOCUMENT ME! */ protected synchronized void syncUpdate() throws SQLException { if (this.updater == null) { if (this.updateSQL == null) { generateStatements(); } this.updater = (PreparedStatement) this.connection .clientPrepareStatement(this.updateSQL); } int numFields = this.fields.length; this.updater.clearParameters(); for (int i = 0; i < numFields; i++) { if (this.thisRow.getColumnValue(i) != null) { this.updater.setBytes(i + 1, (byte[]) this.thisRow.getColumnValue(i), this.fields[i].isBinary(), false); } else { this.updater.setNull(i + 1, 0); } } int numKeys = this.primaryKeyIndicies.size(); if (numKeys == 1) { int index = ((Integer) this.primaryKeyIndicies.get(0)).intValue(); byte[] keyData = (byte[]) this.thisRow.getColumnValue(index); this.updater.setBytes(numFields + 1, keyData, false, false); } else { for (int i = 0; i < numKeys; i++) { byte[] currentVal = (byte[]) this.thisRow.getColumnValue(((Integer) this.primaryKeyIndicies .get(i)).intValue()); if (currentVal != null) { this.updater.setBytes(numFields + i + 1, currentVal, false, false); } else { this.updater.setNull(numFields + i + 1, 0); } } } } /** * JDBC 2.0 Update a column with an ascii stream value. The updateXXX() * methods are used to update column values in the current row, or the * insert row. The updateXXX() methods do not update the underlying * database, instead the updateRow() or insertRow() methods are called to * update the database. * * @param columnIndex * the first column is 1, the second is 2, ... * @param x * the new column value * @param length * the length of the stream * * @exception SQLException * if a database-access error occurs */ public synchronized void updateAsciiStream(int columnIndex, java.io.InputStream x, int length) throws SQLException { if (!this.onInsertRow) { if (!this.doingUpdates) { this.doingUpdates = true; syncUpdate(); } this.updater.setAsciiStream(columnIndex, x, length); } else { this.inserter.setAsciiStream(columnIndex, x, length); this.thisRow.setColumnValue(columnIndex - 1, STREAM_DATA_MARKER); } } /** * JDBC 2.0 Update a column with an ascii stream value. The updateXXX() * methods are used to update column values in the current row, or the * insert row. The updateXXX() methods do not update the underlying * database, instead the updateRow() or insertRow() methods are called to * update the database. * * @param columnName * the name of the column * @param x * the new column value * @param length * of the stream * * @exception SQLException * if a database-access error occurs */ public synchronized void updateAsciiStream(String columnName, java.io.InputStream x, int length) throws SQLException { updateAsciiStream(findColumn(columnName), x, length); } /** * JDBC 2.0 Update a column with a BigDecimal value. The updateXXX() methods * are used to update column values in the current row, or the insert row. * The updateXXX() methods do not update the underlying database, instead * the updateRow() or insertRow() methods are called to update the database. * * @param columnIndex * the first column is 1, the second is 2, ... * @param x * the new column value * * @exception SQLException * if a database-access error occurs */ public synchronized void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { if (!this.onInsertRow) { if (!this.doingUpdates) { this.doingUpdates = true; syncUpdate(); } this.updater.setBigDecimal(columnIndex, x); } else { this.inserter.setBigDecimal(columnIndex, x); if (x == null) { this.thisRow.setColumnValue(columnIndex - 1, null); } else { this.thisRow.setColumnValue(columnIndex - 1, x.toString().getBytes()); } } } /** * JDBC 2.0 Update a column with a BigDecimal value. The updateXXX() methods * are used to update column values in the current row, or the insert row. * The updateXXX() methods do not update the underlying database, instead * the updateRow() or insertRow() methods are called to update the database. * * @param columnName * the name of the column * @param x * the new column value * * @exception SQLException * if a database-access error occurs */ public synchronized void updateBigDecimal(String columnName, BigDecimal x) throws SQLException { updateBigDecimal(findColumn(columnName), x); } /** * JDBC 2.0 Update a column with a binary stream value. The updateXXX() * methods are used to update column values in the current row, or the * insert row. The updateXXX() methods do not update the underlying * database, instead the updateRow() or insertRow() methods are called to * update the database. * * @param columnIndex * the first column is 1, the second is 2, ... * @param x * the new column value * @param length * the length of the stream * * @exception SQLException * if a database-access error occurs */ public synchronized void updateBinaryStream(int columnIndex, java.io.InputStream x, int length) throws SQLException { if (!this.onInsertRow) { if (!this.doingUpdates) { this.doingUpdates = true; syncUpdate(); } this.updater.setBinaryStream(columnIndex, x, length); } else { this.inserter.setBinaryStream(columnIndex, x, length); if (x == null) { this.thisRow.setColumnValue(columnIndex - 1, null); } else { this.thisRow.setColumnValue(columnIndex - 1, STREAM_DATA_MARKER); } } } /** * JDBC 2.0 Update a column with a binary stream value. The updateXXX() * methods are used to update column values in the current row, or the * insert row. The updateXXX() methods do not update the underlying * database, instead the updateRow() or insertRow() methods are called to * update the database. * * @param columnName * the name of the column * @param x * the new column value * @param length * of the stream * * @exception SQLException * if a database-access error occurs */ public synchronized void updateBinaryStream(String columnName, java.io.InputStream x, int length) throws SQLException { updateBinaryStream(findColumn(columnName), x, length); } /** * @see ResultSetInternalMethods#updateBlob(int, Blob) */ public synchronized void updateBlob(int columnIndex, java.sql.Blob blob) throws SQLException { if (!this.onInsertRow) { if (!this.doingUpdates) { this.doingUpdates = true; syncUpdate(); } this.updater.setBlob(columnIndex, blob); } else { this.inserter.setBlob(columnIndex, blob); if (blob == null) { this.thisRow.setColumnValue(columnIndex - 1, null); } else { this.thisRow.setColumnValue(columnIndex - 1, STREAM_DATA_MARKER); } } } /** * @see ResultSetInternalMethods#updateBlob(String, Blob) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -