📄 embedstatement.java
字号:
throw newSQLException(SQLState.INVALID_ST_FETCH_SIZE, new Integer(rows)); }else if ( rows > 0 ) // ignore the call if the value is zero fetchSize = rows; } /** * JDBC 2.0 * * Determine the default fetch size. * @exception SQLException if a database-access error occurs * */ public int getFetchSize() throws SQLException { checkStatus(); return fetchSize; } /** * JDBC 2.0 * * Determine the result set concurrency. * * @exception SQLException Feature not implemented for now. */ public int getResultSetConcurrency() throws SQLException { checkStatus(); return resultSetConcurrency; } /** * JDBC 3.0 * * Retrieves the result set holdability for ResultSet objects * generated by this Statement object. * * @return either ResultSet.HOLD_CURSORS_OVER_COMMIT or * ResultSet.CLOSE_CURSORS_AT_COMMIT * @exception SQLException Feature not implemented for now. */ public final int getResultSetHoldability() throws SQLException { checkStatus(); return resultSetHoldability; } /** * JDBC 2.0 * * Adds a SQL command to the current batch of commmands for the statement. * This method is optional. * * @param sql typically this is a static SQL INSERT or UPDATE statement * @exception SQLException if a database-access error occurs, or the * driver does not support batch statements */ public void addBatch( String sql ) throws SQLException { checkStatus(); synchronized (getConnectionSynchronization()) { if (batchStatements == null) batchStatements = new Vector(); batchStatements.addElement(sql); } } /** * JDBC 2.0 * * Make the set of commands in the current batch empty. * This method is optional. * * @exception SQLException if a database-access error occurs, or the * driver does not support batch statements */ public final void clearBatch() throws SQLException { checkStatus(); synchronized (getConnectionSynchronization()) { batchStatements = null; } } /** * JDBC 2.0 * * Submit a batch of commands to the database for execution. * This method is optional. * * Moving jdbc2.0 batch related code in this class because * callableStatement in jdbc 20 needs this code too and it doesn't derive * from prepared statement in jdbc 20 in our implementation. * BatchUpdateException is the only new class from jdbc 20 which is being * referenced here and in order to avoid any jdk11x problems, using * reflection code to make an instance of that class. * * @return an array of update counts containing one element for each * command in the batch. The array is ordered according * to the order in which commands were inserted into the batch * @exception SQLException if a database-access error occurs, or the * driver does not support batch statements */ public int[] executeBatch() throws SQLException { checkExecStatus(); synchronized (getConnectionSynchronization()) { setupContextStack(); int i = 0; // As per the jdbc 2.0 specs, close the statement object's current resultset // if one is open. // Are there results? // outside of the lower try/finally since results will // setup and restore themselves. clearResultSets(); Vector stmts = batchStatements; batchStatements = null; int size; if (stmts == null) size = 0; else size = stmts.size(); int[] returnUpdateCountForBatch = new int[size]; SQLException sqle; try { for (; i< size; i++) { if (executeBatchElement(stmts.elementAt(i))) throw newSQLException(SQLState.RESULTSET_RETURN_NOT_ALLOWED); returnUpdateCountForBatch[i] = getUpdateCount(); } return returnUpdateCountForBatch; } catch (StandardException se) { sqle = handleException(se); } catch (SQLException sqle2) { sqle = sqle2; } finally { restoreContextStack(); } int successfulUpdateCount[] = new int[i]; for (int j=0; j<i; j++) { successfulUpdateCount[j] = returnUpdateCountForBatch[j]; } SQLException batch = new java.sql.BatchUpdateException(sqle.getMessage(), sqle.getSQLState(), sqle.getErrorCode(), successfulUpdateCount); batch.setNextException(sqle); throw batch; } } /** Execute a single element of the batch. Overridden by EmbedPreparedStatement */ boolean executeBatchElement(Object batchElement) throws SQLException, StandardException { return execute((String)batchElement, false, true, JDBC30Translation.NO_GENERATED_KEYS, null, null); } /** * JDBC 2.0 * * Return the Connection that produced the Statement. * * @exception SQLException Exception if it cannot find the connection * associated to this statement. */ public final java.sql.Connection getConnection() throws SQLException { checkStatus(); java.sql.Connection appConn = getEmbedConnection().getApplicationConnection(); if ((appConn != applicationConnection) || (appConn == null)) throw Util.noCurrentConnection(); return appConn; } /** * JDBC 3.0 * * Moves to this Statement obect's next result, deals with any current ResultSet * object(s) according to the instructions specified by the given flag, and * returns true if the next result is a ResultSet object * * @param current - one of the following Statement constants indicating what * should happen to current ResultSet objects obtained using the method * getResultSetCLOSE_CURRENT_RESULT, KEEP_CURRENT_RESULT, or CLOSE_ALL_RESULTS * @return true if the next result is a ResultSet; false if it is * an update count or there are no more results * @see #execute * @exception SQLException thrown on failure. */ public final boolean getMoreResults(int current) throws SQLException { checkExecStatus(); synchronized (getConnectionSynchronization()) { if (dynamicResults == null) { // we only have the one resultset, so this is // simply a close for us. clearResultSets(); return false; } int startingClose; switch (current) { default: case JDBC30Translation.CLOSE_ALL_RESULTS: startingClose = 0; break; case JDBC30Translation.CLOSE_CURRENT_RESULT: // just close the current result set. startingClose = currentDynamicResultSet; break; case JDBC30Translation.KEEP_CURRENT_RESULT: // make the close loop a no-op. startingClose = dynamicResults.length; break; } // Close loop. SQLException se = null; for (int i = startingClose; i <= currentDynamicResultSet && i < dynamicResults.length; i++) { EmbedResultSet lrs = dynamicResults[i]; if (lrs == null) continue; try { if (!lrs.isClosed) lrs.close(); } catch (SQLException sqle) { if (se == null) se = sqle; else se.setNextException(sqle); } finally { dynamicResults[i] = null; } } if (se != null) { // leave positioned on the current result set (?) throw se; } updateCount = -1; while (++currentDynamicResultSet < dynamicResults.length) { EmbedResultSet lrs = dynamicResults[currentDynamicResultSet]; if (lrs != null) { if (lrs.isClosed) { dynamicResults[currentDynamicResultSet] = null; continue; } results = lrs; return true; } } results = null; return false; } } /** * JDBC 3.0 * * Retrieves any auto-generated keys created as a result of executing this * Statement object. If this Statement is a non-insert statement, * a null ResultSet object is returned. * * @return a ResultSet object containing the auto-generated key(s) generated by * the execution of this Statement object * @exception SQLException if a database access error occurs */ public final java.sql.ResultSet getGeneratedKeys() throws SQLException { if (autoGeneratedKeysResultSet == null) return null; else { execute("VALUES IDENTITY_VAL_LOCAL()", true, false, JDBC30Translation.NO_GENERATED_KEYS, null, null); return results; } } ///////////////////////////////////////////////////////////////////////// // // Implementation specific methods // ///////////////////////////////////////////////////////////////////////// /** Execute the current statement. @exception SQLException thrown on failure. */ boolean executeStatement(Activation a, boolean executeQuery, boolean executeUpdate) throws SQLException { // we don't differentiate the update from the resultset case. // so, there could be a result set. // note: the statement interface will paste together // an activation and make sure the prepared statement // is still valid, so it is preferrable, for now, // to creating our own activation and stuffing it in // the prepared statement. synchronized (getConnectionSynchronization()) { setupContextStack(); // make sure there's context boolean retval; pvs = a.getParameterValueSet(); try { // The following is from the javadoc for java.sql.Statement // Only one ResultSet per Statement can be open at any point in time. // Therefore, if the reading of one ResultSet is interleaved with the // reading of another, each must have been generated by different Statements. // All statement execute methods implicitly close a // statment's current ResultSet if an open one exists. if (results != null) { results.close(); results = null; } clearWarnings(); if (! forMetaData) { commitIfNeeded(); // commit the last statement if needed needCommit(); } else { if (lcc.getActivationCount() > 1) { // we do not want to commit here as there seems to be other // statements/resultSets currently opened for this connection. } else { commitIfNeeded(); // we can legitimately commit needCommit(); } } // if this was a prepared statement, this just // gets it for us, it won't recompile unless it is invalid. PreparedStatement ps = a.getPreparedStatement(); ps.rePrepare(lcc); addWarning(ps.getCompileTimeWarnings()); /* ** WARNING WARNING ** ** Any state set in the activation before execution *must* be copied ** to the new activation in GenericActivationHolder.execute() when ** the statement has been recompiled. State such as ** singleExecution, cursorName, holdability, maxRows. */ if (cursorName != null) { a.setCursorName(cursorName); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -