TransactionTemplate equality for same transaction manager only
Issue: SPR-16572
This commit is contained in:
@@ -259,7 +259,7 @@ public class DefaultTransactionDefinition implements TransactionDefinition, Seri
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
return (other instanceof TransactionDefinition && toString().equals(other.toString()));
|
return (this == other || (other instanceof TransactionDefinition && toString().equals(other.toString())));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -178,4 +178,11 @@ public class TransactionTemplate extends DefaultTransactionDefinition
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
return (this == other || (super.equals(other) && (!(other instanceof TransactionTemplate) ||
|
||||||
|
getTransactionManager() == ((TransactionTemplate) other).getTransactionManager())));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -83,6 +83,7 @@ public class TransactionSupportTests {
|
|||||||
TestTransactionManager tm = new TestTransactionManager(false, true);
|
TestTransactionManager tm = new TestTransactionManager(false, true);
|
||||||
TransactionStatus status = tm.getTransaction(null);
|
TransactionStatus status = tm.getTransaction(null);
|
||||||
tm.commit(status);
|
tm.commit(status);
|
||||||
|
|
||||||
assertTrue("triggered begin", tm.begin);
|
assertTrue("triggered begin", tm.begin);
|
||||||
assertTrue("triggered commit", tm.commit);
|
assertTrue("triggered commit", tm.commit);
|
||||||
assertTrue("no rollback", !tm.rollback);
|
assertTrue("no rollback", !tm.rollback);
|
||||||
@@ -94,6 +95,7 @@ public class TransactionSupportTests {
|
|||||||
TestTransactionManager tm = new TestTransactionManager(false, true);
|
TestTransactionManager tm = new TestTransactionManager(false, true);
|
||||||
TransactionStatus status = tm.getTransaction(null);
|
TransactionStatus status = tm.getTransaction(null);
|
||||||
tm.rollback(status);
|
tm.rollback(status);
|
||||||
|
|
||||||
assertTrue("triggered begin", tm.begin);
|
assertTrue("triggered begin", tm.begin);
|
||||||
assertTrue("no commit", !tm.commit);
|
assertTrue("no commit", !tm.commit);
|
||||||
assertTrue("triggered rollback", tm.rollback);
|
assertTrue("triggered rollback", tm.rollback);
|
||||||
@@ -106,6 +108,7 @@ public class TransactionSupportTests {
|
|||||||
TransactionStatus status = tm.getTransaction(null);
|
TransactionStatus status = tm.getTransaction(null);
|
||||||
status.setRollbackOnly();
|
status.setRollbackOnly();
|
||||||
tm.commit(status);
|
tm.commit(status);
|
||||||
|
|
||||||
assertTrue("triggered begin", tm.begin);
|
assertTrue("triggered begin", tm.begin);
|
||||||
assertTrue("no commit", !tm.commit);
|
assertTrue("no commit", !tm.commit);
|
||||||
assertTrue("triggered rollback", tm.rollback);
|
assertTrue("triggered rollback", tm.rollback);
|
||||||
@@ -117,6 +120,7 @@ public class TransactionSupportTests {
|
|||||||
TestTransactionManager tm = new TestTransactionManager(true, true);
|
TestTransactionManager tm = new TestTransactionManager(true, true);
|
||||||
TransactionStatus status = tm.getTransaction(null);
|
TransactionStatus status = tm.getTransaction(null);
|
||||||
tm.commit(status);
|
tm.commit(status);
|
||||||
|
|
||||||
assertTrue("no begin", !tm.begin);
|
assertTrue("no begin", !tm.begin);
|
||||||
assertTrue("no commit", !tm.commit);
|
assertTrue("no commit", !tm.commit);
|
||||||
assertTrue("no rollback", !tm.rollback);
|
assertTrue("no rollback", !tm.rollback);
|
||||||
@@ -128,6 +132,7 @@ public class TransactionSupportTests {
|
|||||||
TestTransactionManager tm = new TestTransactionManager(true, true);
|
TestTransactionManager tm = new TestTransactionManager(true, true);
|
||||||
TransactionStatus status = tm.getTransaction(null);
|
TransactionStatus status = tm.getTransaction(null);
|
||||||
tm.rollback(status);
|
tm.rollback(status);
|
||||||
|
|
||||||
assertTrue("no begin", !tm.begin);
|
assertTrue("no begin", !tm.begin);
|
||||||
assertTrue("no commit", !tm.commit);
|
assertTrue("no commit", !tm.commit);
|
||||||
assertTrue("no rollback", !tm.rollback);
|
assertTrue("no rollback", !tm.rollback);
|
||||||
@@ -140,6 +145,7 @@ public class TransactionSupportTests {
|
|||||||
TransactionStatus status = tm.getTransaction(null);
|
TransactionStatus status = tm.getTransaction(null);
|
||||||
status.setRollbackOnly();
|
status.setRollbackOnly();
|
||||||
tm.commit(status);
|
tm.commit(status);
|
||||||
|
|
||||||
assertTrue("no begin", !tm.begin);
|
assertTrue("no begin", !tm.begin);
|
||||||
assertTrue("no commit", !tm.commit);
|
assertTrue("no commit", !tm.commit);
|
||||||
assertTrue("no rollback", !tm.rollback);
|
assertTrue("no rollback", !tm.rollback);
|
||||||
@@ -155,6 +161,7 @@ public class TransactionSupportTests {
|
|||||||
protected void doInTransactionWithoutResult(TransactionStatus status) {
|
protected void doInTransactionWithoutResult(TransactionStatus status) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
assertTrue("triggered begin", tm.begin);
|
assertTrue("triggered begin", tm.begin);
|
||||||
assertTrue("triggered commit", tm.commit);
|
assertTrue("triggered commit", tm.commit);
|
||||||
assertTrue("no rollback", !tm.rollback);
|
assertTrue("no rollback", !tm.rollback);
|
||||||
@@ -170,6 +177,7 @@ public class TransactionSupportTests {
|
|||||||
protected void doInTransactionWithoutResult(TransactionStatus status) {
|
protected void doInTransactionWithoutResult(TransactionStatus status) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
assertSame(template, ptm.getDefinition());
|
assertSame(template, ptm.getDefinition());
|
||||||
assertFalse(ptm.getStatus().isRollbackOnly());
|
assertFalse(ptm.getStatus().isRollbackOnly());
|
||||||
}
|
}
|
||||||
@@ -300,9 +308,22 @@ public class TransactionSupportTests {
|
|||||||
assertTrue("Correct isolation level set", template.getIsolationLevel() == TransactionDefinition.ISOLATION_REPEATABLE_READ);
|
assertTrue("Correct isolation level set", template.getIsolationLevel() == TransactionDefinition.ISOLATION_REPEATABLE_READ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void transactionTemplateEquality() {
|
||||||
|
TestTransactionManager tm1 = new TestTransactionManager(false, true);
|
||||||
|
TestTransactionManager tm2 = new TestTransactionManager(false, true);
|
||||||
|
TransactionTemplate template1 = new TransactionTemplate(tm1);
|
||||||
|
TransactionTemplate template2 = new TransactionTemplate(tm2);
|
||||||
|
TransactionTemplate template3 = new TransactionTemplate(tm2);
|
||||||
|
|
||||||
|
assertNotEquals(template1, template2);
|
||||||
|
assertNotEquals(template1, template3);
|
||||||
|
assertEquals(template2, template3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void clear() {
|
||||||
assertTrue(TransactionSynchronizationManager.getResourceMap().isEmpty());
|
assertTrue(TransactionSynchronizationManager.getResourceMap().isEmpty());
|
||||||
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
|
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user