public void doSecondPass(java.util.Map persistentClasses) throws MappingException { if ( value instanceof ManyToOne ) { ManyToOne manyToOne = (ManyToOne) value; PersistentClass ref = (PersistentClass) persistentClasses.get( manyToOne.getReferencedEntityName() ); if ( ref == null ) { throw new AnnotationException( "@OneToOne or @ManyToOne on " + StringHelper.qualify( entityClassName, path ) + " references an unknown entity: " + manyToOne.getReferencedEntityName() ); } manyToOne.setPropertyName( path ); BinderHelper.createSyntheticPropertyReference( columns, ref, null, manyToOne, false, buildingContext ); TableBinder.bindFk( ref, null, columns, manyToOne, unique, buildingContext ); /* * HbmMetadataSourceProcessorImpl does this only when property-ref != null, but IMO, it makes sense event if it is null */ if ( !manyToOne.isIgnoreNotFound() ) manyToOne.createPropertyRefConstraints( persistentClasses ); } else if ( value instanceof OneToOne ) { value.createForeignKey(); } else { throw new AssertionFailure( "FkSecondPass for a wrong value type: " + value.getClass().getName() ); } } }
public void createPropertyRefConstraints(Map persistentClasses) { if (referencedPropertyName!=null) { PersistentClass pc = (PersistentClass) persistentClasses.get(getReferencedEntityName() ); getReferencedPropertyName() + " on " + getReferencedEntityName() );
private PersistentClass getReferenceCollectionClass(Collection collectionValue) { PersistentClass referencedClass = null; if ( collectionValue.getElement() instanceof OneToMany ) { final OneToMany oneToManyValue = (OneToMany) collectionValue.getElement(); referencedClass = oneToManyValue.getAssociatedClass(); } else if ( collectionValue.getElement() instanceof ManyToOne ) { // Case for bi-directional relation with @JoinTable on the owning @ManyToOne side. final ManyToOne manyToOneValue = (ManyToOne) collectionValue.getElement(); referencedClass = manyToOneValue.getMetadata().getEntityBinding( manyToOneValue.getReferencedEntityName() ); } return referencedClass; }
public Type getType() throws MappingException { return getMetadata().getTypeResolver().getTypeFactory().manyToOne( getReferencedEntityName(), referenceToPrimaryKey, getReferencedPropertyName(), getPropertyName(), isLazy(), isUnwrapProxy(), isIgnoreNotFound(), isLogicalOneToOne ); }
handlePropertyReference( sourceDocument, manyToOneBinding.getReferencedEntityName(), propertyRef, true,
targetManyToOne.setLazy( true ); targetManyToOne.setReferencedEntityName( sourceManyToOne.getReferencedEntityName() ); targetValue = targetManyToOne;
public void doSecondPass(java.util.Map persistentClasses) throws MappingException { if ( value instanceof ManyToOne ) { ManyToOne manyToOne = (ManyToOne) value; PersistentClass ref = (PersistentClass) persistentClasses.get( manyToOne.getReferencedEntityName() ); if ( ref == null ) { throw new AnnotationException( "@OneToOne or @ManyToOne on " + StringHelper.qualify( entityClassName, path ) + " references an unknown entity: " + manyToOne.getReferencedEntityName() ); } BinderHelper.createSyntheticPropertyReference( columns, ref, null, manyToOne, false, mappings ); TableBinder.bindFk( ref, null, columns, manyToOne, unique, mappings ); /* * HbmBinder does this only when property-ref != null, but IMO, it makes sense event if it is null */ if ( !manyToOne.isIgnoreNotFound() ) manyToOne.createPropertyRefConstraints( persistentClasses ); } else if ( value instanceof OneToOne ) { ( (OneToOne) value ).createForeignKey(); } else { throw new AssertionFailure( "FkSecondPass for a wrong value type: " + value.getClass().getName() ); } } }
targetManyToOne.setLazy( true ); targetManyToOne.setReferencedEntityName( sourceManyToOne.getReferencedEntityName() ); targetValue = targetManyToOne;
public void doSecondPass(java.util.Map persistentClasses) throws MappingException { if ( value instanceof ManyToOne ) { ManyToOne manyToOne = (ManyToOne) value; PersistentClass ref = (PersistentClass) persistentClasses.get( manyToOne.getReferencedEntityName() ); if ( ref == null ) { throw new AnnotationException( "@OneToOne or @ManyToOne on " + StringHelper.qualify( entityClassName, path ) + " references an unknown entity: " + manyToOne.getReferencedEntityName() ); } BinderHelper.createSyntheticPropertyReference( columns, ref, null, manyToOne, false, mappings ); TableBinder.bindFk( ref, null, columns, manyToOne, unique, mappings ); /* * HbmMetadataSourceProcessorImpl does this only when property-ref != null, but IMO, it makes sense event if it is null */ if ( !manyToOne.isIgnoreNotFound() ) manyToOne.createPropertyRefConstraints( persistentClasses ); } else if ( value instanceof OneToOne ) { ( (OneToOne) value ).createForeignKey(); } else { throw new AssertionFailure( "FkSecondPass for a wrong value type: " + value.getClass().getName() ); } } }
public void doSecondPass(java.util.Map persistentClasses) throws MappingException { if ( value instanceof ManyToOne ) { ManyToOne manyToOne = (ManyToOne) value; PersistentClass ref = (PersistentClass) persistentClasses.get( manyToOne.getReferencedEntityName() ); if ( ref == null ) { throw new AnnotationException( "@OneToOne or @ManyToOne on " + StringHelper.qualify( entityClassName, path ) + " references an unknown entity: " + manyToOne.getReferencedEntityName() ); } BinderHelper.createSyntheticPropertyReference( columns, ref, null, manyToOne, false, mappings ); TableBinder.bindFk( ref, null, columns, manyToOne, unique, mappings ); /* * HbmMetadataSourceProcessorImpl does this only when property-ref != null, but IMO, it makes sense event if it is null */ if ( !manyToOne.isIgnoreNotFound() ) manyToOne.createPropertyRefConstraints( persistentClasses ); } else if ( value instanceof OneToOne ) { ( (OneToOne) value ).createForeignKey(); } else { throw new AssertionFailure( "FkSecondPass for a wrong value type: " + value.getClass().getName() ); } } }
public Type getType() throws MappingException { return TypeFactory.manyToOne( getReferencedEntityName(), getReferencedPropertyName(), isLazy(), isEmbedded(), isIgnoreNotFound() ); }
public void createPropertyRefConstraints(Map persistentClasses) { if (referencedPropertyName!=null) { PersistentClass pc = (PersistentClass) persistentClasses.get(getReferencedEntityName() ); getReferencedPropertyName() + " on " + getReferencedEntityName() );
public void createPropertyRefConstraints(Map persistentClasses) { if (referencedPropertyName!=null) { PersistentClass pc = (PersistentClass) persistentClasses.get(getReferencedEntityName() ); getReferencedPropertyName() + " on " + getReferencedEntityName() );
public Type getType() throws MappingException { return TypeFactory.manyToOne( getReferencedEntityName(), getReferencedPropertyName(), isLazy(), isUnwrapProxy(), isEmbedded(), isIgnoreNotFound() ); }
public ForeignKey createForeignKey() throws MappingException { if ( foreignKey == null ) { // the case of a foreign key to something other than the pk is handled in createPropertyRefConstraints if ( referencedPropertyName == null ) { foreignKey = (ForeignKey) getMappedTable().createForeignKey( getForeignKeyName(), getConstraintColumns(), getReferencedEntityName(), getForeignKeyDefinition(), null ); if ( hasFormula() || "none".equals(getForeignKeyName()) ) { foreignKey.disableCreation(); } } } return foreignKey; }
public Type getType() throws MappingException { return getMappings().getTypeResolver().getTypeFactory().manyToOne( getReferencedEntityName(), getReferencedPropertyName(), isLazy(), isUnwrapProxy(), isEmbedded(), isIgnoreNotFound(), isLogicalOneToOne ); }
public Type getType() throws MappingException { return getMappings().getTypeResolver().getTypeFactory().manyToOne( getReferencedEntityName(), getReferencedPropertyName(), isLazy(), isUnwrapProxy(), isEmbedded(), isIgnoreNotFound(), isLogicalOneToOne ); }
private PersistentClass getReferenceCollectionClass(Collection collectionValue) { PersistentClass referencedClass = null; if ( collectionValue.getElement() instanceof OneToMany ) { final OneToMany oneToManyValue = (OneToMany) collectionValue.getElement(); referencedClass = oneToManyValue.getAssociatedClass(); } else if ( collectionValue.getElement() instanceof ManyToOne ) { // Case for bi-directional relation with @JoinTable on the owning @ManyToOne side. final ManyToOne manyToOneValue = (ManyToOne) collectionValue.getElement(); referencedClass = manyToOneValue.getMetadataBuildingContext().getMetadataCollector().getEntityBinding( manyToOneValue.getReferencedEntityName() ); } return referencedClass; }
@Override public JavaTypeMapping getJavaTypeMapping() { final PersistentClass referencedPersistentClass = getMetadataBuildingContext() .getMetadataCollector() .getEntityBinding( getReferencedEntityName() ); if ( referenceToPrimaryKey || referencedPropertyName == null ) { return referencedPersistentClass.getIdentifier().getJavaTypeMapping(); } else { return referencedPersistentClass.getReferencedProperty( getReferencedPropertyName() ) .getValue() .getJavaTypeMapping(); } } }
/** * Binds a unidirectional one-to-many creating a psuedo back reference property in the process. * * @param property * @param mappings * @param collection */ private static void bindUnidirectionalOneToMany(GrailsDomainClassProperty 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(); prop.setEntityName(property.getDomainClass().getFullName()); prop.setName(UNDERSCORE + addUnderscore(property.getDomainClass().getShortName(), property.getName()) + "Backref"); prop.setUpdateable(false); prop.setInsertable(true); prop.setCollectionRole(collection.getRole()); prop.setValue(collection.getKey()); prop.setOptional(true); referenced.addProperty(prop); }