Skip to content

Commit

Permalink
[JBPM-10187] Trying to avoid nullPointerException in interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado committed Aug 25, 2023
1 parent 613fac1 commit 8b8a73e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected void initNewKnowledgeSession(KieBase kbase, KieSessionConfiguration co

((InternalKnowledgeRuntime) this.ksession).setEndOperationListener( new EndOperationListenerImpl(this.txm, this.sessionInfo ) );

this.runner = new TransactionInterceptor();
this.runner = new TransactionInterceptor(sessionInfo);

TimerJobFactoryManager timerJobFactoryManager = ((InternalKnowledgeRuntime) ksession ).getTimerService().getTimerJobFactoryManager();
if (timerJobFactoryManager instanceof CommandServiceTimerJobFactoryManager) {
Expand Down Expand Up @@ -258,7 +258,7 @@ protected void initExistingKnowledgeSession(Long sessionId,
kruntime.setIdentifier( this.sessionInfo.getId() );
kruntime.setEndOperationListener( new EndOperationListenerImpl( this.txm, this.sessionInfo ) );

this.runner = new TransactionInterceptor();
this.runner = new TransactionInterceptor(sessionInfo);
// apply interceptors
Iterator<ChainableRunner> iterator = this.interceptors.descendingIterator();
while (iterator.hasNext()) {
Expand Down Expand Up @@ -571,14 +571,16 @@ private void registerUpdateSync() {

private class TransactionInterceptor extends AbstractInterceptor {

private SessionInfo sessionInfo;


public TransactionInterceptor() {
public TransactionInterceptor(SessionInfo sessionInfo) {
this.sessionInfo = sessionInfo;
setNext(new PseudoClockRunner());
}

@Override
public RequestContext execute( Executable executable, RequestContext context ) {

if ( !( (InternalExecutable) executable ).canRunInTransaction() ) {
executeNext(executable, context);
if (((InternalExecutable) executable ).requiresDispose()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public PersistentSession persist(PersistentSession entity) {
}

public PersistentSession findSession(Long id) {
logger.trace("Reading session info {}, id");
logger.trace("Reading session info {}",id);
SessionInfo sessionInfo = null;
if( this.pessimisticLocking ) {
sessionInfo = this.em.find( SessionInfo.class, id, lockMode );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private boolean isEntity(Object o){
public void onStart(TransactionManager txm) {
if (persister.get() == null) {
EntityManager em = emf.createEntityManager();
log.trace ("Created EM {} for name {}",em, name);
log.trace ("Created EM {} for JPAPlaceHolder {}:{}",em, this, name);
persister.set(new EntityPersister(em));
}
}
Expand All @@ -212,10 +212,10 @@ public void onStart(TransactionManager txm) {
public void onEnd(TransactionManager txm) {
EntityPersister em = persister.get();
if (em == null) {
log.warn ("EM is null for {} and status {}", name, txm.getStatus());
log.warn ("EM is null for {}:{} and status {}", this, name, txm.getStatus());
return;
}
log.trace ("Executing onEnd for {} with status {}", name, txm.getStatus());
log.trace ("Executing onEnd for {}:{} with status {}", this, name, txm.getStatus());
if(txm.getStatus() == TransactionManager.STATUS_ROLLEDBACK) {
// this is pretty much of a hack but for avoiding issues when rolling back we need to set to null
// the primary key of the entities (simple types)
Expand Down Expand Up @@ -245,7 +245,7 @@ public void onEnd(TransactionManager txm) {
});
}
if (em != null) {
log.trace ("Closing EM {} for name {}",em, name);
log.trace ("Closing EM {} for JPAPlaceHolder {}:{}",em.getEntityManager(), this, name);
em.close();
persister.set(null);
}
Expand Down

0 comments on commit 8b8a73e

Please sign in to comment.