/** * PUBLIC: * The primary key can be specified if used instead of an expression or selection object. */ public void setSingletonSelectionKey(Object selectionKey) { Vector key = new Vector(); key.addElement(selectionKey); setSelectionKey(key); }
/** * PUBLIC: * The primary key can be specified if used instead of an expression or selection object. * @deprecated since EclipseLink 2.1, replaced by setSelectionId(Object) * @see #setSelectionId(Object) */ @Deprecated public void setSingletonSelectionKey(Object selectionKey) { Vector key = new NonSynchronizedVector(); key.add(selectionKey); setSelectionKey(key); }
/** * PUBLIC: * The primary key can be specified if used instead of an expression or selection object. * @deprecated since EclipseLink 2.1, replaced by setSelectionId(Object) * @see #setSelectionId(Object) */ @Deprecated public void setSingletonSelectionKey(Object selectionKey) { Vector key = new NonSynchronizedVector(); key.add(selectionKey); setSelectionKey(key); }
/** * PUBLIC: * Used to set the where clause of the query. * This can be used instead of a where clause expression for single object primary key queries. * The selection object given should have a primary key defined, * this primary key will be used to query the database instance of the same object. * This is a basic form of query by example where only the primary key is required, * it can be used for simple query forms, or testing. */ public void setSelectionObject(Object selectionObject) { if (selectionObject == null) { throw QueryException.selectionObjectCannotBeNull(this); } setSelectionKey(null); // Check if the query needs to be unprepared. if ((this.selectionObject == null) || (this.selectionObject.getClass() != selectionObject.getClass())) { setIsPrepared(false); } setReferenceClass(selectionObject.getClass()); this.selectionObject = selectionObject; }
/** * PUBLIC: * If the PKs were retrieved with the attributes then this method can be used to read the real object from the database. */ public Object readObject(Class javaClass, Session session) { if (getPrimaryKeyValues() == null) { throw QueryException.reportQueryResultWithoutPKs(this); } ReadObjectQuery query = new ReadObjectQuery(javaClass); query.setSelectionKey(getPrimaryKeyValues()); return session.executeQuery(query); }
/** * INTERNAL: * Check if the object is invalid and refresh it. * This is used to ensure that no invalid objects are registered. */ public void checkInvalidObject(Object object, CacheKey cacheKey, ClassDescriptor descriptor) { if (!isNestedUnitOfWork() && (cacheKey.getObject() != null)) { CacheInvalidationPolicy cachePolicy = descriptor.getCacheInvalidationPolicy(); // BUG#6671556 refresh invalid objects when accessed in the unit of work. if (cachePolicy.shouldRefreshInvalidObjectsInUnitOfWork() && cachePolicy.isInvalidated(cacheKey)) { ReadObjectQuery query = new ReadObjectQuery(); query.setReferenceClass(object.getClass()); query.setSelectionKey(cacheKey.getKey()); query.refreshIdentityMapResult(); query.setIsExecutionClone(true); parent.executeQuery(query); } } }
protected Object remoteExecute() { // Do a cache lookup. checkDescriptor(session); // As the selection object is transient, compute the key. if (getSelectionObject() != null) { // Must be checked separately as the expression and row is not yet set. setSelectionKey(getDescriptor().getObjectBuilder().extractPrimaryKeyFromObject(getSelectionObject(), session)); } Object cacheHit = checkEarlyReturn(getSession(), getTranslationRow()); if ((cacheHit != null) || shouldCheckCacheOnly()) { return cacheHit; } return super.remoteExecute(); }
/** * INTERNAL: * This method is used to load a relationship from a list of PKs. * This list may be available if the relationship has been cached. */ public Object valueFromPKList(Object[] pks, AbstractSession session) { Vector pk = null; if (pks[0] == null) return null; if (getReferenceDescriptor().hasCMPPolicy()) { pk = getReferenceDescriptor().getCMPPolicy().createPkVectorFromKey(pks[0], session); } else { pk = (Vector) pks[0]; } ReadObjectQuery query = new ReadObjectQuery(); query.setReferenceClass(getReferenceClass()); query.setSelectionKey(pk); query.setIsExecutionClone(true); return session.executeQuery(query); }
query.setSelectionKey(primaryKeyValues); query.conformResultsInUnitOfWork(); query.setIsExecutionClone(true);
/** * INTERNAL: * This method is used to load a relationship from a list of PKs. This list * may be available if the relationship has been cached. */ public Object valueFromPKList(Object[] pks, AbstractSession session){ ContainerPolicy cp = this.containerPolicy; Object result = cp.containerInstance(pks.length); for (int index = 0; index < pks.length; ++index){ Vector pk = null; if (getReferenceDescriptor().hasCMPPolicy()){ pk = getReferenceDescriptor().getCMPPolicy().createPkVectorFromKey(pks[index], session); }else{ pk = (Vector)pks[index]; } ReadObjectQuery query = new ReadObjectQuery(); query.setReferenceClass(getReferenceClass()); query.setSelectionKey(pk); query.setIsExecutionClone(true); cp.addInto(session.executeQuery(query), result, session); } return result; }
query.setShouldUseWrapperPolicy(false); query.setReferenceClass(getClassType(session)); query.setSelectionKey(getPrimaryKeys()); attributeValue = session.executeQuery(query);
/** * INTERNAL: * Set the properties needed to be cascaded into the custom query inlucding the translation row. */ protected void prepareCustomQuery(DatabaseQuery customQuery) { ReadObjectQuery customReadQuery = (ReadObjectQuery)customQuery; customReadQuery.setShouldRefreshIdentityMapResult(shouldRefreshIdentityMapResult()); customReadQuery.setCascadePolicy(getCascadePolicy()); customReadQuery.setShouldMaintainCache(shouldMaintainCache()); customReadQuery.setShouldUseWrapperPolicy(shouldUseWrapperPolicy()); // CR... was missing some values, execution could cause infinite loop. customReadQuery.setQueryId(getQueryId()); customReadQuery.setExecutionTime(getExecutionTime()); customReadQuery.setShouldLoadResultIntoSelectionObject(shouldLoadResultIntoSelectionObject()); AbstractRecord primaryKeyRow; if (getSelectionObject() != null) { // CR#... Must also set the selection object as may be loading into the object (refresh) customReadQuery.setSelectionObject(getSelectionObject()); // The translation/primary key row will be set in prepareForExecution. } else if (getSelectionKey() != null) { customReadQuery.setSelectionKey(getSelectionKey()); } else { // The primary key row must be used. primaryKeyRow = customQuery.getDescriptor().getObjectBuilder().extractPrimaryKeyRowFromExpression(getSelectionCriteria(), customQuery.getTranslationRow(), customReadQuery.getSession()); customReadQuery.setTranslationRow(primaryKeyRow); } }