mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Add read only database configuration/builder option
When using DatabaseBuilder.readOnlyDatabase(true) then ebean will: - Set the DataSourceBuilder to use autoCommit=true and readOnly=true - Use the same DataSource instance for both dataSource and readOnlyDataSource This is to simplify the setup/configuration for creating a Database that will only have read-only use. Note that readOnly=true is a JDBC hint and for example H2 database effectively ignores that hint where as Postgres will enforce the read-only true nature.
This commit is contained in:
@@ -1053,6 +1053,14 @@ public interface DatabaseBuilder {
|
||||
@Deprecated
|
||||
DatabaseBuilder setSkipDataSourceCheck(boolean skipDataSourceCheck);
|
||||
|
||||
/**
|
||||
* Set to true if this database is used in a read only way.
|
||||
* <p>
|
||||
* The DataSource and read-only DataSource are expected to be the same
|
||||
* and use readOnly=true and autoCommit=true.
|
||||
*/
|
||||
DatabaseBuilder readOnlyDatabase(boolean readOnlyDatabase);
|
||||
|
||||
/**
|
||||
* Set a DataSource.
|
||||
*/
|
||||
@@ -2607,6 +2615,14 @@ public interface DatabaseBuilder {
|
||||
*/
|
||||
boolean skipDataSourceCheck();
|
||||
|
||||
/**
|
||||
* Return true if this database is used in a read only way.
|
||||
* <p>
|
||||
* The DataSource and read-only DataSource are expected to be the same
|
||||
* and use readOnly=true and autoCommit=true.
|
||||
*/
|
||||
boolean readOnlyDatabase();
|
||||
|
||||
/**
|
||||
* Return the DataSource.
|
||||
*/
|
||||
|
||||
@@ -304,6 +304,8 @@ public class DatabaseConfig implements DatabaseBuilder.Settings {
|
||||
|
||||
private boolean skipDataSourceCheck;
|
||||
|
||||
private boolean readOnlyDatabase;
|
||||
|
||||
/**
|
||||
* The data source (if programmatically provided).
|
||||
*/
|
||||
@@ -1343,6 +1345,17 @@ public class DatabaseConfig implements DatabaseBuilder.Settings {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseBuilder readOnlyDatabase(boolean readOnlyDatabase) {
|
||||
this.readOnlyDatabase = readOnlyDatabase;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readOnlyDatabase() {
|
||||
return readOnlyDatabase;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSource getDataSource() {
|
||||
return dataSource;
|
||||
|
||||
Reference in New Issue
Block a user