#2359 - Rename Transaction.getConnection() method to connection() with deprecation

This commit is contained in:
rbygrave
2021-09-08 14:17:30 +12:00
parent 632f04c76b
commit bb9532f42e
21 changed files with 36 additions and 31 deletions
@@ -31,11 +31,11 @@ public class TestBatchOnCascadeExceptionHandling extends BaseTestCase {
try {
EBasicWithUniqueCon v2 = createEntityWithName("conflict", "after");
txn.flush();
Savepoint sp = txn.getConnection().setSavepoint();
Savepoint sp = txn.connection().setSavepoint();
try {
server().save(v2); // unique key violation
} catch (PersistenceException e) {
txn.getConnection().rollback(sp);
txn.connection().rollback(sp);
EBasicWithUniqueCon conflicting = server().find(EBasicWithUniqueCon.class).where().eq("name", "conflict").findOne();
assertThat(conflicting).isNotNull();
@@ -51,7 +51,7 @@ public class TestGeneratedKeys extends BaseTestCase {
private long readSequenceValue(Transaction tx, String sequence) throws SQLException {
Statement stm = null;
try {
stm = tx.getConnection().createStatement();
stm = tx.connection().createStatement();
ResultSet rs = stm.executeQuery("select currval('" + sequence + "')");
rs.next();
@@ -97,7 +97,7 @@ public class TestInsertDuplicateKey extends BaseTestCase {
// typically we would use transaction.commitAndContinue()
// ... this is a rollback and continue type scenario
// ... more sensible to use a second transaction that do this
DB.getDefault().currentTransaction().getConnection().rollback();
DB.getDefault().currentTransaction().connection().rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
@@ -47,7 +47,7 @@ public class SlowDownEBasic implements Trigger {
return;
}
triggerInstalled = true;
try (Transaction txn = DB.beginTransaction(); Statement stmt = txn.getConnection().createStatement()) {
try (Transaction txn = DB.beginTransaction(); Statement stmt = txn.connection().createStatement()) {
stmt.execute("CREATE TRIGGER SLOW_DOWN_E_BASIC BEFORE SELECT ON e_basic " + "CALL \""
+ SlowDownEBasic.class.getName() + "\"");
@@ -51,7 +51,7 @@ public class TestRawSqlNamedParams extends BaseTestCase {
Transaction transaction = DB.beginTransaction();
try {
if ("MariaDB connector/J".equals(transaction.getConnection().getMetaData().getDriverName())) {
if ("MariaDB connector/J".equals(transaction.connection().getMetaData().getDriverName())) {
return; // MariaDb only supports callable statements in the form "? = call function x(?)"
}
CallableSql callableSql = DB.createCallableSql("set @total = 0");
@@ -2,7 +2,6 @@ package org.tests.rawsql;
import io.ebean.BaseTestCase;
import io.ebean.DB;
import io.ebean.FetchConfig;
import io.ebean.RawSql;
import io.ebean.RawSqlBuilder;
import io.ebean.Transaction;
@@ -29,7 +28,7 @@ public class TestRawSqlWithResultSet extends BaseTestCase {
// Transaction supplies our jdbc Connection
Transaction txn = DB.beginTransaction();
try {
pstmt = txn.getConnection().prepareStatement("select id, name, billing_address_id from o_customer");
pstmt = txn.connection().prepareStatement("select id, name, billing_address_id from o_customer");
// ResultSet will be closed by Ebean
ResultSet resultSet = pstmt.executeQuery();
@@ -45,10 +45,10 @@ public class TimezoneTests {
private void fetch() throws SQLException {
try (
Transaction transaction = DB.beginTransaction();
Connection connection = transaction.getConnection();
PreparedStatement statement = connection.prepareStatement("select * from tztest");
ResultSet resultSet = statement.executeQuery()) {
Transaction transaction = DB.beginTransaction();
Connection connection = transaction.connection();
PreparedStatement statement = connection.prepareStatement("select * from tztest");
ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
System.out.println(" zone:" + resultSet.getString("zone"));
@@ -79,9 +79,9 @@ public class TimezoneTests {
}
try (
Transaction transaction = DB.beginTransaction();
Connection connection = transaction.getConnection();
PreparedStatement statement = connection.prepareStatement(insert)) {
Transaction transaction = DB.beginTransaction();
Connection connection = transaction.connection();
PreparedStatement statement = connection.prepareStatement(insert)) {
statement.setString(1, zone);
statement.setTimestamp(2, nowTs);
statement.setTimestamp(3, nowTs);
@@ -26,7 +26,7 @@ public class TestSavepoint extends BaseTestCase {
try (Transaction transaction = DB.beginTransaction()) {
Connection connection = transaction.getConnection();
Connection connection = transaction.connection();
Savepoint savepoint = connection.setSavepoint();
basicVer.setOther("changeOther");
@@ -22,7 +22,7 @@ public class TestTransactionCallback extends BaseTestCase {
public void test_commitAndRollback() {
try (Transaction txn = DB.beginTransaction()) {
DB.register(new MyCallback());
txn.getConnection(); // Ebean assumes writes have occurred
txn.connection(); // Ebean assumes writes have occurred
txn.commit();
}
@@ -45,14 +45,14 @@ public class TestTransactionalRequiresNew extends BaseTestCase {
void doOuter() {
outerTxn = DB.currentTransaction();
log.info("outer before ...{}", outerTxn);
outerConn = outerTxn.getConnection();
outerConn = outerTxn.connection();
new InTransactionalWithRequiresNew().doInner();
// restore the outerTxn
Transaction current = DB.currentTransaction();
log.info("outer after ...{}", current);
assertSame(outerConn, current.getConnection());
assertSame(outerConn, current.connection());
}
}
@@ -64,7 +64,7 @@ public class TestTransactionalRequiresNew extends BaseTestCase {
Transaction innerTxn = DB.currentTransaction();
log.info("inner ...{} {}", innerTxn);
Connection connection = innerTxn.getConnection();
Connection connection = innerTxn.connection();
assertNotSame(connection, outerConn);
}
}