📄 ejb3joincolumn.java
字号:
+ holder.getEntityName() + "." + property.getPropertyName() ); } } public void linkValueUsingDefaultColumnNaming( Column referencedColumn, PersistentClass referencedEntity, SimpleValue value ) { String columnName; String logicalReferencedColumn = getMappings().getLogicalColumnName( referencedColumn.getName(), referencedEntity.getTable() ); boolean mappedBySide = mappedByTableName != null || mappedByPropertyName != null; boolean ownerSide = getPropertyName() != null; Boolean isRefColumnQuoted = StringHelper.isQuoted( logicalReferencedColumn ); String unquotedLogicalReferenceColumn = isRefColumnQuoted ? StringHelper.unquote( logicalReferencedColumn ) : logicalReferencedColumn; if ( mappedBySide ) { String unquotedMappedbyTable = StringHelper.unquote( mappedByTableName ); columnName = getMappings().getNamingStrategy().foreignKeyColumnName( mappedByPropertyName, mappedByEntityName, unquotedMappedbyTable, unquotedLogicalReferenceColumn ); //one element was quoted so we quote if ( isRefColumnQuoted || StringHelper.isQuoted( mappedByTableName ) ) { columnName = StringHelper.quote( columnName ); } } else if ( ownerSide ) { String logicalTableName = getMappings().getLogicalTableName( referencedEntity.getTable() ); String unquotedLogicalTableName = StringHelper.unquote( logicalTableName ); columnName = getMappings().getNamingStrategy().foreignKeyColumnName( getPropertyName(), referencedEntity.getEntityName(), unquotedLogicalTableName, unquotedLogicalReferenceColumn ); //one element was quoted so we quote if ( isRefColumnQuoted || StringHelper.isQuoted( logicalTableName ) ) { columnName = StringHelper.quote( columnName ); } } else { //is an intra-entity hierarchy table join so copy the name by default String logicalTableName = getMappings().getLogicalTableName( referencedEntity.getTable() ); String unquotedLogicalTableName = StringHelper.unquote( logicalTableName ); columnName = getMappings().getNamingStrategy().joinKeyColumnName( unquotedLogicalReferenceColumn, unquotedLogicalTableName ); //one element was quoted so we quote if ( isRefColumnQuoted || StringHelper.isQuoted( logicalTableName ) ) { columnName = StringHelper.quote( columnName ); } } //yuk side effect on an implicit column setLogicalColumnName( columnName ); setReferencedColumn( logicalReferencedColumn ); initMappingColumn( columnName, null, referencedColumn.getLength(), referencedColumn.getPrecision(), referencedColumn.getScale(), getMappingColumn().isNullable(), referencedColumn.getSqlType(), getMappingColumn().isUnique(), false ); linkWithValue( value ); } /** * 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 ); } 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() ); } } //keep it JDK 1.4 compliant //implicit way public static final int NO_REFERENCE = 0; //reference to the pk in an explicit order public static final int PK_REFERENCE = 1; //reference to non pk columns public static final int NON_PK_REFERENCE = 2; public static int checkReferencedColumnsType( Ejb3JoinColumn[] columns, PersistentClass referencedEntity, ExtendedMappings mappings ) { //convenient container to find whether a column is an id one or not Set<Column> idColumns = new HashSet<Column>(); Iterator idColumnsIt = referencedEntity.getKey().getColumnIterator(); while ( idColumnsIt.hasNext() ) { idColumns.add( (Column) idColumnsIt.next() ); } boolean isFkReferencedColumnName = false; boolean noReferencedColumn = true; //build the list of potential tables if ( columns.length == 0 ) return NO_REFERENCE; //shortcut Object columnOwner = BinderHelper.findColumnOwner( referencedEntity, columns[0].getReferencedColumn(), mappings ); if ( columnOwner == null ) { try { throw new MappingException( "Unable to find column with logical name: " + columns[0].getReferencedColumn() + " in " + referencedEntity.getTable() + " and its related " + "supertables and secondary tables" ); } catch (MappingException e) { throw new RecoverableException(e); } } Table matchingTable = columnOwner instanceof PersistentClass ? ( (PersistentClass) columnOwner ).getTable() : ( (Join) columnOwner ).getTable(); //check each referenced column for (Ejb3JoinColumn ejb3Column : columns) { String logicalReferencedColumnName = ejb3Column.getReferencedColumn(); if ( StringHelper.isNotEmpty( logicalReferencedColumnName ) ) { String referencedColumnName = null; try { referencedColumnName = mappings.getPhysicalColumnName( logicalReferencedColumnName, matchingTable ); } catch (MappingException me) { //rewrite the exception throw new MappingException( "Unable to find column with logical name: " + logicalReferencedColumnName + " in " + matchingTable.getName() ); } noReferencedColumn = false; Column refCol = new Column( referencedColumnName ); boolean contains = idColumns.contains( refCol ); if ( !contains ) { isFkReferencedColumnName = true; break; //we know the state } } } if ( isFkReferencedColumnName ) { return NON_PK_REFERENCE; } else if ( noReferencedColumn ) { return NO_REFERENCE; } else if ( idColumns.size() != columns.length ) { //reference use PK but is a subset or a superset return NON_PK_REFERENCE; } else { return PK_REFERENCE; } } public void overrideSqlTypeIfNecessary(org.hibernate.mapping.Column column) { if ( StringHelper.isEmpty( sqlType ) ) { sqlType = column.getSqlType(); if ( getMappingColumn() != null ) getMappingColumn().setSqlType( sqlType ); } } @Override public void redefineColumnName(String columnName, String propertyName, boolean applyNamingStrategy) { if ( StringHelper.isNotEmpty( columnName ) ) { getMappingColumn().setName( applyNamingStrategy ? getMappings().getNamingStrategy().columnName( columnName ) : columnName ); } } public static Ejb3JoinColumn[] buildJoinTableJoinColumns( JoinColumn[] annJoins, Map<String, Join> secondaryTables, PropertyHolder propertyHolder, String propertyName, String mappedBy, ExtendedMappings mappings ) { 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.setMappings( mappings ); currentJoinColumn.setPropertyName( BinderHelper.getRelativePath( propertyHolder, propertyName ) ); currentJoinColumn.setMappedBy( mappedBy ); currentJoinColumn.bind(); joinColumns = new Ejb3JoinColumn[] { currentJoinColumn }; } else { joinColumns = new Ejb3JoinColumn[annJoins.length]; JoinColumn annJoin; int length = annJoins.length; for (int index = 0; index < length; index++) { annJoin = annJoins[index]; Ejb3JoinColumn currentJoinColumn = new Ejb3JoinColumn(); currentJoinColumn.setImplicit( true ); currentJoinColumn.setPropertyHolder( propertyHolder ); currentJoinColumn.setJoins( secondaryTables ); currentJoinColumn.setMappings( mappings ); 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 //done after the annotation to override it currentJoinColumn.bind(); joinColumns[index] = currentJoinColumn; } } return joinColumns; } public void setMappedBy(String entityName, String logicalTableName, String mappedByProperty) { this.mappedByEntityName = entityName; this.mappedByTableName = logicalTableName; this.mappedByPropertyName = mappedByProperty; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -