当前位置: 首页>>代码示例>>Java>>正文


Java SerializationHelper.serialize方法代码示例

本文整理汇总了Java中org.hibernate.util.SerializationHelper.serialize方法的典型用法代码示例。如果您正苦于以下问题:Java SerializationHelper.serialize方法的具体用法?Java SerializationHelper.serialize怎么用?Java SerializationHelper.serialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.util.SerializationHelper的用法示例。


在下文中一共展示了SerializationHelper.serialize方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testConnectedSerialization

import org.hibernate.util.SerializationHelper; //导入方法依赖的package包/类
/**
 * Tests to validate that a session holding JDBC resources will not
 * be allowed to serialize.
 *
 * @throws Throwable
 */
public final void testConnectedSerialization() throws Throwable {
	prepare();
	Session sessionUnderTest = getSessionUnderTest();

	// force the connection to be retained
	sessionUnderTest.createQuery( "from Silly" ).scroll();

	try {
		SerializationHelper.serialize( sessionUnderTest );

		fail( "Serialization of connected session allowed!" );
	}
	catch( IllegalStateException e ) {
		// expected behaviour
	}
	finally {
		release( sessionUnderTest );
		done();
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:27,代码来源:ConnectionManagementTestCase.java

示例2: testManualDisconnectChain

import org.hibernate.util.SerializationHelper; //导入方法依赖的package包/类
/**
 * Test that the legacy manual disconnect()/reconnect() chain works as
 * expected in the given environment.
 *
 * @throws Throwable
 */
public final void testManualDisconnectChain() throws Throwable {
	prepare();
	Session sessionUnderTest = getSessionUnderTest();

	sessionUnderTest.disconnect();

	byte[] bytes = SerializationHelper.serialize( sessionUnderTest );
	checkSerializedState( sessionUnderTest );
	Session s2 = ( Session ) SerializationHelper.deserialize( bytes );
	checkDeserializedState( s2 );

	reconnect( s2 );

	s2.disconnect();
	reconnect( s2 );

	release( sessionUnderTest );
	release( s2 );
	done();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:27,代码来源:ConnectionManagementTestCase.java

示例3: testSerializationOnAfterStatementAggressiveRelease

import org.hibernate.util.SerializationHelper; //导入方法依赖的package包/类
public void testSerializationOnAfterStatementAggressiveRelease() throws Throwable {
	prepare();
	Session s = getSessionUnderTest();
	Silly silly = new Silly( "silly" );
	s.save( silly );

	// this should cause the CM to obtain a connection, and then release it
	s.flush();

	// We should be able to serialize the session at this point...
	SerializationHelper.serialize( s );

	s.delete( silly );
	s.flush();

	release( s );
	done();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:19,代码来源:AggressiveReleaseTest.java

示例4: testAggressiveReleaseWithExplicitDisconnectReconnect

import org.hibernate.util.SerializationHelper; //导入方法依赖的package包/类
public void testAggressiveReleaseWithExplicitDisconnectReconnect() throws Exception {
	DummyTransactionManager.INSTANCE.begin();
	Session s = getSessions().getCurrentSession();

	s.createQuery( "from Item" ).list();

	s.disconnect();
	byte[] bytes = SerializationHelper.serialize( s );
	s = ( Session ) SerializationHelper.deserialize( bytes );
	s.reconnect();

	s.createQuery( "from Item" ).list();

	DummyTransactionManager.INSTANCE.getTransaction().commit();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:16,代码来源:CMTTest.java

示例5: testManualDisconnectedSerialization

import org.hibernate.util.SerializationHelper; //导入方法依赖的package包/类
/**
 * Test that a session which has been manually disconnected will be allowed
 * to serialize.
 *
 * @throws Throwable
 */
public final void testManualDisconnectedSerialization() throws Throwable {
	prepare();
	Session sessionUnderTest = getSessionUnderTest();

	sessionUnderTest.disconnect();

	SerializationHelper.serialize( sessionUnderTest );
	checkSerializedState( sessionUnderTest );

	release( sessionUnderTest );
	done();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:19,代码来源:ConnectionManagementTestCase.java

示例6: testManualDisconnectWithOpenResources

import org.hibernate.util.SerializationHelper; //导入方法依赖的package包/类
/**
 * Test that the legacy manual disconnect()/reconnect() chain works as
 * expected in the given environment.  Similiar to {@link #testManualDisconnectChain}
 * expect that here we force the session to acquire and hold JDBC resources
 * prior to disconnecting.
 *
 * @throws Throwable
 */
public final void testManualDisconnectWithOpenResources() throws Throwable {
	prepare();
	Session sessionUnderTest = getSessionUnderTest();

	Silly silly = new Silly( "tester" );
	sessionUnderTest.save( silly );
	sessionUnderTest.flush();

	sessionUnderTest.createQuery( "from Silly" ).iterate();

	sessionUnderTest.disconnect();
	SerializationHelper.serialize( sessionUnderTest );
	checkSerializedState( sessionUnderTest );

	reconnect( sessionUnderTest );
	sessionUnderTest.createQuery( "from Silly" ).scroll();

	sessionUnderTest.disconnect();
	SerializationHelper.serialize( sessionUnderTest );
	checkSerializedState( sessionUnderTest );

	reconnect( sessionUnderTest );
	sessionUnderTest.delete( silly );
	sessionUnderTest.flush();

	release( sessionUnderTest );
	done();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:37,代码来源:ConnectionManagementTestCase.java

示例7: testSerializationFailsOnAfterStatementAggressiveReleaseWithOpenResources

import org.hibernate.util.SerializationHelper; //导入方法依赖的package包/类
public void testSerializationFailsOnAfterStatementAggressiveReleaseWithOpenResources() throws Throwable {
	prepare();
	Session s = getSessionUnderTest();

	Silly silly = new Silly( "silly" );
	s.save( silly );

	// this should cause the CM to obtain a connection, and then release it
	s.flush();

	// both scroll() and iterate() cause the batcher to hold on
	// to resources, which should make aggresive-release not release
	// the connection (and thus cause serialization to fail)
	ScrollableResults sr = s.createQuery( "from Silly" ).scroll();

	try {
		SerializationHelper.serialize( s );
		fail( "Serialization allowed on connected session; or aggressive release released connection with open resources" );
	}
	catch( IllegalStateException e ) {
		// expected behavior
	}

	// Closing the ScrollableResults does currently force the batcher to
	// aggressively release the connection
	sr.close();
	SerializationHelper.serialize( s );

	s.delete( silly );
	s.flush();

	release( s );
	done();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:35,代码来源:AggressiveReleaseTest.java

示例8: testDetachedCriteria

import org.hibernate.util.SerializationHelper; //导入方法依赖的package包/类
public void testDetachedCriteria() {
	
	DetachedCriteria dc = DetachedCriteria.forClass(Student.class)
		.add( Property.forName("name").eq("Gavin King") )
		.addOrder( Order.asc("studentNumber") )
		.setProjection( Property.forName("studentNumber") );
	
	byte[] bytes = SerializationHelper.serialize(dc);
	
	dc = (DetachedCriteria) SerializationHelper.deserialize(bytes);
	
	Session session = openSession();
	Transaction t = session.beginTransaction();

	Student gavin = new Student();
	gavin.setName("Gavin King");
	gavin.setStudentNumber(232);
	Student bizarroGavin = new Student();
	bizarroGavin.setName("Gavin King");
	bizarroGavin.setStudentNumber(666);
	session.persist(bizarroGavin);
	session.persist(gavin);
	
	List result = dc.getExecutableCriteria(session)
		.setMaxResults(3)
		.list();
	
	assertEquals( result.size(), 2 );
	assertEquals( result.get(0), new Long(232) );
	assertEquals( result.get(1), new Long(666) );
	
	session.delete(gavin);
	session.delete(bizarroGavin);
	t.commit();
	session.close();
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:37,代码来源:CriteriaQueryTest.java

示例9: toBytes

import org.hibernate.util.SerializationHelper; //导入方法依赖的package包/类
private static byte[] toBytes(Object object) throws SerializationException
{
	return SerializationHelper.serialize((Serializable) object);
}
 
开发者ID:equella,项目名称:Equella,代码行数:5,代码来源:HibernateCsvType.java

示例10: toBytes

import org.hibernate.util.SerializationHelper; //导入方法依赖的package包/类
private static byte[] toBytes(Object object) throws SerializationException {
	return SerializationHelper.serialize( (Serializable) object );
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:4,代码来源:SerializableType.java


注:本文中的org.hibernate.util.SerializationHelper.serialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。