Java Code Examples for org.hibernate.type.Type#isAnyType()
The following examples show how to use
org.hibernate.type.Type#isAnyType() .
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: HibernateTraversableResolver.java From lams with GNU General Public License v2.0 | 6 votes |
private void addAssociationsToTheSetForOneProperty(String name, Type type, String prefix, SessionFactoryImplementor factory) { if ( type.isCollectionType() ) { CollectionType collType = (CollectionType) type; Type assocType = collType.getElementType( factory ); addAssociationsToTheSetForOneProperty(name, assocType, prefix, factory); } //ToOne association else if ( type.isEntityType() || type.isAnyType() ) { associations.add( prefix + name ); } else if ( type.isComponentType() ) { CompositeType componentType = (CompositeType) type; addAssociationsToTheSetForAllProperties( componentType.getPropertyNames(), componentType.getSubtypes(), (prefix.equals( "" ) ? name : prefix + name) + ".", factory); } }
Example 2
Source File: AbstractLoadPlanBuildingAssociationVisitationStrategy.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void finishingCollectionIndex(CollectionIndexDefinition indexDefinition) { final Type indexType = indexDefinition.getType(); if ( indexType.isAnyType() ) { // nothing to do because the index graph was not pushed in #startingCollectionIndex. } else if ( indexType.isEntityType() || indexType.isComponentType() ) { // todo : validate the stack? final ExpandingFetchSource fetchSource = popFromStack(); if ( !CollectionFetchableIndex.class.isInstance( fetchSource ) ) { throw new WalkingException( "CollectionReference did not return an expected index graph : " + indexDefinition.getCollectionDefinition().getCollectionPersister().getRole() ); } } log.tracef( "%s Finished collection index graph : %s", StringHelper.repeat( "<<", fetchSourceStack.size() ), indexDefinition.getCollectionDefinition().getCollectionPersister().getRole() ); }
Example 3
Source File: AbstractLoadPlanBuildingAssociationVisitationStrategy.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void finishingCollectionElements(CollectionElementDefinition elementDefinition) { final Type elementType = elementDefinition.getType(); if ( elementType.isAnyType() ) { // nothing to do because the element graph was not pushed in #startingCollectionElement.. } else if ( elementType.isComponentType() || elementType.isAssociationType()) { // pop it from the stack final ExpandingFetchSource popped = popFromStack(); // validation if ( ! CollectionFetchableElement.class.isInstance( popped ) ) { throw new WalkingException( "Mismatched FetchSource from stack on pop" ); } } log.tracef( "%s Finished collection element graph : %s", StringHelper.repeat( "<<", fetchSourceStack.size() ), elementDefinition.getCollectionDefinition().getCollectionPersister().getRole() ); }
Example 4
Source File: MetamodelGraphWalker.java From lams with GNU General Public License v2.0 | 6 votes |
private void visitCollectionElements(CollectionDefinition collectionDefinition) { final CollectionElementDefinition elementDefinition = collectionDefinition.getElementDefinition(); strategy.startingCollectionElements( elementDefinition ); final Type collectionElementType = elementDefinition.getType(); if ( collectionElementType.isAnyType() ) { visitAnyDefinition( elementDefinition.toAnyMappingDefinition() ); } else if ( collectionElementType.isComponentType() ) { visitCompositeDefinition( elementDefinition.toCompositeElementDefinition() ); } else if ( collectionElementType.isEntityType() ) { if ( ! collectionDefinition.getCollectionPersister().isOneToMany() ) { final QueryableCollection queryableCollection = (QueryableCollection) collectionDefinition.getCollectionPersister(); addAssociationKey( new AssociationKey( queryableCollection.getTableName(), queryableCollection.getElementColumnNames() ) ); } visitEntityDefinition( elementDefinition.toEntityDefinition() ); } strategy.finishingCollectionElements( elementDefinition ); }
Example 5
Source File: Cascade.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Cascade an action to a collection */ private void cascadeCollection( final Object child, final CascadeStyle style, final Object anything, final CollectionType type) { CollectionPersister persister = eventSource.getFactory() .getCollectionPersister( type.getRole() ); Type elemType = persister.getElementType(); final int oldCascadeTo = cascadeTo; if ( cascadeTo==AFTER_INSERT_BEFORE_DELETE) { cascadeTo = AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION; } //cascade to current collection elements if ( elemType.isEntityType() || elemType.isAnyType() || elemType.isComponentType() ) { cascadeCollectionElements( child, type, style, elemType, anything, persister.isCascadeDeleteEnabled() ); } cascadeTo = oldCascadeTo; }
Example 6
Source File: Cascade.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
private void cascadeAssociation( final Object child, final Type type, final CascadeStyle style, final Object anything, final boolean isCascadeDeleteEnabled) { if ( type.isEntityType() || type.isAnyType() ) { cascadeToOne( child, type, style, anything, isCascadeDeleteEnabled ); } else if ( type.isCollectionType() ) { cascadeCollection( child, style, anything, (CollectionType) type ); } }
Example 7
Source File: ForeignKeys.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Return null if the argument is an "unsaved" entity (ie. * one with no existing database row), or the input argument * otherwise. This is how Hibernate avoids foreign key constraint * violations. */ private Object nullifyTransientReferences(final Object value, final Type type) throws HibernateException { if ( value == null ) { return null; } else if ( type.isEntityType() ) { EntityType entityType = (EntityType) type; if ( entityType.isOneToOne() ) { return value; } else { String entityName = entityType.getAssociatedEntityName(); return isNullifiable(entityName, value) ? null : value; } } else if ( type.isAnyType() ) { return isNullifiable(null, value) ? null : value; } else if ( type.isComponentType() ) { AbstractComponentType actype = (AbstractComponentType) type; Object[] subvalues = actype.getPropertyValues(value, session); Type[] subtypes = actype.getSubtypes(); boolean substitute = false; for ( int i = 0; i < subvalues.length; i++ ) { Object replacement = nullifyTransientReferences( subvalues[i], subtypes[i] ); if ( replacement != subvalues[i] ) { substitute = true; subvalues[i] = replacement; } } if (substitute) actype.setPropertyValues( value, subvalues, session.getEntityMode() ); return value; } else { return value; } }
Example 8
Source File: Cascade.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Cascade an action to a collection */ private static void cascadeCollection( final CascadingAction action, final CascadePoint cascadePoint, final EventSource eventSource, final int componentPathStackDepth, final Object parent, final Object child, final CascadeStyle style, final Object anything, final CollectionType type) { final CollectionPersister persister = eventSource.getFactory().getCollectionPersister( type.getRole() ); final Type elemType = persister.getElementType(); CascadePoint elementsCascadePoint = cascadePoint; if ( cascadePoint == CascadePoint.AFTER_INSERT_BEFORE_DELETE ) { elementsCascadePoint = CascadePoint.AFTER_INSERT_BEFORE_DELETE_VIA_COLLECTION; } //cascade to current collection elements if ( elemType.isEntityType() || elemType.isAnyType() || elemType.isComponentType() ) { cascadeCollectionElements( action, elementsCascadePoint, eventSource, componentPathStackDepth, parent, child, type, style, elemType, anything, persister.isCascadeDeleteEnabled() ); } }
Example 9
Source File: Cascade.java From lams with GNU General Public License v2.0 | 5 votes |
private static void cascadeAssociation( final CascadingAction action, final CascadePoint cascadePoint, final EventSource eventSource, final int componentPathStackDepth, final Object parent, final Object child, final Type type, final CascadeStyle style, final Object anything, final boolean isCascadeDeleteEnabled) { if ( type.isEntityType() || type.isAnyType() ) { cascadeToOne( action, eventSource, parent, child, type, style, anything, isCascadeDeleteEnabled ); } else if ( type.isCollectionType() ) { cascadeCollection( action, cascadePoint, eventSource, componentPathStackDepth, parent, child, style, anything, (CollectionType) type ); } }
Example 10
Source File: ForeignKeys.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Return null if the argument is an "unsaved" entity (ie. one with no existing database row), or the * input argument otherwise. This is how Hibernate avoids foreign key constraint violations. * * @param value An entity attribute value * @param type An entity attribute type * * @return {@code null} if the argument is an unsaved entity; otherwise return the argument. */ private Object nullifyTransientReferences(final Object value, final Type type) { if ( value == null ) { return null; } else if ( type.isEntityType() ) { final EntityType entityType = (EntityType) type; if ( entityType.isOneToOne() ) { return value; } else { final String entityName = entityType.getAssociatedEntityName(); return isNullifiable( entityName, value ) ? null : value; } } else if ( type.isAnyType() ) { return isNullifiable( null, value ) ? null : value; } else if ( type.isComponentType() ) { final CompositeType actype = (CompositeType) type; final Object[] subvalues = actype.getPropertyValues( value, session ); final Type[] subtypes = actype.getSubtypes(); boolean substitute = false; for ( int i = 0; i < subvalues.length; i++ ) { final Object replacement = nullifyTransientReferences( subvalues[i], subtypes[i] ); if ( replacement != subvalues[i] ) { substitute = true; subvalues[i] = replacement; } } if ( substitute ) { // todo : need to account for entity mode on the CompositeType interface :( actype.setPropertyValues( value, subvalues, EntityMode.POJO ); } return value; } else { return value; } }
Example 11
Source File: MetamodelGraphWalker.java From lams with GNU General Public License v2.0 | 5 votes |
private void visitCollectionIndex(CollectionDefinition collectionDefinition) { final CollectionIndexDefinition collectionIndexDefinition = collectionDefinition.getIndexDefinition(); if ( collectionIndexDefinition == null ) { return; } strategy.startingCollectionIndex( collectionIndexDefinition ); log.debug( "Visiting index for collection : " + currentPropertyPath.getFullPath() ); currentPropertyPath = currentPropertyPath.append( "<index>" ); try { final Type collectionIndexType = collectionIndexDefinition.getType(); if ( collectionIndexType.isAnyType() ) { visitAnyDefinition( collectionIndexDefinition.toAnyMappingDefinition() ); } else if ( collectionIndexType.isComponentType() ) { visitCompositeDefinition( collectionIndexDefinition.toCompositeDefinition() ); } else if ( collectionIndexType.isAssociationType() ) { visitEntityDefinition( collectionIndexDefinition.toEntityDefinition() ); } } finally { currentPropertyPath = currentPropertyPath.getParent(); } strategy.finishingCollectionIndex( collectionIndexDefinition ); }
Example 12
Source File: AbstractLoadPlanBuildingAssociationVisitationStrategy.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void startingCollectionElements(CollectionElementDefinition elementDefinition) { final Type elementType = elementDefinition.getType(); log.tracef( "%s Starting collection element graph : %s", StringHelper.repeat( ">>", fetchSourceStack.size() ), elementDefinition.getCollectionDefinition().getCollectionPersister().getRole() ); final CollectionReference collectionReference = currentCollection(); final CollectionFetchableElement elementGraph = collectionReference.getElementGraph(); if ( elementType.isAssociationType() || elementType.isComponentType() ) { if ( elementGraph == null ) { throw new IllegalStateException( "CollectionReference did not return an expected element graph : " + elementDefinition.getCollectionDefinition().getCollectionPersister().getRole() ); } if ( !elementType.isAnyType() ) { pushToStack( (ExpandingFetchSource) elementGraph ); } } else { if ( elementGraph != null ) { throw new IllegalStateException( "CollectionReference returned an unexpected element graph : " + elementDefinition.getCollectionDefinition().getCollectionPersister().getRole() ); } } }
Example 13
Source File: AbstractLoadPlanBuildingAssociationVisitationStrategy.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void startingCollectionIndex(CollectionIndexDefinition indexDefinition) { final Type indexType = indexDefinition.getType(); log.tracef( "%s Starting collection index graph : %s", StringHelper.repeat( ">>", fetchSourceStack.size() ), indexDefinition.getCollectionDefinition().getCollectionPersister().getRole() ); final CollectionReference collectionReference = currentCollection(); final CollectionFetchableIndex indexGraph = collectionReference.getIndexGraph(); if ( indexType.isEntityType() || indexType.isComponentType() ) { if ( indexGraph == null ) { throw new WalkingException( "CollectionReference did not return an expected index graph : " + indexDefinition.getCollectionDefinition().getCollectionPersister().getRole() ); } if ( !indexType.isAnyType() ) { pushToStack( (ExpandingFetchSource) indexGraph ); } } else { if ( indexGraph != null ) { throw new WalkingException( "CollectionReference returned an unexpected index graph : " + indexDefinition.getCollectionDefinition().getCollectionPersister().getRole() ); } } }
Example 14
Source File: AbstractCollectionPersister.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public CollectionElementDefinition getElementDefinition() { return new CollectionElementDefinition() { @Override public CollectionDefinition getCollectionDefinition() { return AbstractCollectionPersister.this; } @Override public Type getType() { return getElementType(); } @Override public AnyMappingDefinition toAnyMappingDefinition() { final Type type = getType(); if ( ! type.isAnyType() ) { throw new IllegalStateException( "Cannot treat collection element type as ManyToAny" ); } return new StandardAnyTypeDefinition( (AnyType) type, isLazy() || isExtraLazy() ); } @Override public EntityDefinition toEntityDefinition() { if ( !getType().isEntityType() ) { throw new IllegalStateException( "Cannot treat collection element type as entity" ); } return getElementPersister(); } @Override public CompositeCollectionElementDefinition toCompositeElementDefinition() { if ( ! getType().isComponentType() ) { throw new IllegalStateException( "Cannot treat entity collection element type as composite" ); } return new CompositeCollectionElementDefinition() { @Override public String getName() { return ""; } @Override public CompositeType getType() { return (CompositeType) getElementType(); } @Override public boolean isNullable() { return false; } @Override public AttributeSource getSource() { // TODO: what if this is a collection w/in an encapsulated composition attribute? // should return the encapsulated composition attribute instead??? return getOwnerEntityPersister(); } @Override public Iterable<AttributeDefinition> getAttributes() { return CompositionSingularSubAttributesHelper.getCompositeCollectionElementSubAttributes( this ); } @Override public CollectionDefinition getCollectionDefinition() { return AbstractCollectionPersister.this; } }; } }; }
Example 15
Source File: AbstractCollectionPersister.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public CollectionIndexDefinition getIndexDefinition() { if ( ! hasIndex() ) { return null; } return new CollectionIndexDefinition() { @Override public CollectionDefinition getCollectionDefinition() { return AbstractCollectionPersister.this; } @Override public Type getType() { return getIndexType(); } @Override public EntityDefinition toEntityDefinition() { if ( !getType().isEntityType() ) { throw new IllegalStateException( "Cannot treat collection index type as entity" ); } return (EntityPersister) ( (AssociationType) getIndexType() ).getAssociatedJoinable( getFactory() ); } @Override public CompositionDefinition toCompositeDefinition() { if ( ! getType().isComponentType() ) { throw new IllegalStateException( "Cannot treat collection index type as composite" ); } return new CompositeCollectionElementDefinition() { @Override public String getName() { return "index"; } @Override public CompositeType getType() { return (CompositeType) getIndexType(); } @Override public boolean isNullable() { return false; } @Override public AttributeSource getSource() { // TODO: what if this is a collection w/in an encapsulated composition attribute? // should return the encapsulated composition attribute instead??? return getOwnerEntityPersister(); } @Override public Iterable<AttributeDefinition> getAttributes() { return CompositionSingularSubAttributesHelper.getCompositeCollectionIndexSubAttributes( this ); } @Override public CollectionDefinition getCollectionDefinition() { return AbstractCollectionPersister.this; } }; } @Override public AnyMappingDefinition toAnyMappingDefinition() { final Type type = getType(); if ( ! type.isAnyType() ) { throw new IllegalStateException( "Cannot treat collection index type as ManyToAny" ); } return new StandardAnyTypeDefinition( (AnyType) type, isLazy() || isExtraLazy() ); } }; }
Example 16
Source File: ForeignKeys.java From lams with GNU General Public License v2.0 | 4 votes |
private static void collectNonNullableTransientEntities( Nullifier nullifier, Object value, String propertyName, Type type, boolean isNullable, SharedSessionContractImplementor session, NonNullableTransientDependencies nonNullableTransientEntities) { if ( value == null ) { return; } if ( type.isEntityType() ) { final EntityType entityType = (EntityType) type; if ( !isNullable && !entityType.isOneToOne() && nullifier.isNullifiable( entityType.getAssociatedEntityName(), value ) ) { nonNullableTransientEntities.add( propertyName, value ); } } else if ( type.isAnyType() ) { if ( !isNullable && nullifier.isNullifiable( null, value ) ) { nonNullableTransientEntities.add( propertyName, value ); } } else if ( type.isComponentType() ) { final CompositeType actype = (CompositeType) type; final boolean[] subValueNullability = actype.getPropertyNullability(); if ( subValueNullability != null ) { final String[] subPropertyNames = actype.getPropertyNames(); final Object[] subvalues = actype.getPropertyValues( value, session ); final Type[] subtypes = actype.getSubtypes(); for ( int j = 0; j < subvalues.length; j++ ) { collectNonNullableTransientEntities( nullifier, subvalues[j], subPropertyNames[j], subtypes[j], subValueNullability[j], session, nonNullableTransientEntities ); } } } }
Example 17
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; }
Example 18
Source File: AbstractCollectionReference.java From lams with GNU General Public License v2.0 | 4 votes |
private CollectionFetchableIndex buildIndexGraph() { final CollectionPersister persister = collectionQuerySpace.getCollectionPersister(); if ( persister.hasIndex() ) { final Type type = persister.getIndexType(); if ( type.isAssociationType() ) { if ( type.isEntityType() ) { final EntityPersister indexPersister = persister.getFactory().getEntityPersister( ( (EntityType) type ).getAssociatedEntityName() ); final ExpandingEntityQuerySpace entityQuerySpace = QuerySpaceHelper.INSTANCE.makeEntityQuerySpace( collectionQuerySpace, indexPersister, CollectionPropertyNames.COLLECTION_INDICES, (EntityType) persister.getIndexType(), collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(), collectionQuerySpace.canJoinsBeRequired(), allowIndexJoin ); return new CollectionFetchableIndexEntityGraph( this, entityQuerySpace ); } else if ( type.isAnyType() ) { return new CollectionFetchableIndexAnyGraph( this ); } } else if ( type.isComponentType() ) { final ExpandingCompositeQuerySpace compositeQuerySpace = QuerySpaceHelper.INSTANCE.makeCompositeQuerySpace( collectionQuerySpace, new CompositePropertyMapping( (CompositeType) persister.getIndexType(), (PropertyMapping) persister, "" ), CollectionPropertyNames.COLLECTION_INDICES, (CompositeType) persister.getIndexType(), collectionQuerySpace.getExpandingQuerySpaces().generateImplicitUid(), collectionQuerySpace.canJoinsBeRequired(), allowIndexJoin ); return new CollectionFetchableIndexCompositeGraph( this, compositeQuerySpace ); } } return null; }
Example 19
Source File: ForeignKeys.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 4 votes |
/** * Return null if the argument is an "unsaved" entity (ie. one with no existing database row), or the * input argument otherwise. This is how Hibernate avoids foreign key constraint violations. * * @param value An entity attribute value * @param propertyName An entity attribute name * @param type An entity attribute type * * @return {@code null} if the argument is an unsaved entity; otherwise return the argument. */ private CompletionStage<Object> nullifyTransientReferences(Object value, String propertyName, Type type) { final CompletionStage<Object> result; if ( value == null ) { return null; } else if ( type.isEntityType() ) { final EntityType entityType = (EntityType) type; if ( entityType.isOneToOne() ) { return null; } else { // if we're dealing with a lazy property, it may need to be // initialized to determine if the value is nullifiable CompletionStage<Object> fetcher; if ( isDelete && value == LazyPropertyInitializer.UNFETCHED_PROPERTY && !session.getPersistenceContextInternal().isNullifiableEntityKeysEmpty() ) { throw new UnsupportedOperationException("lazy property initialization not supported"); // fetcher = ( (LazyPropertyInitializer) persister ).initializeLazyProperty( propertyName, self, session ); } else { fetcher = CompletionStages.completedFuture( value ); } result = fetcher.thenCompose( fetchedValue -> { if ( fetchedValue == null ) { // The uninitialized value was initialized to null return CompletionStages.nullFuture(); } else { // If the value is not nullifiable, make sure that the // possibly initialized value is returned. return isNullifiable( entityType.getAssociatedEntityName(), fetchedValue ) .thenApply( trans -> trans ? null : fetchedValue ); } } ); } } else if ( type.isAnyType() ) { result = isNullifiable( null, value ).thenApply( trans -> trans ? null : value ); } else if ( type.isComponentType() ) { final CompositeType actype = (CompositeType) type; final Object[] values = actype.getPropertyValues( value, session ); CompletionStage<Void> nullifier = nullifyTransientReferences( propertyName, values, actype.getSubtypes(), actype.getPropertyNames() ); if ( nullifier == null ) { return null; } else { result = nullifier.thenAccept( v -> actype.setPropertyValues( value, values, EntityMode.POJO ) ) .thenApply( v -> value ); } } else { return null; } return result.thenApply( returnedValue -> { trackDirt( value, propertyName, returnedValue ); return returnedValue; } ); }