@SuppressWarnings("unchecked") public List<MappedColumn> getMappedColumns(){ return value.getMappedColumns(); }
private static String columns(Value<?> val) { final StringBuilder columns = new StringBuilder(); List<MappedColumn> mappedColumns = val.getMappedColumns(); final int numberOfColumns = mappedColumns.size(); for ( int i = 0; i < numberOfColumns - 2; i++ ) { columns.append( mappedColumns.get( i ).getText() ); columns.append( ", " ); } columns.append( mappedColumns.get( numberOfColumns - 1 ).getText() ); return columns.toString(); } }
private String columns(Value value) { final StringBuilder builder = new StringBuilder(); final List<MappedColumn> mappedColumns = value.getMappedColumns(); final int numberOfColumns = mappedColumns.size(); if ( numberOfColumns > 0 ) { for ( int i = 0; i < numberOfColumns - 2; i++ ) { builder.append( mappedColumns.get( i ).getText() ); builder.append( ", " ); } builder.append( mappedColumns.get( numberOfColumns - 1 ).getText() ); } return builder.toString(); }
public static void createUniqueConstraint(Value value) { value.getMappedTable().createUniqueKey( value.getMappedColumns() ); }
private void addSyntheticIndexProperty(List value, String propertyAccessorName, ClassAuditingData classAuditingData) { final Value indexValue = value.getIndex(); if ( indexValue != null && !indexValue.getMappedColumns().isEmpty() ) { final String indexColumnName = ( (MappedColumn) indexValue.getMappedColumns().get( 0 ) ).getText(); if ( indexColumnName != null ) { final PropertyAuditingData auditingData = new PropertyAuditingData( indexColumnName, propertyAccessorName, RelationTargetAuditMode.AUDITED, RelationTargetNotFoundAction.DEFAULT, null, null, false, true, indexValue ); classAuditingData.addPropertyAuditingData( indexColumnName, auditingData ); } } }
@SuppressWarnings({"unchecked"}) private String searchMappedBy(PersistentClass referencedClass, Collection collectionValue) { final Iterator<Property> assocClassProps = referencedClass.getPropertyIterator(); while ( assocClassProps.hasNext() ) { final Property property = assocClassProps.next(); if ( property.getValue().getMappedColumns().equals( collectionValue.getKey().getMappedColumns() ) ) { return property.getName(); } } // HHH-7625 // Support ToOne relations with mappedBy that point to an @IdClass key property. return searchMappedByKey( referencedClass, collectionValue ); }
private void checkColumnDuplication(java.util.Set distinctColumns, Value value) throws MappingException { final boolean[] insertability = value.getColumnInsertability(); final boolean[] updatability = value.getColumnUpdateability(); List<MappedColumn> mappedColumns = value.getMappedColumns(); for ( int i = 0; i < mappedColumns.size(); i++ ) { MappedColumn s = mappedColumns.get( i ); // exclude formulas and coluns that are not insertable or updatable // since these values can be be repeated (HHH-5393) if ( !s.isFormula() && ( insertability[i] || updatability[i] ) ) { Column col = (Column) s; if ( !distinctColumns.add( col.getName() ) ) { throw new MappingException( "Repeated column in mapping for collection: " + getRole() + " column: " + col.getName() ); } } } }
@Override protected List<MappedColumn> getDiscriminatorColumns() { if ( isDiscriminatorInsertable() && !getDiscriminator().hasFormula() ) { return getDiscriminator().getMappedColumns(); } else { return super.getDiscriminatorColumns(); } }
void createPrimaryKey() { if ( !isOneToMany() ) { final MappedPrimaryKey pk = new PrimaryKey( getMappedTable() ); pk.addColumns( getKey().getMappedColumns() ); // index should be last column listed boolean isFormula = false; for( MappedColumn selectable : (List<MappedColumn>) getIndex().getMappedColumns() ){ if(selectable.isFormula()){ isFormula = true; } } if (isFormula) { //if it is a formula index, use the element columns in the PK pk.addColumns( getElement().getMappedColumns() ); } else { pk.addColumns( getIndex().getMappedColumns() ); } getMappedTable().setPrimaryKey(pk); } else { // don't create a unique key, 'cos some // databases don't like a UK on nullable // columns /*ArrayList list = new ArrayList(); list.addAll( getKey().getConstraintColumns() ); list.addAll( getIndex().getConstraintColumns() ); getCollectionTable().createUniqueKey(list);*/ } }
private void makeOneToManyMapKeyColumnNullableIfNotInProperty( final XProperty property) { final org.hibernate.mapping.Map map = (org.hibernate.mapping.Map) this.collection; if ( map.isOneToMany() && property.isAnnotationPresent( MapKeyColumn.class ) ) { final Value<?> indexValue = map.getIndex(); if ( indexValue.getColumnSpan() != 1 ) { throw new AssertionFailure( "Map key mapped by @MapKeyColumn does not have 1 column" ); } final MappedColumn mappedColumn = indexValue.getMappedColumns().get( 0 ); if ( mappedColumn.isFormula() ) { throw new AssertionFailure( "Map key mapped by @MapKeyColumn is a Formula" ); } final Column column = (Column) map.getIndex().getMappedColumns().get( 0 ); if ( !column.isNullable() ) { final PersistentClass persistentClass = ( ( OneToMany ) map.getElement() ).getAssociatedClass(); // check if the index column has been mapped by the associated entity to a property; // @MapKeyColumn only maps a column to the primary table for the one-to-many, so we only // need to check "un-joined" properties. if ( !propertyIteratorContainsColumn( persistentClass.getUnjoinedPropertyIterator(), column ) ) { // The index column is not mapped to an associated entity property so we can // safely make the index column nullable. column.setNullable( true ); } } } }
.getEntityBinding( mappedByEntityName ); final Property mappedByProperty = mappedByEntityBinding.getProperty( mappedByPropertyName ); final List<Selectable> mappedColumns = mappedByProperty.getValue().getMappedColumns(); if ( mappedColumns.size() == 0 ) { throw new AnnotationException(
Column col = (Column) identifier.getMappedColumns().get( 0 ); String defaultName = col.getQuotedName();
final List<MappedColumn> mappedColumns = property.getValue().getMappedColumns(); final int numberOfColumns = mappedColumns.size(); if ( numberOfColumns > 0 ) {
); mappedByColumns = element.getMappedColumns(); mappedByColumns = property.getValue().getMappedColumns();
key.setCascadeDeleteEnabled( false ); otherSideProperty.getValue() .getMappedColumns() .forEach( column -> key.addColumn( ( (Column) column ).clone() ) ); persistentClass.addJoin( join );
void createPrimaryKey() { if ( !isOneToMany() ) { final MappedPrimaryKey pk = new PrimaryKey( getMappedTable() ); pk.addColumns( getKey().getMappedColumns() ); for ( Object selectable : getElement().getMappedColumns() ) { if ( selectable instanceof Column ) { Column col = (Column) selectable; if ( !col.isNullable() ) { pk.addColumn( col ); } else { return; } } } if ( pk.getColumnSpan() == getKey().getColumnSpan() ) { //for backward compatibility, allow a set with no not-null //element columns, using all columns in the row locater SQL //TODO: create an implicit not null constraint on all cols? } else { getMappedTable().setPrimaryKey( pk ); } } else { //create an index on the key columns?? } }
element.getMappedColumns(), referencedEntityColumns ); fromAndWhere = getFromAndWhereFormula( targetPropertyPersistentClass.getMappedTable().getQualifiedTableName().toString(), element.getMappedColumns(), associatedClass.getIdentifier().getMappedColumns() );
@Override protected void createBackReferences() { super.createBackReferences(); boolean indexIsFormula = false; final List<MappedColumn> mappedColumns = getCollectionBinding().getIndex().getMappedColumns(); for ( MappedColumn mappedColumn : mappedColumns ) { if ( mappedColumn.isFormula() ) { indexIsFormula = true; } } if ( getCollectionBinding().isOneToMany() && !getCollectionBinding().getKey().isNullable() && !getCollectionBinding().isInverse() && !indexIsFormula ) { final String entityName = ( (OneToMany) getCollectionBinding().getElement() ).getReferencedEntityName(); final PersistentClass referenced = getMappingDocument().getMetadataCollector().getEntityBinding( entityName ); final IndexBackref ib = new IndexBackref( metadataBuildingContext ); ib.setName( '_' + getCollectionBinding().getOwnerEntityName() + "." + getPluralAttributeSource().getName() + "IndexBackref" ); ib.setUpdateable( false ); ib.setSelectable( false ); ib.setCollectionRole( getCollectionBinding().getRole() ); ib.setEntityName( getCollectionBinding().getOwner().getEntityName() ); ib.setValue( getCollectionBinding().getIndex() ); referenced.addProperty( ib ); } } }
positionMappedBy = ( (MappedColumn) indexValue.getMappedColumns().get( 0 ) ).getText();
joinColumns != null && joinColumns.length > 0 ? MetadataTools.getColumnNameIterator( joinColumns ) : MetadataTools.getColumnNameIterator( value.getMappedColumns() ), referencedIdMapping );