/** * Checks whether a property is a unidirectional non-circular one-to-many * * @param property The property to check * @return true if it is unidirectional and a one-to-many */ protected boolean isUnidirectionalOneToMany(PersistentProperty property) { return ((property instanceof org.grails.datastore.mapping.model.types.OneToMany) && !((Association)property).isBidirectional()); }
protected boolean isBidirectionalManyToOne(PersistentProperty currentGrailsProp) { return ((currentGrailsProp instanceof org.grails.datastore.mapping.model.types.ManyToOne) && ((Association)currentGrailsProp).isBidirectional()); }
protected boolean isBidirectionalOneToManyMap(Association property) { return Map.class.isAssignableFrom(property.getType()) && property.isBidirectional(); }
protected boolean isBidirectionalManyToOneWithListMapping(PersistentProperty grailsProperty, Property prop) { if(grailsProperty instanceof Association) { Association association = (Association) grailsProperty; Association otherSide = association.getInverseSide(); return association.isBidirectional() && otherSide != null && prop.getValue() instanceof ManyToOne && List.class.isAssignableFrom(otherSide.getType()); } return false; }
if((this instanceof ManyToOne) && isBidirectional()) {
protected boolean canBindOneToOneWithSingleColumnAndForeignKey(Association currentGrailsProp) { if (currentGrailsProp.isBidirectional()) { final Association otherSide = currentGrailsProp.getInverseSide(); if(otherSide != null) { if (isHasOne(otherSide)) { return false; } if (!currentGrailsProp.isOwningSide() && (otherSide.isOwningSide())) { return true; } } } return false; }
if (isHasOne && !association.isBidirectional()) { throw new MappingException("hasOne property [" + currentGrailsProp.getOwner().getName() + "." + currentGrailsProp.getName() + "] is not bidirectional. Specify the other side of the relationship!"); if (isHasOne && association.isBidirectional()) { value = new OneToOne(mappings, table, persistentClass); bindOneToOne((org.grails.datastore.mapping.model.types.OneToOne) currentGrailsProp, (OneToOne) value, EMPTY_PATH, sessionFactoryBeanName);
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); } } } } }
column.setNullable(false); else if (property instanceof org.grails.datastore.mapping.model.types.OneToOne && association.isBidirectional() && !association.isOwningSide()) { if (isHasOne(((Association) property).getInverseSide())) { column.setNullable(false);
protected String getDefaultColumnName(PersistentProperty property, String sessionFactoryBeanName) { NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName); String columnName = namingStrategy.propertyToColumnName(property.getName()); if (property instanceof Association) { Association association = (Association) property; boolean isBasic = property instanceof Basic; if(isBasic && ((PropertyConfig)property.getMapping().getMappedForm()).getType() != null ) { return columnName; } if (isBasic) { return getForeignKeyForPropertyDomainClass(property, sessionFactoryBeanName); } if (property instanceof ManyToMany) { return getForeignKeyForPropertyDomainClass(property, sessionFactoryBeanName); } if (!association.isBidirectional() && association instanceof org.grails.datastore.mapping.model.types.OneToMany) { String prefix = namingStrategy.classToTableName(property.getOwner().getName()); return addUnderscore(prefix, columnName) + FOREIGN_KEY_SUFFIX; } if (property.isInherited() && isBidirectionalManyToOne(property)) { return namingStrategy.propertyToColumnName(property.getOwner().getName()) + '_'+ columnName + FOREIGN_KEY_SUFFIX; } return columnName + FOREIGN_KEY_SUFFIX; } return columnName; }
c.setUnique(config.isUnique()); else if (property.isBidirectional() && isHasOne(property.getInverseSide())) { c.setUnique(true);