/** * INTERNAL: * Override this method in case the platform needs to do something special for binding literals. * Note that instead of null value a DatabaseField * value may be passed (so that it's type could be used for binding null). */ protected void appendLiteralToCallWithBinding(Call call, Writer writer, Object literal) { ((DatabaseCall)call).appendLiteral(writer, literal); }
/** * Return the SQL string for logging purposes. */ public String getLogString(Accessor accessor) { if (hasParameters()) { StringWriter writer = new StringWriter(); writer.write(getSQLString()); writer.write(Helper.cr()); if (hasParameters()) { AbstractSession session = null; if (getQuery() != null) { session = getQuery().getSession(); } appendLogParameters(getParameters(), accessor, writer, session); } return writer.toString(); } else { return getSQLString(); } }
Object result = null; ResultSet resultSet = null; 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); if (dbCall.areManyRowsReturned()) { Vector tempResult = new Vector(); tempResult.add(result); dbCall.matchFieldOrder(resultSet, accessor, session); if (dbCall.isCursorReturned()) { dbCall.setStatement(statement); dbCall.setResult(resultSet); return dbCall;
/** * Build the sql call from the select statement for selecting the locator */ private DatabaseCall buildCallFromSelectStatementForLocator(SQLSelectStatement selectStatement, WriteObjectQuery writeQuery, DatabaseCall dbCall, AbstractSession session) { DatabaseCall call = selectStatement.buildCall(session); // Locator LOB must not be wrapped (WLS wraps LOBs). call.setIsNativeConnectionRequired(this.isNativeConnectionRequired); //the LOB context must be passed into the new call object call.setContexts(dbCall.getContexts()); //need to explicitly define one row return, otherwise, EL assumes multiple rows return and confuses the accessor call.returnOneRow(); //the query object has to be set in order to access to the platform and login objects call.setQuery(writeQuery); // prepare it call.prepare(session); //finally do the translation call.translate(writeQuery.getTranslationRow(), writeQuery.getModifyRow(), session); return call; }
/** * Fetch the locator(s) from the result set and write LOB value to the table */ public void fetchLocatorAndWriteValue(DatabaseCall dbCall, Object resultSet) throws SQLException { Enumeration enumFields = dbCall.getContexts().getFields().elements(); Enumeration enumValues = dbCall.getContexts().getValues().elements(); AbstractSession executionSession = dbCall.getQuery().getSession().getExecutionSession(dbCall.getQuery()); while (enumFields.hasMoreElements()) { DatabaseField field = (DatabaseField)enumFields.nextElement(); Object value = enumValues.nextElement(); //write the value through the locator executionSession.getPlatform().writeLOB(field, value, (ResultSet)resultSet, executionSession); } }
DatabaseCall call = (DatabaseCall)callsEnum.nextElement(); if (!query.shouldIgnoreBindAllParameters()) { call.setUsesBinding(query.shouldBindAllParameters()); call.setShouldCacheStatement(query.shouldCacheStatement()); call.setQueryTimeout(query.getQueryTimeout()); if (query.isNativeConnectionRequired()) { call.setIsNativeConnectionRequired(true); if (!call.shouldIgnoreFirstRowMaxResultsSettings()){ call.setMaxRows(readQuery.getMaxRows()); if (readQuery.getFirstResult() != 0) { call.setFirstResult(readQuery.getFirstResult()); call.setIsResultSetScrollable(true); call.setResultSetType(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE); call.setResultSetConcurrency(java.sql.ResultSet.CONCUR_READ_ONLY); call.setResultSetFetchSize(readQuery.getFetchSize()); call.prepare(executionSession); call = (DatabaseCall)getDatabaseCall().clone(); setCall(call); call.setUsesBinding(query.shouldBindAllParameters()); call.setShouldCacheStatement(query.shouldCacheStatement());
Object result = null; ResultSet resultSet = null; 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); if (dbCall.shouldBuildOutputRow() || dbCall.hasOutputCursors()) { result = accessor.buildOutputRow((CallableStatement)statement, dbCall, session); if (dbCall.areManyRowsReturned()) { Vector tempResult = new Vector(); tempResult.add(result); dbCall.matchFieldOrder(resultSet, accessor, session); if (dbCall.isCursorReturned()) { dbCall.setStatement(statement); dbCall.setResult(resultSet); return dbCall; if (dbCall.shouldBuildOutputRow() && ! isOutputAllowWithResultSet()) { AbstractRecord outputRow = accessor.buildOutputRow((CallableStatement)statement, dbCall, session); dbCall.getQuery().setProperty("output", outputRow); session.getEventManager().outputParametersDetected(outputRow, dbCall);
Object result = null; ResultSet resultSet = null; if (!dbCall.getReturnsResultSet()) { accessor.executeDirectNoSelect(statement, dbCall, session); result = accessor.buildOutputRow((CallableStatement)statement, dbCall, session); if (dbCall.areManyRowsReturned()) { Vector tempResult = new Vector(); (tempResult).add(result); session.startOperationProfile(SessionProfiler.STATEMENT_EXECUTE, dbCall.getQuery(), SessionProfiler.ALL); try { resultSet = statement.executeQuery(); } finally { session.endOperationProfile(SessionProfiler.STATEMENT_EXECUTE, dbCall.getQuery(), SessionProfiler.ALL); dbCall.matchFieldOrder(resultSet, accessor, session); if (dbCall.isCursorReturned()) { dbCall.setStatement(statement); dbCall.setResult(resultSet); return dbCall; if (dbCall.shouldBuildOutputRow()) { AbstractRecord outputRow = accessor.buildOutputRow((CallableStatement)statement, dbCall, session); dbCall.getQuery().setProperty("output", outputRow); session.getEventManager().outputParametersDetected(outputRow, dbCall);
int lastIndex = 0; int parameterIndex = 0; String queryString = getQueryString(); Writer writer = new CharArrayWriter(queryString.length() + 50); try { Vector parameters = getParameters(); Vector parametersValues = new Vector(parameters.size()); while (lastIndex != -1) { int tokenIndex = queryString.indexOf(argumentMarker(), lastIndex); String token; if (tokenIndex == -1) { setParameters(parametersValues); setQueryString(writer.toString());
DatabaseAccessor accessor = (DatabaseAccessor)unitOfWork.getAccessor(); DatabasePlatform platform = accessor.getPlatform(); DatabaseCall call = (DatabaseCall)getCall().clone(); call.setQuery(this); call.translate(this.translationRow, null, unitOfWork); Statement statement = null; ResultSet resultSet = null; try { accessor.incrementCallCount(unitOfWork); statement = call.prepareStatement(accessor, this.translationRow, unitOfWork); resultSet = accessor.executeSelect(call, statement, unitOfWork); ResultSetMetaData metaData = resultSet.getMetaData(); accessor.releaseStatement(statement, call.getSQLString(), call, unitOfWork);
/** * Unprepare the call if required. * Clone and unprepare stored procedure calls, so they can be reprepared with possible different optional arguments. */ public void unprepare() { DatabaseQuery query = this.query; if (hasMultipleCalls()) { this.calls = ((Vector)this.calls.clone()); int size = this.calls.size(); for (int index = 0; index < size; index++) { DatabaseCall call = (DatabaseCall)this.calls.get(index); if (call.isPrepared() && call.isStoredProcedureCall() && ((StoredProcedureCall)call).hasOptionalArguments()) { call = (DatabaseCall)call.clone(); call.setIsPrepared(false); call.setQuery(query); this.calls.set(index, call); } } } else if (this.call != null) { if (this.call.isPrepared() && this.call.isStoredProcedureCall() && ((StoredProcedureCall)this.call).hasOptionalArguments()) { this.call = (DatabaseCall)this.call.clone(); this.call.setIsPrepared(false); this.call.setQuery(query); } } }
session.log(SessionLog.FINE, SessionLog.SQL, this.previousCall.getSQLString(), null, this.databaseAccessor, false); DatabaseCall.appendLogParameters((Collection)iterator.next(), this.databaseAccessor, writer, session); session.log(SessionLog.FINE, SessionLog.SQL, writer.toString(), null, this.databaseAccessor, false); this.databaseAccessor.writeStatementsCount++; if (this.previousCall.hasOptimisticLock() && (executionCount!=statementCount)){ throw OptimisticLockException.batchStatementExecutionFailure();
/** * Add the parameter. * If using binding bind the parameter otherwise let the platform print it. * The platform may also decide to bind the value. */ public void appendParameter(Writer writer, Object parameter, AbstractSession session) { if (Boolean.TRUE.equals(usesBinding)) { bindParameter(writer, parameter); } else { session.getPlatform().appendParameter(this, writer, parameter); } }
/** * Build a row from the output parameters of a sp call. */ public AbstractRecord buildOutputRow(CallableStatement statement, DatabaseCall call, AbstractSession session) throws DatabaseException { try { return call.buildOutputRow(statement, this, session); } catch (SQLException exception) { DatabaseException commException = processExceptionForCommError(session, exception, null); if (commException != null) throw commException; throw DatabaseException.sqlException(exception, this, session, false); } }
/** * Return the appropriate mechanism, * with the call added as necessary. */ public DatabaseQueryMechanism buildQueryMechanism(DatabaseQuery query, DatabaseQueryMechanism mechanism) { if (mechanism.isCallQueryMechanism() && (mechanism instanceof CallQueryMechanism)) { // Must also add the call singleton... CallQueryMechanism callMechanism = ((CallQueryMechanism)mechanism); if (!callMechanism.hasMultipleCalls()) { callMechanism.addCall(callMechanism.getCall()); callMechanism.setCall(null); } callMechanism.addCall(this); return mechanism; } else { return buildNewQueryMechanism(query); } }
/** * Build the select statement for selecting the locator */ private SQLSelectStatement buildSelectStatementForLocator(WriteObjectQuery writeQuery, DatabaseCall call, AbstractSession session) { SQLSelectStatement selectStatement = new SQLSelectStatement(); Vector tables = writeQuery.getDescriptor().getTables(); selectStatement.setTables(tables); //rather than get ALL fields from the descriptor, only use the LOB-related fields to build the minimal SELECT statement. selectStatement.setFields(call.getContexts().getFields()); //the where clause setting here is sufficient if the object does not map to multiple tables. selectStatement.setWhereClause(writeQuery.getDescriptor().getObjectBuilder().buildPrimaryKeyExpressionFromObject(writeQuery.getObject(), session)); //need pessimistic locking for the locator select selectStatement.setLockingClause(ForUpdateClause.newInstance(ObjectBuildingQuery.LOCK)); if (tables.size() > 1) { //the primary key expression from the primary table Expression expression = selectStatement.getWhereClause(); //additional join from the non-primary tables Expression additionalJoin = writeQuery.getDescriptor().getQueryManager().getAdditionalJoinExpression(); if (additionalJoin != null) { expression = expression.and(additionalJoin); } //where clause now contains extra joins across all tables selectStatement.setWhereClause(expression); } //normalize the statement at the end, such as assign alias to all tables, and build sorting statement selectStatement.normalize(session, writeQuery.getDescriptor()); return selectStatement; }
Object result = null; ResultSet resultSet = null; 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); if (dbCall.shouldBuildOutputRow() || dbCall.hasOutputCursors()) { result = accessor.buildOutputRow((CallableStatement)statement, dbCall, session); if (dbCall.areManyRowsReturned()) { Vector tempResult = new Vector(); tempResult.add(result); dbCall.matchFieldOrder(resultSet, accessor, session); if (dbCall.isCursorReturned()) { dbCall.setStatement(statement); dbCall.setResult(resultSet); return dbCall; if (dbCall.shouldBuildOutputRow() && ! isOutputAllowWithResultSet()) { AbstractRecord outputRow = accessor.buildOutputRow((CallableStatement)statement, dbCall, session); dbCall.getQuery().setProperty("output", outputRow); session.getEventManager().outputParametersDetected(outputRow, dbCall);
/** * Build the sql call from the select statement for selecting the locator */ private DatabaseCall buildCallFromSelectStatementForLocator(SQLSelectStatement selectStatement, WriteObjectQuery writeQuery, DatabaseCall dbCall, AbstractSession session) { DatabaseCall call = selectStatement.buildCall(session); // Locator LOB must not be wrapped (WLS wraps LOBs). call.setIsNativeConnectionRequired(this.isNativeConnectionRequired); //the LOB context must be passed into the new call object call.setContexts(dbCall.getContexts()); //need to explicitly define one row return, otherwise, EL assumes multiple rows return and confuses the accessor call.returnOneRow(); //the query object has to be set in order to access to the platform and login objects call.setQuery(writeQuery); // prepare it call.prepare(session); //finally do the translation call.translate(writeQuery.getTranslationRow(), writeQuery.getModifyRow(), session); return call; }
Object result = null; ResultSet resultSet = null; if (!dbCall.getReturnsResultSet()) { accessor.executeDirectNoSelect(statement, dbCall, session); result = accessor.buildOutputRow((CallableStatement)statement, dbCall, session); if (dbCall.areManyRowsReturned()) { Vector tempResult = new Vector(); (tempResult).add(result); session.startOperationProfile(SessionProfiler.STATEMENT_EXECUTE, dbCall.getQuery(), SessionProfiler.ALL); try { resultSet = statement.executeQuery(); } finally { session.endOperationProfile(SessionProfiler.STATEMENT_EXECUTE, dbCall.getQuery(), SessionProfiler.ALL); dbCall.matchFieldOrder(resultSet, accessor, session); if (dbCall.isCursorReturned()) { dbCall.setStatement(statement); dbCall.setResult(resultSet); return dbCall; if (dbCall.shouldBuildOutputRow()) { AbstractRecord outputRow = accessor.buildOutputRow((CallableStatement)statement, dbCall, session); dbCall.getQuery().setProperty("output", outputRow); session.getEventManager().outputParametersDetected(outputRow, dbCall);
int lastIndex = 0; int parameterIndex = 0; String queryString = getQueryString(); Writer writer = new CharArrayWriter(queryString.length() + 50); try { List parameters = getParameters(); List parametersValues = new ArrayList(parameters.size()); while (lastIndex != -1) { int tokenIndex = queryString.indexOf(argumentMarker(), lastIndex); String token; if (tokenIndex == -1) { setParameters(parametersValues); setQueryString(writer.toString());