本文整理汇总了Java中org.hibernate.util.SerializationHelper类的典型用法代码示例。如果您正苦于以下问题:Java SerializationHelper类的具体用法?Java SerializationHelper怎么用?Java SerializationHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SerializationHelper类属于org.hibernate.util包,在下文中一共展示了SerializationHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
示例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();
}
示例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();
}
示例4: testProxySerializationAfterSessionClosed
import org.hibernate.util.SerializationHelper; //导入依赖的package包/类
public void testProxySerializationAfterSessionClosed() {
Session s = openSession();
Transaction t = s.beginTransaction();
DataPoint dp = new DataPoint();
dp.setDescription("a data point");
dp.setX( new BigDecimal(1.0) );
dp.setY( new BigDecimal(2.0) );
s.persist(dp);
s.flush();
s.clear();
dp = (DataPoint) s.load( DataPoint.class, new Long( dp.getId() ) );
assertFalse( Hibernate.isInitialized(dp) );
s.close();
SerializationHelper.clone( dp );
s = openSession();
t = s.beginTransaction();
s.delete( dp );
t.commit();
s.close();
}
示例5: loadSessionQueryBagFromDB
import org.hibernate.util.SerializationHelper; //导入依赖的package包/类
public static SessionQueryBag loadSessionQueryBagFromDB(HttpSession session , Long userId){
SessionQueryBag queryBag = null;
UserQuery userQuery = null;
if(userId != null){
userQuery = myListLoader.loadUserQuery(userId);
if(userQuery != null && userQuery.getQueryContent()!= null){
session.setAttribute(RembrandtConstants.USER_QUERY, userQuery);
byte[] objectData = userQuery.getQueryContent();
Object obj = null;
try {
obj = SerializationHelper.deserialize(objectData);
if(obj != null && obj instanceof SessionQueryBag){
queryBag = (SessionQueryBag)obj;
}
} catch (SerializationException e) {
System.out.println(e);
logger.error(e.getMessage());
session.removeAttribute(RembrandtConstants.USER_QUERY);
}
}else{
session.removeAttribute(RembrandtConstants.USER_QUERY);
}
}
return queryBag;
}
示例6: testOrphanDeleteOnSaveOrUpdateAfterSerialization
import org.hibernate.util.SerializationHelper; //导入依赖的package包/类
public void testOrphanDeleteOnSaveOrUpdateAfterSerialization() {
Session session = openSession();
Transaction t = session.beginTransaction();
Product prod = new Product();
prod.setName("Widget");
Part part = new Part();
part.setName("Widge");
part.setDescription("part if a Widget");
prod.getParts().add(part);
Part part2 = new Part();
part2.setName("Get");
part2.setDescription("another part if a Widget");
prod.getParts().add(part2);
session.persist(prod);
t.commit();
session.close();
prod.getParts().remove(part);
prod = (Product) SerializationHelper.clone(prod);
session = openSession();
t = session.beginTransaction();
session.saveOrUpdate(prod);
t.commit();
session.close();
session = openSession();
t = session.beginTransaction();
assertNull( session.get(Part.class, "Widge") );
assertNotNull( session.get(Part.class, "Get") );
session.delete( session.get(Product.class, "Widget") );
t.commit();
session.close();
}
示例7: 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();
}
示例8: testProxyArray
import org.hibernate.util.SerializationHelper; //导入依赖的package包/类
public void testProxyArray() throws Exception {
Session s = openSession();
GlarchProxy g = new Glarch();
Glarch g1 = new Glarch();
Glarch g2 = new Glarch();
g.setProxyArray( new GlarchProxy[] { g1, g2 } );
Glarch g3 = new Glarch();
s.save(g3);
g2.setProxyArray( new GlarchProxy[] {null, g3, g} );
Set set = new HashSet();
set.add(g1);
set.add(g2);
g.setProxySet(set);
s.save(g);
s.save(g1);
s.save(g2);
Serializable id = s.getIdentifier(g);
s.flush();
s.connection().commit();
s.close();
s = openSession();
g = (GlarchProxy) s.load(Glarch.class, id);
assertTrue( "array of proxies", g.getProxyArray().length==2 );
assertTrue( "array of proxies", g.getProxyArray()[0]!=null );
assertTrue("deferred load test",g.getProxyArray()[1].getProxyArray()[0]==null );
assertTrue("deferred load test",g.getProxyArray()[1].getProxyArray()[2]==g );
assertTrue( "set of proxies", g.getProxySet().size()==2 );
Iterator iter = s.iterate("from Glarch g");
while ( iter.hasNext() ) {
iter.next();
iter.remove();
}
s.flush();
s.connection().commit();
s.disconnect();
SerializationHelper.deserialize( SerializationHelper.serialize(s) );
s.close();
}
示例9: 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();
}
示例10: 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();
}
示例11: 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();
}
示例12: 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();
}
示例13: testOrphanDeleteOnSaveOrUpdateAfterSerialization
import org.hibernate.util.SerializationHelper; //导入依赖的package包/类
public void testOrphanDeleteOnSaveOrUpdateAfterSerialization() {
Session session = openSession();
Transaction t = session.beginTransaction();
Product prod = new Product( "Widget" );
Part part = new Part( "Widge", "part if a Widget" );
MapKey mapKey = new MapKey( "Top" );
prod.getParts().put( mapKey, part );
Part part2 = new Part( "Get", "another part if a Widget" );
prod.getParts().put( new MapKey( "Bottom" ), part2 );
session.persist( prod );
t.commit();
session.close();
prod.getParts().remove( mapKey );
prod = (Product) SerializationHelper.clone( prod );
session = openSession();
t = session.beginTransaction();
session.saveOrUpdate(prod);
t.commit();
session.close();
session = openSession();
t = session.beginTransaction();
assertNull( session.get(Part.class, "Widge") );
assertNotNull( session.get(Part.class, "Get") );
session.delete( session.get(Product.class, "Widget") );
t.commit();
session.close();
}
示例14: toBytes
import org.hibernate.util.SerializationHelper; //导入依赖的package包/类
private static byte[] toBytes(Object object) throws SerializationException
{
return SerializationHelper.serialize((Serializable) object);
}
示例15: fromBytes
import org.hibernate.util.SerializationHelper; //导入依赖的package包/类
private static Object fromBytes(byte[] bytes) throws SerializationException
{
return SerializationHelper.deserialize(bytes);
}