mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#919 - io.ebean package initial
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package io.ebeaninternal.server.transaction;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* This only works for Postgres and H2 (and doesn't work for Oracle).
|
||||
* <p>
|
||||
* Uses explicit begin statement to start the transactions.
|
||||
*/
|
||||
public class ExplicitJdbcTransaction extends JdbcTransaction {
|
||||
|
||||
public ExplicitJdbcTransaction(String id, boolean explicit, Connection connection, TransactionManager manager) {
|
||||
super(id, explicit, connection, manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkAutoCommit(Connection connection) throws SQLException {
|
||||
// begin the transaction explicitly
|
||||
executeStatement("begin");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performRollback() throws SQLException {
|
||||
// Postgres needs this explicit rollback statement when used with AutoCommit=true
|
||||
executeStatement("rollback");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performCommit() throws SQLException {
|
||||
// Postgres needs this explicit commit statement when used with AutoCommit=true
|
||||
executeStatement("commit");
|
||||
}
|
||||
|
||||
private void executeStatement(String statement) throws SQLException {
|
||||
PreparedStatement stmt = connection.prepareStatement(statement);
|
||||
try {
|
||||
stmt.execute();
|
||||
} finally {
|
||||
stmt.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user