if (targetQuery.shouldPrepare()) { targetQuery.checkPrepare(executionSession, row); targetQuery = (ReadQuery)targetQuery.clone(); targetQuery.setIsExecutionClone(true); targetQuery.setQueryId(sourceQuery.getQueryId()); if (targetQuery.isObjectLevelReadQuery()) { if (sourceQuery.shouldCascadeAllParts() || (this.isPrivateOwned && sourceQuery.shouldCascadePrivateParts()) || (this.cascadeRefresh && sourceQuery.shouldCascadeByMapping())) { if (targetQuery.shouldPrepare()) { targetQuery.checkPrepare(executionSession, row); targetQuery = (ObjectLevelReadQuery)targetQuery.clone(); targetQuery.setIsExecutionClone(true); targetQuery.setCascadePolicy(sourceQuery.getCascadePolicy()); if (targetQuery.shouldMaintainCache()) { targetQuery.setShouldMaintainCache(sourceQuery.shouldMaintainCache()); targetQuery.setSelectionCriteria((Expression)targetQuery.getSelectionCriteria().clone()); ((ObjectLevelReadQuery)targetQuery).setAsOfClause(((ObjectLevelReadQuery)sourceQuery).getAsOfClause()); if (targetQuery.shouldPrepare()) { targetQuery.checkPrepare(executionSession, row); targetQuery = (ObjectLevelReadQuery)targetQuery.clone(); targetQuery.setIsExecutionClone(true);
/** * PUBLIC: * Sets the selection criteria to be used as a where clause to read * reference objects. This criteria is automatically generated by the * TopLink if not explicitly specified by the user. */ public void setSelectionCriteria(Expression anExpression) { if (getSelectionQuery().isReadAllQuery()){ ((ReadAllQuery)getSelectionQuery()).setSelectionCriteria(anExpression); } else { getSelectionQuery().getSQLStatement().setWhereClause(anExpression); } } /**
/** * INTERNAL: * This is different from 'prepareForExecution' in that this is called on the original query, * and the other is called on the copy of the query. * This query is copied for concurrency so this prepare can only setup things that * will apply to any future execution of this query. * * Clear the query cache when a query is prepared. */ protected void prepare() throws QueryException { super.prepare(); if (shouldCacheQueryResults()) { clearQueryResults(getSession()); if (getReferenceClass() != null) { getQueryResultsCachePolicy().getInvalidationClasses().add(getReferenceClass()); } } }
/** * PUBLIC: * Set the fetchSize setting that this query will set on the JDBC Statement * NB - a value of zero means that no call to statement.setFetchSize() will be made. */ public void setFetchSize(int fetchSize) { if ( isPrepared() && this.getCall()!=null) { getCall().setResultSetFetchSize(fetchSize); } this.fetchSize = fetchSize; }
/** * PUBLIC: * Used to set the limit for the maximum number of rows that any ResultSet can contain to the given number. * This method should only be set once per query. To change the max rows use another query. * This method limits the number of candidate results returned to TopLink that can be used to build objects */ public void setMaxRows(int maxRows) { if ( isPrepared() && this.maxRows != maxRows){ if ( this.getCall()!=null && this.getCall().shouldIgnoreMaxResultsSetting() && this.maxRows>0 ){ }else{ setIsPrepared(false); } } this.maxRows = maxRows; shouldCloneCall=true; }
/** * INTERNAL: * This is different from 'prepareForExecution' in that this is called on the original query, * and the other is called on the copy of the query. * This query is copied for concurrency so this prepare can only setup things that * will apply to any future execution of this query. * * Clear the query cache when a query is prepared. */ protected void prepare() throws QueryException { super.prepare(); if (shouldCacheQueryResults()){ clearQueryResults(getSession()); } }
if (executionSession.isHistoricalSession() && !targetQuery.isPrepared()) { targetQuery = (ObjectLevelReadQuery)targetQuery.clone(); targetQuery.setIsExecutionClone(true); targetQuery = (ObjectLevelReadQuery)targetQuery.clone(); targetQuery.setIsExecutionClone(true); if (targetQuery.isObjectLevelReadQuery() && targetQuery.getDescriptor().hasFetchGroupManager()) { FetchGroup sourceFG = sourceQuery.getExecutionFetchGroup(this.getDescriptor()); if (sourceFG != null) { if (targetQuery.shouldPrepare()) { targetQuery.checkPrepare(executionSession, row); targetQuery = (ObjectLevelReadQuery)targetQuery.clone(); targetQuery.setIsExecutionClone(true); ((ObjectLevelReadQuery)targetQuery).setFetchGroup(targetFetchGroup); if (targetQuery.shouldPrepare()) { targetQuery.checkPrepare(executionSession, row); targetQuery = (ObjectLevelReadQuery)targetQuery.clone(); targetQuery.setIsExecutionClone(true); targetQuery.setQueryId(sourceQuery.getQueryId()); if (sourceQuery.usesResultSetAccessOptimization()) { targetQuery.setAccessors(sourceQuery.getAccessors()); if (targetQuery.isObjectLevelReadQuery()) {
ValueReadQuery query; if (!((CursoredStreamPolicy)getPolicy()).hasSizeQuery()) { if (getQuery().isCallQuery()) { throw QueryException.additionalSizeQueryNotSpecified(getQuery()); if (!getQuery().isExpressionQuery()) { throw QueryException.sizeOnlySupportedOnExpressionQueries(getQuery()); selectStatement.setWhereClause(((ExpressionQueryMechanism)getQuery().getQueryMechanism()).buildBaseSelectionCriteria(false, clonedExpressions)); if (getQuery().getDescriptor().hasInheritance() && (getQuery().getDescriptor().getInheritancePolicy().getWithAllSubclassesExpression() != null)) { Expression branchIndicator = getQuery().getDescriptor().getInheritancePolicy().getWithAllSubclassesExpression(); if ((branchIndicator != null) && (selectStatement.getWhereClause() != null)) { selectStatement.setWhereClause(selectStatement.getWhereClause().and(branchIndicator)); selectStatement.setTables((Vector)getQuery().getDescriptor().getTables().clone()); if (((ReadAllQuery)getQuery()).shouldDistinctBeUsed() && (getQuery().getCall().getFields().size() == 1)) { selectStatement.addField(buildCountDistinctExpression(getQuery().getCall().getFields(), ((ReadAllQuery)getQuery()).getExpressionBuilder())); } else { selectStatement.computeDistinct(); if (selectStatement.shouldDistinctBeUsed() && (getQuery().getDescriptor().getPrimaryKeyFields().size() == 1)) { selectStatement.addField(buildCountDistinctExpression(getQuery().getDescriptor().getPrimaryKeyFields(), ((ReadAllQuery)getQuery()).getExpressionBuilder())); } else { selectStatement.addField(((ReadAllQuery)getQuery()).getExpressionBuilder().count()); selectStatement.normalize(getSession(), getQuery().getDescriptor(), clonedExpressions);
/** * Retrieve next object from the remote scrollable cursor */ public Object scrollableCursorNextObject(ObjID remoteScrollableCursorOid, ReadQuery query, DistributedSession session) { Transporter transporter = null; transporter = getRemoteSessionController().scrollableCursorNextObject(new Transporter(remoteScrollableCursorOid)); if (transporter == null) { return null; } if (!transporter.wasOperationSuccessful()) { throw transporter.getException(); } Object object = transporter.getObject(); if (object == null) { // For bug 2797683 do not close if at end of stream. return null; } if (query.isReadAllQuery() && (!query.isReportQuery())) {// could be DataReadQuery object = session.getObjectCorrespondingTo(object, transporter.getObjectDescriptors(), new IdentityHashMap(), (ObjectLevelReadQuery)query); } return object; }
/** * INTERNAL: * Prepare the receiver for execution in a session. */ public void prepareForExecution() throws QueryException { super.prepareForExecution(); DatabaseCall databaseCall = this.getCall(); if ( databaseCall !=null && databaseCall.shouldIgnoreFirstRowMaxResultsSettings() ){ AbstractRecord parameters = this.getTranslationRow(); if (parameters.isEmpty()){ parameters = new DatabaseRecord(); } parameters.add(DatabaseCall.FIRSTRESULT_FIELD, this.getFirstResult()); parameters.add(DatabaseCall.MAXROW_FIELD, session.getPlatform().computeMaxRowsForSQL(this.getFirstResult(), this.getMaxRows())); this.setTranslationRow(parameters); } }
/** * INTERNAL: * Append the temporal selection to the query selection criteria. */ @Override protected ReadQuery prepareHistoricalQuery(ReadQuery targetQuery, ObjectBuildingQuery sourceQuery, AbstractSession executionSession) { if (getHistoryPolicy() != null) { if (targetQuery == getSelectionQuery()) { targetQuery = (ObjectLevelReadQuery)targetQuery.clone(); targetQuery.setIsExecutionClone(true); } if (targetQuery.getSelectionCriteria() == getSelectionQuery().getSelectionCriteria()) { targetQuery.setSelectionCriteria((Expression)targetQuery.getSelectionCriteria().clone()); } if (sourceQuery.getSession().getAsOfClause() != null) { ((ObjectLevelReadQuery)targetQuery).setAsOfClause(sourceQuery.getSession().getAsOfClause()); } else if (((ObjectLevelReadQuery)targetQuery).getAsOfClause() == null) { ((ObjectLevelReadQuery)targetQuery).setAsOfClause(AsOfClause.NO_CLAUSE); } Expression temporalExpression = (this).getHistoryPolicy().additionalHistoryExpression(targetQuery.getSelectionCriteria().getBuilder(), targetQuery.getSelectionCriteria().getBuilder()); targetQuery.setSelectionCriteria(targetQuery.getSelectionCriteria().and(temporalExpression)); } return targetQuery; } }
/** * INTERNAL: * builds and registers an object from a row for cursors. * Behavior is different from the query version in that refreshing is not * supported. */ protected Object buildAndRegisterObject(AbstractRecord row) { ReadQuery query = this.query; if (query.isObjectLevelReadQuery()) { ObjectLevelReadQuery objectQuery = (ObjectLevelReadQuery)query; if (objectQuery.hasBatchReadAttributes() && objectQuery.getBatchFetchPolicy().isIN()) { objectQuery.getBatchFetchPolicy().addDataResults(row); } if (this.session.isUnitOfWork() && (!query.isReportQuery()) && query.shouldMaintainCache() && (objectQuery.shouldConformResultsInUnitOfWork() || objectQuery.getDescriptor().shouldAlwaysConformResultsInUnitOfWork())) { Object object = objectQuery.conformIndividualResult( objectQuery.buildObject(row), (UnitOfWorkImpl)this.session, this.translationRow, this.selectionCriteriaClone, this.initiallyConformingIndex); // Notifies caller to continue until conforming instance found if (object == null) { return InvalidObject.instance; } return object; } } return query.buildObject(row); }
/** * INTERNAL: * Clone the query */ @Override public Object clone() { ObjectBuildingQuery cloneQuery = (ObjectBuildingQuery) super.clone(); cloneQuery.isCacheCheckComplete = this.isCacheCheckComplete; return cloneQuery; } /**
protected void initializeSelectionStatement(AbstractSession session) { if (selectionQuery.isReadAllQuery()){ ((ReadAllQuery)selectionQuery).addAdditionalField((DatabaseField)getDirectField().clone()); } else { SQLSelectStatement statement = (SQLSelectStatement)selectionQuery.getSQLStatement(); statement.addTable(getReferenceTable()); statement.addField((DatabaseField)getDirectField().clone()); getContainerPolicy().addAdditionalFieldsToQuery(selectionQuery, null); statement.normalize(session, null); } if (selectionQuery.isDirectReadQuery()){ ((DirectReadQuery)selectionQuery).setResultType(DataReadQuery.MAP); } }
/** * INTERNAL: * Returns a query that */ ReadQuery getLockRelationTableQueryClone(AbstractSession session, short lockMode) { DirectReadQuery lockRelationTableQueryClone = (DirectReadQuery)lockRelationTableQuery.clone(); SQLSelectStatement statement = new SQLSelectStatement(); statement.addTable(this.relationTable); statement.addField(this.sourceRelationKeyFields.get(0).clone()); statement.setWhereClause((Expression)lockRelationTableQuery.getSelectionCriteria().clone()); statement.setLockingClause(new ForUpdateClause(lockMode)); statement.normalize(session, null); lockRelationTableQueryClone.setSQLStatement(statement); lockRelationTableQueryClone.setIsExecutionClone(true); return lockRelationTableQueryClone; }
/** * INTERNAL: * Retrieve the value through using batch reading. * This executes a single query to read the target for all of the objects and stores the * result of the batch query in the original query to allow the other objects to share the results. */ protected Object batchedValueFromRow(AbstractRecord row, ReadAllQuery query) { ReadQuery batchQuery = (ReadQuery)query.getProperty(this); if (batchQuery == null) { if (query.getBatchReadMappingQueries() != null) { batchQuery = (ReadQuery)query.getBatchReadMappingQueries().get(this); } if (batchQuery == null) { batchQuery = prepareNestedBatchQuery(query); batchQuery.setIsExecutionClone(true); } else { batchQuery = (ReadQuery)batchQuery.clone(); batchQuery.setIsExecutionClone(true); } query.setProperty(this, batchQuery); } return this.indirectionPolicy.valueFromBatchQuery(batchQuery, row, query); }
/** * INTERNAL: * Return the ordering query keys. * Used for Workbench integration. */ public List<Expression> getOrderByQueryKeyExpressions() { List<Expression> expressions = new ArrayList<Expression> (); if ((getSelectionQuery() != null) && getSelectionQuery().isReadAllQuery()) { for (Expression orderExpression : ((ReadAllQuery)getSelectionQuery()).getOrderByExpressions()) { if (orderExpression.isFunctionExpression() && ((FunctionExpression)orderExpression).getBaseExpression().isQueryKeyExpression()) { expressions.add(orderExpression); } } } return expressions; }
private void checkOrderBy(ReadQuery query) { if (query.isReadAllQuery()) { ReadAllQuery readAllQuery = (ReadAllQuery) query; List<Expression> orderBy = readAllQuery.getOrderByExpressions(); if ((orderBy == null) || (orderBy.isEmpty())) { JPARSLogger.warning("no_orderby_clause_for_paging", new Object[] { query.toString() }); } } }
/** * INTERNAL: * Return the accessor associated with the cursor. */ public DatabaseAccessor getAccessor() { // Assume we have a JDBC accessor try { return (DatabaseAccessor)this.query.getAccessor(); } catch (ClassCastException e) { throw QueryException.invalidDatabaseAccessor(this.query.getAccessor()); } }
/** * INTERNAL: * Convert all the class-name-based settings in this query to actual class-based * settings. This method is used when converting a project that has been built * with class names to a project with classes. * @param classLoader */ @Override public void convertClassNamesToClasses(ClassLoader classLoader){ super.convertClassNamesToClasses(classLoader); Class referenceClass = null; try{ if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){ try { referenceClass = AccessController.doPrivileged(new PrivilegedClassForName(getReferenceClassName(), true, classLoader)); } catch (PrivilegedActionException exception) { throw ValidationException.classNotFoundWhileConvertingClassNames(getReferenceClassName(), exception.getException()); } } else { referenceClass = PrivilegedAccessHelper.getClassForName(getReferenceClassName(), true, classLoader); } } catch (ClassNotFoundException exc){ throw ValidationException.classNotFoundWhileConvertingClassNames(getReferenceClassName(), exc); } setReferenceClass(referenceClass); };