org.hibernate.classic.Lifecycle Java Examples

The following examples show how to use org.hibernate.classic.Lifecycle. 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: TypeFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: DefaultDeleteEventListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected boolean invokeDeleteLifecycle(EventSource session, Object entity, EntityPersister persister) {
	callbackRegistry.preRemove( entity );

	if ( persister.implementsLifecycle() ) {
		LOG.debug( "Calling onDelete()" );
		if ( ( (Lifecycle) entity ).onDelete( session ) ) {
			LOG.debug( "Deletion vetoed by onDelete()" );
			return true;
		}
	}
	return false;
}
 
Example #3
Source File: PojoEntityTuplizer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public PojoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) {
		super( entityMetamodel, mappedEntity );
		this.mappedClass = mappedEntity.getMappedClass();
		this.proxyInterface = mappedEntity.getProxyInterface();
		this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedClass );
		this.isBytecodeEnhanced = entityMetamodel.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading();

		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
//			);
		}
	}
 
Example #4
Source File: AbstractSaveEventListener.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
}
 
Example #5
Source File: DefaultPostLoadEventListener.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void onPostLoad(PostLoadEvent event) {
	if ( event.getPersister().implementsLifecycle( event.getSession().getEntityMode() ) ) {
		//log.debug( "calling onLoad()" );
		( ( Lifecycle ) event.getEntity() ).onLoad( event.getSession(), event.getId() );
	}

}
 
Example #6
Source File: DefaultSaveOrUpdateEventListener.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
}
 
Example #7
Source File: DefaultDeleteEventListener.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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;
}
 
Example #8
Source File: PojoEntityTuplizer.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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
//			);
		}
	
	}
 
Example #9
Source File: AbstractSaveEventListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #10
Source File: DefaultPostLoadEventListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onPostLoad(PostLoadEvent event) {
	final Object entity = event.getEntity();

	callbackRegistry.postLoad( entity );

	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() );
	}

}
 
Example #11
Source File: DefaultSaveOrUpdateEventListener.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #12
Source File: Match.java    From core with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Implemented due to Lifecycle interface being implemented. Not actually
 * used.
 */
@Override
public boolean onDelete(Session s) throws CallbackException {
	return Lifecycle.NO_VETO;
}
 
Example #13
Source File: Match.java    From core with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Implemented due to Lifecycle interface being implemented. Not actually
 * used.
 */
@Override
public boolean onUpdate(Session s) throws CallbackException {
	return Lifecycle.NO_VETO;
}
 
Example #14
Source File: Match.java    From core with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Implemented due to Lifecycle interface being implemented. Not actually
 * used.
 */
@Override
public boolean onSave(Session s) throws CallbackException {
	return Lifecycle.NO_VETO;
}
 
Example #15
Source File: Trip.java    From core with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Implemented due to Lifecycle interface being implemented. Not actually
 * used.
 */
@Override
public boolean onDelete(Session s) throws CallbackException {
	return Lifecycle.NO_VETO;
}
 
Example #16
Source File: Trip.java    From core with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Implemented due to Lifecycle interface being implemented. Not actually
 * used.
 */
@Override
public boolean onUpdate(Session s) throws CallbackException {
	return Lifecycle.NO_VETO;
}
 
Example #17
Source File: Trip.java    From core with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Implemented due to Lifecycle interface being implemented. Not actually
 * used.
 */
@Override
public boolean onSave(Session s) throws CallbackException {
	return Lifecycle.NO_VETO;
}
 
Example #18
Source File: ArrivalDeparture.java    From core with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Implemented due to Lifecycle interface being implemented. Not actually
 * used.
 */
@Override
public boolean onDelete(Session s) throws CallbackException {
	return Lifecycle.NO_VETO;
}
 
Example #19
Source File: ArrivalDeparture.java    From core with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Implemented due to Lifecycle interface being implemented. Not actually
 * used.
 */
@Override
public boolean onUpdate(Session s) throws CallbackException {
	return Lifecycle.NO_VETO;
}
 
Example #20
Source File: ArrivalDeparture.java    From core with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Implemented due to Lifecycle interface being implemented. Not actually
 * used.
 */
@Override
public boolean onSave(Session s) throws CallbackException {
	return Lifecycle.NO_VETO;
}
 
Example #21
Source File: PredictionAccuracy.java    From core with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Implemented due to Lifecycle interface being implemented. Not actually
 * used.
 */
@Override
public boolean onDelete(Session s) throws CallbackException {
	return Lifecycle.NO_VETO;
}
 
Example #22
Source File: PredictionAccuracy.java    From core with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Implemented due to Lifecycle interface being implemented. Not actually
 * used.
 */
@Override
public boolean onUpdate(Session s) throws CallbackException {
	return Lifecycle.NO_VETO;
}
 
Example #23
Source File: PredictionAccuracy.java    From core with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Implemented due to Lifecycle interface being implemented. Not actually
 * used.
 */
@Override
public boolean onSave(Session s) throws CallbackException {
	return Lifecycle.NO_VETO;
}
 
Example #24
Source File: TypeFactory.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * 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;

}