Java 类org.hibernate.classic.Lifecycle 实例源码

项目:lams    文件:TypeFactory.java   
public Type byClass(Class clazz, Properties parameters) {
    if ( Type.class.isAssignableFrom( clazz ) ) {
        return type( clazz, parameters );
    }

    if ( CompositeUserType.class.isAssignableFrom( clazz ) ) {
        return customComponent( clazz, parameters );
    }

    if ( UserType.class.isAssignableFrom( clazz ) ) {
        return custom( clazz, parameters );
    }

    if ( Lifecycle.class.isAssignableFrom( clazz ) ) {
        // not really a many-to-one association *necessarily*
        return manyToOne( clazz.getName() );
    }

    if ( Serializable.class.isAssignableFrom( clazz ) ) {
        return serializable( clazz );
    }

    return null;
}
项目:lams    文件:PojoEntityTuplizer.java   
public PojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
        super( entityMetamodel, mappedEntity );
        this.mappedClass = mappedEntity.getMappedClass();
        this.proxyInterface = mappedEntity.getProxyInterface();
        this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass );
        this.isInstrumented = entityMetamodel.isInstrumented();

        Iterator iter = mappedEntity.getPropertyClosureIterator();
        while ( iter.hasNext() ) {
            Property property = (Property) iter.next();
            if ( property.isLazy() ) {
                lazyPropertyNames.add( property.getName() );
            }
        }

        String[] getterNames = new String[propertySpan];
        String[] setterNames = new String[propertySpan];
        Class[] propTypes = new Class[propertySpan];
        for ( int i = 0; i < propertySpan; i++ ) {
            getterNames[i] = getters[i].getMethodName();
            setterNames[i] = setters[i].getMethodName();
            propTypes[i] = getters[i].getReturnType();
        }

        if ( hasCustomAccessors || !Environment.useReflectionOptimizer() ) {
            optimizer = null;
        }
        else {
            // todo : YUCK!!!
            optimizer = Environment.getBytecodeProvider().getReflectionOptimizer( mappedClass, getterNames, setterNames, propTypes );
//          optimizer = getFactory().getSettings().getBytecodeProvider().getReflectionOptimizer(
//                  mappedClass, getterNames, setterNames, propTypes
//          );
        }

    }
项目:lams    文件:PojoEntityTuplizer.java   
public PojoEntityTuplizer(EntityMetamodel entityMetamodel, EntityBinding mappedEntity) {
        super( entityMetamodel, mappedEntity );
        this.mappedClass = mappedEntity.getEntity().getClassReference();
        this.proxyInterface = mappedEntity.getProxyInterfaceType().getValue();
        this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass );
        this.isInstrumented = entityMetamodel.isInstrumented();

        for ( AttributeBinding property : mappedEntity.getAttributeBindingClosure() ) {
            if ( property.isLazy() ) {
                lazyPropertyNames.add( property.getAttribute().getName() );
            }
        }

        String[] getterNames = new String[propertySpan];
        String[] setterNames = new String[propertySpan];
        Class[] propTypes = new Class[propertySpan];
        for ( int i = 0; i < propertySpan; i++ ) {
            getterNames[i] = getters[ i ].getMethodName();
            setterNames[i] = setters[ i ].getMethodName();
            propTypes[i] = getters[ i ].getReturnType();
        }

        if ( hasCustomAccessors || ! Environment.useReflectionOptimizer() ) {
            optimizer = null;
        }
        else {
            // todo : YUCK!!!
            optimizer = Environment.getBytecodeProvider().getReflectionOptimizer(
                    mappedClass, getterNames, setterNames, propTypes
            );
//          optimizer = getFactory().getSettings().getBytecodeProvider().getReflectionOptimizer(
//                  mappedClass, getterNames, setterNames, propTypes
//          );
        }
    }
