public class ServerConfig extends Object
Used to programmatically construct an EbeanServer and optionally register it with the Ebean singleton.
If you just use Ebean without this programmatic configuration Ebean will read the ebean.properties file and take the configuration from there. This usually includes searching the class path and automatically registering any entity classes and listeners etc.
ServerConfig c = new ServerConfig();
c.setName("ordh2");
// read the ebean.properties and load
// those settings into this serverConfig object
c.loadFromProperties();
// generate DDL and run it
c.setDdlGenerate(true);
c.setDdlRun(true);
// add any classes found in the app.data package
c.addPackage("app.data");
// add the names of Jars that contain entities
c.addJar("myJarContainingEntities.jar");
c.addJar("someOtherJarContainingEntities.jar");
// register as the 'Default' server
c.setDefaultServer(true);
EbeanServer server = EbeanServerFactory.create(c);
EbeanServerFactory| Constructor and Description |
|---|
ServerConfig()
Construct a Server Configuration for programmatically creating an
EbeanServer.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(BeanPersistController beanPersistController)
Register a BeanPersistController instance.
|
void |
add(BeanPersistListener<?> beanPersistListener)
Register a BeanPersistListener instance.
|
void |
add(BeanQueryAdapter beanQueryAdapter)
Register a BeanQueryAdapter instance.
|
void |
add(BulkTableEventListener bulkTableEventListener)
Add a BulkTableEventListener
|
void |
add(TransactionEventListener listener)
Register a TransactionEventListener instance
|
void |
addClass(Class<?> cls)
Programmatically add classes (typically entities) that this server should
use.
|
void |
addJar(String jarName)
Add the name of a Jar to search for entities via class path search.
|
void |
addPackage(String packageName)
Add a package to search for entities via class path search.
|
void |
addServerConfigStartup(ServerConfigStartup configStartupListener)
Add a ServerConfigStartup.
|
AutofetchConfig |
getAutofetchConfig()
Return the configuration for the Autofetch feature.
|
List<BulkTableEventListener> |
getBulkTableEventListeners()
Return the list of BulkTableEventListener instances.
|
List<Class<?>> |
getClasses()
Return the classes registered for this server.
|
String |
getDatabaseBooleanFalse()
Return a value used to represent FALSE in the database.
|
String |
getDatabaseBooleanTrue()
Return a value used to represent TRUE in the database.
|
DatabasePlatform |
getDatabasePlatform()
Return the database platform to use for this server.
|
String |
getDatabasePlatformName()
Return the database platform name (can be null).
|
int |
getDatabaseSequenceBatchSize()
Return the number of DB sequence values that should be preallocated.
|
DataSource |
getDataSource()
Return the DataSource.
|
DataSourceConfig |
getDataSourceConfig()
Return the configuration to build a DataSource using Ebean's own DataSource
implementation.
|
String |
getDataSourceJndiName()
Return the JNDI name of the DataSource to use.
|
DbEncrypt |
getDbEncrypt()
Return the DbEncrypt used to encrypt and decrypt properties.
|
EncryptDeployManager |
getEncryptDeployManager()
Return the EncryptDeployManager.
|
EncryptKeyManager |
getEncryptKeyManager()
Return the EncryptKeyManager.
|
Encryptor |
getEncryptor()
Return the Encryptor used to encrypt data on the java client side (as
opposed to DB encryption functions).
|
int |
getEnhanceLogLevel()
Return the log level used for "subclassing" enhancement.
|
ExternalTransactionManager |
getExternalTransactionManager()
Return the external transaction manager.
|
List<String> |
getJars()
Return packages to search for entities via class path search.
|
int |
getLazyLoadBatchSize()
Return the default batch size for lazy loading of beans and collections.
|
String |
getName()
Return the name of the EbeanServer.
|
NamingConvention |
getNamingConvention()
Return the NamingConvention.
|
List<String> |
getPackages()
Return packages to search for entities via class path search.
|
int |
getPersistBatchSize()
Return the batch size used for JDBC batching.
|
List<BeanPersistController> |
getPersistControllers()
Return the BeanPersistController instances.
|
List<BeanPersistListener<?>> |
getPersistListeners()
Return the BeanPersistListener instances.
|
String |
getProperty(String propertyName)
Return a configuration property.
|
String |
getProperty(String propertyName,
String defaultValue)
Return a configuration property using a default value.
|
GlobalProperties.PropertySource |
getPropertySource()
Return a PropertySource for this server.
|
PstmtDelegate |
getPstmtDelegate()
Return the PreparedStatementDelegate.
|
List<BeanQueryAdapter> |
getQueryAdapters()
Return the BeanQueryAdapter instances.
|
int |
getQueryBatchSize()
Gets the query batch size.
|
String |
getResourceDirectory()
Returns the resource directory.
|
ServerCacheFactory |
getServerCacheFactory()
Return the ServerCacheFactory.
|
ServerCacheManager |
getServerCacheManager()
Return the ServerCacheManager.
|
List<ServerConfigStartup> |
getServerConfigStartupListeners()
Return the list of ServerConfigStartup instances.
|
List<TransactionEventListener> |
getTransactionEventListeners()
Return the TransactionEventListener instances.
|
boolean |
isCollectQueryOrigins()
Return true if query plans should also collect their 'origins'.
|
boolean |
isCollectQueryStatsByNode()
Return true if the ebeanServer should collection query statistics by ObjectGraphNode.
|
boolean |
isDdlGenerate()
Return true if the DDL should be generated.
|
boolean |
isDdlRun()
Return true if the DDL should be run.
|
boolean |
isDefaultServer()
Return true if this server should be registered as the "default" server
with the Ebean singleton.
|
boolean |
isPersistBatching()
Returns true if by default JDBC batching is used for persisting or deleting
beans.
|
boolean |
isRegister()
Return true if this server should be registered with the Ebean singleton
when it is created.
|
boolean |
isUpdateChangesOnly()
Return true to only update changed properties.
|
boolean |
isUseJtaTransactionManager()
Return true if we are running in a JTA Transaction manager.
|
boolean |
isUsePersistBatching()
Deprecated.
|
protected void |
loadAutofetchConfig(GlobalProperties.PropertySource p)
This is broken out for the same reason as above - preserve existing behaviour but let it be overridden.
|
protected void |
loadDataSourceSettings(GlobalProperties.PropertySource p)
loads the data source settings to preserve existing behaviour.
|
void |
loadFromProperties()
Load the settings from the ebean.properties file.
|
protected void |
loadSettings(GlobalProperties.PropertySource p)
Load the configuration settings from the properties file.
|
void |
setAutofetchConfig(AutofetchConfig autofetchConfig)
Set the configuration for the Autofetch feature.
|
void |
setClasses(List<Class<?>> classes)
Set the list of classes (entities, listeners, scalarTypes etc) that should
be used for this server.
|
void |
setCollectQueryOrigins(boolean collectQueryOrigins)
Set to true if query plans should collect their 'origin' points.
|
void |
setCollectQueryStatsByNode(boolean collectQueryStatsByNode)
Set to true to collection query execution statistics by ObjectGraphNode.
|
void |
setDatabaseBooleanFalse(String databaseFalse)
Set the value to represent FALSE in the database.
|
void |
setDatabaseBooleanTrue(String databaseTrue)
Set the value to represent TRUE in the database.
|
void |
setDatabasePlatform(DatabasePlatform databasePlatform)
Explicitly set the database platform to use.
|
void |
setDatabasePlatformName(String databasePlatformName)
Explicitly set the database platform name
|
void |
setDatabaseSequenceBatch(int databaseSequenceBatchSize)
Set the number of DB sequence values that should be preallocated and cached
by Ebean.
|
void |
setDatabaseSequenceBatchSize(int databaseSequenceBatchSize)
Set the number of sequences to fetch/preallocate when using DB sequences.
|
void |
setDataSource(DataSource dataSource)
Set a DataSource.
|
void |
setDataSourceConfig(DataSourceConfig dataSourceConfig)
Set the configuration required to build a DataSource using Ebean's own
DataSource implementation.
|
void |
setDataSourceJndiName(String dataSourceJndiName)
Set the JNDI name of the DataSource to use.
|
void |
setDbEncrypt(DbEncrypt dbEncrypt)
Set the DbEncrypt used to encrypt and decrypt properties.
|
void |
setDdlGenerate(boolean ddlGenerate)
Set to true to run the DDL generation on startup.
|
void |
setDdlRun(boolean ddlRun)
Set to true to run the generated DDL on startup.
|
void |
setDefaultServer(boolean defaultServer)
Set true if this EbeanServer should be registered as the "default" server
with the Ebean singleton.
|
void |
setEncryptDeployManager(EncryptDeployManager encryptDeployManager)
Set the EncryptDeployManager.
|
void |
setEncryptKeyManager(EncryptKeyManager encryptKeyManager)
Set the EncryptKeyManager.
|
void |
setEncryptor(Encryptor encryptor)
Set the Encryptor used to encrypt data on the java client side (as opposed
to DB encryption functions).
|
void |
setEnhanceLogLevel(int enhanceLogLevel)
Set the log level used for "subclassing" enhancement.
|
void |
setExternalTransactionManager(ExternalTransactionManager externalTransactionManager)
Set the external transaction manager.
|
void |
setJars(List<String> searchJars)
Set the names of Jars to search for entities via class path search.
|
void |
setLazyLoadBatchSize(int lazyLoadBatchSize)
Set the default batch size for lazy loading.
|
void |
setName(String name)
Set the name of the EbeanServer.
|
void |
setNamingConvention(NamingConvention namingConvention)
Set the NamingConvention.
|
void |
setPackages(List<String> packages)
Set packages to search for entities via class path search.
|
void |
setPersistBatching(boolean persistBatching)
Set to true if you what to use JDBC batching for persisting and deleting
beans.
|
void |
setPersistBatchSize(int persistBatchSize)
Set the batch size used for JDBC batching.
|
void |
setPersistControllers(List<BeanPersistController> persistControllers)
Register all the BeanPersistController instances.
|
void |
setPersistListeners(List<BeanPersistListener<?>> persistListeners)
Register all the BeanPersistListener instances.
|
void |
setPstmtDelegate(PstmtDelegate pstmtDelegate)
Set the PstmtDelegate which can be used to support JDBC driver specific
features.
|
void |
setQueryAdapters(List<BeanQueryAdapter> queryAdapters)
Register all the BeanQueryAdapter instances.
|
void |
setQueryBatchSize(int queryBatchSize)
Sets the query batch size.
|
void |
setRegister(boolean register)
Set to false if you do not want this server to be registered with the Ebean
singleton when it is created.
|
void |
setResourceDirectory(String resourceDirectory)
Sets the resource directory.
|
void |
setServerCacheFactory(ServerCacheFactory serverCacheFactory)
Set the ServerCacheFactory to use.
|
void |
setServerCacheManager(ServerCacheManager serverCacheManager)
Set the ServerCacheManager to use.
|
void |
setTransactionEventListeners(List<TransactionEventListener> transactionEventListeners)
Register all the TransactionEventListener instances.
|
void |
setUpdateChangesOnly(boolean updateChangesOnly)
Set to true to only update changed properties.
|
void |
setUseJtaTransactionManager(boolean useJtaTransactionManager)
Set to true if we are running in a JTA Transaction manager.
|
void |
setUsePersistBatching(boolean persistBatching)
Deprecated.
|
public ServerConfig()
public String getName()
public void setName(String name)
public boolean isRegister()
By default this is set to true.
public void setRegister(boolean register)
By default this is set to true.
public boolean isDefaultServer()
This is only used when setRegister(boolean) is also true.
public void setDefaultServer(boolean defaultServer)
This is only used when setRegister(boolean) is also true.
public boolean isPersistBatching()
With this Ebean will batch up persist requests and use the JDBC batch api. This is a performance optimisation designed to reduce the network chatter.
public boolean isUsePersistBatching()
public void setPersistBatching(boolean persistBatching)
With this Ebean will batch up persist requests and use the JDBC batch api. This is a performance optimisation designed to reduce the network chatter.
public void setUsePersistBatching(boolean persistBatching)
public int getPersistBatchSize()
public void setPersistBatchSize(int persistBatchSize)
public int getLazyLoadBatchSize()
public int getQueryBatchSize()
public void setQueryBatchSize(int queryBatchSize)
queryBatchSize - the new query batch sizepublic void setLazyLoadBatchSize(int lazyLoadBatchSize)
This is the number of beans or collections loaded when lazy loading is invoked by default.
The default value is for this is 1 (load 1 bean or collection).
You can explicitly control the lazy loading batch size for a given join on a query using +lazy(batchSize) or JoinConfig.
public void setDatabaseSequenceBatchSize(int databaseSequenceBatchSize)
This is a performance optimisation to reduce the number times Ebean requests a sequence to be used as an Id for a bean (aka reduce network chatter).
public boolean isUseJtaTransactionManager()
public void setUseJtaTransactionManager(boolean useJtaTransactionManager)
public ExternalTransactionManager getExternalTransactionManager()
public void setExternalTransactionManager(ExternalTransactionManager externalTransactionManager)
public ServerCacheFactory getServerCacheFactory()
public void setServerCacheFactory(ServerCacheFactory serverCacheFactory)
public ServerCacheManager getServerCacheManager()
public void setServerCacheManager(ServerCacheManager serverCacheManager)
public int getEnhanceLogLevel()
public void setEnhanceLogLevel(int enhanceLogLevel)
public NamingConvention getNamingConvention()
If none has been set the default UnderscoreNamingConvention is used.
public void setNamingConvention(NamingConvention namingConvention)
If none is set the default UnderscoreNamingConvention is used.
public AutofetchConfig getAutofetchConfig()
public void setAutofetchConfig(AutofetchConfig autofetchConfig)
public PstmtDelegate getPstmtDelegate()
public void setPstmtDelegate(PstmtDelegate pstmtDelegate)
Typically this means Oracle JDBC driver specific workarounds.
public DataSource getDataSource()
public void setDataSource(DataSource dataSource)
public DataSourceConfig getDataSourceConfig()
public void setDataSourceConfig(DataSourceConfig dataSourceConfig)
public String getDataSourceJndiName()
public void setDataSourceJndiName(String dataSourceJndiName)
By default a prefix of "java:comp/env/jdbc/" is used to lookup the DataSource. This prefix is not used if dataSourceJndiName starts with "java:".
public String getDatabaseBooleanTrue()
This is used for databases that do not support boolean natively.
The value returned is either a Integer or a String (e.g. "1", or "T").
public void setDatabaseBooleanTrue(String databaseTrue)
This is used for databases that do not support boolean natively.
The value set is either a Integer or a String (e.g. "1", or "T").
public String getDatabaseBooleanFalse()
This is used for databases that do not support boolean natively.
The value returned is either a Integer or a String (e.g. "0", or "F").
public void setDatabaseBooleanFalse(String databaseFalse)
This is used for databases that do not support boolean natively.
The value set is either a Integer or a String (e.g. "0", or "F").
public int getDatabaseSequenceBatchSize()
public void setDatabaseSequenceBatch(int databaseSequenceBatchSize)
This is only used for DB's that use sequences and is a performance optimisation. This reduces the number of times Ebean needs to get a sequence value from the Database reducing network chatter.
By default this value is 10 so when we need another Id (and don't have one in our cache) Ebean will fetch 10 id's from the database. Note that when the cache drops to have full (which is 5 by default) Ebean will fetch another batch of Id's in a background thread.
public String getDatabasePlatformName()
If null then the platform is determined automatically via the JDBC driver information.
public void setDatabasePlatformName(String databasePlatformName)
If none is set then the platform is determined automatically via the JDBC driver information.
This can be used when the Database Platform can not be automatically detected from the JDBC driver (possibly 3rd party JDBC driver). It is also useful when you want to do offline DDL generation for a database platform that you don't have access to.
Values are oracle, h2, postgres, mysql, mssqlserver2005.
DataSourceConfig.setOffline(boolean)public DatabasePlatform getDatabasePlatform()
public void setDatabasePlatform(DatabasePlatform databasePlatform)
If none is set then the platform is determined via the databasePlatformName or automatically via the JDBC driver information.
public EncryptKeyManager getEncryptKeyManager()
public void setEncryptKeyManager(EncryptKeyManager encryptKeyManager)
This is required when you want to use encrypted properties.
You can also set this in ebean.proprerties:
# set via ebean.properties ebean.encryptKeyManager=com.avaje.tests.basic.encrypt.BasicEncyptKeyManager
public EncryptDeployManager getEncryptDeployManager()
This is optionally used to programmatically define which columns are
encrypted instead of using the Encrypted Annotation.
public void setEncryptDeployManager(EncryptDeployManager encryptDeployManager)
This is optionally used to programmatically define which columns are
encrypted instead of using the Encrypted Annotation.
public Encryptor getEncryptor()
public void setEncryptor(Encryptor encryptor)
Ebean has a default implementation that it will use if you do not set your own Encryptor implementation.
public DbEncrypt getDbEncrypt()
Note that if this is not set then the DbPlatform may already have a DbEncrypt set and that will be used.
public void setDbEncrypt(DbEncrypt dbEncrypt)
Note that if this is not set then the DbPlatform may already have a DbEncrypt set (H2, MySql, Postgres and Oracle platforms have a DbEncrypt)
public void setDdlGenerate(boolean ddlGenerate)
public void setDdlRun(boolean ddlRun)
public boolean isDdlGenerate()
public boolean isDdlRun()
public void addClass(Class<?> cls)
The class can be an Entity, Embedded type, ScalarType, BeanPersistListener, BeanFinder or BeanPersistController.
If no classes are specified then the classes are found automatically via searching the class path.
Alternatively the classes can be added via setClasses(List).
cls - the entity type (or other type) that should be registered by this
server.public void addPackage(String packageName)
This is only used if classes have not been explicitly specified.
public List<String> getPackages()
This is only used if classes have not been explicitly specified.
public void setPackages(List<String> packages)
This is only used if classes have not been explicitly specified.
public void addJar(String jarName)
This is only used if classes have not been explicitly specified.
If you are using ebean.properties you can specify jars to search by setting a ebean.search.jars property.
# EBean will search through classes for entities, but will not search jar files # unless you tell it to do so, for performance reasons. Set this value to a # comma-delimited list of jar files you want ebean to search. ebean.search.jars=example.jar
public List<String> getJars()
This is only used if classes have not been explicitly specified.
public void setJars(List<String> searchJars)
This is only used if classes have not been explicitly specified.
public void setClasses(List<Class<?>> classes)
If no classes are specified then the classes are found automatically via searching the class path.
Alternatively the classes can contain added via addClass(Class).
public List<Class<?>> getClasses()
public boolean isUpdateChangesOnly()
public void setUpdateChangesOnly(boolean updateChangesOnly)
public boolean isCollectQueryStatsByNode()
public void setCollectQueryStatsByNode(boolean collectQueryStatsByNode)
These statistics can be used to highlight code/query 'origin points' that result in lots of lazy loading.
It is considered safe/fine to have this set to true for production.
This information can be later retrieved via MetaInfoManager.
MetaInfoManagerpublic boolean isCollectQueryOrigins()
public void setCollectQueryOrigins(boolean collectQueryOrigins)
This information can be later retrieved via MetaInfoManager.
MetaInfoManagerpublic String getResourceDirectory()
public void setResourceDirectory(String resourceDirectory)
public void add(BeanQueryAdapter beanQueryAdapter)
Note alternatively you can use setQueryAdapters(List) to set all
the BeanQueryAdapter instances.
public List<BeanQueryAdapter> getQueryAdapters()
public void setQueryAdapters(List<BeanQueryAdapter> queryAdapters)
Note alternatively you can use add(BeanQueryAdapter) to add
BeanQueryAdapter instances one at a time.
public void add(BeanPersistController beanPersistController)
Note alternatively you can use setPersistControllers(List) to set
all the BeanPersistController instances.
public List<BeanPersistController> getPersistControllers()
public void setPersistControllers(List<BeanPersistController> persistControllers)
Note alternatively you can use add(BeanPersistController) to add
BeanPersistController instances one at a time.
public void add(TransactionEventListener listener)
Note alternatively you can use setTransactionEventListeners(List)
to set all the TransactionEventListener instances.
public List<TransactionEventListener> getTransactionEventListeners()
public void setTransactionEventListeners(List<TransactionEventListener> transactionEventListeners)
Note alternatively you can use add(TransactionEventListener) to
add TransactionEventListener instances one at a time.
public void add(BeanPersistListener<?> beanPersistListener)
Note alternatively you can use setPersistListeners(List) to set
all the BeanPersistListener instances.
public List<BeanPersistListener<?>> getPersistListeners()
public void add(BulkTableEventListener bulkTableEventListener)
public List<BulkTableEventListener> getBulkTableEventListeners()
public void addServerConfigStartup(ServerConfigStartup configStartupListener)
public List<ServerConfigStartup> getServerConfigStartupListeners()
public void setPersistListeners(List<BeanPersistListener<?>> persistListeners)
Note alternatively you can use add(BeanPersistListener) to add
BeanPersistListener instances one at a time.
public void loadFromProperties()
public GlobalProperties.PropertySource getPropertySource()
public String getProperty(String propertyName, String defaultValue)
protected void loadDataSourceSettings(GlobalProperties.PropertySource p)
p - - The defined property source passed to load settingsprotected void loadAutofetchConfig(GlobalProperties.PropertySource p)
p - protected void loadSettings(GlobalProperties.PropertySource p)
Copyright © 2014. All Rights Reserved.