org.hibernate.impl.SessionImpl Java Examples

The following examples show how to use org.hibernate.impl.SessionImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HibernateUtils.java    From jdal with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize Collection (detached or not)
 * @param collection collection to initialize
 * @param session Session to use for initialization
 */
public static void initializeCollection(Collection collection, Session session) {
	if (collection instanceof AbstractPersistentCollection) {
		AbstractPersistentCollection ps = (AbstractPersistentCollection) collection;
		log.debug("Initalizing PersistentCollection of role: " + ps.getRole());	
		if (!ps.wasInitialized()) {
			SessionImpl source = (SessionImpl) session;
			PersistenceContext context = source.getPersistenceContext();
			CollectionPersister cp = source.getFactory().getCollectionPersister(ps.getRole());
			
			if (context.getCollectionEntry(ps) == null) {  // detached
				context.addUninitializedDetachedCollection(cp, ps);
			}
			
			ps.setCurrentSession(context.getSession());
			Hibernate.initialize(collection);
		}
	}
}
 
Example #2
Source File: ParentChildTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testReplicate() throws Exception {
	Session s = openSession();
	Container baz = new Container();
	Contained f = new Contained();
	List list = new ArrayList();
	list.add(baz);
	f.setBag(list);
	List list2 = new ArrayList();
	list2.add(f);
	baz.setBag(list2);
	s.save(f);
	s.save(baz);
	s.flush();
	s.connection().commit();
	s.close();
	s = openSession();
	s.replicate(baz, ReplicationMode.OVERWRITE);
	
	// HHH-2378
	SessionImpl x = (SessionImpl)s;
	EntityEntry entry = x.getPersistenceContext().getEntry( baz );
	assertNull(entry.getVersion());
	
	s.flush();
	s.connection().commit();
	s.close();
	s = openSession();
	s.replicate(baz, ReplicationMode.IGNORE);
	s.flush();
	s.connection().commit();
	s.close();
	s = openSession();
	s.delete(baz);
	s.delete(f);
	s.flush();
	s.connection().commit();
	s.close();
}
 
Example #3
Source File: AggressiveReleaseTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testBorrowedConnections() throws Throwable {
	prepare();
	Session s = getSessionUnderTest();

	Connection conn = s.connection();
	assertTrue( ( ( SessionImpl ) s ).getJDBCContext().getConnectionManager().hasBorrowedConnection() );
	conn.close();
	assertFalse( ( ( SessionImpl ) s ).getJDBCContext().getConnectionManager().hasBorrowedConnection() );

	release( s );
	done();
}
 
Example #4
Source File: HibernateTransactionManager.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Return whether the given Hibernate Session will always hold the same
 * JDBC Connection. This is used to check whether the transaction manager
 * can safely prepare and clean up the JDBC Connection used for a transaction.
 * <p>Default implementation checks the Session's connection release mode
 * to be "on_close". Unfortunately, this requires casting to SessionImpl,
 * as of Hibernate 3.1. If that cast doesn't work, we'll simply assume
 * we're safe and return {@code true}.
 * @param session the Hibernate Session to check
 * @see org.hibernate.impl.SessionImpl#getConnectionReleaseMode()
 * @see org.hibernate.ConnectionReleaseMode#ON_CLOSE
 */
protected boolean isSameConnectionForEntireSession(Session session) {
	if (!(session instanceof SessionImpl)) {
		// The best we can do is to assume we're safe.
		return true;
	}
	ConnectionReleaseMode releaseMode = ((SessionImpl) session).getConnectionReleaseMode();
	return ConnectionReleaseMode.ON_CLOSE.equals(releaseMode);
}
 
Example #5
Source File: HibernateTransactionManager.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Return whether the given Hibernate Session will always hold the same
 * JDBC Connection. This is used to check whether the transaction manager
 * can safely prepare and clean up the JDBC Connection used for a transaction.
 * <p>Default implementation checks the Session's connection release mode
 * to be "on_close". Unfortunately, this requires casting to SessionImpl,
 * as of Hibernate 3.1. If that cast doesn't work, we'll simply assume
 * we're safe and return {@code true}.
 * @param session the Hibernate Session to check
 * @see org.hibernate.impl.SessionImpl#getConnectionReleaseMode()
 * @see org.hibernate.ConnectionReleaseMode#ON_CLOSE
 */
protected boolean isSameConnectionForEntireSession(Session session) {
	if (!(session instanceof SessionImpl)) {
		// The best we can do is to assume we're safe.
		return true;
	}
	ConnectionReleaseMode releaseMode = ((SessionImpl) session).getConnectionReleaseMode();
	return ConnectionReleaseMode.ON_CLOSE.equals(releaseMode);
}