new SerializablePlaceholderResolverStrategy( ClassObjectMarshallingStrategyAcceptor.DEFAULT )} );
final KnowledgeStoreService kstore = (KnowledgeStoreService) ctx.getBean( "kstore1" );
final KnowledgeBase kbRollback = (KnowledgeBase) ctx.getBean( "kbRollback" );
TransactionTemplate txTemplate = new TransactionTemplate( txManager );
final StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) txTemplate.execute( new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
StatefulKnowledgeSession kNewSession = kstore.newStatefulKnowledgeSession( kbRollback,
null,
env );
kNewSession.setGlobal( "list",
list );
kNewSession.insert( 1 );
kNewSession.insert( 2 );
return kNewSession;
}
} );
final int sessionId = ksession.getId();
txTemplate = new TransactionTemplate( txManager );
txTemplate.execute( new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
ksession.insert( 3 );
status.setRollbackOnly();
return null;
}
} );
txTemplate = new TransactionTemplate( txManager );
txTemplate.execute( new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
ksession.fireAllRules();
return null;
}
} );
assertEquals( 2,
list.size() );
txTemplate = new TransactionTemplate( txManager );
txTemplate.execute( new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
ksession.insert( 3 );
ksession.insert( 4 );
return null;
}
} );
txTemplate = new TransactionTemplate( txManager );
txTemplate.execute( new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
ksession.insert( 5 );
ksession.insert( 6 );
status.setRollbackOnly();
return null;
}
} );
txTemplate = new TransactionTemplate( txManager );
txTemplate.execute( new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
ksession.fireAllRules();
return null;
}
} );
assertEquals( 4,
list.size() );
ksession.dispose();
// now load the ksession
final StatefulKnowledgeSession ksession2 = JPAKnowledgeService.loadStatefulKnowledgeSession( sessionId,
kbRollback,
null,
env );
txTemplate = new TransactionTemplate( txManager );
txTemplate.execute( new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
ksession2.setGlobal( "list",
list );
ksession2.insert( 7 );
ksession2.insert( 8 );
return null;
}
} );
txTemplate.execute( new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
ksession2.fireAllRules();
return null;
}
} );