mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1232 - Performance: Add support for a second read-only DataSource (for implicit query-only transactions)
This commit is contained in:
+45
@@ -0,0 +1,45 @@
|
||||
package io.ebeaninternal.server.transaction;
|
||||
|
||||
import io.ebeaninternal.api.SpiTransaction;
|
||||
import io.ebeaninternal.util.JdbcClose;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Aware of read only autoCommit based DataSource.
|
||||
* <p>
|
||||
* This means for implicit query only transactions we can:
|
||||
* - Use the read only DataSource
|
||||
* - Skip explicit commit (as we use AutoCommit instead)
|
||||
* </p>
|
||||
*/
|
||||
class TransactionFactoryBasicWithRead extends TransactionFactoryBasic {
|
||||
|
||||
|
||||
private final DataSource readOnlyDataSource;
|
||||
|
||||
TransactionFactoryBasicWithRead(TransactionManager manager, DataSourceSupplier dataSourceSupplier) {
|
||||
super(manager, dataSourceSupplier);
|
||||
this.readOnlyDataSource = dataSourceSupplier.getReadOnlyDataSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpiTransaction createQueryTransaction(Object tenantId) {
|
||||
|
||||
Connection connection = null;
|
||||
try {
|
||||
connection = readOnlyDataSource.getConnection();
|
||||
return new ImplicitReadOnlyTransaction(connection);
|
||||
|
||||
} catch (PersistenceException ex) {
|
||||
JdbcClose.close(connection);
|
||||
throw ex;
|
||||
|
||||
} catch (SQLException ex) {
|
||||
throw new PersistenceException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user