本文整理汇总了Java中org.hibernate.proxy.LazyInitializer.getSession方法的典型用法代码示例。如果您正苦于以下问题:Java LazyInitializer.getSession方法的具体用法?Java LazyInitializer.getSession怎么用?Java LazyInitializer.getSession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.proxy.LazyInitializer
的用法示例。
在下文中一共展示了LazyInitializer.getSession方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIdentifier
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
@Override
public Serializable getIdentifier(Object object) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
if ( object instanceof HibernateProxy ) {
LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
if ( li.getSession() != this ) {
throw new TransientObjectException( "The proxy was not associated with this session" );
}
return li.getIdentifier();
}
else {
EntityEntry entry = persistenceContext.getEntry(object);
if ( entry == null ) {
throw new TransientObjectException( "The instance was not associated with this session" );
}
return entry.getId();
}
}
示例2: getIdentifier
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
public Serializable getIdentifier(Object object) throws HibernateException {
errorIfClosed();
checkTransactionSynchStatus();
if ( object instanceof HibernateProxy ) {
LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
if ( li.getSession() != this ) {
throw new TransientObjectException( "The proxy was not associated with this session" );
}
return li.getIdentifier();
}
else {
EntityEntry entry = persistenceContext.getEntry(object);
if ( entry == null ) {
throw new TransientObjectException( "The instance was not associated with this session" );
}
return entry.getId();
}
}
示例3: reassociateProxy
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
/**
* Associate a proxy that was instantiated by another session with this session
*
* @param li The proxy initializer.
* @param proxy The proxy to reassociate.
*/
private void reassociateProxy(LazyInitializer li, HibernateProxy proxy) {
if ( li.getSession() != this.getSession() ) {
final EntityPersister persister = session.getFactory().getEntityPersister( li.getEntityName() );
final EntityKey key = session.generateEntityKey( li.getIdentifier(), persister );
// any earlier proxy takes precedence
proxiesByKey.putIfAbsent( key, proxy );
proxy.getHibernateLazyInitializer().setSession( session );
}
}
示例4: contains
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
@Override
public boolean contains(Object object) {
errorIfClosed();
checkTransactionSynchStatus();
if ( object instanceof HibernateProxy ) {
//do not use proxiesByKey, since not all
//proxies that point to this session's
//instances are in that collection!
LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
if ( li.isUninitialized() ) {
//if it is an uninitialized proxy, pointing
//with this session, then when it is accessed,
//the underlying instance will be "contained"
return li.getSession()==this;
}
else {
//if it is initialized, see if the underlying
//instance is contained, since we need to
//account for the fact that it might have been
//evicted
object = li.getImplementation();
}
}
// A session is considered to contain an entity only if the entity has
// an entry in the session's persistence context and the entry reports
// that the entity has not been removed
EntityEntry entry = persistenceContext.getEntry( object );
delayedAfterCompletion();
return entry != null && entry.getStatus() != Status.DELETED && entry.getStatus() != Status.GONE;
}
示例5: getClass
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
/**
* Hibernate makes {@link Class#getClass()} diffficult ...
* @param example The class that we want to call {@link Class#getClass()} on
* @return The type of the given object
*/
public Class getClass(Object example)
{
if (example instanceof HibernateProxy)
{
HibernateProxy proxy = (HibernateProxy) example;
LazyInitializer initializer = proxy.getHibernateLazyInitializer();
SessionImplementor implementor = initializer.getSession();
if (initializer.isUninitialized())
{
try
{
// getImplementation is going to want to talk to a session
if (implementor.isClosed())
{
// Give up and return example.getClass();
return example.getClass();
}
}
catch (NoSuchMethodError ex)
{
// We must be using Hibernate 3.0/3.1 which doesn't have
// this method
}
}
return initializer.getImplementation().getClass();
}
else
{
return example.getClass();
}
}
示例6: getClass
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
/**
* Hibernate makes {@link Class#getClass()} difficult ...
* @param example The class that we want to call {@link Class#getClass()} on
* @return The type of the given object
*/
public Class<?> getClass(Object example)
{
if (example instanceof HibernateProxy)
{
HibernateProxy proxy = (HibernateProxy) example;
LazyInitializer initializer = proxy.getHibernateLazyInitializer();
SessionImplementor implementor = initializer.getSession();
if (initializer.isUninitialized())
{
try
{
// getImplementation is going to want to talk to a session
if (implementor.isClosed())
{
// Give up and return example.getClass();
return example.getClass();
}
}
catch (NoSuchMethodError ex)
{
// We must be using Hibernate 3.0/3.1 which doesn't have
// this method
}
}
return initializer.getImplementation().getClass();
}
else
{
return example.getClass();
}
}
示例7: reassociateProxy
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
/**
* Associate a proxy that was instantiated by another session with this session
*
* @param li The proxy initializer.
* @param proxy The proxy to reassociate.
*/
private void reassociateProxy(LazyInitializer li, HibernateProxy proxy) {
if ( li.getSession() != this.getSession() ) {
EntityPersister persister = session.getFactory().getEntityPersister( li.getEntityName() );
EntityKey key = new EntityKey( li.getIdentifier(), persister, session.getEntityMode() );
// any earlier proxy takes precedence
if ( !proxiesByKey.containsKey( key ) ) {
proxiesByKey.put( key, proxy );
}
proxy.getHibernateLazyInitializer().setSession( session );
}
}
示例8: contains
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
public boolean contains(Object object) {
errorIfClosed();
checkTransactionSynchStatus();
if ( object instanceof HibernateProxy ) {
//do not use proxiesByKey, since not all
//proxies that point to this session's
//instances are in that collection!
LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
if ( li.isUninitialized() ) {
//if it is an uninitialized proxy, pointing
//with this session, then when it is accessed,
//the underlying instance will be "contained"
return li.getSession()==this;
}
else {
//if it is initialized, see if the underlying
//instance is contained, since we need to
//account for the fact that it might have been
//evicted
object = li.getImplementation();
}
}
// A session is considered to contain an entity only if the entity has
// an entry in the session's persistence context and the entry reports
// that the entity has not been removed
EntityEntry entry = persistenceContext.getEntry( object );
return entry != null && entry.getStatus() != Status.DELETED && entry.getStatus() != Status.GONE;
}
示例9: unsetProxyHibernateSession
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
/**
* Unset proxy hibernate session.
*
* @param entity the entity
* @param hibernateSession the hibernate session
*/
public static void unsetProxyHibernateSession(IEntity entity, Session hibernateSession) {
if (entity instanceof HibernateProxy) {
LazyInitializer li = ((HibernateProxy) entity)
.getHibernateLazyInitializer();
if (li.getSession() != null && li.getSession() != hibernateSession) {
li.unsetSession();
}
}
}
示例10: getValue
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
public Object getValue(Object bean) throws MarshallException
{
if (!(bean instanceof HibernateProxy))
{
// This is not a hibernate dynamic proxy, just use it
return super.getValue(bean);
}
else
{
// If the property is already initialized, use it
boolean initialized = Hibernate.isPropertyInitialized(bean, descriptor.getName());
if (initialized)
{
// This might be a lazy-collection so we need to double check
Object reply = super.getValue(bean);
initialized = Hibernate.isInitialized(reply);
}
if (initialized)
{
return super.getValue(bean);
}
else
{
// If the session bound to the property is live, use it
HibernateProxy proxy = (HibernateProxy) bean;
LazyInitializer initializer = proxy.getHibernateLazyInitializer();
SessionImplementor implementor = initializer.getSession();
if (implementor.isOpen())
{
return super.getValue(bean);
}
// So the property needs database access, and the session is closed
// We'll need to try get another session
ServletContext context = WebContextFactory.get().getServletContext();
Session session = H3SessionAjaxFilter.getCurrentSession(context);
if (session != null)
{
session.update(bean);
return super.getValue(bean);
}
return null;
}
}
}
示例11: getValue
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
@Override
public Object getValue(Object bean) throws ConversionException
{
if (!(bean instanceof HibernateProxy))
{
// This is not a hibernate dynamic proxy, just use it
return super.getValue(bean);
}
else
{
// If the property is already initialized, use it
boolean initialized = Hibernate.isPropertyInitialized(bean, descriptor.getName());
if (initialized)
{
// This might be a lazy-collection so we need to double check
Object reply = super.getValue(bean);
initialized = Hibernate.isInitialized(reply);
}
if (initialized)
{
return super.getValue(bean);
}
else
{
// If the session bound to the property is live, use it
HibernateProxy proxy = (HibernateProxy) bean;
LazyInitializer initializer = proxy.getHibernateLazyInitializer();
SessionImplementor implementor = initializer.getSession();
if (implementor.isOpen())
{
return super.getValue(bean);
}
// So the property needs database access, and the session is closed
// We'll need to try get another session
ServletContext context = WebContextFactory.get().getServletContext();
Session session = H3SessionAjaxFilter.getCurrentSession(context);
if (session != null)
{
session.update(bean);
return super.getValue(bean);
}
return null;
}
}
}
示例12: getValue
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
@Override
public Object getValue(Object bean) throws ConversionException
{
if (!(bean instanceof HibernateProxy))
{
// This is not a hibernate dynamic proxy, just use it
return super.getValue(bean);
}
else
{
// If the property is already initialized, use it
boolean initialized = Hibernate.isPropertyInitialized(bean, descriptor.getName());
if (initialized)
{
// This might be a lazy-collection so we need to double check
Object reply = super.getValue(bean);
initialized = Hibernate.isInitialized(reply);
}
if (initialized)
{
return super.getValue(bean);
}
else
{
// If the session bound to the property is live, use it
HibernateProxy proxy = (HibernateProxy) bean;
LazyInitializer initializer = proxy.getHibernateLazyInitializer();
SessionImplementor implementor = initializer.getSession();
if (implementor.isOpen())
{
return super.getValue(bean);
}
// So the property needs database access, and the session is closed
// We'll need to try get another session
ServletContext context = WebContextFactory.get().getServletContext();
Session session = H4SessionAjaxFilter.getCurrentSession(context);
if (session != null)
{
session.update(bean);
return super.getValue(bean);
}
return null;
}
}
}
示例13: onPersist
import org.hibernate.proxy.LazyInitializer; //导入方法依赖的package包/类
/**
* Handle the given create event.
*
* @param event The create event to be handled.
* @throws HibernateException
*/
public void onPersist(PersistEvent event, Map createCache) throws HibernateException {
final SessionImplementor source = event.getSession();
final Object object = event.getObject();
final Object entity;
if (object instanceof HibernateProxy) {
LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
if ( li.isUninitialized() ) {
if ( li.getSession()==source ) {
return; //NOTE EARLY EXIT!
}
else {
throw new PersistentObjectException("uninitialized proxy passed to persist()");
}
}
entity = li.getImplementation();
}
else {
entity = object;
}
int entityState = getEntityState(
entity,
event.getEntityName(),
source.getPersistenceContext().getEntry(entity),
source
);
switch (entityState) {
case DETACHED:
throw new PersistentObjectException(
"detached entity passed to persist: " +
getLoggableName( event.getEntityName(), entity )
);
case PERSISTENT:
entityIsPersistent(event, createCache);
break;
case TRANSIENT:
entityIsTransient(event, createCache);
break;
default:
throw new ObjectDeletedException(
"deleted entity passed to persist",
null,
getLoggableName( event.getEntityName(), entity )
);
}
}