/** * Build a selection query for the primary key values. */ protected ReadObjectQuery getReadObjectQuery(Class referenceClass, Object primaryKey, Map properties) { ReadObjectQuery query = getReadObjectQuery(properties); query.setReferenceClass(referenceClass); query.setSelectionId(primaryKey); return query; }
/** * 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); } setSelectionId(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: * 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); } setSelectionId(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 (getId() == null) { throw QueryException.reportQueryResultWithoutPKs(this); } ReadObjectQuery query = new ReadObjectQuery(javaClass); query.setSelectionId(getId()); return session.executeQuery(query); }
/** * 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 (getId() == null) { throw QueryException.reportQueryResultWithoutPKs(this); } ReadObjectQuery query = new ReadObjectQuery(javaClass); query.setSelectionId(getId()); 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 checkAndRefreshInvalidObject(Object object, CacheKey cacheKey, ClassDescriptor descriptor) { if (isConsideredInvalid(object, cacheKey, descriptor)) { ReadObjectQuery query = new ReadObjectQuery(); query.setReferenceClass(object.getClass()); query.setSelectionId(cacheKey.getKey()); query.refreshIdentityMapResult(); query.setIsExecutionClone(true); this.executeQuery(query); } }
/** * 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. */ @Override public Object valueFromPKList(Object[] pks, AbstractRecord foreignKeys, AbstractSession session) { if (pks.length == 0 || pks[0] == null) return null; ReadObjectQuery query = new ReadObjectQuery(); query.setReferenceClass(getReferenceClass()); query.setSelectionId(pks[0]); query.setIsExecutionClone(true); query.setSession(session); return session.executeQuery(query); }
/** * 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. */ @Override public Object valueFromPKList(Object[] pks, AbstractRecord foreignKeys, AbstractSession session) { if (pks.length == 0 || pks[0] == null) return null; ReadObjectQuery query = new ReadObjectQuery(); query.setReferenceClass(getReferenceClass()); query.setSelectionId(pks[0]); query.setIsExecutionClone(true); query.setSession(session); return session.executeQuery(query); }
ReadObjectQuery query = new ReadObjectQuery(); query.setReferenceClass(descriptor.getJavaClass()); query.setSelectionId(primaryKey); query.checkCacheOnly(); Object cachedEntity = session.executeQuery(query); query.setSelectionId(primaryKey);
/** * INTERNAL: * Check if the object is invalid and refresh it. * This is used to ensure that no invalid objects are registered. */ public void checkAndRefreshInvalidObject(Object object, CacheKey cacheKey, ClassDescriptor descriptor) { if (isConsideredInvalid(object, cacheKey, descriptor)) { // cuba begin: always load refreshed object Boolean prevSoftDeletion = org.eclipse.persistence.internal.helper.CubaUtil.setSoftDeletion(false); try { ReadObjectQuery query = new ReadObjectQuery(); query.setReferenceClass(object.getClass()); query.setSelectionId(cacheKey.getKey()); query.refreshIdentityMapResult(); query.setIsExecutionClone(true); this.executeQuery(query); } finally { org.eclipse.persistence.internal.helper.CubaUtil.setSoftDeletion(prevSoftDeletion); } // ReadObjectQuery query = new ReadObjectQuery(); // query.setReferenceClass(object.getClass()); // query.setSelectionId(cacheKey.getKey()); // query.refreshIdentityMapResult(); // query.setIsExecutionClone(true); // this.executeQuery(query); // cuba end } }
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. setSelectionId(getDescriptor().getObjectBuilder().extractPrimaryKeyFromObject(getSelectionObject(), session)); } Object cacheHit = checkEarlyReturn(getSession(), getTranslationRow()); if ((cacheHit != null) || shouldCheckCacheOnly()) { if (cacheHit == InvalidObject.instance) { return null; } return cacheHit; } return super.remoteExecute(); }
query.setSelectionId(primaryKey); query.conformResultsInUnitOfWork(); query.setIsExecutionClone(true);
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. setSelectionId(getDescriptor().getObjectBuilder().extractPrimaryKeyFromObject(getSelectionObject(), session)); } Object cacheHit = checkEarlyReturn(getSession(), getTranslationRow()); if ((cacheHit != null) || shouldCheckCacheOnly()) { if (cacheHit == InvalidObject.instance) { return null; } return cacheHit; } return super.remoteExecute(); }
query.setSelectionId(primaryKey); query.conformResultsInUnitOfWork(); query.setIsExecutionClone(true);
query.setShouldUseWrapperPolicy(false); query.setReferenceClass(getClassType(targetSession)); query.setSelectionId(getId()); attributeValue = targetSession.executeQuery(query);
query.setShouldUseWrapperPolicy(false); query.setReferenceClass(getClassType(targetSession)); query.setSelectionId(getId()); attributeValue = targetSession.executeQuery(query);
query.setSelectionId(selectionKey);
query.setSelectionId(selectionKey);