Package org.appng.core.service
Class DatabaseService
- java.lang.Object
-
- org.appng.core.service.MigrationService
-
- org.appng.core.service.DatabaseService
-
public class DatabaseService extends MigrationService
A service offering methods for creating and migratingDatabaseConnection
s of aSiteApplication
.- Author:
- Matthias Müller
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.appng.core.service.MigrationService
MigrationService.MigrationStatus
-
-
Field Summary
Fields Modifier and Type Field Description protected DatabaseConnectionRepository
databaseConnectionRepository
-
Fields inherited from class org.appng.core.service.MigrationService
APP_NG_ROOT_DATABASE, DATABASE_MAX_CONNECTIONS, DATABASE_MIN_CONNECTIONS, DATABASE_NAME, DATABASE_NAME_PREFIX, DATABASE_REPAIR, DATABASE_TYPE, DATABASE_VALIDATION_PERIOD, DATABASE_VALIDATION_QUERY, HIBERNATE_CONNECTION_DRIVER_CLASS, HIBERNATE_CONNECTION_PASSWORD, HIBERNATE_CONNECTION_URL, HIBERNATE_CONNECTION_USERNAME
-
-
Constructor Summary
Constructors Constructor Description DatabaseService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
dropApplicationConnection(DatabaseConnection databaseConnection, DataSource dataSource)
DatabaseConnection
getRootConnectionOfType(DatabaseConnection.DatabaseType type)
protected String
getUserName(Site site, Application application)
protected void
initApplicationConnection(DatabaseConnection applicationConnection, DataSource dataSource)
DatabaseConnection
initDatabase(Properties config, boolean managed, boolean setActive)
Configures and (optionally) migrates the appNG rootDatabaseConnection
from the givenProperties
.MigrationService.MigrationStatus
manageApplicationConnection(SiteApplication siteApplication, File sqlFolder, String databasePrefix)
Migrates the database for the givenSiteApplication
.void
resetApplicationConnection(SiteApplication siteApplication, String databasePrefix)
Resets the configuration for theDatabaseConnection
(if existing) of the givenSiteApplication
to the default values.void
save(DatabaseConnection databaseConnection)
Persists the givenDatabaseConnection
.DatabaseConnection
setActiveConnection(DatabaseConnection rootConnection, boolean changeManagedState)
Configures the appNG rootDatabaseConnection
s by either creating a new one or updating the existingDatabaseConnection
for eachDatabaseConnection.DatabaseType
.-
Methods inherited from class org.appng.core.service.MigrationService
getDataSource, getDataSource, getFlyway, getPlatformConnection, initDatabase, initDatabase, migrate, status, status, statusComplete, statusComplete, statusComplete
-
-
-
-
Field Detail
-
databaseConnectionRepository
@Autowired protected DatabaseConnectionRepository databaseConnectionRepository
-
-
Method Detail
-
initApplicationConnection
protected void initApplicationConnection(DatabaseConnection applicationConnection, DataSource dataSource) throws IOException, URISyntaxException
- Throws:
IOException
URISyntaxException
-
resetApplicationConnection
public void resetApplicationConnection(SiteApplication siteApplication, String databasePrefix)
Resets the configuration for theDatabaseConnection
(if existing) of the givenSiteApplication
to the default values.- Parameters:
siteApplication
- aSiteApplication
-
getUserName
protected String getUserName(Site site, Application application)
-
dropApplicationConnection
protected void dropApplicationConnection(DatabaseConnection databaseConnection, DataSource dataSource) throws IOException, URISyntaxException
- Throws:
IOException
URISyntaxException
-
initDatabase
@Transactional public DatabaseConnection initDatabase(Properties config, boolean managed, boolean setActive)
Configures and (optionally) migrates the appNG rootDatabaseConnection
from the givenProperties
.- Parameters:
config
- the properties read from "/conf/appNG.properties"managed
- whether to make the connection managedsetActive
- if the connection should be set as he active root connection, creating a newDatabaseConnection
if necessary. Only applied ifMigrationService.status(DatabaseConnection)
returns a non-null value.- Returns:
- the appNG root
DatabaseConnection
-
setActiveConnection
@Transactional public DatabaseConnection setActiveConnection(DatabaseConnection rootConnection, boolean changeManagedState)
Configures the appNG rootDatabaseConnection
s by either creating a new one or updating the existingDatabaseConnection
for eachDatabaseConnection.DatabaseType
. Also checks if the connections are working and callsDatabaseConnection#setActive(false)
if this is not the case.- Parameters:
rootConnection
- the current root connectionchangeManagedState
- if set totrue
, the managed state for an existing connection is set torootConnection#isManaged()
-
getRootConnectionOfType
public DatabaseConnection getRootConnectionOfType(DatabaseConnection.DatabaseType type)
-
manageApplicationConnection
@Transactional public MigrationService.MigrationStatus manageApplicationConnection(SiteApplication siteApplication, File sqlFolder, String databasePrefix)
Migrates the database for the givenSiteApplication
.- Parameters:
siteApplication
- theSiteApplication
to migrate the database forsqlFolder
- the root folder for the migration-scripts provided by theSiteApplication
databasePrefix
- the prefix for the database to create- Returns:
- the
MigrationService.MigrationStatus
-
save
@Transactional public void save(DatabaseConnection databaseConnection)
Persists the givenDatabaseConnection
.- Parameters:
databaseConnection
- the connection to persist.
-
-