Search in sources :

Example 1 with CustomEntityDirtinessStrategy

use of org.hibernate.CustomEntityDirtinessStrategy in project hibernate-orm by hibernate.

the class AbstractEntityEntry method isUnequivocallyNonDirty.

@SuppressWarnings({ "SimplifiableIfStatement" })
private boolean isUnequivocallyNonDirty(Object entity) {
    if (entity instanceof SelfDirtinessTracker) {
        boolean uninitializedProxy = false;
        if (entity instanceof PersistentAttributeInterceptable) {
            final PersistentAttributeInterceptable interceptable = (PersistentAttributeInterceptable) entity;
            final PersistentAttributeInterceptor interceptor = interceptable.$$_hibernate_getInterceptor();
            if (interceptor instanceof EnhancementAsProxyLazinessInterceptor) {
                EnhancementAsProxyLazinessInterceptor enhancementAsProxyLazinessInterceptor = (EnhancementAsProxyLazinessInterceptor) interceptor;
                return !enhancementAsProxyLazinessInterceptor.hasWrittenFieldNames();
            }
        } else if (entity instanceof HibernateProxy) {
            uninitializedProxy = ((HibernateProxy) entity).getHibernateLazyInitializer().isUninitialized();
        }
        // we never have to check an uninitialized proxy
        return uninitializedProxy || !persister.hasCollections() && !persister.hasMutableProperties() && !((SelfDirtinessTracker) entity).$$_hibernate_hasDirtyAttributes();
    }
    if (entity instanceof PersistentAttributeInterceptable) {
        final PersistentAttributeInterceptable interceptable = (PersistentAttributeInterceptable) entity;
        final PersistentAttributeInterceptor interceptor = interceptable.$$_hibernate_getInterceptor();
        if (interceptor instanceof EnhancementAsProxyLazinessInterceptor) {
            // we never have to check an uninitialized proxy
            return true;
        }
    }
    final CustomEntityDirtinessStrategy customEntityDirtinessStrategy = getPersistenceContext().getSession().getFactory().getCustomEntityDirtinessStrategy();
    if (customEntityDirtinessStrategy.canDirtyCheck(entity, getPersister(), (Session) getPersistenceContext().getSession())) {
        return !customEntityDirtinessStrategy.isDirty(entity, getPersister(), (Session) getPersistenceContext().getSession());
    }
    if (getPersister().hasMutableProperties()) {
        return false;
    }
    return false;
}
Also used : CustomEntityDirtinessStrategy(org.hibernate.CustomEntityDirtinessStrategy) PersistentAttributeInterceptor(org.hibernate.engine.spi.PersistentAttributeInterceptor) PersistentAttributeInterceptable(org.hibernate.engine.spi.PersistentAttributeInterceptable) HibernateProxy(org.hibernate.proxy.HibernateProxy) SelfDirtinessTracker(org.hibernate.engine.spi.SelfDirtinessTracker) EnhancementAsProxyLazinessInterceptor(org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor) Session(org.hibernate.Session)

Aggregations

CustomEntityDirtinessStrategy (org.hibernate.CustomEntityDirtinessStrategy)1 Session (org.hibernate.Session)1 EnhancementAsProxyLazinessInterceptor (org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor)1 PersistentAttributeInterceptable (org.hibernate.engine.spi.PersistentAttributeInterceptable)1 PersistentAttributeInterceptor (org.hibernate.engine.spi.PersistentAttributeInterceptor)1 SelfDirtinessTracker (org.hibernate.engine.spi.SelfDirtinessTracker)1 HibernateProxy (org.hibernate.proxy.HibernateProxy)1