protected void logCascadeMapping(Association grailsProperty, String cascadeStrategy, PersistentEntity referenced) { if (LOG.isDebugEnabled() & referenced != null) { String assType = getAssociationDescription(grailsProperty); LOG.debug("Mapping cascade strategy for " + assType + " property " + grailsProperty.getOwner().getName() + "." + grailsProperty.getName() + " referencing type [" + referenced.getJavaClass().getName() + "] -> [CASCADE: " + cascadeStrategy + "]"); } }
@Override public String toString() { return getOwner().getName() + "->" + getName(); }
/** * Binds a many-to-many relationship. A many-to-many consists of * - a key (a DependentValue) * - an element * * The element is a ManyToOne from the association table to the target entity * * @param property The grails property * @param element The ManyToOne element * @param mappings The mappings */ protected void bindManyToMany(Association property, ManyToOne element, Mappings mappings, String sessionFactoryBeanName) { bindManyToOne(property, element, EMPTY_PATH, mappings, sessionFactoryBeanName); element.setReferencedEntityName(property.getOwner().getName()); }
public static String associationtoString(String desc, Association a) { return desc + a.getOwner().getName() + "-> " + a.getName() + " ->" + a.getAssociatedEntity().getName(); }
protected void configureOwningSide(Association association) { PersistentEntity associatedEntity = association.getAssociatedEntity(); if(associatedEntity == null) { association.setOwningSide(true); } else { if (association.isBidirectional()) { if (associatedEntity.isOwningEntity(association.getOwner())) { association.setOwningSide(true); } } else { if (association instanceof OneToOne) { if (associatedEntity.isOwningEntity(association.getOwner())) association.setOwningSide(true); } else if (!(association instanceof Basic)) { if (associatedEntity.isOwningEntity(association.getOwner())) { association.setOwningSide(true); } else { association.setOwningSide(false); } } } } }
/** * @return The inverse side or null if the association is not bidirectional */ public Association getInverseSide() { final PersistentProperty associatedProperty = associatedEntity.getPropertyByName(referencedPropertyName); if (associatedProperty == null) return null; if (associatedProperty instanceof Association) { return (Association) associatedProperty; } throw new IllegalMappingException("The inverse side [" + associatedEntity.getName() + "." + associatedProperty.getName() + "] of the association [" + getOwner().getName() + "." + getName() + "] is not valid. Associations can only map to other entities and collection types."); }
PersistentEntity refDomainClass = property instanceof ManyToMany ? property.getOwner() : property.getAssociatedEntity(); Mapping mapping = getMapping(refDomainClass); boolean isComposite = hasCompositeIdentifier(mapping);
protected void bindOneToOne(final org.grails.datastore.mapping.model.types.OneToOne property, OneToOne oneToOne, String path, String sessionFactoryBeanName) { PropertyConfig config = getPropertyConfig(property); final Association otherSide = property.getInverseSide(); final boolean hasOne = isHasOne(otherSide); oneToOne.setConstrained(hasOne); oneToOne.setForeignKeyType(oneToOne.isConstrained() ? ForeignKeyDirection.FOREIGN_KEY_FROM_PARENT : ForeignKeyDirection.FOREIGN_KEY_TO_PARENT); oneToOne.setAlternateUniqueKey(true); if (config != null && config.getFetchMode() != null) { oneToOne.setFetchMode(config.getFetchMode()); } else { oneToOne.setFetchMode(FetchMode.DEFAULT); } oneToOne.setReferencedEntityName(otherSide.getOwner().getName()); oneToOne.setPropertyName(property.getName()); bindOneToOneInternal(property, oneToOne, path); if (hasOne) { PropertyConfig pc = getPropertyConfig(property); bindSimpleValue(property, oneToOne, path, pc, sessionFactoryBeanName); } else { oneToOne.setReferencedPropertyName(otherSide.getName()); } }
Association inverseSide = association.getInverseSide(); if (inverseSide != null) { EntityAccess inverseAccess = createEntityAccess(inverseSide.getOwner(), associatedObject); inverseAccess.setProperty(inverseSide.getName(), obj);