private boolean samePersistentType(final EntityKey otherKey) { if ( otherKey.persister == persister ) { return true; } else { return Objects.equals( otherKey.persister.getRootEntityName(), persister.getRootEntityName() ); } }
@Override public boolean wasInsertedDuringTransaction(EntityPersister persister, Serializable id) { // again, we only really care if the entity is cached if ( persister.canWriteToCache() ) { if ( insertedKeysMap != null ) { final List<Serializable> insertedEntityIds = insertedKeysMap.get( persister.getRootEntityName() ); if ( insertedEntityIds != null ) { return insertedEntityIds.contains( id ); } } } return false; }
@Override public void registerInsertedKey(EntityPersister persister, Serializable id) { // we only are worried about registering these if the persister defines caching if ( persister.canWriteToCache() ) { if ( insertedKeysMap == null ) { insertedKeysMap = new HashMap<>(); } final String rootEntityName = persister.getRootEntityName(); List<Serializable> insertedEntityIds = insertedKeysMap.get( rootEntityName ); if ( insertedEntityIds == null ) { insertedEntityIds = new ArrayList<>(); insertedKeysMap.put( rootEntityName, insertedEntityIds ); } insertedEntityIds.add( id ); } }
NaturalIdStatisticsImpl(EntityPersister rootEntityDescriptor) { super( () -> rootEntityDescriptor.getNaturalIdCacheAccessStrategy() != null ? rootEntityDescriptor.getNaturalIdCacheAccessStrategy().getRegion() : null ); this.rootEntityName = rootEntityDescriptor.getRootEntityName(); final ReadWriteLock lock = new ReentrantReadWriteLock(); this.readLock = lock.readLock(); this.writeLock = lock.writeLock(); }
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; }
public static Object staticCreateEntityKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { return new CacheKeyImplementation( id, persister.getIdentifierType(), persister.getRootEntityName(), tenantIdentifier, factory ); }
EntityStatisticsImpl(EntityPersister rootEntityDescriptor) { super( () -> rootEntityDescriptor.getCacheAccessStrategy() != null ? rootEntityDescriptor.getCacheAccessStrategy().getRegion() : null ); this.rootEntityName = rootEntityDescriptor.getRootEntityName(); }
/** * It is only valid to define natural ids at the root of an entity hierarchy. This method makes sure we are * using the root persister. * * @param persister The persister representing the entity type. * * @return The root persister. */ protected EntityPersister locatePersisterForKey(EntityPersister persister) { return persistenceContext.getSession().getFactory().getEntityPersister( persister.getRootEntityName() ); }
public static Object staticCreateNaturalIdKey(Object[] naturalIdValues, EntityPersister persister, SharedSessionContractImplementor session) { return new NaturalIdCacheKey( naturalIdValues, persister.getPropertyTypes(), persister.getNaturalIdentifierProperties(), persister.getRootEntityName(), session ); }
protected void evictEntityData(EntityPersister entityDescriptor) { EntityPersister rootEntityDescriptor = entityDescriptor; if ( entityDescriptor.isInherited() && ! entityDescriptor.getEntityName().equals( entityDescriptor.getRootEntityName() ) ) { rootEntityDescriptor = getSessionFactory().getMetamodel().entityPersister( entityDescriptor.getRootEntityName() ); } evictEntityData( rootEntityDescriptor.getNavigableRole(), rootEntityDescriptor.getCacheAccessStrategy() ); }
private EntityPersister locateProperPersister(EntityPersister persister) { return session.getFactory().getMetamodel().entityPersister( persister.getRootEntityName() ); }
public NavigableRole getRootEntityRole(EntityPersister entityDescriptor) { final String rootEntityName = entityDescriptor.getRootEntityName(); if ( entityDescriptor.getEntityName().equals( rootEntityName ) ) { return entityDescriptor.getNavigableRole(); } else { final EntityPersister rootEntityDescriptor = entityDescriptor.getFactory() .getMetamodel() .entityPersister( rootEntityName ); return rootEntityDescriptor.getNavigableRole(); } }
.getMetamodel() .entityPersister( action.getEntityName() ) .getRootEntityName() );
final EntityType entityType = (EntityType) type; final String entityName = entityType.getName(); final String rootEntityName = action.getSession().getFactory().getMetamodel().entityPersister( entityName ).getRootEntityName(); !sessionFactory.getMetamodel().collectionPersister( collectionType.getRole() ).isManyToMany() ) { String entityName = collectionType.getAssociatedEntityName( sessionFactory ); String rootEntityName = action.getSession().getFactory().getMetamodel().entityPersister( entityName ).getRootEntityName(); batchIdentifier.getChildEntityNames().add( entityName ); if ( !rootEntityName.equals( entityName ) ) {
final Type mockType = mock(Type.class); when (entityPersister.getRootEntityName()).thenReturn("EntityName");
LOG.trace( "Resolved natural key -> primary key resolution in session cache: " + persister.getRootEntityName() + "#[" + Arrays.toString( naturalIdValues ) + "]" ); Arrays.toString( naturalIdValues ), pk, persister.getRootEntityName() );
final long milliseconds = TimeUnit.MILLISECONDS.convert( endTime - startTime, TimeUnit.NANOSECONDS ); factory.getStatistics().naturalIdQueryExecuted( event.getEntityPersister().getRootEntityName(), milliseconds );
@Override public Object createEntityKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { return new CacheKeyImpl(id, persister.getIdentifierType(), persister.getRootEntityName(), tenantIdentifier, factory); }
public void evict(Class persistentClass, Serializable id) throws HibernateException { EntityPersister p = getEntityPersister( persistentClass.getName() ); if ( p.hasCache() ) { if ( log.isDebugEnabled() ) { log.debug( "evicting second-level cache: " + MessageHelper.infoString(p, id, this) ); } CacheKey cacheKey = new CacheKey( id, p.getIdentifierType(), p.getRootEntityName(), EntityMode.POJO, this ); p.getCache().remove( cacheKey ); } }
public void afterTransactionCompletion(boolean success) throws HibernateException { final CacheKey ck = new CacheKey( getId(), getPersister().getIdentifierType(), getPersister().getRootEntityName(), getSession().getEntityMode(), getSession().getFactory() ); if ( getPersister().hasCache() ) getPersister().getCache().release(ck, lock); }