Java Code Examples for org.hibernate.persister.collection.CollectionPersister#getElementType()
The following examples show how to use
org.hibernate.persister.collection.CollectionPersister#getElementType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractPersistentCollection.java From lams with GNU General Public License v2.0 | 6 votes |
@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; }
Example 2
Source File: PersistentMapElementHolder.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner) throws HibernateException { Type elementType = persister.getElementType(); Type indexType = persister.getIndexType(); final String indexNodeName = getIndexAttributeName(persister); Serializable[] cached = (Serializable[]) disassembled; for ( int i=0; i<cached.length; ) { Object index = indexType.assemble( cached[i++], getSession(), owner ); Object object = elementType.assemble( cached[i++], getSession(), owner ); Element subelement = element.addElement( persister.getElementNodeName() ); elementType.setToXMLNode( subelement, object, persister.getFactory() ); String indexString = ( (NullableType) indexType ).toXMLString( index, persister.getFactory() ); setIndex( subelement, indexNodeName, indexString ); } }
Example 3
Source File: PersistentMapElementHolder.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public Serializable disassemble(CollectionPersister persister) throws HibernateException { Type elementType = persister.getElementType(); Type indexType = persister.getIndexType(); final String indexNodeName = getIndexAttributeName(persister); List elements = element.elements( persister.getElementNodeName() ); int length = elements.size(); Serializable[] result = new Serializable[length*2]; for ( int i=0; i<length*2; ) { Element elem = (Element) elements.get(i/2); Object object = elementType.fromXMLNode( elem, persister.getFactory() ); final String indexString = getIndex(elem, indexNodeName, i); Object index = ( (NullableType) indexType ).fromXMLString( indexString, persister.getFactory() ); result[i++] = indexType.disassemble( index, getSession(), null ); result[i++] = elementType.disassemble( object, getSession(), null ); } return result; }
Example 4
Source File: PersistentSet.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException { final Type elementType = persister.getElementType(); final java.util.Map sn = (java.util.Map) getSnapshot(); if ( sn.size()!=set.size() ) { return false; } else { for ( Object test : set ) { final Object oldValue = sn.get( test ); if ( oldValue == null || elementType.isDirty( oldValue, test, getSession() ) ) { return false; } } return true; } }
Example 5
Source File: PersistentList.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException { final Type elementType = persister.getElementType(); final List sn = (List) getSnapshot(); if ( sn.size()!=this.list.size() ) { return false; } final Iterator itr = list.iterator(); final Iterator snapshotItr = sn.iterator(); while ( itr.hasNext() ) { if ( elementType.isDirty( itr.next(), snapshotItr.next(), getSession() ) ) { return false; } } return true; }
Example 6
Source File: PersistentIdentifierBag.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException { final Type elementType = persister.getElementType(); final Map snap = (Map) getSnapshot(); if ( snap.size()!= values.size() ) { return false; } for ( int i=0; i<values.size(); i++ ) { final Object value = values.get( i ); final Object id = identifiers.get( i ); if ( id == null ) { return false; } final Object old = snap.get( id ); if ( elementType.isDirty( old, value, getSession() ) ) { return false; } } return true; }
Example 7
Source File: PersistentSet.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException { Type elementType = persister.getElementType(); java.util.Map sn = (java.util.Map) getSnapshot(); if ( sn.size()!=set.size() ) { return false; } else { Iterator iter = set.iterator(); while ( iter.hasNext() ) { Object test = iter.next(); Object oldValue = sn.get(test); if ( oldValue==null || elementType.isDirty( oldValue, test, getSession() ) ) return false; } return true; } }
Example 8
Source File: AliasResolutionContextImpl.java From lams with GNU General Public License v2.0 | 6 votes |
private EntityReferenceAliases createCollectionElementAliases( CollectionPersister collectionPersister, String tableAlias, String elementQuerySpaceUid) { if ( !collectionPersister.getElementType().isEntityType() ) { return null; } else { final EntityType entityElementType = (EntityType) collectionPersister.getElementType(); return generateEntityReferenceAliases( elementQuerySpaceUid, tableAlias, (EntityPersister) entityElementType.getAssociatedJoinable( sessionFactory() ) ); } }
Example 9
Source File: PersistentIndexedElementHolder.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public Object readFrom(ResultSet rs, CollectionPersister persister, CollectionAliases descriptor, Object owner) throws HibernateException, SQLException { Object object = persister.readElement( rs, owner, descriptor.getSuffixedElementAliases(), getSession() ); final Type elementType = persister.getElementType(); final SessionFactoryImplementor factory = persister.getFactory(); String indexNode = getIndexAttributeName(persister); Element elem = element.addElement( persister.getElementNodeName() ); elementType.setToXMLNode( elem, object, factory ); final Type indexType = persister.getIndexType(); final Object indexValue = persister.readIndex( rs, descriptor.getSuffixedIndexAliases(), getSession() ); final String index = ( (NullableType) indexType ).toXMLString( indexValue, factory ); setIndex(elem, indexNode, index); return object; }
Example 10
Source File: PersistentElementHolder.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public Iterator entries(CollectionPersister persister) { final Type elementType = persister.getElementType(); List elements = element.elements( persister.getElementNodeName() ); int length = elements.size(); List result = new ArrayList(length); for ( int i=0; i<length; i++ ) { Element elem = (Element) elements.get(i); Object object = elementType.fromXMLNode( elem, persister.getFactory() ); result.add(object); } return result.iterator(); }
Example 11
Source File: PersistentIndexedElementHolder.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public Iterator entries(CollectionPersister persister) { final Type elementType = persister.getElementType(); String indexNode = getIndexAttributeName(persister); List elements = element.elements( persister.getElementNodeName() ); int length = elements.size(); List result = new ArrayList(length); for ( int i=0; i<length; i++ ) { Element elem = (Element) elements.get(i); Object object = elementType.fromXMLNode( elem, persister.getFactory() ); result.add( new IndexedValue( getIndex(elem, indexNode, i), object ) ); } return result.iterator(); }
Example 12
Source File: PersistentElementHolder.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public Serializable getSnapshot(CollectionPersister persister) throws HibernateException { final Type elementType = persister.getElementType(); List elements = element.elements( persister.getElementNodeName() ); ArrayList snapshot = new ArrayList( elements.size() ); for ( int i=0; i<elements.size(); i++ ) { Element elem = (Element) elements.get(i); Object value = elementType.fromXMLNode( elem, persister.getFactory() ); Object copy = elementType.deepCopy(value , getSession().getEntityMode(), persister.getFactory() ); snapshot.add(copy); } return snapshot; }
Example 13
Source File: Cascade.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 5 votes |
/** * Cascade an action to a collection */ private void cascadeCollection( final int componentPathStackDepth, final Object child, final CascadeStyle style, final CollectionType type) { final CollectionPersister persister = eventSource.getFactory().getMetamodel().collectionPersister( type.getRole() ); final Type elemType = persister.getElementType(); CascadePoint elementsCascadePoint = cascadePoint; if ( cascadePoint == CascadePoint.AFTER_INSERT_BEFORE_DELETE ) { cascadePoint = CascadePoint.AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION; } //cascade to current collection elements if ( elemType.isEntityType() || elemType.isAnyType() || elemType.isComponentType() ) { cascadeCollectionElements( componentPathStackDepth, child, type, style, elemType, persister.isCascadeDeleteEnabled() ); } cascadePoint = elementsCascadePoint; }
Example 14
Source File: PersistentArrayHolder.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException { final Type elementType = persister.getElementType(); final Serializable snapshot = getSnapshot(); final int xlen = Array.getLength( snapshot ); if ( xlen!= Array.getLength( array ) ) { return false; } for ( int i=0; i<xlen; i++) { if ( elementType.isDirty( Array.get( snapshot, i ), Array.get( array, i ), getSession() ) ) { return false; } } return true; }
Example 15
Source File: PersistentElementHolder.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public Serializable disassemble(CollectionPersister persister) throws HibernateException { Type elementType = persister.getElementType(); List elements = element.elements( persister.getElementNodeName() ); int length = elements.size(); Serializable[] result = new Serializable[length]; for ( int i=0; i<length; i++ ) { Element elem = (Element) elements.get(i); Object object = elementType.fromXMLNode( elem, persister.getFactory() ); result[i] = elementType.disassemble( object, getSession(), null ); } return result; }
Example 16
Source File: PersistentListElementHolder.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public Serializable disassemble(CollectionPersister persister) throws HibernateException { Type elementType = persister.getElementType(); final String indexNodeName = getIndexAttributeName(persister); List elements = element.elements( persister.getElementNodeName() ); int length = elements.size(); Serializable[] result = new Serializable[length]; for ( int i=0; i<length; i++ ) { Element elem = (Element) elements.get(i); Object object = elementType.fromXMLNode( elem, persister.getFactory() ); Integer index = (Integer) Hibernate.INTEGER.fromStringValue( getIndex(elem, indexNodeName, i) ); result[ index.intValue() ] = elementType.disassemble( object, getSession(), null ); } return result; }
Example 17
Source File: PersistentBag.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public boolean equalsSnapshot(CollectionPersister persister) throws HibernateException { Type elementType = persister.getElementType(); EntityMode entityMode = getSession().getEntityMode(); List sn = (List) getSnapshot(); if ( sn.size()!=bag.size() ) return false; Iterator iter = bag.iterator(); while ( iter.hasNext() ) { Object elt = iter.next(); final boolean unequal = countOccurrences(elt, bag, elementType, entityMode) != countOccurrences(elt, sn, elementType, entityMode); if ( unequal ) return false; } return true; }
Example 18
Source File: PersistentBag.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public Iterator getDeletes(CollectionPersister persister, boolean indexIsFormula) throws HibernateException { //if ( !persister.isOneToMany() ) throw new AssertionFailure("Not implemented for Bags"); Type elementType = persister.getElementType(); EntityMode entityMode = getSession().getEntityMode(); ArrayList deletes = new ArrayList(); List sn = (List) getSnapshot(); Iterator olditer = sn.iterator(); int i=0; while ( olditer.hasNext() ) { Object old = olditer.next(); Iterator newiter = bag.iterator(); boolean found = false; if ( bag.size()>i && elementType.isSame( old, bag.get(i++), entityMode ) ) { //a shortcut if its location didn't change! found = true; } else { //search for it //note that this code is incorrect for other than one-to-many while ( newiter.hasNext() ) { if ( elementType.isSame( old, newiter.next(), entityMode ) ) { found = true; break; } } } if (!found) deletes.add(old); } return deletes.iterator(); }
Example 19
Source File: PersistentListElementHolder.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public void initializeFromCache(CollectionPersister persister, Serializable disassembled, Object owner) throws HibernateException { Type elementType = persister.getElementType(); final String indexNodeName = getIndexAttributeName(persister); Serializable[] cached = (Serializable[]) disassembled; for ( int i=0; i<cached.length; i++ ) { Object object = elementType.assemble( cached[i], getSession(), owner ); Element subelement = element.addElement( persister.getElementNodeName() ); elementType.setToXMLNode( subelement, object, persister.getFactory() ); setIndex( subelement, indexNodeName, Integer.toString(i) ); } }
Example 20
Source File: AbstractCollectionReference.java From lams with GNU General Public License v2.0 | 4 votes |
private CollectionFetchableElement buildElementGraph() { final CollectionPersister persister = collectionQuerySpace.getCollectionPersister(); final Type type = persister.getElementType(); if ( type.isAssociationType() ) { if ( type.isEntityType() ) { final EntityPersister elementPersister = persister.getFactory().getEntityPersister( ( (EntityType) type ).getAssociatedEntityName() ); final ExpandingEntityQuerySpace entityQuerySpace = QuerySpaceHelper.INSTANCE.makeEntityQuerySpace( collectionQuerySpace, elementPersister, CollectionPropertyNames.COLLECTION_ELEMENTS, (EntityType) persister.getElementType(), collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(), collectionQuerySpace.canJoinsBeRequired(), allowElementJoin ); return new CollectionFetchableElementEntityGraph( this, entityQuerySpace ); } else if ( type.isAnyType() ) { return new CollectionFetchableElementAnyGraph( this ); } } else if ( type.isComponentType() ) { final ExpandingCompositeQuerySpace compositeQuerySpace = QuerySpaceHelper.INSTANCE.makeCompositeQuerySpace( collectionQuerySpace, new CompositePropertyMapping( (CompositeType) persister.getElementType(), (PropertyMapping) persister, "" ), CollectionPropertyNames.COLLECTION_ELEMENTS, (CompositeType) persister.getElementType(), collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(), collectionQuerySpace.canJoinsBeRequired(), allowElementJoin ); return new CollectionFetchableElementCompositeGraph( this, compositeQuerySpace ); } return null; }