public Iterator getColumnIterator() { return value.getColumnIterator(); }
private String columns(Value value) { final StringBuilder builder = new StringBuilder(); final Iterator<Selectable> selectableItr = value.getColumnIterator(); while ( selectableItr.hasNext() ) { builder.append( selectableItr.next().getText() ); if ( selectableItr.hasNext() ) { builder.append( ", " ); } } return builder.toString(); }
private static String columns(Value val) { StringBuilder columns = new StringBuilder(); Iterator iter = val.getColumnIterator(); while ( iter.hasNext() ) { columns.append( ( (Selectable) iter.next() ).getText() ); if ( iter.hasNext() ) columns.append( ", " ); } return columns.toString(); } }
public static void createUniqueConstraint(Value value) { Iterator iter = value.getColumnIterator(); ArrayList cols = new ArrayList(); while ( iter.hasNext() ) { cols.add( iter.next() ); } value.getTable().createUniqueKey( cols ); }
private void addSyntheticIndexProperty(List value, String propertyAccessorName, ClassAuditingData classAuditingData) { final Value indexValue = value.getIndex(); if ( indexValue != null && indexValue.getColumnIterator().hasNext() ) { final String indexColumnName = indexValue.getColumnIterator().next().getText(); if ( indexColumnName != null ) { final PropertyAuditingData auditingData = new PropertyAuditingData( indexColumnName, propertyAccessorName, ModificationStore.FULL, RelationTargetAuditMode.AUDITED, null, null, false, true, indexValue ); classAuditingData.addPropertyAuditingData( indexColumnName, auditingData ); } } }
@SuppressWarnings({"unchecked"}) private String searchMappedByKey(PersistentClass referencedClass, Collection collectionValue) { final Iterator<Value> assocIdClassProps = referencedClass.getKeyClosureIterator(); while ( assocIdClassProps.hasNext() ) { final Value value = assocIdClassProps.next(); // make sure its a 'Component' because IdClass is registered as this type. if ( value instanceof Component ) { final Component component = (Component) value; final Iterator<Property> componentPropertyIterator = component.getPropertyIterator(); while ( componentPropertyIterator.hasNext() ) { final Property property = componentPropertyIterator.next(); final Iterator<Selectable> propertySelectables = property.getValue().getColumnIterator(); final Iterator<Selectable> collectionSelectables = collectionValue.getKey().getColumnIterator(); if ( Tools.iteratorsContentEqual( propertySelectables, collectionSelectables ) ) { return property.getName(); } } } } return null; }
private void checkColumnDuplication(java.util.Set distinctColumns, Value value) throws MappingException { final boolean[] insertability = value.getColumnInsertability(); final boolean[] updatability = value.getColumnUpdateability(); final Iterator<Selectable> iterator = value.getColumnIterator(); int i = 0; while ( iterator.hasNext() ) { Selectable s = iterator.next(); // 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() ); } } i++; } }
@SuppressWarnings({"unchecked"}) private String searchMappedBy(PersistentClass referencedClass, Collection collectionValue) { final Iterator<Property> assocClassProps = referencedClass.getPropertyIterator(); while ( assocClassProps.hasNext() ) { final Property property = assocClassProps.next(); if ( Tools.iteratorsContentEqual( property.getValue().getColumnIterator(), collectionValue.getKey().getColumnIterator() ) ) { return property.getName(); } } // HHH-7625 // Support ToOne relations with mappedBy that point to an @IdClass key property. return searchMappedByKey( referencedClass, collectionValue ); }
protected Iterator getDiscriminatorColumnIterator() { if ( isDiscriminatorInsertable() && !getDiscriminator().hasFormula() ) { return getDiscriminator().getColumnIterator(); } else { return super.getDiscriminatorColumnIterator(); } }
@Test public void testColumnDefinition() { Column idCol = ( Column ) metadata().getEntityBinding( Ball.class.getName() ) .getIdentifierProperty().getValue().getColumnIterator().next(); assertEquals( "ball_id", idCol.getName() ); }
@Override protected void afterMetadataBuilt(Metadata metadata) { Collection children = metadata.getCollectionBinding( Parent.class.getName() + ".children" ); Component childComponents = ( Component ) children.getElement(); Formula f = ( Formula ) childComponents.getProperty( "bioLength" ).getValue().getColumnIterator().next(); SQLFunction lengthFunction = metadata.getDatabase().getJdbcEnvironment().getDialect().getFunctions().get( "length" ); if ( lengthFunction != null ) { ArrayList args = new ArrayList(); args.add( "bio" ); f.setFormula( lengthFunction.render( StandardBasicTypes.INTEGER, args, null ) ); } }
private Element buildProperty( Element parent, PropertyAuditingData propertyAuditingData, Value value, boolean insertable, boolean key) { final Element propMapping = MetadataTools.addProperty( parent, propertyAuditingData.getName(), isAddNestedType( value ) ? null : getBasicTypeName( value.getType() ), propertyAuditingData.isForceInsertable() || insertable, key ); MetadataTools.addColumns( propMapping, value.getColumnIterator() ); return propMapping; }
@Test public void testDiscriminatorFormulaInAuditTable() { assert parentAudit.getDiscriminator().hasFormula(); Iterator iterator = parentAudit.getDiscriminator().getColumnIterator(); while ( iterator.hasNext() ) { Object o = iterator.next(); if ( o instanceof Formula ) { Formula formula = (Formula) o; Assert.assertEquals( ParentEntity.DISCRIMINATOR_QUERY, formula.getText() ); return; } } assert false; }
@SuppressWarnings({"unchecked"}) boolean addManyToOne( Element parent, PropertyAuditingData propertyAuditingData, Value value, SimpleMapperBuilder mapper) { final Type type = value.getType(); // A null mapper occurs when adding to composite-id element final Element manyToOneElement = parent.addElement( mapper != null ? "many-to-one" : "key-many-to-one" ); manyToOneElement.addAttribute( "name", propertyAuditingData.getName() ); manyToOneElement.addAttribute( "class", type.getName() ); // HHH-11107 // Use FK hbm magic value 'none' to skip making foreign key constraints between the Envers // schema and the base table schema when a @ManyToOne is present in an identifier. if ( mapper == null ) { manyToOneElement.addAttribute( "foreign-key", "none" ); } MetadataTools.addColumns( manyToOneElement, value.getColumnIterator() ); return true; }
@Override protected void afterMetadataBuilt(Metadata metadata) { // Oracle and Postgres do not have year() functions, so we need to // redefine the 'User.person.yob' formula // // consider temporary until we add the capability to define // mapping formulas which can use dialect-registered functions... PersistentClass user = metadata.getEntityBinding( User.class.getName() ); org.hibernate.mapping.Property personProperty = user.getProperty( "person" ); Component component = ( Component ) personProperty.getValue(); Formula f = ( Formula ) component.getProperty( "yob" ).getValue().getColumnIterator().next(); SQLFunction yearFunction = metadata.getDatabase().getJdbcEnvironment().getDialect().getFunctions().get( "year" ); if ( yearFunction == null ) { // the dialect not know to support a year() function, so rely on the // ANSI SQL extract function f.setFormula( "extract( year from dob )"); } else { List args = new ArrayList(); args.add( "dob" ); f.setFormula( yearFunction.render( StandardBasicTypes.INTEGER, args, null ) ); } }
protected void validateCustomerOrders(Metadata metadata) { final Collection collectionBinding = metadata.getCollectionBinding( Customer.class.getName() + ".orders" ); assertNotNull( collectionBinding ); validateCustomerOrdersTableName( collectionBinding.getCollectionTable().getQuotedName() ); assertEquals( 1, collectionBinding.getKey().getColumnSpan() ); validateCustomerOrdersKeyColumn( (Column) collectionBinding.getKey().getColumnIterator().next() ); assertEquals( 1, collectionBinding.getElement().getColumnSpan() ); validateCustomerOrdersElementColumn( (Column) collectionBinding.getElement().getColumnIterator().next() ); }
protected void validateCustomerIndustries(Metadata metadata) { final Collection collectionBinding = metadata.getCollectionBinding( Customer.class.getName() + ".industries" ); assertNotNull( collectionBinding ); validateCustomerIndustriesTableName( collectionBinding.getCollectionTable().getQuotedName() ); assertEquals( 1, collectionBinding.getKey().getColumnSpan() ); validateCustomerIndustriesKeyColumn( (Column) collectionBinding.getKey().getColumnIterator().next() ); assertEquals( 1, collectionBinding.getElement().getColumnSpan() ); validateCustomerIndustriesElementColumn( (Column) collectionBinding.getElement().getColumnIterator().next() ); }
protected void validateCustomerRegisteredTrademarks(Metadata metadata) { final Collection collectionBinding = metadata.getCollectionBinding( Customer.class.getName() + ".registeredTrademarks" ); assertNotNull( collectionBinding ); validateCustomerRegisteredTrademarksTableName( collectionBinding.getCollectionTable().getQuotedName() ); assertEquals( 1, collectionBinding.getKey().getColumnSpan() ); validateCustomerRegisteredTrademarksKeyColumn( (Column) collectionBinding.getKey().getColumnIterator().next() ); assertEquals( 1, collectionBinding.getElement().getColumnSpan() ); validateCustomerRegisteredTrademarksElementColumn( (Column) collectionBinding.getElement() .getColumnIterator() .next() ); }
@SuppressWarnings({"unchecked"}) private Triple<Element, ExtendedPropertyMapper, String> generateMappingData( PersistentClass pc, EntityXmlMappingData xmlMappingData, AuditTableData auditTableData, IdMappingData idMapper) { final Element classMapping = MetadataTools.createEntity( xmlMappingData.getMainXmlMapping(), auditTableData, pc.getDiscriminatorValue(), pc.isAbstract() ); final ExtendedPropertyMapper propertyMapper = new MultiPropertyMapper(); // Checking if there is a discriminator column if ( pc.getDiscriminator() != null ) { final Element discriminatorElement = classMapping.addElement( "discriminator" ); // Database column or SQL formula allowed to distinguish entity types MetadataTools.addColumnsOrFormulas( discriminatorElement, pc.getDiscriminator().getColumnIterator() ); discriminatorElement.addAttribute( "type", pc.getDiscriminator().getType().getName() ); } // Adding the id mapping classMapping.add( (Element) idMapper.getXmlMapping().clone() ); // Adding the "revision type" property addRevisionType( classMapping, classMapping ); addAdditionalColumns( classMapping ); return Triple.make( classMapping, propertyMapper, null ); }
@Override protected void createBackReferences() { super.createBackReferences(); boolean indexIsFormula = false; Iterator itr = getCollectionBinding().getIndex().getColumnIterator(); while ( itr.hasNext() ) { if ( ( (Selectable) itr.next() ).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(); 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 ); } } }