/** * ADVANCED: * Configure the mapping to use a container policy. * The policy manages the access to the collection. */ public void setContainerPolicy(ContainerPolicy containerPolicy) { this.containerPolicy = containerPolicy; ((ReadAllQuery)getSelectionQuery()).setContainerPolicy(containerPolicy); }
/** * PUBLIC: * Provide order support for queryKeyName in ascending order */ public void addAscendingOrdering(String queryKeyName) { if (queryKeyName == null) { return; } ((ReadAllQuery)getSelectionQuery()).addAscendingOrdering(queryKeyName); }
/** * PUBLIC: * Provide order support for queryKeyName in descending order. */ public void addDescendingOrdering(String queryKeyName) { if (queryKeyName == null) { return; } ((ReadAllQuery)getSelectionQuery()).addDescendingOrdering(queryKeyName); }
/** * PUBLIC: * Set the name of the session to execute the mapping's queries under. * This can be used by the session broker to override the default session * to be used for the target class. */ public void setSessionName(String name) { getDeleteAllQuery().setSessionName(name); getSelectionQuery().setSessionName(name); }
/** * PUBLIC: * Provide order support for queryKeyName in ascending order. * Called from the EJBAnnotationsProcessor when an @OrderBy on an * aggregate is found. */ public void addAggregateOrderBy(String aggregateName, String queryKeyName, boolean isDescending) { this.hasOrderBy = true; ReadAllQuery readAllQuery = (ReadAllQuery) getSelectionQuery(); ExpressionBuilder builder = readAllQuery.getExpressionBuilder(); Expression expression = builder.get(aggregateName).get(queryKeyName).toUpperCase(); if (isDescending) { readAllQuery.addOrdering(expression.descending()); } else { readAllQuery.addOrdering(expression.ascending()); } }
/** * INTERNAL: * Initialize the state of mapping. */ public void initialize(AbstractSession session) throws DescriptorException { super.initialize(session); setFields(collectFields()); getContainerPolicy().prepare(getSelectionQuery(), session); // Check that the container policy is correct for the collection type. if ((!usesIndirection()) && (!getAttributeAccessor().getAttributeClass().isAssignableFrom(getContainerPolicy().getContainerClass()))) { throw DescriptorException.incorrectCollectionPolicy(this, getAttributeAccessor().getAttributeClass(), getContainerPolicy().getContainerClass()); } }
/** * INTERNAL: * All the privately owned parts are read */ protected Object readPrivateOwnedForObject(ObjectLevelModifyQuery modifyQuery) throws DatabaseException { if (modifyQuery.getSession().isUnitOfWork()) { return getRealCollectionAttributeValueFromObject(modifyQuery.getBackupClone(), modifyQuery.getSession()); } else { // cr 3819 prepareTranslationRow(modifyQuery.getTranslationRow(), modifyQuery.getObject(), modifyQuery.getSession()); return modifyQuery.getSession().executeQuery(getSelectionQuery(), modifyQuery.getTranslationRow()); } }
/** * INTERNAL: * Checks if object is deleted from the database or not. */ public boolean verifyDelete(Object object, AbstractSession session) throws DatabaseException { // Row is built for translation if (isReadOnly()) { return true; } if (isPrivateOwned()) { Object objects = getRealCollectionAttributeValueFromObject(object, session); ContainerPolicy containerPolicy = getContainerPolicy(); for (Object iter = containerPolicy.iteratorFor(objects); containerPolicy.hasNext(iter);) { if (!session.verifyDelete(containerPolicy.next(iter, session))) { return false; } } } AbstractRecord row = getDescriptor().getObjectBuilder().buildRowForTranslation(object, session); //cr 3819 added the line below to fix the translationtable to ensure that it // contains the required values prepareTranslationRow(row, object, session); Object value = session.executeQuery(getSelectionQuery(), row); return getContainerPolicy().isEmpty(value); }