FileDocCategorySizeDatePackage
PersisterFactory.javaAPI DocHibernate 3.2.55224Sat Feb 19 00:06:06 GMT 2005org.hibernate.persister

PersisterFactory

public final class PersisterFactory extends Object
Factory for EntityPersister and CollectionPersister instances
author
Gavin King

Fields Summary
private static final Class[]
PERSISTER_CONSTRUCTOR_ARGS
private static final Class[]
COLLECTION_PERSISTER_CONSTRUCTOR_ARGS
Constructors Summary
private PersisterFactory()

Methods Summary
private static org.hibernate.persister.entity.EntityPersistercreate(java.lang.Class persisterClass, org.hibernate.mapping.PersistentClass model, org.hibernate.cache.CacheConcurrencyStrategy cache, org.hibernate.engine.SessionFactoryImplementor factory, org.hibernate.engine.Mapping cfg)

		Constructor pc;
		try {
			pc = persisterClass.getConstructor(PERSISTER_CONSTRUCTOR_ARGS);
		}
		catch (Exception e) {
			throw new MappingException( "Could not get constructor for " + persisterClass.getName(), e );
		}

		try {
			return (EntityPersister) pc.newInstance( new Object[] { model, cache, factory, cfg } );
		}
		catch (InvocationTargetException ite) {
			Throwable e = ite.getTargetException();
			if (e instanceof HibernateException) {
				throw (HibernateException) e;
			}
			else {
				throw new MappingException( "Could not instantiate persister " + persisterClass.getName(), e );
			}
		}
		catch (Exception e) {
			throw new MappingException( "Could not instantiate persister " + persisterClass.getName(), e );
		}
	
private static org.hibernate.persister.collection.CollectionPersistercreate(java.lang.Class persisterClass, org.hibernate.cfg.Configuration cfg, org.hibernate.mapping.Collection model, org.hibernate.cache.CacheConcurrencyStrategy cache, org.hibernate.engine.SessionFactoryImplementor factory)

		Constructor pc;
		try {
			pc = persisterClass.getConstructor(COLLECTION_PERSISTER_CONSTRUCTOR_ARGS);
		}
		catch (Exception e) {
			throw new MappingException( "Could not get constructor for " + persisterClass.getName(), e );
		}

		try {
			return (CollectionPersister) pc.newInstance( new Object[] { model, cache, cfg, factory } );
		}
		catch (InvocationTargetException ite) {
			Throwable e = ite.getTargetException();
			if (e instanceof HibernateException) {
				throw (HibernateException) e;
			}
			else {
				throw new MappingException( "Could not instantiate collection persister " + persisterClass.getName(), e );
			}
		}
		catch (Exception e) {
			throw new MappingException( "Could not instantiate collection persister " + persisterClass.getName(), e );
		}
	
public static org.hibernate.persister.entity.EntityPersistercreateClassPersister(org.hibernate.mapping.PersistentClass model, org.hibernate.cache.CacheConcurrencyStrategy cache, org.hibernate.engine.SessionFactoryImplementor factory, org.hibernate.engine.Mapping cfg)


	   
			  
			  
			 
			 
	  
		Class persisterClass = model.getEntityPersisterClass();
		if (persisterClass==null || persisterClass==SingleTableEntityPersister.class) {
			return new SingleTableEntityPersister(model, cache, factory, cfg);
		}
		else if (persisterClass==JoinedSubclassEntityPersister.class) {
			return new JoinedSubclassEntityPersister(model, cache, factory, cfg);
		}
		else if (persisterClass==UnionSubclassEntityPersister.class) {
			return new UnionSubclassEntityPersister(model, cache, factory, cfg);
		}
		else {
			return create(persisterClass, model, cache, factory, cfg);
		}
	
public static org.hibernate.persister.collection.CollectionPersistercreateCollectionPersister(org.hibernate.cfg.Configuration cfg, org.hibernate.mapping.Collection model, org.hibernate.cache.CacheConcurrencyStrategy cache, org.hibernate.engine.SessionFactoryImplementor factory)

		Class persisterClass = model.getCollectionPersisterClass();
		if(persisterClass==null) { // default behavior
			return model.isOneToMany() ?
				(CollectionPersister) new OneToManyPersister(model, cache, cfg, factory) :
				(CollectionPersister) new BasicCollectionPersister(model, cache, cfg, factory);
		}
		else {
			return create(persisterClass, cfg, model, cache, factory);
		}