@Override @SuppressWarnings("unchecked") public Serializable disassemble(CollectionPersister persister) throws HibernateException { final Serializable[] result = new Serializable[ map.size() * 2 ]; final Iterator itr = map.entrySet().iterator(); int i=0; while ( itr.hasNext() ) { final Map.Entry e = (Map.Entry) itr.next(); result[i++] = persister.getIndexType().disassemble( e.getKey(), getSession(), null ); result[i++] = persister.getElementType().disassemble( e.getValue(), getSession(), null ); } return result; }
@Override public Object replaceElements( final Object original, final Object target, final Object owner, final java.util.Map copyCache, final SharedSessionContractImplementor session) throws HibernateException { CollectionPersister cp = session.getFactory().getMetamodel().collectionPersister( getRole() ); java.util.Map result = (java.util.Map) target; result.clear(); for ( Object o : ( (Map) original ).entrySet() ) { Map.Entry me = (Map.Entry) o; Object key = cp.getIndexType().replace( me.getKey(), null, session, owner, copyCache ); Object value = cp.getElementType().replace( me.getValue(), null, session, owner, copyCache ); result.put( key, value ); } return result; }
@Override public boolean needsRecreate(CollectionPersister persister) { // Workaround for situations like HHH-7072. If the collection element is a component that consists entirely // of nullable properties, we currently have to forcefully recreate the entire collection. See the use // of hasNotNullableColumns in the AbstractCollectionPersister constructor for more info. In order to delete // row-by-row, that would require SQL like "WHERE ( COL = ? OR ( COL is null AND ? is null ) )", rather than // the current "WHERE COL = ?" (fails for null for most DBs). Note that // the param would have to be bound twice. Until we eventually add "parameter bind points" concepts to the // AST in ORM 5+, handling this type of condition is either extremely difficult or impossible. Forcing // recreation isn't ideal, but not really any other option in ORM 4. // Selecting a type used in where part of update statement // (must match condidion in org.hibernate.persister.collection.BasicCollectionPersister.doUpdateRows). // See HHH-9474 Type whereType; if ( persister.hasIndex() ) { whereType = persister.getIndexType(); } else { whereType = persister.getElementType(); } if ( whereType instanceof CompositeType ) { CompositeType componentIndexType = (CompositeType) whereType; return !componentIndexType.hasNotNullProperty(); } return false; }
@Override @SuppressWarnings("unchecked") public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner) throws HibernateException { final Serializable[] array = (Serializable[]) disassembled; final int size = array.length; beforeInitialize( persister, size ); for ( int i = 0; i < size; i+=2 ) { map.put( persister.getIndexType().assemble( array[i], getSession(), owner ), persister.getElementType().assemble( array[i+1], getSession(), owner ) ); } }
public MapKeyAttribute(CriteriaBuilderImpl criteriaBuilder, MapAttribute<?, K, ?> attribute) { this.attribute = attribute; this.jpaType = attribute.getKeyType(); this.jpaBinableJavaType = attribute.getKeyJavaType(); this.jpaBindableType = Type.PersistenceType .ENTITY.equals( jpaType.getPersistenceType() ) ? BindableType.ENTITY_TYPE : BindableType.SINGULAR_ATTRIBUTE; String guessedRoleName = determineRole( attribute ); SessionFactoryImplementor sfi = criteriaBuilder.getEntityManagerFactory().getSessionFactory(); mapPersister = sfi.getCollectionPersister( guessedRoleName ); if ( mapPersister == null ) { throw new IllegalStateException( "Could not locate collection persister [" + guessedRoleName + "]" ); } mapKeyType = mapPersister.getIndexType(); if ( mapKeyType == null ) { throw new IllegalStateException( "Could not determine map-key type [" + guessedRoleName + "]" ); } this.persistentAttributeType = mapKeyType.isEntityType() ? PersistentAttributeType.MANY_TO_ONE : mapKeyType.isComponentType() ? PersistentAttributeType.EMBEDDED : PersistentAttributeType.BASIC; }
private CollectionFetchableIndex buildIndexGraph() { final CollectionPersister persister = collectionQuerySpace.getCollectionPersister(); if ( persister.hasIndex() ) { final Type type = persister.getIndexType(); if ( type.isAssociationType() ) { if ( type.isEntityType() ) { indexPersister, CollectionPropertyNames.COLLECTION_INDICES, (EntityType) persister.getIndexType(), collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(), collectionQuerySpace.canJoinsBeRequired(), collectionQuerySpace, new CompositePropertyMapping( (CompositeType) persister.getIndexType(), (PropertyMapping) persister, "" ), CollectionPropertyNames.COLLECTION_INDICES, (CompositeType) persister.getIndexType(), collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(), collectionQuerySpace.canJoinsBeRequired(),
); collectionPersisterMap.put( model.getRole(), persister ); Type indexType = persister.getIndexType(); if ( indexType != null && indexType.isAssociationType() && !indexType.isAnyType() ) { String entityName = ( (AssociationType) indexType ).getAssociatedEntityName( sessionFactory );
protected AbstractCollectionReference( ExpandingCollectionQuerySpace collectionQuerySpace, PropertyPath propertyPath, boolean shouldIncludeJoins) { this.collectionQuerySpace = collectionQuerySpace; this.propertyPath = propertyPath; this.allowElementJoin = shouldIncludeJoins; // Currently we can only allow a join for the collection index if all of the following are true: // - collection element joins are allowed; // - index is an EntityType; // - index values are not "formulas" (e.g., a @MapKey index is translated into "formula" value(s)). // Hibernate cannot currently support eager joining of associations within a component (@Embeddable) as an index. if ( shouldIncludeJoins && collectionQuerySpace.getCollectionPersister().hasIndex() && collectionQuerySpace.getCollectionPersister().getIndexType().isEntityType() ) { final String[] indexFormulas = ( (QueryableCollection) collectionQuerySpace.getCollectionPersister() ).getIndexFormulas(); final int nNonNullFormulas = ArrayHelper.countNonNull( indexFormulas ); this.allowIndexJoin = nNonNullFormulas == 0; } else { this.allowIndexJoin = false; } // All other fields must be initialized before building this.index and this.element. this.index = buildIndexGraph(); this.element = buildElementGraph(); }
rightHandSide.getCollectionPersister().getIndexType().isEntityType() ) {
); if ( rootReturn.allowIndexJoin() && rootReturn.getCollectionPersister().getIndexType().isEntityType() ) { final EntityReference indexEntityReference = rootReturn.getIndexGraph().resolveEntityReference(); final EntityReferenceAliases indexEntityReferenceAliases = aliasResolutionContext.generateEntityReferenceAliases(
public Serializable disassemble(CollectionPersister persister) throws HibernateException { Serializable[] result = new Serializable[ map.size() * 2 ]; Iterator iter = map.entrySet().iterator(); int i=0; while ( iter.hasNext() ) { java.util.Map.Entry e = (java.util.Map.Entry) iter.next(); result[i++] = persister.getIndexType().disassemble( e.getKey(), getSession(), null ); result[i++] = persister.getElementType().disassemble( e.getValue(), getSession(), null ); } return result; }
public Serializable disassemble(CollectionPersister persister) throws HibernateException { Serializable[] result = new Serializable[ map.size() * 2 ]; Iterator iter = map.entrySet().iterator(); int i=0; while ( iter.hasNext() ) { Map.Entry e = (Map.Entry) iter.next(); result[i++] = persister.getIndexType().disassemble( e.getKey(), getSession(), null ); result[i++] = persister.getElementType().disassemble( e.getValue(), getSession(), null ); } return result; }
public Object getIndex(Object entry, int i, CollectionPersister persister) { String index = ( (IndexedValue) entry ).index; final Type indexType = persister.getIndexType(); return ( (NullableType) indexType ).fromXMLString( index, persister.getFactory() ); }
public Object getIndex(Object entry, int i, CollectionPersister persister) { String index = ( (IndexedValue) entry ).index; final Type indexType = persister.getIndexType(); return ( (XmlRepresentableType) indexType ).fromXMLString( index, persister.getFactory() ); }
public Object getIndex(Object entry, int i, CollectionPersister persister) { String index = ( (IndexedValue) entry ).index; final Type indexType = persister.getIndexType(); return ( (NullableType) indexType ).fromXMLString( index, persister.getFactory() ); }
public Object getIndex(Object entry, int i, CollectionPersister persister) { String index = ( (IndexedValue) entry ).index; final Type indexType = persister.getIndexType(); return ( (XmlRepresentableType) indexType ).fromXMLString( index, persister.getFactory() ); }
public PersistentSortedMap(SessionImplementor session, CollectionPersister persister, Comparator comparator, Serializable disassembled, Object owner) throws HibernateException { super(session); this.comparator=comparator; beforeInitialize(persister); Serializable[] array = (Serializable[]) disassembled; for (int i=0; i<array.length; i+=2 ) map.put( persister.getIndexType().assemble( array[i], session, owner ), persister.getElementType().assemble( array[i+1], session, owner ) ); setInitialized(); }
public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner) throws HibernateException { Serializable[] array = ( Serializable[] ) disassembled; int size = array.length; beforeInitialize( persister, size ); for ( int i = 0; i < size; i+=2 ) { map.put( persister.getIndexType().assemble( array[i], getSession(), owner ), persister.getElementType().assemble( array[i+1], getSession(), owner ) ); } }
public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner) throws HibernateException { beforeInitialize(persister); Serializable[] array = (Serializable[]) disassembled; for (int i=0; i<array.length; i+=2 ) map.put( persister.getIndexType().assemble( array[i], getSession(), owner ), persister.getElementType().assemble( array[i+1], getSession(), owner ) ); }
public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner) throws HibernateException { Serializable[] array = ( Serializable[] ) disassembled; int size = array.length; beforeInitialize( persister, size ); for ( int i = 0; i < size; i+=2 ) { map.put( persister.getIndexType().assemble( array[i], getSession(), owner ), persister.getElementType().assemble( array[i+1], getSession(), owner ) ); } }