protected Collection createCollection(PersistentClass persistentClass) { return new org.hibernate.mapping.Map( getBuildingContext(), persistentClass ); }
@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 ); } } }
mapProperty.getValue(), map, targetPropertyName, associatedClass, targetPropertyPersistentClass, buildingContext ); map.setIndex( indexValue ); org.hibernate.mapping.Map mapValue = (org.hibernate.mapping.Map) this.collection; if ( isIndexOfEntities ) { element = new ManyToOne( buildingContext, mapValue.getCollectionTable() ); mapValue.setIndex( element ); element.setReferencedEntityName( mapKeyType ); StringHelper.qualify( mapValue.getRole(), "mapkey" ), keyXClass, property, holder.prepare( property ); PersistentClass owner = mapValue.getOwner(); AccessType accessType; inheritanceStatePerClass ); mapValue.setIndex( component ); column.setTable( mapValue.getCollectionTable() ); elementBinder.setPersistentClassName( propertyHolder.getEntityName() ); elementBinder.setAccessType( accessType ); mapValue.setIndex( elementBinder.make() );
public CollectionType getDefaultCollectionType() { if ( isSorted() ) { return getMetadata().getTypeResolver() .getTypeFactory() .sortedMap( getRole(), getReferencedPropertyName(), getComparator() ); } else if ( hasOrder() ) { return getMetadata().getTypeResolver() .getTypeFactory() .orderedMap( getRole(), getReferencedPropertyName() ); } else { return getMetadata().getTypeResolver() .getTypeFactory() .map( getRole(), getReferencedPropertyName() ); } }
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 Selectable selectable = indexValue.getColumnIterator().next(); if ( selectable.isFormula() ) { throw new AssertionFailure( "Map key mapped by @MapKeyColumn is a Formula" ); } Column column = (Column) map.getIndex().getColumnIterator().next(); 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 ); } } } }
SimpleValue value = new SimpleValue( map.getCollectionTable() ); bindSimpleValue( subnode, value, map.isOneToMany(), IndexedCollection.DEFAULT_INDEX_COLUMN_NAME, mappings ); if ( !value.isTypeSpecified() ) { throw new MappingException( "map index element must specify a type: " + map.getRole() ); map.setIndex( value ); map.setIndexNodeName( subnode.attributeValue("node") ); ManyToOne mto = new ManyToOne( map.getCollectionTable() ); bindManyToOne( subnode, mto, IndexedCollection.DEFAULT_INDEX_COLUMN_NAME, map .isOneToMany(), mappings ); map.setIndex( mto ); subnode, component, map.getRole() + ".index", map.isOneToMany(), mappings, inheritedMetas ); map.setIndex( component ); Any any = new Any( map.getCollectionTable() ); bindAny( subnode, any, map.isOneToMany(), mappings );
public CollectionType getDefaultCollectionType() { return isSorted() ? TypeFactory.sortedMap( getRole(), getReferencedPropertyName(), isEmbedded(), getComparator() ) : TypeFactory.map( getRole(), getReferencedPropertyName(), isEmbedded() ); }
bindCollectionSecondPass(property, mappings, persistentClasses, map, sessionFactoryBeanName); SimpleValue value = new SimpleValue(mappings, map.getCollectionTable()); throw new MappingException("map index element must specify a type: " + map.getRole()); map.setIndex(value); SimpleValue elt = new SimpleValue(mappings, map.getCollectionTable()); map.setElement(elt); map.setInverse(false);
subnode, value, map.isOneToMany(), IndexedCollection.DEFAULT_INDEX_COLUMN_NAME, mappings + map.getRole() ); map.setIndex( value ); map.setIndexNodeName( subnode.attributeValue("node") ); ManyToOne mto = new ManyToOne( map.getCollectionTable() ); bindManyToOne( subnode, mto, IndexedCollection.DEFAULT_INDEX_COLUMN_NAME, map.isOneToMany(), mappings ); subnode, component, map.getRole() + ".index", map.isOneToMany(), mappings,
targetPropertyPersistentClass ); map.setIndex( indexValue ); org.hibernate.mapping.Map mapValue = (org.hibernate.mapping.Map) this.collection; if ( isIndexOfEntities ) { element = new ManyToOne( buildingContext, mapValue.getMappedTable() ); mapValue.setIndex( element ); element.setReferencedEntityName( mapKeyType ); StringHelper.qualify( mapValue.getRole(), "mapkey" ), keyXClass, property, holder.prepare( property ); final PersistentClass owner = mapValue.getOwner(); AccessType accessType; inheritanceStatePerClass ); mapValue.setIndex( component ); column.setTable( mapValue.getMappedTable() ); mapValue.setIndex( elementBinder.make() ); elementBinder.setType( property,
public Value getHibernateValue() { return ( (Map) getPropertyMapping().getValue() ).getIndex(); }
final SimpleValue value = new SimpleValue( mappingDocument, collectionBinding.getCollectionTable() ); bindSimpleValueType( collectionBinding.setIndex( value ); false ); collectionBinding.setIndex( componentBinding ); final ManyToOne mapKeyBinding = new ManyToOne( mappingDocument, collectionBinding.getCollectionTable() ); collectionBinding.setIndex( mapKeyBinding ); final Any mapKeyBinding = new Any( mappingDocument, collectionBinding.getCollectionTable() ); bindAny( pluralAttributeSource.getAttributePath().append( "key" ) ); collectionBinding.setIndex( mapKeyBinding );
public Object accept(Map o) { if ( o.isSorted() ) { return "java.util.SortedMap"; } return super.accept(o); }
@Override @SuppressWarnings("unchecked") public CollectionSemantics getCollectionSemantics() { final Comparator comparator = getComparator(); if ( comparator != null ) { return StandardSortedMapSemantics.INSTANCE; } if ( hasOrder() ) { return StandardOrderedMapSemantics.INSTANCE; } return StandardMapSemantics.INSTANCE; } }
@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 ); }
@Override public Collection create(ToMany property, PersistentClass owner, String path, Mappings mappings, String sessionFactoryBeanName) throws MappingException { org.hibernate.mapping.Map map = new org.hibernate.mapping.Map(mappings, owner); map.setTypeName(getTypeName(property)); binder.bindCollection(property, map, owner, mappings, path, sessionFactoryBeanName); return map; } };
final BasicValue value = new BasicValue( mappingDocument, collectionBinding.getMappedTable() ); bindSimpleValueType( collectionBinding.setIndex( value ); false ); collectionBinding.setIndex( componentBinding ); final ManyToOne mapKeyBinding = new ManyToOne( mappingDocument, collectionBinding.getMappedTable() ); collectionBinding.setIndex( mapKeyBinding ); final Any mapKeyBinding = new Any( mappingDocument, collectionBinding.getMappedTable() ); bindAny( pluralAttributeSource.getAttributeRole().append( "key" ) ); collectionBinding.setIndex( mapKeyBinding );
public static void bindIdentifierCollectionSecondPass(Element node, IdentifierCollection collection, java.util.Map persistentClasses, Mappings mappings, java.util.Map inheritedMetas) throws MappingException { bindCollectionSecondPass( node, collection, persistentClasses, mappings, inheritedMetas ); Element subnode = node.element( "collection-id" ); SimpleValue id = new SimpleValue( collection.getCollectionTable() ); bindSimpleValue( subnode, id, false, IdentifierCollection.DEFAULT_IDENTIFIER_COLUMN_NAME, mappings ); collection.setIdentifier( id ); makeIdentifier( subnode, id, mappings ); }