use of com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException in project midpoint by Evolveum.
the class SqlAuditServiceFactory method init.
@Override
public synchronized void init(Configuration config) throws AuditServiceFactoryException {
LOGGER.info("Initializing Sql audit service factory.");
try {
repositoryFactory.init(config);
} catch (RepositoryServiceFactoryException ex) {
throw new AuditServiceFactoryException(ex.getMessage(), ex);
}
LOGGER.info("Sql audit service factory initialization complete.");
}
use of com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException in project midpoint by Evolveum.
the class SqlAuditServiceFactory method destroy.
@Override
public synchronized void destroy() throws AuditServiceFactoryException {
LOGGER.info("Destroying Sql audit service factory.");
try {
repositoryFactory.destroy();
} catch (RepositoryServiceFactoryException ex) {
throw new AuditServiceFactoryException(ex.getMessage(), ex);
}
LOGGER.info("Sql audit service factory destroy complete.");
}
use of com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException in project midpoint by Evolveum.
the class SqlRepositoryFactory method prepareJdbcUrlPrefix.
/**
* Prepares a prefix (first part) of JDBC URL for embedded database. Used also by configurator of tasks (quartz)
* and workflow (activiti) modules; they add their own db names and parameters to this string.
*
* @param config
* @return prefix of JDBC URL like jdbc:h2:file:d:\midpoint\midpoint
*/
public String prepareJdbcUrlPrefix(SqlRepositoryConfiguration config) throws RepositoryServiceFactoryException {
if (StringUtils.isEmpty(config.getFileName())) {
config.setFileName("midpoint");
}
if (StringUtils.isEmpty(config.getBaseDir())) {
LOGGER.debug("Base dir path in configuration was not defined.");
if (StringUtils.isNotEmpty(System.getProperty(MIDPOINT_HOME_VARIABLE))) {
config.setBaseDir(System.getProperty(MIDPOINT_HOME_VARIABLE));
LOGGER.info("Using {} with value {} as base dir for configuration.", new Object[] { MIDPOINT_HOME_VARIABLE, config.getBaseDir() });
} else if (StringUtils.isNotEmpty(System.getProperty(USER_HOME_VARIABLE))) {
config.setBaseDir(System.getProperty(USER_HOME_VARIABLE));
LOGGER.info("Using {} with value {} as base dir for configuration.", new Object[] { USER_HOME_VARIABLE, config.getBaseDir() });
} else {
config.setBaseDir(".");
LOGGER.info("Using '.' as base dir for configuration ({}, or {} was not defined).", new Object[] { MIDPOINT_HOME_VARIABLE, USER_HOME_VARIABLE });
}
}
File baseDir = new File(config.getBaseDir());
if (!baseDir.exists() || !baseDir.isDirectory()) {
throw new RepositoryServiceFactoryException("File '" + config.getBaseDir() + "' defined as baseDir doesn't exist or is not a directory.");
}
StringBuilder jdbcUrl = new StringBuilder("jdbc:h2:");
if (config.isAsServer()) {
//jdbc:h2:tcp://<server>[:<port>]/[<path>]<databaseName>
jdbcUrl.append("tcp://127.0.0.1:");
jdbcUrl.append(config.getPort());
jdbcUrl.append("/");
jdbcUrl.append(config.getFileName());
} else {
//jdbc:h2:[file:][<path>]<databaseName>
jdbcUrl.append("file:");
File databaseFile = new File(config.getBaseDir(), config.getFileName());
jdbcUrl.append(databaseFile.getAbsolutePath());
}
return jdbcUrl.toString();
}
use of com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException in project midpoint by Evolveum.
the class SqlRepositoryFactory method startServer.
private void startServer() throws RepositoryServiceFactoryException {
SqlRepositoryConfiguration config = getSqlConfiguration();
checkPort(config.getPort());
try {
String[] serverArguments = createArguments(config);
if (LOGGER.isTraceEnabled()) {
String stringArgs = StringUtils.join(serverArguments, " ");
LOGGER.trace("Starting H2 server with arguments: {}", stringArgs);
}
server = Server.createTcpServer(serverArguments);
server.start();
} catch (Exception ex) {
throw new RepositoryServiceFactoryException(ex.getMessage(), ex);
}
}
use of com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException in project midpoint by Evolveum.
the class SqlRepositoryFactory method dropDatabaseIfExists.
private void dropDatabaseIfExists(SqlRepositoryConfiguration config) throws RepositoryServiceFactoryException {
if (!config.isDropIfExists()) {
LOGGER.info("Database wont be deleted, dropIfExists=false.");
return;
}
LOGGER.info("Deleting database.");
File file = new File(config.getBaseDir());
final String fileName = config.getFileName();
try {
//removing files based on http://www.h2database.com/html/features.html#database_file_layout
File dbFileOld = new File(file, fileName + ".h2.db");
removeFile(dbFileOld);
File dbFile = new File(file, fileName + ".mv.db");
removeFile(dbFile);
File lockFile = new File(file, fileName + ".lock.db");
removeFile(lockFile);
File traceFile = new File(file, fileName + ".trace.db");
removeFile(traceFile);
File[] tempFiles = file.listFiles((parent, name) -> {
if (name.matches("^" + fileName + "\\.[0-9]*\\.temp\\.db$")) {
return true;
}
return false;
});
if (tempFiles != null) {
for (File temp : tempFiles) {
removeFile(temp);
}
}
File lobDir = new File(file, fileName + ".lobs.db");
if (lobDir.exists() && lobDir.isDirectory()) {
LOGGER.info("Deleting directory '{}'", new Object[] { lobDir.getAbsolutePath() });
FileUtils.deleteDirectory(lobDir);
}
} catch (Exception ex) {
throw new RepositoryServiceFactoryException("Couldn't drop existing database files, reason: " + ex.getMessage(), ex);
}
}
Aggregations