项目:lams    文件:DefaultDeleteEventListener.java   
protected boolean invokeDeleteLifecycle(EventSource session, Object entity, EntityPersister persister) {
    if ( persister.implementsLifecycle() ) {
        LOG.debug( "Calling onDelete()" );
        if ( ( (Lifecycle) entity ).onDelete( session ) ) {
            LOG.debug( "Deletion vetoed by onDelete()" );
            return true;
        }
    }
    return false;
}
项目:lams    文件:DefaultSaveOrUpdateEventListener.java   
protected boolean invokeUpdateLifecycle(Object entity, EntityPersister persister, EventSource source) {
    if ( persister.implementsLifecycle() ) {
        LOG.debug( "Calling onUpdate()" );
        if ( ( (Lifecycle) entity ).onUpdate( source ) ) {
            LOG.debug( "Update vetoed by onUpdate()" );
            return true;
        }
    }
    return false;
}
项目:lams    文件:AbstractSaveEventListener.java   
protected boolean invokeSaveLifecycle(Object entity, EntityPersister persister, EventSource source) {
    // Sub-insertions should occur before containing insertion so
    // Try to do the callback now
    if ( persister.implementsLifecycle() ) {
        LOG.debug( "Calling onSave()" );
        if ( ((Lifecycle) entity).onSave( source ) ) {
            LOG.debug( "Insertion vetoed by onSave()" );
            return true;
        }
    }
    return false;
}
项目:cacheonix-core    文件:PojoEntityTuplizer.java   
public PojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
        super( entityMetamodel, mappedEntity );
        this.mappedClass = mappedEntity.getMappedClass();
        this.proxyInterface = mappedEntity.getProxyInterface();
        this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass );
        this.validatableImplementor = Validatable.class.isAssignableFrom( mappedClass );

        Iterator iter = mappedEntity.getPropertyClosureIterator();
        while ( iter.hasNext() ) {
            Property property = (Property) iter.next();
            if ( property.isLazy() ) {
                lazyPropertyNames.add( property.getName() );
            }
        }

        String[] getterNames = new String[propertySpan];
        String[] setterNames = new String[propertySpan];
        Class[] propTypes = new Class[propertySpan];
        for ( int i = 0; i < propertySpan; i++ ) {
            getterNames[i] = getters[i].getMethodName();
            setterNames[i] = setters[i].getMethodName();
            propTypes[i] = getters[i].getReturnType();
        }

        if ( hasCustomAccessors || !Environment.useReflectionOptimizer() ) {
            optimizer = null;
        }
        else {
            // todo : YUCK!!!
            optimizer = Environment.getBytecodeProvider().getReflectionOptimizer( mappedClass, getterNames, setterNames, propTypes );
//          optimizer = getFactory().getSettings().getBytecodeProvider().getReflectionOptimizer(
//                  mappedClass, getterNames, setterNames, propTypes
//          );
        }

    }
