.getValue(); DependantValue key = new DependantValue( collValue.getCollectionTable(), keyVal ); key.setTypeName( null ); Ejb3Column.checkPropertyConsistency( joinColumns, collValue.getOwnerEntityName() ); key.setNullable( joinColumns.length == 0 || joinColumns[0].isNullable() ); key.setUpdateable( joinColumns.length == 0 || joinColumns[0].isUpdatable() ); key.setCascadeDeleteEnabled( cascadeDeleteEnabled ); collValue.setKey( key ); ForeignKey fk = property != null ? property.getAnnotation( ForeignKey.class ) : null; String fkName = fk != null ? fk.name() : ""; if ( !BinderHelper.isDefault( fkName ) ) key.setForeignKeyName( fkName ); return key;
DependantValue key = new DependantValue( buildingContext, collValue.getCollectionTable(), keyVal ); key.setTypeName( null ); Ejb3Column.checkPropertyConsistency( joinColumns, collValue.getOwnerEntityName() ); key.setNullable( joinColumns.length == 0 || joinColumns[0].isNullable() ); key.setUpdateable( joinColumns.length == 0 || joinColumns[0].isUpdatable() ); key.setCascadeDeleteEnabled( cascadeDeleteEnabled ); collValue.setKey( key ); if ( property != null ) { final ForeignKey fk = property.getAnnotation( ForeignKey.class ); if ( fk != null && !BinderHelper.isEmptyAnnotationValue( fk.name() ) ) { key.setForeignKeyName( fk.name() ); if ( collectionTableAnn != null ) { if ( collectionTableAnn.foreignKey().value() == ConstraintMode.NO_CONSTRAINT ) { key.setForeignKeyName( "none" ); key.setForeignKeyName( StringHelper.nullIfEmpty( collectionTableAnn.foreignKey().name() ) ); key.setForeignKeyDefinition( StringHelper.nullIfEmpty( collectionTableAnn.foreignKey().foreignKeyDefinition() ) ); if ( key.getForeignKeyName() == null && key.getForeignKeyDefinition() == null && collectionTableAnn.joinColumns().length == 1 ) { JoinColumn joinColumn = collectionTableAnn.joinColumns()[0]; key.setForeignKeyName( StringHelper.nullIfEmpty( joinColumn.foreignKey().name() ) ); key.setForeignKeyDefinition( StringHelper.nullIfEmpty( joinColumn.foreignKey().foreignKeyDefinition() ) ); key.setForeignKeyName( "none" ); key.setForeignKeyName( StringHelper.nullIfEmpty( foreignKeyName ) ); key.setForeignKeyDefinition( StringHelper.nullIfEmpty( foreignKeyDefinition ) );
keyVal = (KeyValue) getCollectionBinding().getOwner().getRecursiveProperty( propRef ).getValue(); final DependantValue key = new DependantValue( mappingDocument, getCollectionBinding().getCollectionTable(), keyVal ); key.setForeignKeyName( keySource.getExplicitForeignKeyName() ); key.setCascadeDeleteEnabled( getPluralAttributeSource().getKeySource().isCascadeDeleteEnabled() ); key.createForeignKey(); getCollectionBinding().setKey( key ); key.setNullable( getPluralAttributeSource().getKeySource().areValuesNullableByDefault() ); key.setUpdateable( getPluralAttributeSource().getKeySource().areValuesIncludedInUpdateByDefault() );
@Test public void testProperCallbacks() { final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( serviceRegistry ) .buildMetadata(); final Table tbl = new Table(); final RootClass rootClass = new RootClass( metadataBuildingContext ); ValueVisitor vv = new ValueVisitorValidator(); MetadataBuildingContextTestingImpl metadataBuildingContext = new MetadataBuildingContextTestingImpl(); new Any( metadataBuildingContext, tbl ).accept( vv ); new Array( metadataBuildingContext, rootClass ).accept( vv ); new Bag( metadataBuildingContext, rootClass ).accept( vv ); new Component( metadataBuildingContext, rootClass ).accept( vv ); new DependantValue( metadataBuildingContext, tbl, null ).accept( vv ); new IdentifierBag( metadataBuildingContext, rootClass ).accept( vv ); new List( metadataBuildingContext, rootClass ).accept( vv ); new ManyToOne( metadataBuildingContext, tbl ).accept( vv ); new Map( metadataBuildingContext, rootClass ).accept( vv ); new OneToMany( metadataBuildingContext, rootClass ).accept( vv ); new OneToOne( metadataBuildingContext, tbl, rootClass ).accept( vv ); new PrimitiveArray( metadataBuildingContext, rootClass ).accept( vv ); new Set( metadataBuildingContext, rootClass ).accept( vv ); new SimpleValue( metadataBuildingContext ).accept( vv ); }
private void bindJoinToPersistentClass(Join join, Ejb3JoinColumn[] ejb3JoinColumns, MetadataBuildingContext buildingContext) { SimpleValue key = new DependantValue( buildingContext, join.getTable(), persistentClass.getIdentifier() ); join.setKey( key ); setFKNameIfDefined( join ); key.setCascadeDeleteEnabled( false ); TableBinder.bindFk( persistentClass, null, ejb3JoinColumns, key, false, buildingContext ); join.createPrimaryKey(); join.createForeignKey(); persistentClass.addJoin( join ); }
String colToPropertyName = reference.getActualToColumn().getActualPropertyName(); refProp = getRefProperty(clazzOne, colToPropertyName); dv = new DependantValue(mappings, clazzMany.getTable(), refProp.getPersistentClass().getKey()); dv.setNullable(true); dv.setUpdateable(true); Column col = (Column) it.next(); if (col.getName().equals(colFromName)) { dv.addColumn(col); manyColumns.add(col); break;
/** * Creates the DependentValue object that forms a primary key reference for the collection. * * @param mappings * @param property The grails property * @param collection The collection object * @param persistentClasses * @return The DependantValue (key) */ private static DependantValue createPrimaryKeyValue(Mappings mappings, @SuppressWarnings("unused") GrailsDomainClassProperty property, Collection collection, @SuppressWarnings("unused") Map<?, ?> persistentClasses) { KeyValue keyValue; DependantValue key; String propertyRef = collection.getReferencedPropertyName(); // this is to support mapping by a property if (propertyRef == null) { keyValue = collection.getOwner().getIdentifier(); } else { keyValue = (KeyValue) collection.getOwner().getProperty(propertyRef).getValue(); } if (LOG.isDebugEnabled()) LOG.debug("[GrailsDomainBinder] creating dependant key value to table [" + keyValue.getTable().getName() + "]"); key = new DependantValue(mappings, collection.getCollectionTable(), keyValue); key.setTypeName(null); // make nullable and non-updateable key.setNullable(true); key.setUpdateable(false); return key; }
keyVal = (KeyValue) collection.getOwner().getProperty( propRef ).getValue(); SimpleValue key = new DependantValue( collection.getCollectionTable(), keyVal ); key.setCascadeDeleteEnabled( "cascade" .equals( subnode.attributeValue( "on-delete" ) ) ); ( (DependantValue) key ).setNullable( notNull == null || notNull.getValue().equals( "false" ) ); Attribute updateable = subnode.attribute( "update" ); ( (DependantValue) key ).setUpdateable( updateable == null || updateable.getValue().equals( "true" ) );
keyVal = (KeyValue) getCollectionBinding().getOwner().getRecursiveProperty( propRef ).getValue(); final DependantValue key = new DependantValue( mappingDocument, getCollectionBinding().getMappedTable(), keyVal ); key.setForeignKeyName( keySource.getExplicitForeignKeyName() ); key.setCascadeDeleteEnabled( getPluralAttributeSource().getKeySource().isCascadeDeleteEnabled() ); getCollectionBinding().getMappedTable().createForeignKey( keySource.getExplicitForeignKeyName(), key.getMappedColumns(), getCollectionBinding().getOwner().getEntityName(), keySource.getReferencedPropertyName(), getCollectionBinding().setKey( key ); key.setNullable( getPluralAttributeSource().getKeySource().areValuesNullableByDefault() ); key.setUpdateable( getPluralAttributeSource().getKeySource().areValuesIncludedInUpdateByDefault() );
final DependantValue keyBinding = new DependantValue( mappingDocument, primaryTable, ); if ( mappingDocument.getBuildingOptions().useNationalizedCharacterData() ) { keyBinding.makeNationalized(); keyBinding.setCascadeDeleteEnabled( entitySource.isCascadeDeleteEnabled() ); relationalObjectBinder.bindColumns( mappingDocument, keyBinding.setForeignKeyName( entitySource.getExplicitForeignKeyName() );
oneColumns, manyColumns, refs); dv.setForeignKeyName(relationship.getQualifiedName()); dv.setTypeName(null); dv.setNullable(false); set.setKey(dv); } else {
.getValue(); DependantValue key = new DependantValue( collValue.getCollectionTable(), keyVal ); key.setTypeName( null ); Ejb3Column.checkPropertyConsistency( joinColumns, collValue.getOwnerEntityName() ); key.setNullable( joinColumns.length == 0 || joinColumns[0].isNullable() ); key.setUpdateable( joinColumns.length == 0 || joinColumns[0].isUpdatable() ); key.setCascadeDeleteEnabled( cascadeDeleteEnabled ); collValue.setKey( key ); ForeignKey fk = property != null ? property.getAnnotation( ForeignKey.class ) : null;
value.setNullable(false); value.setUpdateable(true); prop.setOptional(false);
property.setPropertyAccessorName( referencedProperty.getPropertyAccessorName() ); final BasicValue referencedValue = (BasicValue) referencedProperty.getValueMapping(); final DependantValue value = new DependantValue( buildingContext, component.getMappedTable(), referencedValue ); property.setValue( value ); value.setExplicitTypeName( referencedValue.getTypeName() ); value.setTypeParameters( referencedValue.getTypeParameters() ); final List<MappedColumn> mappedColumns = referencedValue.getMappedColumns(); if ( joinColumns[0].isNameDeferred() ) { value.getMappedTable().getNameIdentifier(), columnName, false ); value.addColumn( valueColumn );
@SuppressWarnings("rawtypes") public void doSecondPass(Map persistentClasses) throws MappingException { Value element = collection.getElement(); DependantValue elementDependantValue = null; String oldElementForeignKeyName = null; if(element instanceof DependantValue) { elementDependantValue = (DependantValue)element; oldElementForeignKeyName = elementDependantValue.getForeignKeyName(); elementDependantValue.setForeignKeyName("none"); // Workaround to avoid DependantValue to create foreignkey just because reference columns are not the same + no need to create keys already in the db! } Value key = collection.getKey(); DependantValue keyDependantValue = null; String oldKeyForeignKeyName = null; if (key instanceof DependantValue) { keyDependantValue = (DependantValue)key; oldKeyForeignKeyName = keyDependantValue.getForeignKeyName(); keyDependantValue.setForeignKeyName("none"); } super.doSecondPass(persistentClasses); if(elementDependantValue!=null) { elementDependantValue.setForeignKeyName(oldElementForeignKeyName); } if (keyDependantValue != null) { keyDependantValue.setForeignKeyName(oldKeyForeignKeyName); } }
protected void linkValueUsingAColumnCopy(PersistentProperty prop, Column column, DependantValue key) { Column mappingColumn = new Column(); mappingColumn.setName(column.getName()); mappingColumn.setLength(column.getLength()); mappingColumn.setNullable(prop.isNullable()); mappingColumn.setSqlType(column.getSqlType()); mappingColumn.setValue(key); key.addColumn(mappingColumn); key.getTable().addColumn(mappingColumn); }
SimpleValue key = new DependantValue( buildingContext, join.getTable(), persistentClass.getIdentifier() );
String colToPropertyName = reference.getActualToColumn().getActualPropertyName(); refProp = getRefProperty(clazzOne, colToPropertyName); dv = new DependantValue(mappings, clazzMany.getTable(), refProp.getPersistentClass().getKey()); dv.setNullable(true); dv.setUpdateable(true); Column col = (Column) it.next(); if (col.getName().equals(colFromName)) { dv.addColumn(col); manyColumns.add(col); break;
/** * Creates the DependentValue object that forms a primary key reference for the collection. * * @param mappings * @param property The grails property * @param collection The collection object * @param persistentClasses * @return The DependantValue (key) */ protected DependantValue createPrimaryKeyValue(Mappings mappings, PersistentProperty property, Collection collection, Map<?, ?> persistentClasses) { KeyValue keyValue; DependantValue key; String propertyRef = collection.getReferencedPropertyName(); // this is to support mapping by a property if (propertyRef == null) { keyValue = collection.getOwner().getIdentifier(); } else { keyValue = (KeyValue) collection.getOwner().getProperty(propertyRef).getValue(); } if (LOG.isDebugEnabled()) LOG.debug("[GrailsDomainBinder] creating dependant key value to table [" + keyValue.getTable().getName() + "]"); key = new DependantValue(mappings, collection.getCollectionTable(), keyValue); key.setTypeName(null); // make nullable and non-updateable key.setNullable(true); key.setUpdateable(false); return key; }
keyVal = (KeyValue) collection.getOwner().getRecursiveProperty( propRef ).getValue(); SimpleValue key = new DependantValue( mappings, collection.getCollectionTable(), keyVal ); key.setCascadeDeleteEnabled( "cascade" .equals( subnode.attributeValue( "on-delete" ) ) ); ( (DependantValue) key ).setNullable( notNull == null || notNull.getValue().equals( "false" ) ); Attribute updateable = subnode.attribute( "update" ); ( (DependantValue) key ).setUpdateable( updateable == null || updateable.getValue().equals( "true" ) );