Ejb3JoinColumn[] joinColumns; if ( annJoins == null ) { Ejb3JoinColumn currentJoinColumn = new Ejb3JoinColumn(); currentJoinColumn.setImplicit( true ); currentJoinColumn.setNullable( false ); //I break the spec, but it's for good currentJoinColumn.setPropertyHolder( propertyHolder ); currentJoinColumn.setJoins( secondaryTables ); currentJoinColumn.setBuildingContext( buildingContext ); currentJoinColumn.setPropertyName( BinderHelper.getRelativePath( propertyHolder, propertyName ) ); currentJoinColumn.setMappedBy( mappedBy ); currentJoinColumn.bind(); for (int index = 0; index < length; index++) { annJoin = annJoins[index]; Ejb3JoinColumn currentJoinColumn = new Ejb3JoinColumn(); currentJoinColumn.setImplicit( true ); currentJoinColumn.setPropertyHolder( propertyHolder ); currentJoinColumn.setJoins( secondaryTables ); currentJoinColumn.setBuildingContext( buildingContext ); currentJoinColumn.setPropertyName( BinderHelper.getRelativePath( propertyHolder, propertyName ) ); currentJoinColumn.setMappedBy( mappedBy ); currentJoinColumn.setJoinAnnotation( annJoin, propertyName ); currentJoinColumn.setNullable( false ); //I break the spec, but it's for good currentJoinColumn.bind(); joinColumns[index] = currentJoinColumn;
ejb3JoinColumns[0] = Ejb3JoinColumn.buildJoinColumn( null, null, if ( nbrOfJoinColumns == 0 ) { ejb3JoinColumns = new Ejb3JoinColumn[1]; ejb3JoinColumns[0] = Ejb3JoinColumn.buildJoinColumn( null, null, if ( pkColumnsAnn != null ) { for (int colIndex = 0; colIndex < nbrOfJoinColumns; colIndex++) { ejb3JoinColumns[colIndex] = Ejb3JoinColumn.buildJoinColumn( pkColumnsAnn[colIndex], null, ejb3JoinColumns[colIndex] = Ejb3JoinColumn.buildJoinColumn( null, joinColumnsAnn[colIndex], joinColumn.forceNotNull();
public static Ejb3JoinColumn[] buildJoinColumnsOrFormulas( JoinColumnOrFormula[] anns, String mappedBy, Map<String, Join> joins, PropertyHolder propertyHolder, String propertyName, MetadataBuildingContext buildingContext) { Ejb3JoinColumn [] joinColumns = new Ejb3JoinColumn[anns.length]; for (int i = 0; i < anns.length; i++) { JoinColumnOrFormula join = anns[i]; JoinFormula formula = join.formula(); if (formula.value() != null && !formula.value().equals("")) { joinColumns[i] = buildJoinFormula( formula, mappedBy, joins, propertyHolder, propertyName, buildingContext ); } else { joinColumns[i] = buildJoinColumns( new JoinColumn[] { join.column() }, mappedBy, joins, propertyHolder, propertyName, buildingContext )[0]; } } return joinColumns; }
public void addDefaultJoinColumnName(PersistentClass referencedEntity, String logicalReferencedColumn) { final String columnName = buildDefaultColumnName( referencedEntity, logicalReferencedColumn ); getMappingColumn().setName( columnName ); setLogicalColumnName( columnName ); }
MetadataBuildingContext buildingContext) { super(); setImplicit( isImplicit ); setSqlType( sqlType ); setLogicalColumnName( name ); setNullable( nullable ); setUnique( unique ); setInsertable( insertable ); setUpdatable( updatable ); setExplicitTableName( secondaryTable ); setPropertyHolder( propertyHolder ); setJoins( joins ); setBuildingContext( buildingContext ); setPropertyName( BinderHelper.getRelativePath( propertyHolder, propertyName ) ); bind(); this.referencedColumn = referencedColumn; this.mappedBy = mappedBy;
/** * build join formula */ public static Ejb3JoinColumn buildJoinFormula( JoinFormula ann, String mappedBy, Map<String, Join> joins, PropertyHolder propertyHolder, String propertyName, MetadataBuildingContext buildingContext) { Ejb3JoinColumn formulaColumn = new Ejb3JoinColumn(); formulaColumn.setFormula( ann.value() ); formulaColumn.setReferencedColumn(ann.referencedColumnName()); formulaColumn.setBuildingContext( buildingContext ); formulaColumn.setPropertyHolder( propertyHolder ); formulaColumn.setJoins( joins ); formulaColumn.setPropertyName( BinderHelper.getRelativePath( propertyHolder, propertyName ) ); formulaColumn.bind(); return formulaColumn; }
) { super(); setImplicit( isImplicit ); setSqlType( sqlType ); setLogicalColumnName( name ); setNullable( nullable ); setUnique( unique ); setInsertable( insertable ); setUpdatable( updatable ); setSecondaryTableName( secondaryTable ); setPropertyHolder( propertyHolder ); setJoins( joins ); setMappings( mappings ); setPropertyName( BinderHelper.getRelativePath( propertyHolder, propertyName ) ); bind(); this.referencedColumn = referencedColumn; this.mappedBy = mappedBy;
associatedClass = columns[0].getPropertyHolder() == null ? null : columns[0].getPropertyHolder().getPersistentClass(); final String mappedByProperty = columns[0].getMappedBy(); if ( StringHelper.isNotEmpty( mappedByProperty ) ) { final Property property = associatedClass.getRecursiveProperty( columns[0].getMappedBy() ); Iterator mappedByColumns; if ( property.getValue() instanceof Collection ) { columns[0].overrideFromReferencedColumnIfNecessary( column ); columns[0].linkValueUsingAColumnCopy( column, value ); else if ( columns[0].isImplicit() ) { columns[0].linkValueUsingDefaultColumnNaming( column, referencedEntity, value ); columns[0].overrideFromReferencedColumnIfNecessary( column ); int fkEnum = Ejb3JoinColumn.checkReferencedColumnsType( columns, referencedEntity, buildingContext ); String propertyName = columns[0].getPropertyName(); if ( propertyName != null ) { Collection collection = (Collection) referencedEntity.getRecursiveProperty( propertyName ) String referencedColumn = joinCol.getReferencedColumn(); referencedColumn = buildingContext.getMetadataCollector().getPhysicalColumnName( table,
if ( columns[0].isImplicit() || StringHelper.isNotEmpty( columns[0].getMappedBy() ) ) { return; int fkEnum = Ejb3JoinColumn.checkReferencedColumnsType( columns, ownerEntity, context ); PersistentClass associatedClass = columns[0].getPropertyHolder() != null ? columns[0].getPropertyHolder().getPersistentClass() : null; if ( Ejb3JoinColumn.NON_PK_REFERENCE == fkEnum ) { propertyNameBuffer.append( "_" ).append( columns[0].getPropertyName().replace( '.', '_' ) ); String syntheticPropertyName = propertyNameBuffer.toString(); Object columnOwner = findColumnOwner( ownerEntity, columns[0].getReferencedColumn(), context ); List<Property> properties = findPropertiesByColumns( columnOwner, columns, context ); columnsList.append( "referencedColumnNames(" ); for (Ejb3JoinColumn column : columns) { columnsList.append( column.getReferencedColumn() ).append( ", " ); .append( associatedEntity.getEntityName() ) .append( "." ) .append( columns[0].getPropertyName() ) .append( " " ); if ( columns[0].getPropertyHolder() != null ) { columnsList.append( "of " ) .append( columns[0].getPropertyHolder().getEntityName() ) .append( "." ) .append( columns[0].getPropertyName() )
if ( joinColumns.length > 0 && StringHelper.isNotEmpty( joinColumns[0].getMappedBy() ) ) { String entityName = joinColumns[0].getManyToManyOwnerSideEntityName() != null ? "inverse__" + joinColumns[0].getManyToManyOwnerSideEntityName() : joinColumns[0].getPropertyHolder().getEntityName(); String propRef = buildingContext.getMetadataCollector().getPropertyReferencedAssociation( entityName, joinColumns[0].getMappedBy() ); if ( propRef != null ) { 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 );
protected void addColumnBinding(SimpleValue value) { if ( StringHelper.isEmpty( mappedBy ) ) { String unquotedLogColName = StringHelper.unquote( getLogicalColumnName() ); String unquotedRefColumn = StringHelper.unquote( getReferencedColumn() ); String logicalColumnName = getMappings().getNamingStrategy() .logicalCollectionColumnName( unquotedLogColName, getPropertyName(), unquotedRefColumn ); if ( StringHelper.isQuoted( getLogicalColumnName() ) || StringHelper.isQuoted( getLogicalColumnName() ) ) { logicalColumnName = StringHelper.quote( logicalColumnName ); } getMappings().addColumnBinding( logicalColumnName, getMappingColumn(), value.getTable() ); } }
associatedClass = columns[0].getPropertyHolder() == null ? null : columns[0].getPropertyHolder() .getPersistentClass(); final String mappedByProperty = columns[0].getMappedBy(); if ( StringHelper.isNotEmpty( mappedByProperty ) ) { final Property property = associatedClass.getRecursiveProperty( columns[0].getMappedBy() ); Iterator mappedByColumns; if ( property.getValue() instanceof Collection ) { columns[0].overrideSqlTypeIfNecessary( column ); columns[0].linkValueUsingAColumnCopy( column, value ); else if ( columns[0].isImplicit() ) { columns[0].overrideSqlTypeIfNecessary( column ); columns[0].linkValueUsingDefaultColumnNaming( column, referencedEntity, value ); int fkEnum = Ejb3JoinColumn.checkReferencedColumnsType( columns, referencedEntity, mappings ); String propertyName = columns[0].getPropertyName(); if ( propertyName != null ) { Collection collection = (Collection) referencedEntity.getRecursiveProperty( propertyName ) String referencedColumn = joinCol.getReferencedColumn(); referencedColumn = mappings.getPhysicalColumnName( referencedColumn, table ); if ( referencedColumn.equals( col.getName() ) ) {
public void linkValueUsingDefaultColumnNaming( Column referencedColumn, PersistentClass referencedEntity, SimpleValue value) { String logicalReferencedColumn = getBuildingContext().getMetadataCollector().getLogicalColumnName( referencedEntity.getTable(), referencedColumn.getQuotedName() ); String columnName = buildDefaultColumnName( referencedEntity, logicalReferencedColumn ); //yuk side effect on an implicit column setLogicalColumnName( columnName ); setReferencedColumn( logicalReferencedColumn ); initMappingColumn( columnName, null, referencedColumn.getLength(), referencedColumn.getPrecision(), referencedColumn.getScale(), getMappingColumn() != null ? getMappingColumn().isNullable() : false, referencedColumn.getSqlType(), getMappingColumn() != null ? getMappingColumn().isUnique() : false, false ); linkWithValue( value ); }
ManyToAny anyAnn = property.getAnnotation( ManyToAny.class ); if ( LOG.isDebugEnabled() ) { String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName(); if ( isCollectionOfEntities && unique ) { LOG.debugf("Binding a OneToMany: %s through an association table", path); String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName(); throw new AnnotationException( "Use of @OneToMany or @ManyToMany targeting an unmapped class: " + path + "[" + collType + "]" String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName(); throw new AnnotationException( "@JoinTable is mandatory when @ManyToAny is used: " + path JoinTable joinTableAnn = parentPropertyHolder.getJoinTable( property ); if ( joinTableAnn != null && joinTableAnn.inverseJoinColumns().length > 0 ) { String path = collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName(); throw new AnnotationException( "Use of @JoinTable.inverseJoinColumns targeting an unmapped class: " + path + "[" + collType + "]" boolean mappedBy = !BinderHelper.isEmptyAnnotationValue( joinColumns[0].getMappedBy() ); if ( mappedBy ) { if ( !isCollectionOfEntities ) { collValue.getOwnerEntityName() + "." + joinColumns[0].getPropertyName() );
@Override protected void addColumnBinding(SimpleValue value) { if ( StringHelper.isEmpty( mappedBy ) ) { // was the column explicitly quoted in the mapping/annotation // TODO: in metamodel, we need to better split global quoting and explicit quoting w/ respect to logical names boolean isLogicalColumnQuoted = StringHelper.isQuoted( getLogicalColumnName() ); final ObjectNameNormalizer nameNormalizer = getBuildingContext().getObjectNameNormalizer(); final String logicalColumnName = nameNormalizer.normalizeIdentifierQuotingAsString( getLogicalColumnName() ); final String referencedColumn = nameNormalizer.normalizeIdentifierQuotingAsString( getReferencedColumn() ); final String unquotedLogColName = StringHelper.unquote( logicalColumnName ); final String unquotedRefColumn = StringHelper.unquote( referencedColumn ); String logicalCollectionColumnName = StringHelper.isNotEmpty( unquotedLogColName ) ? unquotedLogColName : getPropertyName() + '_' + unquotedRefColumn; logicalCollectionColumnName = getBuildingContext().getMetadataCollector() .getDatabase() .getJdbcEnvironment() .getIdentifierHelper() .toIdentifier( logicalCollectionColumnName, isLogicalColumnQuoted ) .render(); getBuildingContext().getMetadataCollector().addColumnNameBinding( value.getTable(), logicalCollectionColumnName, getMappingColumn() ); } }
column.setPersistentClass( associatedClass, joins, inheritanceStatePerClass ); column.setJoins( joins ); collection.setCollectionTable( column.getTable() ); PersistentClass referenced = buildingContext.getMetadataCollector().getEntityBinding( entityName ); Backref prop = new Backref(); prop.setName( '_' + fkJoinColumns[0].getPropertyName() + '_' + fkJoinColumns[0].getLogicalColumnName() + "Backref" ); prop.setUpdateable( false ); prop.setSelectable( false );
/** * used for mappedBy cases */ public void linkValueUsingAColumnCopy(Column column, SimpleValue value) { initMappingColumn( //column.getName(), column.getQuotedName(), null, column.getLength(), column.getPrecision(), column.getScale(), getMappingColumn().isNullable(), column.getSqlType(), getMappingColumn().isUnique(), false //We do copy no strategy here ); linkWithValue( value ); }
return Ejb3JoinColumn.buildJoinColumns( joinColumnAnnotations, null, return Ejb3JoinColumn.buildJoinColumnsOrFormulas( joinColumnOrFormulaAnnotations, null, JoinFormula ann = property.getAnnotation( JoinFormula.class ); Ejb3JoinColumn[] ejb3JoinColumns = new Ejb3JoinColumn[1]; ejb3JoinColumns[0] = Ejb3JoinColumn.buildJoinFormula( ann, null,
boolean unique, MetadataBuildingContext buildingContext) { final String mappedBy = columns[0].getMappedBy(); if ( StringHelper.isNotEmpty( mappedBy ) ) { final Property property = referencedEntity.getRecursiveProperty( mappedBy ); columns[0].linkValueUsingAColumnCopy( column, value );
if ( actualColumns == null || actualColumns.length == 0 ) { return new Ejb3JoinColumn[] { buildJoinColumn( null, mappedBy, Ejb3JoinColumn[] result = new Ejb3JoinColumn[size]; for (int index = 0; index < size; index++) { result[index] = buildJoinColumn( actualColumns[index], mappedBy,