当前位置: 首页>>代码示例>>Java>>正文


Java SessionFactoryImplementor.getEntityPersister方法代码示例

本文整理汇总了Java中org.hibernate.engine.SessionFactoryImplementor.getEntityPersister方法的典型用法代码示例。如果您正苦于以下问题:Java SessionFactoryImplementor.getEntityPersister方法的具体用法?Java SessionFactoryImplementor.getEntityPersister怎么用?Java SessionFactoryImplementor.getEntityPersister使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.engine.SessionFactoryImplementor的用法示例。


在下文中一共展示了SessionFactoryImplementor.getEntityPersister方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getQueryableCollection

import org.hibernate.engine.SessionFactoryImplementor; //导入方法依赖的package包/类
protected QueryableCollection getQueryableCollection(String entityName, String propertyName, SessionFactoryImplementor factory)
        throws HibernateException {
	PropertyMapping ownerMapping = ( PropertyMapping ) factory.getEntityPersister( entityName );
	Type type = ownerMapping.toType( propertyName );
	if ( !type.isCollectionType() ) {
		throw new MappingException(
		        "Property path [" + entityName + "." + propertyName + "] does not reference a collection"
		);
	}

	String role = ( ( CollectionType ) type ).getRole();
	try {
		return ( QueryableCollection ) factory.getCollectionPersister( role );
	}
	catch ( ClassCastException cce ) {
		throw new QueryException( "collection role is not queryable: " + role );
	}
	catch ( Exception e ) {
		throw new QueryException( "collection role not found: " + role );
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:22,代码来源:AbstractEmptinessExpression.java

示例2: getSubclassEntityPersister

import org.hibernate.engine.SessionFactoryImplementor; //导入方法依赖的package包/类
public EntityPersister getSubclassEntityPersister(Object instance, SessionFactoryImplementor factory, EntityMode entityMode) {
	if ( !hasSubclasses() ) {
		return this;
	}
	else {
		// TODO : really need a way to do something like :
		//      getTuplizer(entityMode).determineConcreteSubclassEntityName(instance)
		Class clazz = instance.getClass();
		if ( clazz == getMappedClass( entityMode ) ) {
			return this;
		}
		else {
			String subclassEntityName = getSubclassEntityName( clazz );
			if ( subclassEntityName == null ) {
				throw new HibernateException(
						"instance not of expected entity type: " + clazz.getName() +
						" is not a: " + getEntityName()
					);
			}
			else {
				return factory.getEntityPersister( subclassEntityName );
			}
		}
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:26,代码来源:AbstractEntityPersister.java

示例3: getHashCode

import org.hibernate.engine.SessionFactoryImplementor; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public int getHashCode(Object x, EntityMode entityMode, SessionFactoryImplementor factory) {
	EntityPersister persister = factory.getEntityPersister(associatedEntityName);
	if ( !persister.canExtractIdOutOfEntity() ) {
		return super.getHashCode(x, entityMode);
	}

	final Serializable id;
	if (x instanceof HibernateProxy) {
		id = ( (HibernateProxy) x ).getHibernateLazyInitializer().getIdentifier();
	}
	else {
		id = persister.getIdentifier(x, entityMode);
	}
	return persister.getIdentifierType().getHashCode(id, entityMode, factory);
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:19,代码来源:EntityType.java

示例4: toSqlString

import org.hibernate.engine.SessionFactoryImplementor; //导入方法依赖的package包/类
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
	
	final SessionImplementor session = ( (CriteriaImpl) criteria ).getSession(); //ugly!
	final SessionFactoryImplementor factory = session.getFactory();
	
	final OuterJoinLoadable persister = (OuterJoinLoadable) factory.getEntityPersister( criteriaImpl.getEntityOrClassName() );
	CriteriaQueryTranslator innerQuery = new CriteriaQueryTranslator( 
			factory, 
			criteriaImpl, 
			criteriaImpl.getEntityOrClassName(), //implicit polymorphism not supported (would need a union) 
			criteriaQuery.generateSQLAlias(),
			criteriaQuery
		);
	
	params = innerQuery.getQueryParameters(); //TODO: bad lifecycle....
	types = innerQuery.getProjectedTypes();
	
	//String filter = persister.filterFragment( innerQuery.getRootSQLALias(), session.getEnabledFilters() );
	
	String sql = new Select( factory.getDialect() )
		.setWhereClause( innerQuery.getWhereCondition() )
		.setGroupByClause( innerQuery.getGroupBy() )
		.setSelectClause( innerQuery.getSelect() )
		.setFromClause(
				persister.fromTableFragment( innerQuery.getRootSQLALias() ) +   
				persister.fromJoinFragment( innerQuery.getRootSQLALias(), true, false )
			)
		.toStatementString();
	
	final StringBuffer buf = new StringBuffer()
		.append( toLeftSqlString(criteria, criteriaQuery) );
	if (op!=null) buf.append(' ').append(op).append(' ');
	if (quantifier!=null) buf.append(quantifier).append(' ');
	return buf.append('(').append(sql).append(')')
		.toString();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:38,代码来源:SubqueryExpression.java

示例5: destructure

import org.hibernate.engine.SessionFactoryImplementor; //导入方法依赖的package包/类
public Object destructure(Object item, SessionFactoryImplementor factory) {
	Map map = (Map) item;
	boolean lazyPropertiesUnfetched = ( (Boolean) map.get("_lazyPropertiesUnfetched") ).booleanValue();
	String subclass = (String) map.get("_subclass");
	Object version = map.get("_version");
	EntityPersister subclassPersister = factory.getEntityPersister(subclass);
	String[] names = subclassPersister.getPropertyNames();
	Serializable[] state = new Serializable[names.length];
	for ( int i=0; i<names.length; i++ ) {
		state[i] = (Serializable) map.get( names[i] );
	}
	return new CacheEntry(state, subclass, lazyPropertiesUnfetched, version);
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:14,代码来源:StructuredCacheEntry.java

示例6: findQueryableUsingImports

import org.hibernate.engine.SessionFactoryImplementor; //导入方法依赖的package包/类
/**
 * Given a (potentially unqualified) class name, locate its persister.
 *
 * @param sfi The session factory implementor.
 * @param className The (potentially unqualified) class name.
 * @return The defined persister for this class, or null if none found.
 */
public static Queryable findQueryableUsingImports(SessionFactoryImplementor sfi, String className) {
	final String importedClassName = sfi.getImportedClassName( className );
	if ( importedClassName == null ) {
		return null;
	}
	try {
		return ( Queryable ) sfi.getEntityPersister( importedClassName );
	}
	catch ( MappingException me ) {
		return null;
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:20,代码来源:SessionFactoryHelper.java

示例7: BulkOperationCleanupAction

import org.hibernate.engine.SessionFactoryImplementor; //导入方法依赖的package包/类
/** Create an action that will evict collection and entity regions based on queryspaces (table names).
 *  TODO: cache the autodetected information and pass it in instead.
 **/
public BulkOperationCleanupAction(SessionImplementor session, Set querySpaces) {
	this.session = session;

	Set tmpSpaces = new HashSet(querySpaces);
	SessionFactoryImplementor factory = session.getFactory();
	Iterator iterator = factory.getAllClassMetadata().entrySet().iterator();
	while ( iterator.hasNext() ) {
		Map.Entry entry = (Map.Entry) iterator.next();
		String entityName = (String) entry.getKey();
		EntityPersister persister = factory.getEntityPersister( entityName );
		Serializable[] entitySpaces = persister.getQuerySpaces();

		if (affectedEntity( querySpaces, entitySpaces )) {
			if ( persister.hasCache() ) {
				affectedEntityNames.add( persister.getEntityName() );
			}
			Set roles = session.getFactory().getCollectionRolesByEntityParticipant( persister.getEntityName() );
			if ( roles != null ) {
				affectedCollectionRoles.addAll( roles );
			}
			for ( int y = 0; y < entitySpaces.length; y++ ) {
				tmpSpaces.add( entitySpaces[y] );
			}
		}

	}
	this.spaces = (Serializable[]) tmpSpaces.toArray( new Serializable[tmpSpaces.size()] );		
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:32,代码来源:BulkOperationCleanupAction.java

示例8: isEqual

import org.hibernate.engine.SessionFactoryImplementor; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public boolean isEqual(Object x, Object y, EntityMode entityMode, SessionFactoryImplementor factory) {
	EntityPersister persister = factory.getEntityPersister(associatedEntityName);
	if ( !persister.canExtractIdOutOfEntity() ) {
		return super.isEqual(x, y, entityMode);
	}

	Serializable xid;
	if (x instanceof HibernateProxy) {
		xid = ( (HibernateProxy) x ).getHibernateLazyInitializer()
				.getIdentifier();
	}
	else {
		xid = persister.getIdentifier(x, entityMode);
	}

	Serializable yid;
	if (y instanceof HibernateProxy) {
		yid = ( (HibernateProxy) y ).getHibernateLazyInitializer()
				.getIdentifier();
	}
	else {
		yid = persister.getIdentifier(y, entityMode);
	}

	return persister.getIdentifierType()
			.isEqual(xid, yid, entityMode, factory);
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:31,代码来源:EntityType.java

示例9: toLoggableString

import org.hibernate.engine.SessionFactoryImplementor; //导入方法依赖的package包/类
/**
 * Generate a loggable representation of an instance of the value mapped by this type.
 *
 * @param value The instance to be logged.
 * @param factory The session factory.
 * @return The loggable string.
 * @throws HibernateException Generally some form of resolution problem.
 */
public String toLoggableString(Object value, SessionFactoryImplementor factory) {
	if ( value == null ) {
		return "null";
	}
	
	EntityPersister persister = factory.getEntityPersister( associatedEntityName );
	StringBuffer result = new StringBuffer().append( associatedEntityName );

	if ( persister.hasIdentifierProperty() ) {
		final EntityMode entityMode = persister.guessEntityMode( value );
		final Serializable id;
		if ( entityMode == null ) {
			if ( isEmbeddedInXML ) {
				throw new ClassCastException( value.getClass().getName() );
			}
			id = ( Serializable ) value;
		}
		else {
			id = getIdentifier( value, persister, entityMode );
		}
		
		result.append( '#' )
			.append( persister.getIdentifierType().toLoggableString( id, factory ) );
	}
	
	return result.toString();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:36,代码来源:EntityType.java

示例10: loadByUniqueKey

import org.hibernate.engine.SessionFactoryImplementor; //导入方法依赖的package包/类
/**
 * Load an instance by a unique key that is not the primary key.
 *
 * @param entityName The name of the entity to load
 * @param uniqueKeyPropertyName The name of the property defining the uniqie key.
 * @param key The unique key property value.
 * @param session The originating session.
 * @return The loaded entity
 * @throws HibernateException generally indicates problems performing the load.
 */
public Object loadByUniqueKey(
		String entityName, 
		String uniqueKeyPropertyName, 
		Object key, 
		SessionImplementor session) throws HibernateException {
	final SessionFactoryImplementor factory = session.getFactory();
	UniqueKeyLoadable persister = ( UniqueKeyLoadable ) factory.getEntityPersister( entityName );

	//TODO: implement caching?! proxies?!

	EntityUniqueKey euk = new EntityUniqueKey(
			entityName, 
			uniqueKeyPropertyName, 
			key, 
			getIdentifierOrUniqueKeyType( factory ),
			session.getEntityMode(), 
			session.getFactory()
	);

	final PersistenceContext persistenceContext = session.getPersistenceContext();
	Object result = persistenceContext.getEntity( euk );
	if ( result == null ) {
		result = persister.loadByUniqueKey( uniqueKeyPropertyName, key, session );
	}
	return result == null ? null : persistenceContext.proxyFor( result );
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:37,代码来源:EntityType.java

示例11: assembleCacheEntry

import org.hibernate.engine.SessionFactoryImplementor; //导入方法依赖的package包/类
private Object assembleCacheEntry(
		final CacheEntry entry,
		final Serializable id,
		final EntityPersister persister,
		final LoadEvent event) throws HibernateException {
	
	final Object optionalObject = event.getInstanceToLoad();
	final EventSource session = event.getSession();
	final SessionFactoryImplementor factory = session.getFactory();
	
	if ( log.isTraceEnabled() ) {
		log.trace(
				"assembling entity from second-level cache: " +
				MessageHelper.infoString( persister, id, factory )
			);
	}

	EntityPersister subclassPersister = factory.getEntityPersister( entry.getSubclass() );
	Object result = optionalObject == null ? 
			session.instantiate( subclassPersister, id ) : optionalObject;
			
	// make it circular-reference safe
	TwoPhaseLoad.addUninitializedCachedEntity( 
			new EntityKey( id, subclassPersister, session.getEntityMode() ), 
			result, 
			subclassPersister, 
			LockMode.NONE, 
			entry.areLazyPropertiesUnfetched(),
			entry.getVersion(),
			session
		);

	Type[] types = subclassPersister.getPropertyTypes();
	Object[] values = entry.assemble( result, id, subclassPersister, session.getInterceptor(), session ); // intializes result by side-effect
	TypeFactory.deepCopy( 
			values, 
			types, 
			subclassPersister.getPropertyUpdateability(), 
			values, 
			session
		);
	
	Object version = Versioning.getVersion( values, subclassPersister );
	if ( log.isTraceEnabled() ) log.trace( "Cached Version: " + version );
	
	final PersistenceContext persistenceContext = session.getPersistenceContext();
	persistenceContext.addEntry( 
			result, 
			Status.MANAGED, 
			values, 
			null, 
			id, 
			version, 
			LockMode.NONE, 
			true, 
			subclassPersister, 
			false, 
			entry.areLazyPropertiesUnfetched() 
		);
	subclassPersister.afterInitialize( result, entry.areLazyPropertiesUnfetched(), session );
	persistenceContext.initializeNonLazyCollections();
	// upgrade the lock if necessary:
	//lock(result, lockMode);

	//PostLoad is needed for EJB3
	//TODO: reuse the PostLoadEvent...
	PostLoadEvent postLoadEvent = new PostLoadEvent(session).setEntity(result)
			.setId(id).setPersister(persister);
	PostLoadEventListener[] listeners = session.getListeners().getPostLoadEventListeners();
	for ( int i = 0; i < listeners.length; i++ ) {
		listeners[i].onPostLoad(postLoadEvent);
	}
	
	return result;
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:76,代码来源:DefaultLoadEventListener.java

示例12: getAssociatedJoinable

import org.hibernate.engine.SessionFactoryImplementor; //导入方法依赖的package包/类
/**
 * Retrieves the {@link Joinable} defining the associated entity.
 *
 * @param factory The session factory.
 * @return The associated joinable
 * @throws MappingException Generally indicates an invalid entity name.
 */
public Joinable getAssociatedJoinable(SessionFactoryImplementor factory) throws MappingException {
	return ( Joinable ) factory.getEntityPersister( associatedEntityName );
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:11,代码来源:EntityType.java


注:本文中的org.hibernate.engine.SessionFactoryImplementor.getEntityPersister方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。