/** * 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(); ((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); //the LOB context must be passed into the new call object call.setContexts(dbCall.getContexts()); //need to explictly define one rwo return, otherwise, TL 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); } }
if (isCursorOutputProcedure()) { throw ValidationException.multipleCursorsNotSupported(toString()); } else { hasFoundOutCursor = true; throw ValidationException.wrongUsageOfSetCustomArgumentTypeMethod(toString()); for (int i = 0; i < getParameters().size(); i++) { Object parameter = getParameters().elementAt(i); Integer parameterType = (Integer)getParameterTypes().elementAt(i); if (parameterType == MODIFY) { getParameterTypes().setElementAt(CUSTOM_MODIFY, i); setShouldBuildOutputRow(true); setIsCallableStatementRequired(true); DatabaseField outField = (DatabaseField)((Object[])parameter)[1]; if (outField.getType() == null) { DatabaseField typeOutField = getFieldWithTypeFromDescriptor(outField); if (typeOutField != null) { outField = (DatabaseField)typeOutField.clone(); boolean isCursor = parameterType == OUT_CURSOR; if (!isCursor) { setShouldBuildOutputRow(true); setIsCallableStatementRequired(true); DatabaseField outField = (DatabaseField)parameter;
DatabaseCall call = (DatabaseCall)callsEnum.nextElement(); if (!query.shouldIgnoreBindAllParameters()) { call.setUsesBinding(query.shouldBindAllParameters()); call.setShouldCacheStatement(query.shouldCacheStatement()); 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.prepare(executionSession); call = (DatabaseCall)getDatabaseCall().clone(); setCall(call); call.setUsesBinding(query.shouldBindAllParameters()); call.setShouldCacheStatement(query.shouldCacheStatement()); 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);
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(); ((Vector)tempResult).add(result); session.endOperationProfile(SessionProfiler.STATEMENT_EXECUTE); 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);
/** * 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 (usesBinding == FalseUndefinedTrue.True) { 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); } catch (SQLException exception) { throw DatabaseException.sqlException(exception, call, this, session); } }
/** * 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(); //additioanl join from the non-primary tables Expression additionalJoin = (Expression)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; }
databaseCall.bindParameter(writer, dbValue); nBoundParameters = 1; } else { } else if (dbValue instanceof byte[]) { if (usesByteArrayBinding()) { databaseCall.bindParameter(writer, dbValue); nBoundParameters = 1; } else { nBoundParameters = printValuelist((Vector)dbValue, databaseCall, writer); } else if ((parameter instanceof Struct) || (parameter instanceof Array) || (parameter instanceof Ref)) { databaseCall.bindParameter(writer, parameter); nBoundParameters = 1; } else if (oracle.toplink.essentials.internal.helper.Helper.isCollection(dbValue)) { } else if (dbValue instanceof BindCallCustomParameter) { databaseCall.bindParameter(writer, dbValue); nBoundParameters = 1; } else if ((dbValue instanceof Struct) || (dbValue instanceof Array) || (dbValue instanceof Ref)) { databaseCall.bindParameter(writer, dbValue); nBoundParameters = 1; } else {