/** * INTERNAL: * All values are printed as ? to allow for parameter binding or translation during the execute of the call. */ public void appendLiteral(Writer writer, Object literal) { try { writer.write(argumentMarker()); } catch (IOException exception) { throw ValidationException.fileError(exception); } getParameters().add(literal); getParameterTypes().add(LITERAL); }
/** * INTERNAL: * Cache a clone of the update SQL calls based on the updated fields. * If the max size is reached, do not cache the call. * The call's query must be dereferenced in order to allow the GC of a related session. * PERF: Allow caching of the update SQL call to avoid regeneration. */ public void putCachedUpdateCalls(Vector updateFields, Vector updateCalls) { Vector vectorToCache = updateCalls; if (!updateCalls.isEmpty()) { int updateCallsSize = updateCalls.size(); vectorToCache = new NonSynchronizedVector(updateCallsSize); for (int i = 0; i < updateCallsSize; i++) { DatasourceCall updateCall = (DatasourceCall)updateCalls.get(i); // clone call and dereference query for DatasourceCall and EJBQLCall DatasourceCall clonedUpdateCall = (DatasourceCall) updateCall.clone(); clonedUpdateCall.setQuery(null); vectorToCache.add(clonedUpdateCall); } } this.cachedUpdateCalls.put(updateFields, vectorToCache); }
if (getQueryString().indexOf("#") == -1) { if (this.getQuery().shouldBindAllParameters() && getQueryString().indexOf("?") == -1){ return; translatePureSQLCustomQuery(); return; if (!hasArgumentMark(getQueryString(),'#')) { if (this.getQuery().shouldBindAllParameters() && !hasArgumentMark(getQueryString(),'?')){ return; translatePureSQLCustomQuery(); return; String queryString = getQueryString(); Writer writer = new CharArrayWriter(queryString.length() + 50); try { if (poundIndex != -1) { int wordEndIndex = poundIndex + 1; while ((wordEndIndex < queryString.length()) && (whitespace().indexOf(queryString.charAt(wordEndIndex)) == -1)) { wordEndIndex = wordEndIndex + 1; DatabaseField field = createField(fieldName); appendInOut(writer, field); } else { String fieldName = queryString.substring(poundIndex + 3, wordEndIndex); DatabaseField field = createField(fieldName); appendOut(writer, field);
if ((this.parameters == null) || getParameters().isEmpty()) { if (getQueryString().indexOf(argumentMarker()) == -1) { return; String queryString = getQueryString(); Writer writer = new CharArrayWriter(queryString.length() + 50); try { List parameterFields = getParameters(); List<Integer> parameterTypes = getParameterTypes(); setParameters(new ArrayList(parameterFields.size())); while (lastIndex != -1) { int tokenIndex = queryString.indexOf(argumentMarker(), lastIndex); String token; if (tokenIndex == -1) { DatabaseField field = (DatabaseField)parameter; Object value = modifyRow.get(field); appendParameter(writer, value, session); } else if (parameterType == CUSTOM_MODIFY) { DatabaseField field = (DatabaseField)parameter; appendParameter(writer, value, session); } else if (parameterType == TRANSLATION) { Object value = null; value = ((ParameterExpression)parameter).getValue(translationRow, getQuery(), session); } else {
String queryString = getQueryString(); int parameterIndex = 1; // this is the parameter index Writer writer = new CharArrayWriter(queryString.length() + 50); if (markIndex != -1) { // found the question mark now find the named token int wordEndIndex = markIndex + 1; while ((wordEndIndex < queryString.length()) && (whitespace().indexOf(queryString.charAt(wordEndIndex)) == -1)) { wordEndIndex = wordEndIndex + 1; DatabaseField field = createField(fieldName); appendIn(writer, field); lastIndex = wordEndIndex; }else{ DatabaseField field = createField(String.valueOf(parameterIndex)); parameterIndex++; appendIn(writer, field); throw ValidationException.fileError(exception); setQueryString(writer.toString());
/** * 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); } } }
/** * Execute the call. It is assumed the call has been fully prepared. * @exception DatabaseException - an error has occurred on the database. */ protected Object executeCall(DatasourceCall databaseCall) throws DatabaseException { // For CR 2923 must move to session we will execute call on now // so correct DatasourcePlatform used by translate. AbstractSession sessionToUse = this.query.getExecutionSession(); DatasourceCall clonedCall = (DatasourceCall)databaseCall.clone(); clonedCall.setQuery(this.query); clonedCall.translate(this.query.getTranslationRow(), getModifyRow(), sessionToUse); return sessionToUse.executeCall(clonedCall, this.query.getTranslationRow(), this.query); }
if (query.shouldCloneCall()) { call = (DatabaseCall)call.clone(); call.setQuery(query); this.calls.set(index, call); configureDatabaseCall((DatabaseCall)call); call.prepare(executionSession); this.call = (DatasourceCall)this.call.clone(); this.call.setQuery(query); configureDatabaseCall((DatabaseCall)call); this.call.prepare(executionSession);
/** * Clone the DatasourceCall and Vector<DatasourceCall>. */ public DatabaseQueryMechanism clone(DatabaseQuery queryClone) { DatasourceCallQueryMechanism clone = (DatasourceCallQueryMechanism)super.clone(queryClone); if(this.call != null) { DatasourceCall callclone = (DatasourceCall)this.call.clone(); clone.setCall(callclone); } if(this.calls != null) { Vector callsclone = (Vector)this.calls.clone(); clone.setCalls(callsclone); } return clone; }
/** * The parameters are the values in order of occurrence in call. * This is lazy initialized to conserve space on calls that have no parameters. */ public boolean hasParameters() { return (parameters != null) && (!getParameters().isEmpty()); }
/** * Return the appropriate mechanism, * with the call added as necessary. */ public DatabaseQueryMechanism buildQueryMechanism(DatabaseQuery query, DatabaseQueryMechanism mechanism) { if (mechanism.isCallQueryMechanism() && (mechanism instanceof DatasourceCallQueryMechanism)) { // Must also add the call singleton... DatasourceCallQueryMechanism callMechanism = ((DatasourceCallQueryMechanism)mechanism); if (!callMechanism.hasMultipleCalls()) { callMechanism.addCall(callMechanism.getCall()); callMechanism.setCall(null); } callMechanism.addCall(this); return mechanism; } else { return buildNewQueryMechanism(query); } }
if (getQueryString().indexOf(this.query.getParameterDelimiter()) == -1) { if (this.getQuery().shouldBindAllParameters() && getQueryString().indexOf("?") == -1) { return; translatePureSQLCustomQuery(); return; if (!hasArgumentMark(getQueryString(), this.query.getParameterDelimiterChar(), '\'') || !hasArgumentMark(getQueryString(), this.query.getParameterDelimiterChar(), '\"') || !hasArgumentMark(getQueryString(), this.query.getParameterDelimiterChar(), '`')) { if (this.getQuery().shouldBindAllParameters() && !hasArgumentMark(getQueryString(),'?', '\'')) { return; translatePureSQLCustomQuery(); return; String queryString = getQueryString(); Writer writer = new CharArrayWriter(queryString.length() + 50); try { if (poundIndex != -1) { int wordEndIndex = poundIndex + 1; while ((wordEndIndex < queryString.length()) && (whitespace().indexOf(queryString.charAt(wordEndIndex)) == -1)) { wordEndIndex = wordEndIndex + 1; DatabaseField field = createField(fieldName); appendInOut(writer, field); } else { String fieldName = queryString.substring(poundIndex + 3, wordEndIndex);
if ((this.parameters == null) || getParameters().isEmpty()) { if (getQueryString().indexOf(argumentMarker()) == -1) { return; String queryString = getQueryString(); Writer writer = new CharArrayWriter(queryString.length() + 50); try { List parameterFields = getParameters(); List<Integer> parameterTypes = getParameterTypes(); setParameters(new ArrayList(parameterFields.size())); while (lastIndex != -1) { int tokenIndex = queryString.indexOf(argumentMarker(), lastIndex); String token; if (tokenIndex == -1) { DatabaseField field = (DatabaseField)parameter; Object value = modifyRow.get(field); appendParameter(writer, value, session); } else if (parameterType == CUSTOM_MODIFY) { DatabaseField field = (DatabaseField)parameter; appendParameter(writer, value, session); } else if (parameterType == TRANSLATION) { Object value = null; value = ((ParameterExpression)parameter).getValue(translationRow, getQuery(), session); } else {
String queryString = getQueryString(); int parameterIndex = 1; // this is the parameter index Writer writer = new CharArrayWriter(queryString.length() + 50); if (markIndex != -1) { // found the question mark now find the named token int wordEndIndex = markIndex + 1; while ((wordEndIndex < queryString.length()) && (whitespace().indexOf(queryString.charAt(wordEndIndex)) == -1)) { wordEndIndex = wordEndIndex + 1; DatabaseField field = createField(fieldName); appendIn(writer, field); lastIndex = wordEndIndex; }else{ DatabaseField field = createField(String.valueOf(parameterIndex)); parameterIndex++; appendIn(writer, field); throw ValidationException.fileError(exception); setQueryString(writer.toString());
/** * 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); } } }
/** * Execute the call. It is assumed the call has been fully prepared. * @exception DatabaseException - an error has occurred on the database. */ protected Object executeCall(DatasourceCall databaseCall) throws DatabaseException { // For CR 2923 must move to session we will execute call on now // so correct DatasourcePlatform used by translate. AbstractSession sessionToUse = this.query.getExecutionSession(); DatasourceCall clonedCall = (DatasourceCall)databaseCall.clone(); clonedCall.setQuery(this.query); clonedCall.translate(this.query.getTranslationRow(), getModifyRow(), sessionToUse); return sessionToUse.executeCall(clonedCall, this.query.getTranslationRow(), this.query); }
if (query.shouldCloneCall()) { call = (DatabaseCall)call.clone(); call.setQuery(query); this.calls.set(index, call); configureDatabaseCall((DatabaseCall)call); call.prepare(executionSession); this.call = (DatasourceCall)this.call.clone(); this.call.setQuery(query); configureDatabaseCall((DatabaseCall)call); this.call.prepare(executionSession);
/** * The parameters are the values in order of occurrence in call. * This is lazy initialized to conserve space on calls that have no parameters. */ public boolean hasParameters() { return (parameters != null) && (!getParameters().isEmpty()); }
/** * Return the appropriate mechanism, * with the call added as necessary. */ public DatabaseQueryMechanism buildQueryMechanism(DatabaseQuery query, DatabaseQueryMechanism mechanism) { if (mechanism.isCallQueryMechanism() && (mechanism instanceof DatasourceCallQueryMechanism)) { // Must also add the call singleton... DatasourceCallQueryMechanism callMechanism = ((DatasourceCallQueryMechanism)mechanism); if (!callMechanism.hasMultipleCalls()) { callMechanism.addCall(callMechanism.getCall()); callMechanism.setCall(null); } callMechanism.addCall(this); return mechanism; } else { return buildNewQueryMechanism(query); } }