/** * INTERNAL: * Build and return an appropriate Accessor. * The default is a DatabaseAccessor. */ public Accessor buildAccessor() { return new DatabaseAccessor(); }
/** * Disconnect from the datasource. * Added for bug 3046465 to ensure the statement cache is cleared. */ @Override public void disconnect(AbstractSession session) throws DatabaseException { clearStatementCache(session); super.disconnect(session); }
/** * Execute the call. * The execution can differ slightly depending on the type of call. * The call may be parameterized where the arguments are in the translation row. * The row will be empty if there are no parameters. * @return depending of the type either the row count, row or vector of rows. */ @Override public Object basicExecuteCall(Call call, AbstractRecord translationRow, AbstractSession session) throws DatabaseException { return basicExecuteCall(call, translationRow, session, true); }
/** * Execute the EclipseLink dynamically batched/concatenated statement. */ protected void executeBatchedStatement(PreparedStatement statement, AbstractSession session) throws DatabaseException { try { executeDirectNoSelect(statement, null, session); } catch (RuntimeException exception) { try {// Ensure that the statement is closed, but still ensure that the real exception is thrown. closeStatement(statement, session, null); } catch (SQLException closeException) { } throw exception; } // This is in a separate try block to ensure that the real exception is not masked by the close exception. try { closeStatement(statement, session, null); } catch (SQLException exception) { //With an external connection pool the connection may be null after this call, if it is we will //be unable to determine if it is a connection based exception so treat it as if it wasn't. DatabaseException commException = processExceptionForCommError(session, exception, null); if (commException != null) throw commException; throw DatabaseException.sqlException(exception, this, session, false); } }
DatabaseAccessor accessor = new DatabaseAccessor(); PreparedStatement statement = accessor.getPreparedStatement("SELECT * FROM mainpage WHERE ID=0"); ResultSet resultSet = statement.executeQuery(); resultSet.next(); mainPic = request.getPart("mainPic"); resultSet.updateBlob("mainPic", mainPic.getInputStream());
Map<String, Statement> statementCache = getStatementCache(); synchronized (statementCache) { PreparedStatement preparedStatement = (PreparedStatement)statement; preparedStatement.clearParameters(); resetStatementFromCall(preparedStatement, call); if (statementCache.size() > getPlatform().getStatementCacheSize()) { closeStatement(removedStatement, session, call); } else { decrementCallCount(); closeStatement(statement, session, call); resetStatementFromCall(statement, call); setIsDynamicStatementInUse(false); decrementCallCount(); } else { closeStatement(statement, session, call);
if (batch && isInBatchWritingMode(session)) { getActiveBatchWritingMechanism(session).appendCall(session, dbCall); getActiveBatchWritingMechanism(session).executeBatchedStatements(session); incrementCallCount(session); if (session.shouldLog(SessionLog.FINE, SessionLog.SQL)) {// Avoid printing if no logging required. Connection connection = getConnection(); if (connection != null) { connectionHash = connection.hashCode(); session.log(SessionLog.FINE, SessionLog.SQL, buildLogString(dbCall, connectionHash,-1), (Object[])null, this, false); dbCall.setExecuteReturnValue(execute(dbCall, statement, session)); dbCall.setStatement(statement); this.possibleFailure = false; result = executeNoSelect(dbCall, statement, session); this.writeStatementsCount++; if (dbCall.isLOBLocatorNeeded()) { getLOBWriter().addCall(dbCall); resultSet = executeSelect(dbCall, statement, session); this.readStatementsCount++; if (!dbCall.shouldIgnoreFirstRowSetting() && dbCall.getFirstResult() != 0) { result = processResultSet(resultSet, dbCall, statement, session);
ResultSet resultSet = null; try { incrementCallCount(session); resultSet = getConnectionMetaData().getTables(catalog, schema, tableName, types); Vector fields = buildSortedFields(null, resultSet, session); ResultSetMetaData metaData = resultSet.getMetaData(); result.addElement(fetchRow(fields, resultSet, metaData, session)); DatabaseException commException = processExceptionForCommError(session, sqlException, null); if (commException != null) throw commException; decrementCallCount();
if (isInBatchWritingMode(session)) { if (dbCall.isNothingReturned() && (!dbCall.hasOptimisticLock() || getPlatform().usesNativeBatchWriting() ) && (!dbCall.shouldBuildOutputRow()) && (getPlatform().usesJDBCBatchWriting() || (!dbCall.hasParameters())) && (!dbCall.isLOBLocatorNeeded())) { getActiveBatchWritingMechanism().appendCall(session, dbCall); getActiveBatchWritingMechanism().executeBatchedStatements(session); incrementCallCount(session); if (session.shouldLog(SessionLog.FINE, SessionLog.SQL)) {// Avoid printing if no logging required. session.log(SessionLog.FINE, SessionLog.SQL, dbCall.getLogString(this), (Object[])null, this, false); result = executeNoSelect(dbCall, statement, session); if (!isInBatchWritingMode(session)) { writeStatementsCount++; getLOBWriter().addCall(dbCall); if (!isInBatchWritingMode(session)) { storedProcedureStatementsCount++; resultSet = executeSelect(dbCall, statement, session); if (!isInBatchWritingMode(session)) { readStatementsCount++; getLOBWriter().fetchLocatorAndWriteValue(dbCall, resultSet); } else { result = fetchRow(dbCall.getFields(), resultSet, metaData, session);
if (!dbCall.getReturnsResultSet()) {// no result set is expected if (dbCall.isCursorOutputProcedure()) { result = accessor.executeNoSelect(dbCall, statement, session); resultSet = (ResultSet)((CallableStatement)statement).getObject(dbCall.getCursorOutIndex()); } else { accessor.executeDirectNoSelect(statement, dbCall, session); result = accessor.buildOutputRow((CallableStatement)statement, dbCall, session); resultSet = accessor.executeSelect(dbCall, statement, session);
session.startOperationProfile(SessionProfiler.SqlPrepare, null, SessionProfiler.ALL); try { statement = this.databaseAccessor.getConnection().createStatement(); for (String sql : this.sqlStrings) { statement.addBatch(sql); RuntimeException exceptionToThrow = this.databaseAccessor.processExceptionForCommError(session, exception, null); try {// Ensure that the statement is closed, but still ensure that the real exception is thrown. this.databaseAccessor.closeStatement(statement, session, null); } catch (SQLException closeException) { } catch (RuntimeException exception) { try {// Ensure that the statement is closed, but still ensure that the real exception is thrown. this.databaseAccessor.closeStatement(statement, session, null); } catch (SQLException closeException) {
try { returnValue = this.getPlatform().executeBatch(statement, isStatementPrepared); } catch (SQLException exception) { DatabaseException commException = processExceptionForCommError(session, exception, dbCall); if (commException != null) throw commException; try {// Ensure that the statement is closed, but still ensure that the real exception is thrown. closeStatement(statement, session, dbCall); } catch (SQLException closeException) { } catch (RuntimeException exception) { try {// Ensure that the statement is closed, but still ensure that the real exception is thrown. closeStatement(statement, session, dbCall); } catch (SQLException closeException) { releaseStatement(statement, dbCall.getSQLString(), dbCall, session); } else { closeStatement(statement, session, null); DatabaseException commException = processExceptionForCommError(session, exception, dbCall); if (commException != null) throw commException; throw DatabaseException.sqlException(exception, this, session, false);
results.addElement(fetchRow(dbCall.getFields(), resultSet, metaData, session)); hasNext = resultSet.next(); RuntimeException exceptionToThrow = processExceptionForCommError(session, exception, dbCall); try {// Ensure that the statement is closed, but still ensure that the real exception is thrown. closeStatement(statement, session, dbCall); } catch (Exception closeException) { } catch (RuntimeException exception) { try {// Ensure that the statement is closed, but still ensure that the real exception is thrown. closeStatement(statement, session, dbCall); } catch (Exception closeException) { DatabaseAccessor.this.releaseStatement(statement, dbCall.getSQLString(), dbCall, session); } catch (SQLException exception) { DatabaseException commException = processExceptionForCommError(session, exception, dbCall); if (commException != null) results.throwException(commException); results.throwException(DatabaseException.sqlException(exception, DatabaseAccessor.this, session, false));
if (call.usesBinding(session) && call.shouldCacheStatement(session)) { Map statementCache = getStatementCache(); synchronized (statementCache) { statement = (PreparedStatement)statementCache.get(call.getSQLString()); Connection nativeConnection = getConnection(); if (nativeConnection==null){ throw DatabaseException.databaseAccessorConnectionIsNull(this, session); nativeConnection = getPlatform().getConnection(session, nativeConnection); } else if (call.isDynamicCall(session)) { statement = allocateDynamicStatement(nativeConnection); } else { statement = nativeConnection.prepareStatement(call.getSQLString());
int rowCount = (Integer)this.databaseAccessor.basicExecuteCall(this.lastCallAppended, null, session, false); if (this.usesOptimisticLocking) { if (rowCount != 1) { this.databaseAccessor.incrementCallCount(session);// Decrement occurs in close. this.databaseAccessor.executeBatchedStatement(statement, session); } else { this.executionCount = this.databaseAccessor.executeJDK12BatchStatement(statement, null, session, false); if (this.usesOptimisticLocking && (executionCount != statementCount)) { throw OptimisticLockException.batchStatementExecutionFailure();
try { boolean shouldUnwrapConnection = session.getPlatform().usesNativeBatchWriting(); statement = (PreparedStatement)this.databaseAccessor.prepareStatement(this.previousCall, session, shouldUnwrapConnection); databaseAccessor.getPlatform().prepareBatchStatement(statement); if(queryTimeoutCache > DescriptorQueryManager.NoTimeout) { executionCount += this.databaseAccessor.getPlatform().addBatch(statement); RuntimeException exceptionToThrow = this.databaseAccessor.processExceptionForCommError(session, exception, lastCallAppended); try { this.databaseAccessor.closeStatement(statement, session, null); } catch (SQLException closeException) { try { this.databaseAccessor.closeStatement(statement, session, null); } catch (SQLException closeException) {
/** * Execute the statement. */ protected Integer executeNoSelect(DatabaseCall call, Statement statement, AbstractSession session) throws DatabaseException { Integer rowCount = executeDirectNoSelect(statement, call, session); // Allow for procs with outputs to be raised as events for error handling. if (call.shouldBuildOutputRow()) { AbstractRecord outputRow = buildOutputRow((CallableStatement)statement, call, session); call.getQuery().setProperty("output", outputRow); if (session.hasEventManager()) { session.getEventManager().outputParametersDetected(outputRow, call); } } return rowCount; }
/** * Connect to the database. * Exceptions are caught and re-thrown as EclipseLink exceptions. * Must set the transaction isolation. */ @Override protected void connectInternal(Login login, AbstractSession session) throws DatabaseException { super.connectInternal(login, session); checkTransactionIsolation(session); try { session.getPlatform().initializeConnectionData(getConnection()); } catch (java.sql.SQLException sqlEx) { DatabaseException commException = processExceptionForCommError(session, sqlEx, null); if (commException != null) throw commException; throw DatabaseException.sqlException(sqlEx, this, session, false); } }
DatabasePlatform platform = session.getPlatform(); boolean shouldUnwrapConnection = platform.usesNativeBatchWriting(); statement = (PreparedStatement)this.databaseAccessor.prepareStatement(this.previousCall, session, shouldUnwrapConnection); RuntimeException exceptionToThrow = this.databaseAccessor.processExceptionForCommError(session, exception, lastCallAppended); try { this.databaseAccessor.closeStatement(statement, session, null); } catch (SQLException closeException) { try { this.databaseAccessor.closeStatement(statement, session, null); } catch (SQLException closeException) {
int rowCount = (Integer)this.databaseAccessor.basicExecuteCall(this.previousCall, null, session, false); if (this.previousCall.hasOptimisticLock()) { if (rowCount != 1) { this.databaseAccessor.incrementCallCount(session);// Decrement occurs in close. this.executionCount += this.databaseAccessor.executeJDK12BatchStatement(statement, this.lastCallAppended, session, true); this.databaseAccessor.writeStatementsCount++;