Class BibernateDatabaseSettings
java.lang.Object
io.github.blyznytsiaorg.bibernate.config.BibernateDatabaseSettings
Configuration class for Bibernate database settings.
It provides methods to create a data source, access database properties, and configure various settings.
- Since:
- 1.0
- Author:
- Blyzhnytsia Team
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final String
private static final String
static final String
private static final String
static final String
private final TransactionalDatasource
static final String
static final String
static final String
static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
static final String
private RedisConfiguration
private static final String
private static final String
private static final String
private static final String
-
Constructor Summary
ConstructorDescriptionBibernateDatabaseSettings
(Map<String, String> bibernateSettingsProperties) Constructs a new BibernateDatabaseSettings instance with the specified Bibernate settings properties and file name. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
Checks database settings to ensure they are consistent.private TransactionalDatasource
Creates a Hikari data source using the configured properties.int
Retrieves the batch size configuration for batch processing from the Bibernate settings properties.private boolean
getPropertyBoolean
(String key, String defaultValue) Retrieves a boolean property value from the Bibernate settings.private String
getPropertyString
(String key, String defaultValue) Retrieves a String property value from the Bibernate settings.Gets the host of the second level cache (Redis).int
Gets the port of the second level cache (Redis).boolean
Checks if query collection is enabled.boolean
Checks if DDL auto creation is enabled.boolean
Checks if Flyway migration is enabled.boolean
Checks if the second level cache is enabled.boolean
Checks if SQL logging is enabled.void
setRedisConfiguration
(RedisConfiguration redisConfiguration) Sets the Redis configuration for distributed caching.
-
Field Details
-
DB_URL
- See Also:
-
DB_USER
- See Also:
-
DB_PASSWORD
- See Also:
-
DB_MAXIMUM_POOL_SIZE
- See Also:
-
SHOW_SQL
- See Also:
-
BATCH_SIZE
- See Also:
-
COLLECT_QUERIES
- See Also:
-
FLYWAY_ENABLED
- See Also:
-
SECOND_LEVEL_CACHE
- See Also:
-
SECOND_LEVEL_CACHE_HOST
- See Also:
-
SECOND_LEVEL_CACHE_POST
- See Also:
-
BB2DDL_AUTO
- See Also:
-
BIBERNATE_APPLICATION_PROPERTIES
- See Also:
-
DEFAULT_BOOLEAN_FALSE_VALUE
- See Also:
-
DEFAULT_REDIS_HOST
- See Also:
-
DEFAULT_REDIS_PORT
- See Also:
-
DEFAULT_BATCH_SIZE
- See Also:
-
DEFAULT_MAXIMUM_POOL_SIZE
- See Also:
-
NONE
- See Also:
-
CREATE
- See Also:
-
DEFAULT_DB_CONNECTION_URL
- See Also:
-
DEFAULT_DB_USERNAME
- See Also:
-
DEFAULT_DB_PASSWORD
- See Also:
-
bibernateSettingsProperties
-
dataSource
-
redisConfiguration
-
-
Constructor Details
-
BibernateDatabaseSettings
Constructs a new BibernateDatabaseSettings instance with the specified Bibernate settings properties and file name.- Parameters:
bibernateSettingsProperties
- the Bibernate settings properties loaded from a configuration file
-
-
Method Details
-
setRedisConfiguration
Sets the Redis configuration for distributed caching.- Parameters:
redisConfiguration
- the Redis configuration to be set
-
createDataSource
Creates a Hikari data source using the configured properties.- Returns:
- the HikariDataSource object
-
isShowSql
public boolean isShowSql()Checks if SQL logging is enabled.- Returns:
- true if SQL logging is enabled, otherwise false
-
isCollectQueries
public boolean isCollectQueries()Checks if query collection is enabled.- Returns:
- true if query collection is enabled, otherwise false
-
isFlywayEnabled
public boolean isFlywayEnabled()Checks if Flyway migration is enabled.- Returns:
- true if Flyway migration is enabled, otherwise false
-
isDDLCreate
public boolean isDDLCreate()Checks if DDL auto creation is enabled.- Returns:
- true if DDL auto create is enabled, otherwise false
-
isSecondLevelCacheEnabled
public boolean isSecondLevelCacheEnabled()Checks if the second level cache is enabled.- Returns:
- true if the second level cache is enabled, otherwise false
-
getSecondLevelCacheHost
Gets the host of the second level cache (Redis).- Returns:
- the host of the second level cache
-
getSecondLevelCachePost
public int getSecondLevelCachePost()Gets the port of the second level cache (Redis).- Returns:
- the port of the second level cache
-
getBatchSize
public int getBatchSize()Retrieves the batch size configuration for batch processing from the Bibernate settings properties. If the batch size is not explicitly configured, the method returns the default batch size value.- Returns:
- The configured batch size for batch processing or the default batch size if not explicitly set.
-
getPropertyBoolean
Retrieves a boolean property value from the Bibernate settings.- Parameters:
key
- the property keydefaultValue
- the default value if the property is not found- Returns:
- the boolean property value
-
getPropertyString
Retrieves a String property value from the Bibernate settings.- Parameters:
key
- the property keydefaultValue
- the default value if the property is not found- Returns:
- the String property value
-
checkDatabaseSettings
private void checkDatabaseSettings()Checks database settings to ensure they are consistent. If Flyway is enabled and DDL auto is set to "create", it throws a BibernateGeneralException.- Throws:
BibernateGeneralException
-