Search in sources :

Example 6 with RepositoryServiceFactoryException

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.");
}
Also used : AuditServiceFactoryException(com.evolveum.midpoint.audit.api.AuditServiceFactoryException) RepositoryServiceFactoryException(com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException)

Example 7 with RepositoryServiceFactoryException

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.");
}
Also used : AuditServiceFactoryException(com.evolveum.midpoint.audit.api.AuditServiceFactoryException) RepositoryServiceFactoryException(com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException)

Example 8 with RepositoryServiceFactoryException

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();
}
Also used : File(java.io.File) RepositoryServiceFactoryException(com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException)

Example 9 with RepositoryServiceFactoryException

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);
    }
}
Also used : RepositoryServiceFactoryException(com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException) IOException(java.io.IOException) BindException(java.net.BindException) RepositoryServiceFactoryException(com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException)

Example 10 with RepositoryServiceFactoryException

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);
    }
}
Also used : File(java.io.File) RepositoryServiceFactoryException(com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException) IOException(java.io.IOException) BindException(java.net.BindException) RepositoryServiceFactoryException(com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException)

Aggregations

RepositoryServiceFactoryException (com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException)11 File (java.io.File)3 IOException (java.io.IOException)3 BindException (java.net.BindException)3 AuditServiceFactoryException (com.evolveum.midpoint.audit.api.AuditServiceFactoryException)2 MidpointConfiguration (com.evolveum.midpoint.common.configuration.api.MidpointConfiguration)2 SqlRepositoryConfiguration (com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration)2 SqlRepositoryFactory (com.evolveum.midpoint.repo.sql.SqlRepositoryFactory)2 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)2 RepositoryFactory (com.evolveum.midpoint.init.RepositoryFactory)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 PropertyVetoException (java.beans.PropertyVetoException)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 ServerSocket (java.net.ServerSocket)1 Properties (java.util.Properties)1 PostConstruct (javax.annotation.PostConstruct)1 NamingException (javax.naming.NamingException)1 Configuration (org.apache.commons.configuration.Configuration)1