项目:cacheonix-core    文件:DefaultDeleteEventListener.java   
protected boolean invokeDeleteLifecycle(EventSource session, Object entity, EntityPersister persister) {
    if ( persister.implementsLifecycle( session.getEntityMode() ) ) {
        log.debug( "calling onDelete()" );
        if ( ( ( Lifecycle ) entity ).onDelete( session ) ) {
            log.debug( "deletion vetoed by onDelete()" );
            return true;
        }
    }
    return false;
}
项目:cacheonix-core    文件:DefaultSaveOrUpdateEventListener.java   
protected boolean invokeUpdateLifecycle(Object entity, EntityPersister persister, EventSource source) {
    if ( persister.implementsLifecycle( source.getEntityMode() ) ) {
        log.debug( "calling onUpdate()" );
        if ( ( ( Lifecycle ) entity ).onUpdate( source ) ) {
            log.debug( "update vetoed by onUpdate()" );
            return true;
        }
    }
    return false;
}
项目:cacheonix-core    文件:DefaultPostLoadEventListener.java   
public void onPostLoad(PostLoadEvent event) {
    if ( event.getPersister().implementsLifecycle( event.getSession().getEntityMode() ) ) {
        //log.debug( "calling onLoad()" );
        ( ( Lifecycle ) event.getEntity() ).onLoad( event.getSession(), event.getId() );
    }

}
项目:cacheonix-core    文件:AbstractSaveEventListener.java   
protected boolean invokeSaveLifecycle(Object entity, EntityPersister persister, EventSource source) {
    // Sub-insertions should occur before containing insertion so
    // Try to do the callback now
    if ( persister.implementsLifecycle( source.getEntityMode() ) ) {
        log.debug( "calling onSave()" );
        if ( ( ( Lifecycle ) entity ).onSave( source ) ) {
            log.debug( "insertion vetoed by onSave()" );
            return true;
        }
    }
    return false;
}
项目:lams    文件:DefaultPostLoadEventListener.java   
@Override
public void onPostLoad(PostLoadEvent event) {
    final Object entity = event.getEntity();
    final EntityEntry entry = event.getSession().getPersistenceContext().getEntry( entity );
    if ( entry == null ) {
        throw new AssertionFailure( "possible non-threadsafe access to the session" );
    }

    final LockMode lockMode = entry.getLockMode();
    if ( LockMode.PESSIMISTIC_FORCE_INCREMENT.equals( lockMode ) ) {
        final EntityPersister persister = entry.getPersister();
        final Object nextVersion = persister.forceVersionIncrement(
                entry.getId(),
                entry.getVersion(),
                event.getSession()
        );
        entry.forceLocked( entity, nextVersion );
    }
    else if ( LockMode.OPTIMISTIC_FORCE_INCREMENT.equals( lockMode ) ) {
        final EntityIncrementVersionProcess incrementVersion = new EntityIncrementVersionProcess( entity, entry );
        event.getSession().getActionQueue().registerProcess( incrementVersion );
    }
    else if ( LockMode.OPTIMISTIC.equals( lockMode ) ) {
        final EntityVerifyVersionProcess verifyVersion = new EntityVerifyVersionProcess( entity, entry );
        event.getSession().getActionQueue().registerProcess( verifyVersion );
    }

    if ( event.getPersister().implementsLifecycle() ) {
        //log.debug( "calling onLoad()" );
        ( (Lifecycle) event.getEntity() ).onLoad( event.getSession(), event.getId() );
    }

}
项目:cacheonix-core    文件:TypeFactory.java   
/**
 * Uses heuristics to deduce a Hibernate type given a string naming the type or Java class.
 * Return an instance of <tt>org.hibernate.type.Type</tt>.
 */
public static Type heuristicType(String typeName, Properties parameters)
        throws MappingException {
    Type type = TypeFactory.basic( typeName );
    if ( type == null ) {
        Class typeClass;
        try {
            typeClass = ReflectHelper.classForName( typeName );
        }
        catch (ClassNotFoundException cnfe) {
            typeClass = null;
        }
        if ( typeClass != null ) {
            if ( Type.class.isAssignableFrom( typeClass ) ) {
                try {
                    type = (Type) typeClass.newInstance();
                }
                catch (Exception e) {
                    throw new MappingException( 
                            "Could not instantiate Type: " + typeClass.getName(),
                            e 
                        );
                }
                injectParameters(type, parameters);
            }
            else if ( CompositeUserType.class.isAssignableFrom( typeClass ) ) {
                type = new CompositeCustomType( typeClass, parameters );
            }
            else if ( UserType.class.isAssignableFrom( typeClass ) ) {
                type = new CustomType( typeClass, parameters );
            }
            else if ( Lifecycle.class.isAssignableFrom( typeClass ) ) {
                type = Hibernate.entity( typeClass );
            }
            else if ( Serializable.class.isAssignableFrom( typeClass ) ) {
                type = Hibernate.serializable( typeClass );
            }
        }
    }
    return type;

}