@Override public Type getSemiResolvedType(SessionFactoryImplementor factory) { return getAssociatedEntityPersister( factory ).getIdentifierType(); }
@Override public int compareTo(Object other) { final EntityAction action = (EntityAction) other; //sort first by entity name final int roleComparison = entityName.compareTo( action.entityName ); if ( roleComparison != 0 ) { return roleComparison; } else { //then by id return persister.getIdentifierType().compare( id, action.id ); } }
public Type getIdentifierType(String className) throws MappingException { return getMetamodel().entityPersister( className ).getIdentifierType(); } public String getIdentifierPropertyName(String className) throws MappingException {
private boolean sameIdentifier(final EntityKey otherKey) { return persister.getIdentifierType().isEqual( otherKey.identifier, this.identifier, persister.getFactory() ); }
public static Object staticCreateEntityKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { return new CacheKeyImplementation( id, persister.getIdentifierType(), persister.getRootEntityName(), tenantIdentifier, factory ); }
private int generateHashCode() { int result = 17; final String rootEntityName = persister.getRootEntityName(); result = 37 * result + ( rootEntityName != null ? rootEntityName.hashCode() : 0 ); result = 37 * result + persister.getIdentifierType().getHashCode( identifier, persister.getFactory() ); return result; }
protected Object getObjectFromList(List results, Serializable id, SharedSessionContractImplementor session) { for ( Object obj : results ) { final boolean equal = persister.getIdentifierType().isEqual( id, session.getContextEntityIdentifier( obj ), session.getFactory() ); if ( equal ) { return obj; } } return null; }
protected Object getObjectFromList(List results, Serializable id, SharedSessionContractImplementor session) { for ( Object obj : results ) { final boolean equal = persister.getIdentifierType().isEqual( id, session.getContextEntityIdentifier( obj ), session.getFactory() ); if ( equal ) { return obj; } } return null; }
private NonEncapsulatedEntityIdentifierDescription buildNonEncapsulatedCompositeIdentifierDescription( ExpandingCompositeQuerySpace compositeQuerySpace) { return new NonEncapsulatedEntityIdentifierDescription( this, compositeQuerySpace, (CompositeType) getEntityPersister().getIdentifierType(), getPropertyPath().append( EntityPersister.ENTITY_ID ) ); }
private EncapsulatedEntityIdentifierDescription buildEncapsulatedCompositeIdentifierDescription( ExpandingCompositeQuerySpace compositeQuerySpace) { return new EncapsulatedEntityIdentifierDescription( this, compositeQuerySpace, (CompositeType) getEntityPersister().getIdentifierType(), getPropertyPath().append( EntityPersister.ENTITY_ID ) ); }
/** * @param sessionFactory Session factory. * @param entityName Entity name. * * @return List of property names representing entity identifier. */ private static List<String> identifierPropertyNames(SessionFactoryImplementor sessionFactory, String entityName) { final String identifierPropertyName = sessionFactory.getMetamodel().entityPersister( entityName ).getIdentifierPropertyName(); if ( identifierPropertyName != null ) { // Single id. return Arrays.asList( identifierPropertyName ); } final Type identifierType = sessionFactory.getMetamodel().entityPersister( entityName ).getIdentifierType(); if ( identifierType instanceof EmbeddedComponentType ) { // Multiple ids. final EmbeddedComponentType embeddedComponentType = (EmbeddedComponentType) identifierType; return Arrays.asList( embeddedComponentType.getPropertyNames() ); } return Collections.emptyList(); } }
public void associationProcessed(OuterJoinableAssociation oja, int position) { associationsByAlias.put( oja.getRhsAlias(), oja ); positionsByAlias.put( oja.getRhsAlias(), position ); EntityPersister entityPersister = null; if ( oja.getJoinableType().isCollectionType() ) { entityPersister = ( ( QueryableCollection) oja.getJoinable() ).getElementPersister(); } else if ( oja.getJoinableType().isEntityType() ) { entityPersister = ( EntityPersister ) oja.getJoinable(); } if ( entityPersister != null && entityPersister.getIdentifierType().isComponentType() && ! entityPersister.getEntityMetamodel().getIdentifierProperty().isEmbedded() && hasAssociation( (CompositeType) entityPersister.getIdentifierType() ) ) { aliasesForAssociationsWithCompositesIds.add( oja.getRhsAlias() ); } }
@Override public int getHashCode(Object x, SessionFactoryImplementor factory) { EntityPersister persister = getAssociatedEntityPersister( factory ); if ( !persister.canExtractIdOutOfEntity() ) { return super.getHashCode( x ); } final Serializable id; if ( x instanceof HibernateProxy ) { id = ( (HibernateProxy) x ).getHibernateLazyInitializer().getIdentifier(); } else { final Class mappedClass = persister.getMappedClass(); if ( mappedClass.isAssignableFrom( x.getClass() ) ) { id = persister.getIdentifier( x ); } else { id = (Serializable) x; } } return persister.getIdentifierType().getHashCode( id, factory ); }
/** * Handle the given load event. * * @param event The load event to be handled. * * @throws HibernateException */ public void onLoad( final LoadEvent event, final LoadEventListener.LoadType loadType) throws HibernateException { final EntityPersister persister = getPersister( event ); if ( persister == null ) { throw new HibernateException( "Unable to locate persister: " + event.getEntityClassName() ); } final Class idClass = persister.getIdentifierType().getReturnedClass(); if ( idClass != null && !idClass.isInstance( event.getEntityId() ) && !DelayedPostInsertIdentifier.class.isInstance( event.getEntityId() ) ) { checkIdClass( persister, event, loadType, idClass ); } doOnLoad( persister, event, loadType ); }
@Override public ExpandingCompositeQuerySpace makeCompositeIdentifierQuerySpace() { final String compositeQuerySpaceUid = getUid() + "-id"; final ExpandingCompositeQuerySpace rhs = getExpandingQuerySpaces().makeCompositeQuerySpace( compositeQuerySpaceUid, new CompositePropertyMapping( (CompositeType) getEntityPersister().getIdentifierType(), (PropertyMapping) getEntityPersister(), getEntityPersister().getIdentifierPropertyName() ), canJoinsBeRequired() ); final JoinDefinedByMetadata join = JoinHelper.INSTANCE.createCompositeJoin( this, EntityPersister.ENTITY_ID, rhs, canJoinsBeRequired(), (CompositeType) persister.getIdentifierType() ); internalGetJoins().add( join ); return rhs; } }
protected QueryParameters buildQueryParameters( Serializable id, Serializable[] ids, Object optionalObject, LockOptions lockOptions) { Type[] types = new Type[ids.length]; Arrays.fill( types, persister().getIdentifierType() ); QueryParameters qp = new QueryParameters(); qp.setPositionalParameterTypes( types ); qp.setPositionalParameterValues( ids ); qp.setOptionalObject( optionalObject ); qp.setOptionalEntityName( persister().getEntityName() ); qp.setOptionalId( id ); qp.setLockOptions( lockOptions ); return qp; }
protected QueryParameters buildQueryParameters( Serializable id, Serializable[] ids, Object optionalObject, LockOptions lockOptions) { Type[] types = new Type[ids.length]; Arrays.fill( types, persister().getIdentifierType() ); QueryParameters qp = new QueryParameters(); qp.setPositionalParameterTypes( types ); qp.setPositionalParameterValues( ids ); qp.setOptionalObject( optionalObject ); qp.setOptionalEntityName( persister().getEntityName() ); qp.setOptionalId( id ); qp.setLockOptions( lockOptions ); return qp; }
private EntityLoader createUniqueKeyLoader( Type uniqueKeyType, String[] columns, LoadQueryInfluencers loadQueryInfluencers) { if ( uniqueKeyType.isEntityType() ) { String className = ( (EntityType) uniqueKeyType ).getAssociatedEntityName(); uniqueKeyType = getFactory().getMetamodel().entityPersister( className ).getIdentifierType(); } return new EntityLoader( this, columns, uniqueKeyType, 1, LockMode.NONE, getFactory(), loadQueryInfluencers ); }
/** * make sure user didn't mangle the id */ public void checkId(Object object, EntityPersister persister, Serializable id, SessionImplementor session) throws HibernateException { if ( id != null && id instanceof DelayedPostInsertIdentifier ) { // this is a situation where the entity id is assigned by a post-insert generator // and was saved outside the transaction forcing it to be delayed return; } if ( persister.canExtractIdOutOfEntity() ) { Serializable oid = persister.getIdentifier( object, session ); if ( id == null ) { throw new AssertionFailure( "null id in " + persister.getEntityName() + " entry (don't flush the Session after an exception occurs)" ); } if ( !persister.getIdentifierType().isEqual( id, oid, session.getFactory() ) ) { throw new HibernateException( "identifier of an instance of " + persister.getEntityName() + " was altered from " + id + " to " + oid ); } } }
@Override public Object load(Serializable id, Object optionalObject, SharedSessionContractImplementor session) { LOG.debugf( "Loading entity: %s using named query: %s", persister.getEntityName(), queryName ); // IMPL NOTE: essentially we perform the named query (which loads the entity into the PC), and then // do an internal lookup of the entity from the PC. final AbstractProducedQuery query = (AbstractProducedQuery) session.getNamedQuery( queryName ); if ( query.getParameterMetadata().hasNamedParameters() ) { query.setParameter( query.getNamedParameters()[0], id, persister.getIdentifierType() ); } else { query.setParameter( position, id, persister.getIdentifierType() ); } query.setOptionalId( id ); query.setOptionalEntityName( persister.getEntityName() ); query.setOptionalObject( optionalObject ); query.setFlushMode( FlushMode.MANUAL ); query.list(); // now look up the object we are really interested in! // (this lets us correctly handle proxies and multi-row or multi-column queries) return session.getPersistenceContext().getEntity( session.generateEntityKey( id, persister ) ); } }