/** * @return Whether this association is lazy */ public boolean isLazy() { return getFetchStrategy() == FetchType.EAGER && getMapping().getMappedForm().isLazy(); }
public String getTypeName(ToMany property) { return binder.getTypeName(property, binder.getPropertyConfig(property), getMapping(property.getOwner())); } }
protected boolean shouldBindCollectionWithForeignKey(ToMany property) { return ((property instanceof org.grails.datastore.mapping.model.types.OneToMany) && property.isBidirectional() || !shouldCollectionBindWithJoinColumn(property)) && !Map.class.isAssignableFrom(property.getType()) && !(property instanceof ManyToMany) && !(property instanceof Basic); }
if (!property.isBidirectional() && (property instanceof org.grails.datastore.mapping.model.types.OneToMany)) { throw new DatastoreConfigurationException("Default sort for associations ["+property.getOwner().getName()+"->" + property.getName() + "] are not supported with unidirectional one to many relationships."); PersistentEntity referenced = property.getAssociatedEntity(); if (referenced != null) { PersistentProperty propertyToSortBy = referenced.getPropertyByName(propConfig.getSort()); String associatedClassName = property.getAssociatedEntity().getName(); PersistentEntity referenced = property.getAssociatedEntity(); if (collection.isOneToMany()) { if (property.isBidirectional()) { Association otherSide = property.getInverseSide(); if ((otherSide instanceof org.grails.datastore.mapping.model.types.ToOne) && shouldBindCollectionWithForeignKey(property)) { linkBidirectionalOneToMany(collection, associatedClass, key, otherSide); } else if ((otherSide instanceof ManyToMany) || Map.class.isAssignableFrom(property.getType())) { bindDependentKeyValue(property, key, mappings, sessionFactoryBeanName); PersistentProperty otherSide = property.getInverseSide(); if (property.isBidirectional()) { if (LOG.isDebugEnabled()) LOG.debug("[GrailsDomainBinder] Mapping other side " + otherSide.getOwner().getName() + "." + otherSide.getName() + " -> " + collection.getCollectionTable().getName() + " as ManyToOne"); collection.setElement(element); bindCollectionForPropertyConfig(collection, propConfig); if (property.isCircular()) {
final boolean isManyToMany = property instanceof ManyToMany; if (isManyToMany && !property.isOwningSide()) { throw new MappingException("Invalid association [" + property + "]. List collection types only supported on the owning side of a many-to-many relationship."); v.createForeignKey(); if (property.isBidirectional()) { Mapping m = getMapping(mappedClass); boolean compositeIdProperty = isCompositeIdProperty(m, property.getInverseSide()); if (!compositeIdProperty) { Backref prop = new Backref(); final PersistentEntity owner = property.getOwner(); prop.setEntityName(owner.getName()); prop.setName(UNDERSCORE + addUnderscore(owner.getJavaClass().getSimpleName(), property.getName()) + "Backref"); prop.setSelectable(false); prop.setUpdateable(false); if (!property.isCircular()) { value.setNullable(false); ib.setName(UNDERSCORE + property.getName() + "IndexBackref"); ib.setUpdateable(false); ib.setSelectable(false);
NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName); String propertyColumnName = namingStrategy.propertyToColumnName(property.getName()); String left = getTableName(property.getOwner(), sessionFactoryBeanName); if (Map.class.isAssignableFrom(property.getType())) { if (hasJoinTableMapping) { return jt.getName(); String right = getTableName(property.getAssociatedEntity(), sessionFactoryBeanName); return jt.getName(); if (property.isOwningSide()) { return addUnderscore(left, propertyColumnName); if (property.isOwningSide()) { return addUnderscore(left, right);
addUnderscore(namingStrategy.propertyToColumnName(property.getName()), namingStrategy.propertyToColumnName(className)); String typeName = getTypeName(property, config, getMapping(property.getOwner())); if (typeName == null) { Type type = mappings.getTypeResolver().basic(className); String domainName = property.getOwner().getName(); throw new MappingException("Missing type or column for column["+columnName+"] on domain["+domainName+"] referencing["+className+"]"); final PersistentEntity domainClass = property.getAssociatedEntity();
collection.setRole(qualify(property.getOwner().getName(), propertyName)); bindCollectionTable(property, mappings, collection, owner.getTable(), sessionFactoryBeanName); if (!property.isOwningSide()) { collection.setInverse(true);
@Override public boolean isNullable() { if(isCircular() && !isBidirectional()) { return true; } else { return super.isNullable(); } } }
/** * @param property * @param manyToOne */ protected void bindUnidirectionalOneToManyInverseValues(ToMany property, ManyToOne manyToOne) { PropertyConfig config = getPropertyConfig(property); if (config == null) { manyToOne.setLazy(true); } else { manyToOne.setIgnoreNotFound(config.getIgnoreNotFound()); final FetchMode fetch = config.getFetchMode(); if(!fetch.equals(FetchMode.JOIN) && !fetch.equals(FetchMode.EAGER)) { manyToOne.setLazy(true); } final Boolean lazy = config.getLazy(); if(lazy != null) { manyToOne.setLazy(lazy); } } // set referenced entity manyToOne.setReferencedEntityName(property.getAssociatedEntity().getName()); }
map.setElement(elt); String typeName = getTypeName(property,getPropertyConfig(property), getMapping(property.getOwner())); if (typeName == null ) {