本文整理汇总了Java中org.hibernate.engine.SessionImplementor.getFactory方法的典型用法代码示例。如果您正苦于以下问题:Java SessionImplementor.getFactory方法的具体用法?Java SessionImplementor.getFactory怎么用?Java SessionImplementor.getFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.engine.SessionImplementor
的用法示例。
在下文中一共展示了SessionImplementor.getFactory方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getElementsIterator
import org.hibernate.engine.SessionImplementor; //导入方法依赖的package包/类
/**
* Get an iterator over the element set of the collection, which may not yet be wrapped
*
* @param collection The collection to be iterated
* @param session The session from which the request is originating.
* @return The iterator.
*/
public Iterator getElementsIterator(Object collection, SessionImplementor session) {
if ( session.getEntityMode()==EntityMode.DOM4J ) {
final SessionFactoryImplementor factory = session.getFactory();
final CollectionPersister persister = factory.getCollectionPersister( getRole() );
final Type elementType = persister.getElementType();
List elements = ( (Element) collection ).elements( persister.getElementNodeName() );
ArrayList results = new ArrayList();
for ( int i=0; i<elements.size(); i++ ) {
Element value = (Element) elements.get(i);
results.add( elementType.fromXMLNode( value, factory ) );
}
return results.iterator();
}
else {
return getElementsIterator(collection);
}
}
示例2: toSqlString
import org.hibernate.engine.SessionImplementor; //导入方法依赖的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();
}
示例3: createSubselectInitializer
import org.hibernate.engine.SessionImplementor; //导入方法依赖的package包/类
protected CollectionInitializer createSubselectInitializer(SubselectFetch subselect, SessionImplementor session) {
return new SubselectCollectionLoader(
this,
subselect.toSubselectString( getCollectionType().getLHSPropertyName() ),
subselect.getResult(),
subselect.getQueryParameters(),
subselect.getNamedParameterLocMap(),
session.getFactory(),
session.getEnabledFilters()
);
}
示例4: createSubselectInitializer
import org.hibernate.engine.SessionImplementor; //导入方法依赖的package包/类
protected CollectionInitializer createSubselectInitializer(SubselectFetch subselect, SessionImplementor session) {
return new SubselectOneToManyLoader(
this,
subselect.toSubselectString( getCollectionType().getLHSPropertyName() ),
subselect.getResult(),
subselect.getQueryParameters(),
subselect.getNamedParameterLocMap(),
session.getFactory(),
session.getEnabledFilters()
);
}
示例5: execute
import org.hibernate.engine.SessionImplementor; //导入方法依赖的package包/类
public void execute() throws HibernateException {
EntityPersister persister = getPersister();
SessionImplementor session = getSession();
Object instance = getInstance();
Serializable id = getId();
boolean veto = preInsert();
// Don't need to lock the cache here, since if someone
// else inserted the same pk first, the insert would fail
if ( !veto ) {
persister.insert( id, state, instance, session );
EntityEntry entry = session.getPersistenceContext().getEntry( instance );
if ( entry == null ) {
throw new AssertionFailure( "possible nonthreadsafe access to session" );
}
entry.postInsert();
if ( persister.hasInsertGeneratedProperties() ) {
persister.processInsertGeneratedProperties( id, instance, state, session );
if ( persister.isVersionPropertyGenerated() ) {
version = Versioning.getVersion(state, persister);
}
entry.postUpdate(instance, state, version);
}
}
final SessionFactoryImplementor factory = getSession().getFactory();
if ( isCachePutEnabled( persister, session ) ) {
CacheEntry ce = new CacheEntry(
state,
persister,
persister.hasUninitializedLazyProperties( instance, session.getEntityMode() ),
version,
session,
instance
);
cacheEntry = persister.getCacheEntryStructure().structure(ce);
final CacheKey ck = new CacheKey(
id,
persister.getIdentifierType(),
persister.getRootEntityName(),
session.getEntityMode(),
session.getFactory()
);
// boolean put = persister.getCache().insert(ck, cacheEntry);
boolean put = persister.getCache().insert( ck, cacheEntry, version );
if ( put && factory.getStatistics().isStatisticsEnabled() ) {
factory.getStatisticsImplementor()
.secondLevelCachePut( getPersister().getCache().getRegionName() );
}
}
postInsert();
if ( factory.getStatistics().isStatisticsEnabled() && !veto ) {
factory.getStatisticsImplementor()
.insertEntity( getPersister().getEntityName() );
}
}
示例6: BulkOperationCleanupAction
import org.hibernate.engine.SessionImplementor; //导入方法依赖的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()] );
}
示例7: loadByUniqueKey
import org.hibernate.engine.SessionImplementor; //导入方法依赖的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 );
}
示例8: addCollectionToCache
import org.hibernate.engine.SessionImplementor; //导入方法依赖的package包/类
/**
* Add the collection to the second-level cache
*
* @param lce The entry representing the collection to add
* @param persister The persister
*/
private void addCollectionToCache(LoadingCollectionEntry lce, CollectionPersister persister) {
final SessionImplementor session = getLoadContext().getPersistenceContext().getSession();
final SessionFactoryImplementor factory = session.getFactory();
if ( log.isDebugEnabled() ) {
log.debug( "Caching collection: " + MessageHelper.collectionInfoString( persister, lce.getKey(), factory ) );
}
if ( !session.getEnabledFilters().isEmpty() && persister.isAffectedByEnabledFilters( session ) ) {
// some filters affecting the collection are enabled on the session, so do not do the put into the cache.
log.debug( "Refusing to add to cache due to enabled filters" );
// todo : add the notion of enabled filters to the CacheKey to differentiate filtered collections from non-filtered;
// but CacheKey is currently used for both collections and entities; would ideally need to define two seperate ones;
// currently this works in conjuction with the check on
// DefaultInitializeCollectionEventHandler.initializeCollectionFromCache() (which makes sure to not read from
// cache with enabled filters).
return; // EARLY EXIT!!!!!
}
final Comparator versionComparator;
final Object version;
if ( persister.isVersioned() ) {
versionComparator = persister.getOwnerEntityPersister().getVersionType().getComparator();
final Object collectionOwner = getLoadContext().getPersistenceContext().getCollectionOwner( lce.getKey(), persister );
version = getLoadContext().getPersistenceContext().getEntry( collectionOwner ).getVersion();
}
else {
version = null;
versionComparator = null;
}
CollectionCacheEntry entry = new CollectionCacheEntry( lce.getCollection(), persister );
CacheKey cacheKey = new CacheKey(
lce.getKey(),
persister.getKeyType(),
persister.getRole(),
session.getEntityMode(),
session.getFactory()
);
boolean put = persister.getCache().put(
cacheKey,
persister.getCacheEntryStructure().structure(entry),
session.getTimestamp(),
version,
versionComparator,
factory.getSettings().isMinimalPutsEnabled() && session.getCacheMode()!= CacheMode.REFRESH
);
if ( put && factory.getStatistics().isStatisticsEnabled() ) {
factory.getStatisticsImplementor().secondLevelCachePut( persister.getCache().getRegionName() );
}
}
示例9: lock
import org.hibernate.engine.SessionImplementor; //导入方法依赖的package包/类
/**
* @see LockingStrategy#lock
*/
public void lock(
Serializable id,
Object version,
Object object,
SessionImplementor session) throws StaleObjectStateException, JDBCException {
if ( !lockable.isVersioned() ) {
throw new HibernateException( "write locks via update not supported for non-versioned entities [" + lockable.getEntityName() + "]" );
}
// todo : should we additionally check the current isolation mode explicitly?
SessionFactoryImplementor factory = session.getFactory();
try {
PreparedStatement st = session.getBatcher().prepareSelectStatement( sql );
try {
lockable.getVersionType().nullSafeSet( st, version, 1, session );
int offset = 2;
lockable.getIdentifierType().nullSafeSet( st, id, offset, session );
offset += lockable.getIdentifierType().getColumnSpan( factory );
if ( lockable.isVersioned() ) {
lockable.getVersionType().nullSafeSet( st, version, offset, session );
}
int affected = st.executeUpdate();
if ( affected < 0 ) {
factory.getStatisticsImplementor().optimisticFailure( lockable.getEntityName() );
throw new StaleObjectStateException( lockable.getEntityName(), id );
}
}
finally {
session.getBatcher().closeStatement( st );
}
}
catch ( SQLException sqle ) {
throw JDBCExceptionHelper.convert(
session.getFactory().getSQLExceptionConverter(),
sqle,
"could not lock: " + MessageHelper.infoString( lockable, id, session.getFactory() ),
sql
);
}
}
示例10: lock
import org.hibernate.engine.SessionImplementor; //导入方法依赖的package包/类
/**
* @see LockingStrategy#lock
*/
public void lock(
Serializable id,
Object version,
Object object,
SessionImplementor session) throws StaleObjectStateException, JDBCException {
SessionFactoryImplementor factory = session.getFactory();
try {
PreparedStatement st = session.getBatcher().prepareSelectStatement( sql );
try {
lockable.getIdentifierType().nullSafeSet( st, id, 1, session );
if ( lockable.isVersioned() ) {
lockable.getVersionType().nullSafeSet(
st,
version,
lockable.getIdentifierType().getColumnSpan( factory ) + 1,
session
);
}
ResultSet rs = st.executeQuery();
try {
if ( !rs.next() ) {
if ( factory.getStatistics().isStatisticsEnabled() ) {
factory.getStatisticsImplementor()
.optimisticFailure( lockable.getEntityName() );
}
throw new StaleObjectStateException( lockable.getEntityName(), id );
}
}
finally {
rs.close();
}
}
finally {
session.getBatcher().closeStatement( st );
}
}
catch ( SQLException sqle ) {
throw JDBCExceptionHelper.convert(
session.getFactory().getSQLExceptionConverter(),
sqle,
"could not lock: " + MessageHelper.infoString( lockable, id, session.getFactory() ),
sql
);
}
}
示例11: initializeCollectionFromCache
import org.hibernate.engine.SessionImplementor; //导入方法依赖的package包/类
/**
* Try to initialize a collection from the cache
*/
private boolean initializeCollectionFromCache(
Serializable id,
CollectionPersister persister,
PersistentCollection collection,
SessionImplementor source)
throws HibernateException {
if ( !source.getEnabledFilters().isEmpty() && persister.isAffectedByEnabledFilters( source ) ) {
log.trace( "disregarding cached version (if any) of collection due to enabled filters ");
return false;
}
final boolean useCache = persister.hasCache() &&
source.getCacheMode().isGetEnabled();
if ( !useCache ) {
return false;
}
else {
final SessionFactoryImplementor factory = source.getFactory();
final CacheKey ck = new CacheKey(
id,
persister.getKeyType(),
persister.getRole(),
source.getEntityMode(),
source.getFactory()
);
Object ce = persister.getCache().get( ck, source.getTimestamp() );
if ( factory.getStatistics().isStatisticsEnabled() ) {
if (ce==null) {
factory.getStatisticsImplementor().secondLevelCacheMiss(
persister.getCache().getRegionName()
);
}
else {
factory.getStatisticsImplementor().secondLevelCacheHit(
persister.getCache().getRegionName()
);
}
}
if (ce==null) {
return false;
}
else {
CollectionCacheEntry cacheEntry = (CollectionCacheEntry) persister.getCacheEntryStructure()
.destructure(ce, factory);
final PersistenceContext persistenceContext = source.getPersistenceContext();
cacheEntry.assemble(
collection,
persister,
persistenceContext.getCollectionOwner(id, persister)
);
persistenceContext.getCollectionEntry(collection).postInitialize(collection);
//addInitializedCollection(collection, persister, id);
return true;
}
}
}
示例12: loadFromSecondLevelCache
import org.hibernate.engine.SessionImplementor; //导入方法依赖的package包/类
/**
* Attempts to load the entity from the second-level cache.
*
* @param event The load event
* @param persister The persister for the entity being requested for load
* @param options The load options.
* @return The entity from the second-level cache, or null.
* @throws HibernateException
*/
protected Object loadFromSecondLevelCache(
final LoadEvent event,
final EntityPersister persister,
final LoadEventListener.LoadType options) throws HibernateException {
final SessionImplementor source = event.getSession();
final boolean useCache = persister.hasCache() &&
source.getCacheMode().isGetEnabled() &&
event.getLockMode().lessThan(LockMode.READ);
if (useCache) {
final SessionFactoryImplementor factory = source.getFactory();
final CacheKey ck = new CacheKey(
event.getEntityId(),
persister.getIdentifierType(),
persister.getRootEntityName(),
source.getEntityMode(),
source.getFactory()
);
Object ce = persister.getCache()
.get( ck, source.getTimestamp() );
if ( factory.getStatistics().isStatisticsEnabled() ) {
if (ce==null) {
factory.getStatisticsImplementor().secondLevelCacheMiss(
persister.getCache().getRegionName()
);
}
else {
factory.getStatisticsImplementor().secondLevelCacheHit(
persister.getCache().getRegionName()
);
}
}
if ( ce != null ) {
CacheEntry entry = (CacheEntry) persister.getCacheEntryStructure()
.destructure(ce, factory);
// Entity was found in second-level cache...
return assembleCacheEntry(
entry,
event.getEntityId(),
persister,
event
);
}
}
return null;
}