protected void bindOneToMany(org.grails.datastore.mapping.model.types.OneToMany currentGrailsProp, OneToMany one, Mappings mappings) { one.setReferencedEntityName(currentGrailsProp.getAssociatedEntity().getName()); one.setIgnoreNotFound(true); }
public void run() { updateToManyIndices(e, updateId, toManyKeys, false); if (doesRequirePropertyIndexing()) { toIndex.put(persistentEntity.getIdentity(), updateId); updatePropertyIndices(updateId, toIndex, toUnindex); } for (OneToMany inverseCollection : inverseCollectionUpdates.keySet()) { final Serializable primaryKey = inverseCollectionUpdates.get(inverseCollection); final NativeEntryEntityPersister inversePersister = (NativeEntryEntityPersister) session.getPersister(inverseCollection.getOwner()); final AssociationIndexer associationIndexer = inversePersister.getAssociationIndexer(e, inverseCollection); associationIndexer.index(primaryKey, updateId); } } };
/** * Delete collections before owner delete. */ protected void cascadeBeforeDelete(PersistentEntity persistentEntity, EntityAccess entityAccess, K key, Object instance) { List<PersistentProperty> props = persistentEntity.getPersistentProperties(); for (PersistentProperty prop : props) { String propertyKey = getPropertyKey(prop); if (prop instanceof OneToMany) { OneToMany oneToMany = (OneToMany)prop; if (oneToMany.isOwningSide() && oneToMany.doesCascade(CascadeType.REMOVE)) { if (Collection.class.isAssignableFrom(oneToMany.getType())) { cascadeDeleteCollection(entityAccess, oneToMany); } } } else if (prop instanceof ManyToMany) { ManyToMany manyToMany = (ManyToMany)prop; if (manyToMany.isOwningSide() && manyToMany.doesCascade(CascadeType.REMOVE)) { Object propValue = entityAccess.getProperty(manyToMany.getName()); if (Collection.class.isAssignableFrom(manyToMany.getType())) { cascadeDeleteCollection(entityAccess, manyToMany); } } } } }
@Override public boolean isNullable() { if(isCircular() && !isBidirectional()) { return true; } else { return super.isNullable(); } } }
/** * Binds a unidirectional one-to-many creating a psuedo back reference property in the process. * * @param property * @param mappings * @param collection */ protected void bindUnidirectionalOneToMany(org.grails.datastore.mapping.model.types.OneToMany property, Mappings mappings, Collection collection) { Value v = collection.getElement(); v.createForeignKey(); String entityName; if (v instanceof ManyToOne) { ManyToOne manyToOne = (ManyToOne) v; entityName = manyToOne.getReferencedEntityName(); } else { entityName = ((OneToMany) v).getReferencedEntityName(); } collection.setInverse(false); PersistentClass referenced = mappings.getClass(entityName); Backref prop = new Backref(); PersistentEntity owner = property.getOwner(); prop.setEntityName(owner.getName()); prop.setName(UNDERSCORE + addUnderscore(owner.getJavaClass().getSimpleName(), property.getName()) + "Backref"); prop.setUpdateable(false); prop.setInsertable(true); prop.setCollectionRole(collection.getRole()); prop.setValue(collection.getKey()); prop.setOptional(true); referenced.addProperty(prop); }
final OneToMany oneToMany = (OneToMany) prop; final Object propValue = entityAccess.getProperty(oneToMany.getName()); if (propValue instanceof Collection) { Collection associatedObjects = (Collection) propValue; if (isInitializedCollection(associatedObjects)) { PersistentEntity associatedEntity = oneToMany.getAssociatedEntity(); if(associatedEntity != null) { EntityPersister associationPersister = (EntityPersister) session.getPersister(associatedEntity); Class associationType = associatedEntity.getJavaClass(); persistentCollection = getPersistentCollection(associatedObjects, associationType); entityAccess.setPropertyNoConversion(oneToMany.getName(), persistentCollection); persistentCollection.markDirty(); newCollection = true; toManyKeys.put(oneToMany, keys); if (newCollection ) { entityAccess.setProperty(oneToMany.getName(), associatedObjects);
final OneToMany oneToMany = (OneToMany) persistentProperty; final Object propValue = embeddedEntityAccess.getProperty(oneToMany.getName()); if (propValue instanceof Collection) { Collection associatedObjects = (Collection) propValue;
if (oneToMany.isOwningSide() && oneToMany.doesCascade(CascadeType.REMOVE)) { if (Collection.class.isAssignableFrom(oneToMany.getType())) { cascadeDeleteCollection(entityAccess, oneToMany);