/** * 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); }
/** * 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; }
/** * 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); } } getCachedUpdateCalls().put(updateFields, vectorToCache); }
/** * 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); } } getCachedUpdateCalls().put(updateFields, vectorToCache); }
/** * 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); } } }
/** * 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); }
/** * 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); }
/** * 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); }
/** * Update the foreign key fields when resolving a bi-directional reference in a UOW. * This is rare to occur for non-relational, however if it does each of the calls must be re-executed. */ protected void updateForeignKeyFieldAfterInsert(WriteObjectQuery writeQuery) { writeQuery.setModifyRow(this.getDescriptor().getObjectBuilder().buildRow(writeQuery.getObject(), this.getSession(), WriteType.INSERT)); // For CR 2923 must move to session we will execute call on now // so correct DatasourcePlatform used by translate. AbstractSession sessionToUse = this.query.getExecutionSession(); // yes - this is a bit ugly... Vector calls = ((DatasourceCallQueryMechanism)this.getDescriptor().getQueryManager().getUpdateQuery().getQueryMechanism()).getCalls(); for (Enumeration stream = calls.elements(); stream.hasMoreElements();) { DatasourceCall call = (DatasourceCall)((DatasourceCall)stream.nextElement()).clone(); call.setQuery(writeQuery); sessionToUse.executeCall(call, this.getTranslationRow(), writeQuery); } } }
/** * Update the foreign key fields when resolving a bi-directional reference in a UOW. * This is rare to occur for non-relational, however if it does each of the calls must be re-executed. */ protected void updateForeignKeyFieldAfterInsert(WriteObjectQuery writeQuery) { writeQuery.setModifyRow(this.getDescriptor().getObjectBuilder().buildRow(writeQuery.getObject(), this.getSession(), WriteType.INSERT)); // For CR 2923 must move to session we will execute call on now // so correct DatasourcePlatform used by translate. AbstractSession sessionToUse = this.query.getExecutionSession(); // yes - this is a bit ugly... Vector calls = ((DatasourceCallQueryMechanism)this.getDescriptor().getQueryManager().getUpdateQuery().getQueryMechanism()).getCalls(); for (Enumeration stream = calls.elements(); stream.hasMoreElements();) { DatasourceCall call = (DatasourceCall)((DatasourceCall)stream.nextElement()).clone(); call.setQuery(writeQuery); sessionToUse.executeCall(call, this.getTranslationRow(), writeQuery); } } }
/** * Update the foreign key fields when resolving a bi-directonal reference in a UOW. * This is rare to occur for non-relational, however if it does each of the calls must be re-executed. */ protected void updateForeignKeyFieldAfterInsert(WriteObjectQuery writeQuery) { writeQuery.setModifyRow(this.getDescriptor().getObjectBuilder().buildRow(writeQuery.getObject(), this.getSession())); // For CR 2923 must move to session we will execute call on now // so correct DatasourcePlatform used by translate. AbstractSession sessionToUse = this.query.getExecutionSession(); // yes - this is a bit ugly... Vector calls = ((DatasourceCallQueryMechanism)this.getDescriptor().getQueryManager().getUpdateQuery().getQueryMechanism()).getCalls(); for (Enumeration stream = calls.elements(); stream.hasMoreElements();) { DatasourceCall call = (DatasourceCall)((DatasourceCall)stream.nextElement()).clone(); call.setQuery(writeQuery); sessionToUse.executeCall(call, this.getTranslationRow(), writeQuery); } } }
/** * ADVANCED: * This can be used to access a queries translated SQL if they have been prepared, (i.e. query.prepareCall()). * The Record argument is one of (Record, XMLRecord) that contains the query arguments. * @see #prepareCall(org.eclipse.persistence.sessions.Session, Record) */ public String getTranslatedSQLString(org.eclipse.persistence.sessions.Session session, Record translationRow) { prepareCall(session, translationRow); //CR#2859559 fix to use Session and Record interfaces not impl classes. CallQueryMechanism queryMechanism = (CallQueryMechanism)getQueryMechanism(); if (queryMechanism.getCall() == null) { return null; } SQLCall call = (SQLCall)queryMechanism.getCall().clone(); call.setUsesBinding(false); call.translate((AbstractRecord)translationRow, queryMechanism.getModifyRow(), (AbstractSession)session); return call.getSQLString(); }
/** * ADVANCED: This can be used to access a queries translated SQL if they * have been prepared, (i.e. query.prepareCall()). The Record argument is * one of (Record, XMLRecord) that contains the query arguments. * * @see #prepareCall(org.eclipse.persistence.sessions.Session, Record) */ public String getTranslatedSQLString(org.eclipse.persistence.sessions.Session session, Record translationRow) { prepareCall(session, translationRow); // CR#2859559 fix to use Session and Record interfaces not impl classes. CallQueryMechanism queryMechanism = (CallQueryMechanism) getQueryMechanism(); if (queryMechanism.getCall() == null) { return null; } SQLCall call = (SQLCall) queryMechanism.getCall().clone(); call.setUsesBinding(false); call.translate((AbstractRecord) translationRow, queryMechanism.getModifyRow(), (AbstractSession) session); return call.getSQLString(); }
/** * ADVANCED: This can be used to access a queries translated SQL if they * have been prepared, (i.e. query.prepareCall()). The Record argument is * one of (Record, XMLRecord) that contains the query arguments. * * @see #prepareCall(org.eclipse.persistence.sessions.Session, Record) */ public String getTranslatedSQLString(org.eclipse.persistence.sessions.Session session, Record translationRow) { prepareCall(session, translationRow); // CR#2859559 fix to use Session and Record interfaces not impl classes. CallQueryMechanism queryMechanism = (CallQueryMechanism) getQueryMechanism(); if (queryMechanism.getCall() == null) { return null; } SQLCall call = (SQLCall) queryMechanism.getCall().clone(); call.setUsesBinding(false); call.translate((AbstractRecord) translationRow, queryMechanism.getModifyRow(), (AbstractSession) session); return call.getSQLString(); }
/** * Read all rows from the database, return ResultSet * @exception DatabaseException - an error has occurred on the database */ public DatabaseCall selectResultSet() throws DatabaseException { try { // For CR 2923 must move to session we will execute call on now // so correct DatasourcePlatform used by translate. AbstractSession sessionToUse = this.query.getExecutionSession(); DatabaseCall clonedCall = (DatabaseCall)this.call.clone(); clonedCall.setQuery(this.query); clonedCall.translate(this.query.getTranslationRow(), getModifyRow(), sessionToUse); clonedCall.returnCursor(); return (DatabaseCall)sessionToUse.executeCall(clonedCall, this.query.getTranslationRow(), this.query); } catch (java.lang.ClassCastException e) { throw QueryException.invalidDatabaseCall(this.call); } }
/** * Read all rows from the database, return ResultSet * @exception DatabaseException - an error has occurred on the database */ public DatabaseCall selectResultSet() throws DatabaseException { try { // For CR 2923 must move to session we will execute call on now // so correct DatasourcePlatform used by translate. AbstractSession sessionToUse = this.query.getExecutionSession(); DatabaseCall clonedCall = (DatabaseCall)this.call.clone(); clonedCall.setQuery(this.query); clonedCall.translate(this.query.getTranslationRow(), getModifyRow(), sessionToUse); clonedCall.returnCursor(); return (DatabaseCall)sessionToUse.executeCall(clonedCall, this.query.getTranslationRow(), this.query); } catch (java.lang.ClassCastException e) { throw QueryException.invalidDatabaseCall(this.call); } }