类org.hibernate.impl.SessionImpl源码实例Demo

下面列出了怎么用org.hibernate.impl.SessionImpl的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: jdal   文件: HibernateUtils.java
/**
 * 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);
		}
	}
}
 
源代码2 项目: cacheonix-core   文件: ParentChildTest.java
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();
}
 
源代码3 项目: cacheonix-core   文件: AggressiveReleaseTest.java
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();
}
 
源代码4 项目: lams   文件: HibernateTransactionManager.java
/**
 * 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);
}
 
/**
 * 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);
}
 
 类所在包
 类方法
 同包方法