/** * INTERNAL: * Return the container policy for the mapping. */ protected ContainerPolicy getContainerPolicy() { if (this.containerPolicy == null) { this.containerPolicy = getCollectionMapping().getContainerPolicy(); } return this.containerPolicy; }
/** * INTERNAL: * Returns whether the mapping has listOrderField. */ protected boolean usesListOrderField() { if(this.valueHolder instanceof UnitOfWorkValueHolder) { return ((CollectionMapping)((UnitOfWorkValueHolder)this.valueHolder).getMapping()).getListOrderField() != null; } else { return false; } }
/** * PUBLIC: * If transparent indirection is used, a special map will be placed in the source * object's attribute. * Fetching of the contents of the map from the database will be delayed * until absolutely necessary. (Any message sent to the map will cause * the contents to be faulted in from the database.) * This can result in rather significant performance gains, without having to change * the source object's attribute from Map (or Map or Hashtable) to * ValueHolderInterface.<p> * The key used in the Map is the value returned by a call to the zero parameter * method named methodName. The method should be a zero argument method implemented (or * inherited) by the value to be inserted into the Map. */ public void useTransparentMap(String methodName) { setIndirectionPolicy(new TransparentIndirectionPolicy()); useMapClass(ClassConstants.IndirectMap_Class, methodName); ContainerPolicy policy = ContainerPolicy.buildPolicyFor(Hashtable.class); policy.setKeyName(methodName, getReferenceClass()); setSelectionQueryContainerPolicy(policy); }
/** * PUBLIC: * Provide order support for queryKeyName in descending or ascending order. * Called from the jpa metadata processing of an order by value. */ public void addOrderBy(String queryKeyName, boolean isDescending) { if (isDescending) { addDescendingOrdering(queryKeyName); } else { addAscendingOrdering(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); } /**
/** * INTERNAL: * Not sure were this is used, MW? */ public void useMapClassName(String concreteClassName, String methodName) { // the reference class has to be specified before coming here if (getReferenceClassName() == null) { throw DescriptorException.referenceClassNotSpecified(this); } MapContainerPolicy policy = new MapContainerPolicy(concreteClassName); policy.setKeyName(methodName, getReferenceClass().getName()); setContainerPolicy(policy); }
/** * INTERNAL: * Checks if object is deleted from the database or not. */ @Override public boolean verifyDelete(Object object, AbstractSession session) throws DatabaseException { // Row is built for translation if (isReadOnly()) { return true; } if (isPrivateOwned() || isCascadeRemove()) { Object objects = getRealCollectionAttributeValueFromObject(object, session); ContainerPolicy containerPolicy = this.containerPolicy; 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, getDescriptor(), session); Object value = session.executeQuery(getSelectionQuery(), row); return this.containerPolicy.isEmpty(value); }
ClassDescriptor elementDesc = mapping.getContainerPolicy().getElementDescriptor(); if (elementDesc != null && !(mapping.isMapKeyMapping() || mapping.isDirectMapMapping())) { if(mapping.isDirectCollectionMapping() || mapping.isAbstractCompositeDirectCollectionMapping() || mapping.isDirectCollectionMapping()) { attributeClass = mapping.getAttributeClassification(); } else if(mapping.isMapKeyMapping()) { ContainerPolicy policy = mapping.getContainerPolicy(); if (policy.isMapPolicy()) { MapContainerPolicy mapPolicy = (MapContainerPolicy) mapping.getContainerPolicy(); attributeClass = mapPolicy.getElementClass(); } else { } else if (mapping.isManyToManyMapping() || mapping.isOneToManyMapping()) { attributeClass = mapping.getReferenceClass(); } else if (mapping.isAggregateCollectionMapping()) {
Object cloneAttribute = getAttributeValueFromObject(object); if ((cloneAttribute == null) || (!this.indirectionPolicy.objectIsInstantiated(cloneAttribute))) { if (cloneAttribute instanceof IndirectCollection) { if (collection.hasDeferredChanges()) { Iterator iterator = collection.getAddedElements().iterator(); boolean cascade = isCascadePersist(); while (iterator.hasNext()) { Object nextObject = iterator.next(); if (isCandidateForPrivateOwnedRemoval()){ uow.removePrivateOwnedObject(this, nextObject); Object cloneObjectCollection = getRealCollectionAttributeValueFromObject(object, uow); Object iterator = containerPolicy.iteratorFor(cloneObjectCollection); boolean cascade = isCascadePersist(); while (containerPolicy.hasNext(iterator)) { Object wrappedObject = containerPolicy.nextEntry(iterator, uow); Object nextObject = containerPolicy.unwrapIteratorResult(wrappedObject); if (isCandidateForPrivateOwnedRemoval()) { uow.removePrivateOwnedObject(this, nextObject);
collection.setReadOnly(collectionMapping.isReadOnly()); collection.setSavedWithParent(collectionMapping.isCascadePersist()); collection.setDeletedWithParent(collectionMapping.isCascadeRemove()); collection.setLoadedAtParentLoadTime(collectionMapping.isCascadeRefresh() && !collectionMapping.isLazy()); collection.setLoadedDynamicallyUponUse(collectionMapping.isCascadeRefresh() && collectionMapping.isLazy()); } else { PluralAttributeImpl<?, ?, ?> coll = (PluralAttributeImpl<?, ?, ?>) cd; CollectionMapping collectionMapping = coll.getCollectionMapping(); if (collectionMapping.getSelectionQuery() instanceof ObjectLevelReadQuery) { ObjectLevelReadQuery readQuery = (ObjectLevelReadQuery) collectionMapping.getSelectionQuery(); List<Expression> orderByExpressions = readQuery.getOrderByExpressions(); for (Expression expression : orderByExpressions) {
protected void objectOrderChangedDuringUpdate(WriteObjectQuery query, Object orderChangedObject, int orderIndex) { prepareTranslationRow(query.getTranslationRow(), query.getObject(), query.getSession()); AbstractRecord databaseRow = new DatabaseRecord(); // Extract target field and its value. Construct insert statement and execute it List<DatabaseField> targetPrimaryKeyFields = getTargetPrimaryKeyFields(); int size = targetPrimaryKeyFields.size(); for (int index = 0; index < size; index++) { DatabaseField targetPrimaryKey = targetPrimaryKeyFields.get(index); Object targetKeyValue = getReferenceDescriptor().getObjectBuilder().extractValueFromObjectForField(orderChangedObject, targetPrimaryKey, query.getSession()); databaseRow.put(targetPrimaryKey, targetKeyValue); } databaseRow.put(listOrderField, orderIndex); query.getSession().executeQuery(changeOrderTargetQuery, databaseRow); }
/** * PUBLIC: * Provide order support for queryKeyName in descending order. */ public void addDescendingOrdering(String queryKeyName) { this.hasOrderBy = true; if (queryKeyName == null) { return; } ((ReadAllQuery)getSelectionQuery()).addDescendingOrdering(queryKeyName); }
/** * 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.getDescriptor(), modifyQuery.getSession()); return modifyQuery.getSession().executeQuery(getSelectionQuery(), modifyQuery.getTranslationRow()); } }
Class collectionClass = collectionMapping.getContainerPolicy().getContainerClass(); if (collectionMapping.getReferenceClass() != null) { collectionName = collectionMapping.getReferenceClass().getSimpleName(); if ((collectionName == null) && (collectionMapping.getAttributeClassification() != null)) { collectionName = collectionMapping.getAttributeClassification().getSimpleName(); if (collectionMapping.getContainerPolicy().isMapPolicy()) { String mapKeyType = ((MapContainerPolicy) collectionMapping.getContainerPolicy()).getKeyType().getClass().getSimpleName(); target = collectionType + "<" + mapKeyType + ", " + collectionName + ">"; } else {
/** * INTERNAL: * Cascade perform delete through mappings that require the cascade */ public void cascadePerformRemoveIfRequired(Object object, UnitOfWorkImpl uow, Map visitedObjects) { if (!isCascadeRemove()) { return; } Object cloneAttribute = getAttributeValueFromObject(object); if (cloneAttribute == null) { return; } ContainerPolicy cp = this.containerPolicy; Object cloneObjectCollection = null; cloneObjectCollection = getRealCollectionAttributeValueFromObject(object, uow); Object cloneIter = cp.iteratorFor(cloneObjectCollection); while (cp.hasNext(cloneIter)) { Object wrappedObject = cp.nextEntry(cloneIter, uow); Object nextObject = cp.unwrapIteratorResult(wrappedObject); if ((nextObject != null) && (!visitedObjects.containsKey(nextObject))) { visitedObjects.put(nextObject, nextObject); uow.performRemove(nextObject, visitedObjects); cp.cascadePerformRemoveIfRequired(wrappedObject, uow, visitedObjects); } } }
if(collectionMapping.getListOrderField() != null) { joinRow.put(collectionMapping.getListOrderField(), null); collectionMapping.getContainerPolicy().addFieldsForMapKey(joinRow);
/** * INTERNAL: * This method is used to calculate the differences between two collections. */ public void compareCollectionsForChange(Object oldCollection, Object newCollection, ChangeRecord changeRecord, AbstractSession session) { this.containerPolicy.compareCollectionsForChange(oldCollection, newCollection, (CollectionChangeRecord) changeRecord, session, getReferenceDescriptor()); }
/** * Force instantiation of the load group. */ @Override public void load(final Object object, AttributeItem item, final AbstractSession session, final boolean fromFetchGroup) { instantiateAttribute(object, session); if (item.getGroup() != null && (!fromFetchGroup || session.isUnitOfWork()) ){ //if UOW make sure the nested attributes are loaded as the clones will not be instantiated Object value = getRealAttributeValueFromObject(object, session); ContainerPolicy cp = this.containerPolicy; for (Object iterator = cp.iteratorFor(value); cp.hasNext(iterator);) { Object wrappedObject = cp.nextEntry(iterator, session); Object nestedObject = cp.unwrapIteratorResult(wrappedObject); session.load(nestedObject, item.getGroup(nestedObject.getClass()), getReferenceDescriptor(), fromFetchGroup); } } }
/** * INTERNAL: * Verifies listOrderField's table, if none found sets the default one. * Precondition: listOrderField != null. */ protected void buildListOrderField() { if(this.listOrderField.hasTableName()) { if(!this.getReferenceDescriptor().getDefaultTable().equals(this.listOrderField.getTable())) { throw DescriptorException.listOrderFieldTableIsWrong(this.getDescriptor(), this, this.listOrderField.getTable(), this.getReferenceDescriptor().getDefaultTable()); } } else { this.listOrderField.setTable(this.getReferenceDescriptor().getDefaultTable()); } this.listOrderField = this.getReferenceDescriptor().buildField(this.listOrderField); }
/** * PUBLIC: * Configure the mapping to use an instance of the specified container class * to hold the target objects. The key used to index a value in the * <code>Map</code> is the value returned by a call to the specified * zero-argument method. * The method must be implemented by the class (or a superclass) of any * value to be inserted into the <code>Map</code>. * <p>The container class must implement (directly or indirectly) the * <code>java.util.Map</code> interface. * <p>To facilitate resolving the method, the mapping's referenceClass * must set before calling this method. */ public void useMapClass(Class concreteClass, String keyName) { // the reference class has to be specified before coming here if (getReferenceClassName() == null) { throw DescriptorException.referenceClassNotSpecified(this); } ContainerPolicy policy = ContainerPolicy.buildPolicyFor(concreteClass); policy.setKeyName(keyName, getReferenceClassName()); setContainerPolicy(policy); }