/** * Access to the session (via the PersistenceContext) to which this delegate ultimately belongs. * * @return The session */ protected SharedSessionContractImplementor session() { return persistenceContext.getSession(); }
/** * It is only valid to define natural ids at the root of an entity hierarchy. This method makes sure we are * using the root persister. * * @param persister The persister representing the entity type. * * @return The root persister. */ protected EntityPersister locatePersisterForKey(EntityPersister persister) { return persistenceContext.getSession().getFactory().getEntityPersister( persister.getRootEntityName() ); }
private static EntityEntry deserializeEntityEntry(char[] entityEntryClassNameArr, ObjectInputStream ois, StatefulPersistenceContext rtn){ EntityEntry entry = null; final String entityEntryClassName = new String( entityEntryClassNameArr ); final Class entityEntryClass = rtn.getSession().getFactory().getServiceRegistry().getService( ClassLoaderService.class ).classForName( entityEntryClassName ); try { final Method deserializeMethod = entityEntryClass.getDeclaredMethod( "deserialize", ObjectInputStream.class, PersistenceContext.class ); entry = (EntityEntry) deserializeMethod.invoke( null, ois, rtn ); } catch (NoSuchMethodException e) { log.errorf( "Enable to deserialize [%s]", entityEntryClassName ); } catch (InvocationTargetException e) { log.errorf( "Enable to deserialize [%s]", entityEntryClassName ); } catch (IllegalAccessException e) { log.errorf( "Enable to deserialize [%s]", entityEntryClassName ); } return entry; }
aCollectionEntryArray.getKey().unsetSession( getSession() );
private void setProxyReadOnly(HibernateProxy proxy, boolean readOnly) { if ( proxy.getHibernateLazyInitializer().getSession() != getSession() ) { throw new AssertionFailure( "Attempt to set a proxy to read-only that is associated with a different session" ); } proxy.getHibernateLazyInitializer().setReadOnly( readOnly ); }
/** * 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().getMetamodel().entityPersister( li.getEntityName() ); final EntityKey key = session.generateEntityKey( li.getIdentifier(), persister ); // any earlier proxy takes precedence proxiesByKey.putIfAbsent( key, proxy ); proxy.getHibernateLazyInitializer().setSession( session ); } }
@Override public void setReadOnly(Object object, boolean readOnly) { if ( object == null ) { throw new AssertionFailure( "object must be non-null." ); } if ( isReadOnly( object ) == readOnly ) { return; } if ( object instanceof HibernateProxy ) { final HibernateProxy proxy = (HibernateProxy) object; setProxyReadOnly( proxy, readOnly ); if ( Hibernate.isInitialized( proxy ) ) { setEntityReadOnly( proxy.getHibernateLazyInitializer().getImplementation(), readOnly ); } } else { setEntityReadOnly( object, readOnly ); // PersistenceContext.proxyFor( entity ) returns entity if there is no proxy for that entity // so need to check the return value to be sure it is really a proxy final Object maybeProxy = getSession().getPersistenceContext().proxyFor( object ); if ( maybeProxy instanceof HibernateProxy ) { setProxyReadOnly( (HibernateProxy) maybeProxy, readOnly ); } } }
/** * Access to the session (via the PersistenceContext) to which this delegate ultimately belongs. * * @return The session */ protected SharedSessionContractImplementor session() { return persistenceContext.getSession(); }
aCollectionEntryArray.getKey().unsetSession( getSession() );
private void replacePersistenceContext(StatefulPersistenceContext persistenceContextNew) { if ( persistenceContextNew.getSession() != null ) { throw new IllegalStateException( "new persistence context is already connected to a session " ); } persistenceContext.clear(); ObjectInputStream ois = null; try { ois = new ObjectInputStream( new ByteArrayInputStream( serializePersistenceContext( persistenceContextNew ) ) ); this.persistenceContext = StatefulPersistenceContext.deserialize( ois, this ); } catch (IOException ex) { throw new SerializationException( "could not deserialize the persistence context", ex ); } catch (ClassNotFoundException ex) { throw new SerializationException( "could not deserialize the persistence context", ex ); } finally { try { if (ois != null) ois.close(); } catch (IOException ignore) { } } }
private void replacePersistenceContext(StatefulPersistenceContext persistenceContextNew) { if ( persistenceContextNew.getSession() != null ) { throw new IllegalStateException( "new persistence context is already connected to a session " ); } persistenceContext.clear(); ObjectInputStream ois = null; try { ois = new ObjectInputStream( new ByteArrayInputStream( serializePersistenceContext( persistenceContextNew ) ) ); this.persistenceContext = StatefulPersistenceContext.deserialize( ois, this ); } catch (IOException ex) { throw new SerializationException( "could not deserialize the persistence context", ex ); } catch (ClassNotFoundException ex) { throw new SerializationException( "could not deserialize the persistence context", ex ); } finally { try { if (ois != null) ois.close(); } catch (IOException ignore) { } } }
private static EntityEntry deserializeEntityEntry(char[] entityEntryClassNameArr, ObjectInputStream ois, StatefulPersistenceContext rtn){ EntityEntry entry = null; final String entityEntryClassName = new String( entityEntryClassNameArr ); final Class entityEntryClass = rtn.getSession().getFactory().getServiceRegistry().getService( ClassLoaderService.class ).classForName( entityEntryClassName ); try { final Method deserializeMethod = entityEntryClass.getDeclaredMethod( "deserialize", ObjectInputStream.class, PersistenceContext.class ); entry = (EntityEntry) deserializeMethod.invoke( null, ois, rtn ); } catch (NoSuchMethodException e) { log.errorf( "Enable to deserialize [%s]", entityEntryClassName ); } catch (InvocationTargetException e) { log.errorf( "Enable to deserialize [%s]", entityEntryClassName ); } catch (IllegalAccessException e) { log.errorf( "Enable to deserialize [%s]", entityEntryClassName ); } return entry; }
private void setProxyReadOnly(HibernateProxy proxy, boolean readOnly) { if ( proxy.getHibernateLazyInitializer().getSession() != getSession() ) { throw new AssertionFailure( "Attempt to set a proxy to read-only that is associated with a different session" ); } proxy.getHibernateLazyInitializer().setReadOnly( readOnly ); }
private void setProxyReadOnly(HibernateProxy proxy, boolean readOnly) { if ( proxy.getHibernateLazyInitializer().getSession() != getSession() ) { throw new AssertionFailure( "Attempt to set a proxy to read-only that is associated with a different session" ); } proxy.getHibernateLazyInitializer().setReadOnly( readOnly ); }
private void setProxyReadOnly(HibernateProxy proxy, boolean readOnly) { if ( proxy.getHibernateLazyInitializer().getSession() != getSession() ) { throw new AssertionFailure( "Attempt to set a proxy to read-only that is associated with a different session" ); } proxy.getHibernateLazyInitializer().setReadOnly( readOnly ); }
/** * 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 if ( !proxiesByKey.containsKey( key ) ) { proxiesByKey.put( key, proxy ); } proxy.getHibernateLazyInitializer().setSession( session ); } }
/** * 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 if ( !proxiesByKey.containsKey( key ) ) { proxiesByKey.put( key, proxy ); } proxy.getHibernateLazyInitializer().setSession( session ); } }
/** * 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 EntityTypeDescriptor entityDescriptor = session.getFactory().getMetamodel().findEntityDescriptor( li.getEntityName() ); final EntityKey key = session.generateEntityKey( li.getIdentifier(), entityDescriptor ); // any earlier proxy takes precedence proxiesByKey.putIfAbsent( key, proxy ); proxy.getHibernateLazyInitializer().setSession( session ); } }
@Override public void setReadOnly(Object object, boolean readOnly) { if ( object == null ) { throw new AssertionFailure( "object must be non-null." ); } if ( isReadOnly( object ) == readOnly ) { return; } if ( object instanceof HibernateProxy ) { HibernateProxy proxy = ( HibernateProxy ) object; setProxyReadOnly( proxy, readOnly ); if ( Hibernate.isInitialized( proxy ) ) { setEntityReadOnly( proxy.getHibernateLazyInitializer().getImplementation(), readOnly ); } } else { setEntityReadOnly( object, readOnly ); // PersistenceContext.proxyFor( entity ) returns entity if there is no proxy for that entity // so need to check the return value to be sure it is really a proxy Object maybeProxy = getSession().getPersistenceContext().proxyFor( object ); if ( maybeProxy instanceof HibernateProxy ) { setProxyReadOnly( ( HibernateProxy ) maybeProxy, readOnly ); } } }
@Override public void setReadOnly(Object object, boolean readOnly) { if ( object == null ) { throw new AssertionFailure( "object must be non-null." ); } if ( isReadOnly( object ) == readOnly ) { return; } if ( object instanceof HibernateProxy ) { final HibernateProxy proxy = (HibernateProxy) object; setProxyReadOnly( proxy, readOnly ); if ( Hibernate.isInitialized( proxy ) ) { setEntityReadOnly( proxy.getHibernateLazyInitializer().getImplementation(), readOnly ); } } else { setEntityReadOnly( object, readOnly ); // PersistenceContext.proxyFor( entity ) returns entity if there is no proxy for that entity // so need to check the return value to be sure it is really a proxy final Object maybeProxy = getSession().getPersistenceContext().proxyFor( object ); if ( maybeProxy instanceof HibernateProxy ) { setProxyReadOnly( (HibernateProxy) maybeProxy, readOnly ); } } }