/** INTERNAL: Clone the query. */ public Object clone() { ReadAllQuery cloneQuery = (ReadAllQuery) super.clone(); // Don't use setters as that will trigger unprepare cloneQuery.containerPolicy = getContainerPolicy().clone(cloneQuery); return cloneQuery; }
/** * INTERNAL: Return if the query is equal to the other. This is used to allow dynamic expression * query SQL to be cached. */ public boolean equals(Object object) { if (this == object) { return true; } if (!super.equals(object)) { return false; } ReadAllQuery query = (ReadAllQuery) object; if (!getContainerPolicy().equals(query.getContainerPolicy())) { return false; } return true; }
public void test() { ReadAllQuery query = new ReadAllQuery(Employee.class); query.dontMaintainCache(); query.addPartialAttribute("nonExistant"); try { getSession().executeQuery(query); } catch (QueryException exception) { if (exception.getErrorCode() == QueryException.SPECIFIED_PARTIAL_ATTRIBUTE_DOES_NOT_EXIST) { correctException = true; } else { correctException = false; throw exception; } } }
public void setup() { getSession().getIdentityMapAccessor().initializeIdentityMaps(); getAbstractSession().beginTransaction(); descriptor = getSession().getProject().getDescriptors().get(Employee.class); // Read Object readObjectQuery = descriptor.getQueryManager().getReadObjectQuery(); QueryRedirector redirector = new MethodBaseQueryRedirector(RedirectorOnDescriptorTest.class, "readObject"); ReadObjectQuery roq = new ReadObjectQuery(descriptor.getJavaClass()); roq.setRedirector(redirector); descriptor.getQueryManager().setReadObjectQuery(roq); // Read All readAllQuery = descriptor.getQueryManager().getReadAllQuery(); redirector = new MethodBaseQueryRedirector(RedirectorOnDescriptorTest.class, "readAll"); ReadAllQuery raq = new ReadAllQuery(descriptor.getJavaClass()); raq.setRedirector(redirector); descriptor.getQueryManager().setReadAllQuery(raq); // Delete Object deleteObjectQuery = descriptor.getQueryManager().getDeleteQuery(); redirector = new MethodBaseQueryRedirector(RedirectorOnDescriptorTest.class, "deleteObject"); DeleteObjectQuery doq = new DeleteObjectQuery(); doq.setRedirector(redirector); descriptor.getQueryManager().setDeleteQuery(doq); // Insert Object insertQuery = descriptor.getQueryManager().getInsertQuery(); redirector = new MethodBaseQueryRedirector(RedirectorOnDescriptorTest.class, "insertObject"); InsertObjectQuery ioq = new InsertObjectQuery(); ioq.setRedirector(redirector); descriptor.getQueryManager().setInsertQuery(ioq); // Update Object updateQuery = descriptor.getQueryManager().getUpdateQuery(); redirector = new MethodBaseQueryRedirector(RedirectorOnDescriptorTest.class, "updateObject"); UpdateObjectQuery uoq = new UpdateObjectQuery(); uoq.setRedirector(redirector); descriptor.getQueryManager().setUpdateQuery(uoq); }
/** INTERNAL: Set the properties needed to be cascaded into the custom query. */ protected void prepareCustomQuery(DatabaseQuery customQuery) { ReadAllQuery customReadQuery = (ReadAllQuery) customQuery; customReadQuery.setContainerPolicy(getContainerPolicy()); customReadQuery.setCascadePolicy(getCascadePolicy()); customReadQuery.setShouldRefreshIdentityMapResult(shouldRefreshIdentityMapResult()); customReadQuery.setShouldMaintainCache(shouldMaintainCache()); customReadQuery.setShouldUseWrapperPolicy(shouldUseWrapperPolicy()); }
/** * INTERNAL: Select all objects for an interface descriptor. This is accomplished by selecting for * all of the concrete classes and then merging the objects. * * @return Vector containing all objects. * @exception DatabaseException - an error has occurred on the database. */ public Object selectAllObjectsUsingMultipleTableSubclassRead(ReadAllQuery query) throws DatabaseException { org.eclipse.persistence.internal.queries.ContainerPolicy containerPolicy = query.getContainerPolicy(); Object objects = containerPolicy.containerInstance(1); for (Enumeration childDescriptors = getChildDescriptors().elements(); childDescriptors.hasMoreElements(); ) { ClassDescriptor descriptor = (ClassDescriptor) childDescriptors.nextElement(); objects = containerPolicy.concatenateContainers( objects, descriptor.getInterfacePolicy().selectAllObjects(query)); } return objects; }
/** * INTERNAL: Prepare the query from the prepared query. This allows a dynamic query to prepare * itself directly from a prepared query instance. This is used in the JPQL parse cache to allow * preparsed queries to be used to prepare dynamic queries. This only copies over properties that * are configured through JPQL. */ public void prepareFromQuery(DatabaseQuery query) { super.prepareFromQuery(query); if (query.isReadAllQuery()) { ReadAllQuery readQuery = (ReadAllQuery) query; this.containerPolicy = readQuery.containerPolicy; if (readQuery.hasHierarchicalExpressions()) { this.orderSiblingsByExpressions = readQuery.getOrderSiblingsByExpressions(); this.connectByExpression = readQuery.getConnectByExpression(); this.startWithExpression = readQuery.getStartWithExpression(); } if (readQuery.hasBatchReadAttributes()) { this.batchReadAttributeExpressions = readQuery.batchReadAttributeExpressions; this.batchReadMappingQueries = readQuery.batchReadMappingQueries; this.batchReadAttributes = readQuery.batchReadAttributes; } } }
/** INTERNAL: Select all objects for a concrete descriptor. */ protected Object selectAllObjects(ReadAllQuery query) { ReadAllQuery concreteQuery = (ReadAllQuery) query.deepClone(); concreteQuery.setReferenceClass(descriptor.getJavaClass()); concreteQuery.setDescriptor(descriptor); // Avoid cloning the query again ... concreteQuery.setIsExecutionClone(true); concreteQuery .getExpressionBuilder() .setQueryClassAndDescriptor(descriptor.getJavaClass(), descriptor); // Update the selection criteria if needed as well and don't lose // the translation row. if (concreteQuery.getQueryMechanism().getSelectionCriteria() != null) { // make sure query builder is used for the selection criteria as deepClone will create // two separate builders. concreteQuery.setSelectionCriteria( concreteQuery .getQueryMechanism() .getSelectionCriteria() .rebuildOn(concreteQuery.getExpressionBuilder())); return query.getSession().executeQuery(concreteQuery, query.getTranslationRow()); } return query.getSession().executeQuery(concreteQuery); }