mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-17 08:35:13 +00:00
HHH-13562 List of TransactionObserver for JdbcResourceLocalTransactionCoordinatorImpl should be lazily initialized
This commit is contained in:
parent
25ca80b1c5
commit
3e17be9832
@ -7,6 +7,7 @@
|
|||||||
package org.hibernate.resource.transaction.backend.jdbc.internal;
|
package org.hibernate.resource.transaction.backend.jdbc.internal;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.persistence.RollbackException;
|
import javax.persistence.RollbackException;
|
||||||
import javax.transaction.Status;
|
import javax.transaction.Status;
|
||||||
@ -50,7 +51,7 @@ public class JdbcResourceLocalTransactionCoordinatorImpl implements TransactionC
|
|||||||
|
|
||||||
private int timeOut = -1;
|
private int timeOut = -1;
|
||||||
|
|
||||||
private final transient List<TransactionObserver> observers;
|
private transient List<TransactionObserver> observers = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a ResourceLocalTransactionCoordinatorImpl instance. package-protected to ensure access goes through
|
* Construct a ResourceLocalTransactionCoordinatorImpl instance. package-protected to ensure access goes through
|
||||||
@ -62,7 +63,6 @@ public class JdbcResourceLocalTransactionCoordinatorImpl implements TransactionC
|
|||||||
TransactionCoordinatorBuilder transactionCoordinatorBuilder,
|
TransactionCoordinatorBuilder transactionCoordinatorBuilder,
|
||||||
TransactionCoordinatorOwner owner,
|
TransactionCoordinatorOwner owner,
|
||||||
JdbcResourceTransactionAccess jdbcResourceTransactionAccess) {
|
JdbcResourceTransactionAccess jdbcResourceTransactionAccess) {
|
||||||
this.observers = new ArrayList<>();
|
|
||||||
this.transactionCoordinatorBuilder = transactionCoordinatorBuilder;
|
this.transactionCoordinatorBuilder = transactionCoordinatorBuilder;
|
||||||
this.jdbcResourceTransactionAccess = jdbcResourceTransactionAccess;
|
this.jdbcResourceTransactionAccess = jdbcResourceTransactionAccess;
|
||||||
this.transactionCoordinatorOwner = owner;
|
this.transactionCoordinatorOwner = owner;
|
||||||
@ -81,8 +81,13 @@ public class JdbcResourceLocalTransactionCoordinatorImpl implements TransactionC
|
|||||||
* @return TransactionObserver
|
* @return TransactionObserver
|
||||||
*/
|
*/
|
||||||
private Iterable<TransactionObserver> observers() {
|
private Iterable<TransactionObserver> observers() {
|
||||||
|
if ( observers == null || observers.isEmpty() ) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
else {
|
||||||
return new ArrayList<>( observers );
|
return new ArrayList<>( observers );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TransactionDriver getTransactionDriverControl() {
|
public TransactionDriver getTransactionDriverControl() {
|
||||||
@ -203,13 +208,18 @@ private void afterCompletionCallback(boolean successful) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addObserver(TransactionObserver observer) {
|
public void addObserver(TransactionObserver observer) {
|
||||||
|
if ( observers == null ) {
|
||||||
|
observers = new ArrayList<>( 6 );
|
||||||
|
}
|
||||||
observers.add( observer );
|
observers.add( observer );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeObserver(TransactionObserver observer) {
|
public void removeObserver(TransactionObserver observer) {
|
||||||
|
if ( observers != null ) {
|
||||||
observers.remove( observer );
|
observers.remove( observer );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The delegate bridging between the local (application facing) transaction and the "physical" notion of a
|
* The delegate bridging between the local (application facing) transaction and the "physical" notion of a
|
||||||
|
@ -270,7 +270,9 @@ public void testSharedSessionTransactionObserver() throws Exception {
|
|||||||
}
|
}
|
||||||
assertNotNull("Observers field was not found", field);
|
assertNotNull("Observers field was not found", field);
|
||||||
|
|
||||||
assertEquals(0, ((Collection) field.get(((SessionImplementor) session).getTransactionCoordinator())).size());
|
//Some of these collections could be lazily initialize: check for null before invoking size()
|
||||||
|
final Collection collection = (Collection) field.get( ( (SessionImplementor) session ).getTransactionCoordinator() );
|
||||||
|
assertTrue(collection == null || collection.size() == 0 );
|
||||||
|
|
||||||
//open secondary sessions with managed options and immediately close
|
//open secondary sessions with managed options and immediately close
|
||||||
Session secondarySession;
|
Session secondarySession;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user