Search in sources :

Example 1 with DatabasePlatformsRegistry

use of com.manydesigns.portofino.model.database.platforms.DatabasePlatformsRegistry in project Portofino by ManyDesigns.

the class PersistenceTest method setup.

protected void setup(FileObject appDir) throws Exception {
    Configuration configuration = new PropertiesConfiguration();
    final DatabasePlatformsRegistry databasePlatformsRegistry = new DatabasePlatformsRegistry(configuration);
    databasePlatformsRegistry.addDatabasePlatform(new H2DatabasePlatform());
    databaseModule = new DatabaseModule() {

        @Override
        public void destroy() {
            if (subscription != null) {
                subscription.dispose();
                subscription = null;
            }
        }
    };
    databaseModule.applicationDirectory = appDir;
    databaseModule.configuration = new ConfigurationSource(configuration, null);
    persistence = databaseModule.getPersistence(databasePlatformsRegistry, new CacheResetListenerRegistry());
    databaseModule.init();
    persistence.start();
    setupJPetStore();
    setupHibernateTest();
    persistence.initModel();
}
Also used : H2DatabasePlatform(com.manydesigns.portofino.database.platforms.H2DatabasePlatform) ConfigurationSource(com.manydesigns.portofino.config.ConfigurationSource) Configuration(org.apache.commons.configuration2.Configuration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) DatabasePlatformsRegistry(com.manydesigns.portofino.model.database.platforms.DatabasePlatformsRegistry) CacheResetListenerRegistry(com.manydesigns.portofino.cache.CacheResetListenerRegistry) DatabaseModule(com.manydesigns.portofino.modules.DatabaseModule) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 2 with DatabasePlatformsRegistry

use of com.manydesigns.portofino.model.database.platforms.DatabasePlatformsRegistry in project Portofino by ManyDesigns.

the class CrudActionTest method setup.

protected void setup(FileObject appDir) throws Exception {
    Configuration configuration = new PropertiesConfiguration();
    DatabasePlatformsRegistry databasePlatformsRegistry = new DatabasePlatformsRegistry(configuration);
    databasePlatformsRegistry.addDatabasePlatform(new H2DatabasePlatform());
    persistence = new Persistence(appDir, new ConfigurationSource(configuration, null), databasePlatformsRegistry);
    persistence.start();
    setupJPetStore();
    persistence.initModel();
}
Also used : Persistence(com.manydesigns.portofino.persistence.Persistence) H2DatabasePlatform(com.manydesigns.portofino.database.platforms.H2DatabasePlatform) ConfigurationSource(com.manydesigns.portofino.config.ConfigurationSource) CrudConfiguration(com.manydesigns.portofino.resourceactions.crud.configuration.database.CrudConfiguration) Configuration(org.apache.commons.configuration2.Configuration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) DatabasePlatformsRegistry(com.manydesigns.portofino.model.database.platforms.DatabasePlatformsRegistry) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 3 with DatabasePlatformsRegistry

use of com.manydesigns.portofino.model.database.platforms.DatabasePlatformsRegistry in project Portofino by ManyDesigns.

the class DatabaseModule method getPersistence.

@Bean
public Persistence getPersistence(@Autowired DatabasePlatformsRegistry databasePlatformsRegistry, @Autowired CacheResetListenerRegistry cacheResetListenerRegistry) throws FileSystemException {
    Persistence persistence = new Persistence(applicationDirectory, configuration, databasePlatformsRegistry);
    persistence.cacheResetListenerRegistry = cacheResetListenerRegistry;
    if (applicationContext != null) {
        // We may want it to be null when testing
        applicationContext.getAutowireCapableBeanFactory().autowireBean(persistence);
    }
    FileObject generatedClassesRoot = applicationDirectory.resolveFile(GENERATED_CLASSES_DIRECTORY_NAME);
    generatedClassesRoot.createFolder();
    AllFileSelector allFileSelector = new AllFileSelector();
    // When the entity mode is POJO:
    // - make generated classes visible to shared classes and actions;
    // - write them in the application directory so the user's IDE and tools can know about them.
    subscription = persistence.databaseSetupEvents.subscribe(e -> {
        String databaseName = e.setup.getDatabase().getDatabaseName();
        FileObject inMemoryDatabaseDir = e.setup.getCodeBase().getRoot().resolveFile(databaseName);
        FileObject externalDatabaseDir = generatedClassesRoot.resolveFile(databaseName);
        externalDatabaseDir.deleteAll();
        switch(e.type) {
            case Persistence.DatabaseSetupEvent.ADDED:
                persistenceCodeBase.add(e.setup.getCodeBase());
                if (e.setup.getEntityMode() == EntityMode.POJO) {
                    externalDatabaseDir.copyFrom(inMemoryDatabaseDir, allFileSelector);
                }
                break;
            case Persistence.DatabaseSetupEvent.REMOVED:
                persistenceCodeBase.remove(e.setup.getCodeBase());
                externalDatabaseDir.deleteAll();
                inMemoryDatabaseDir.deleteAll();
                break;
            case Persistence.DatabaseSetupEvent.REPLACED:
                persistenceCodeBase.replace(e.oldSetup.getCodeBase(), e.setup.getCodeBase());
                externalDatabaseDir.deleteAll();
                if (e.setup.getEntityMode() == EntityMode.POJO) {
                    externalDatabaseDir.copyFrom(inMemoryDatabaseDir, allFileSelector);
                }
                break;
        }
    });
    return persistence;
}
Also used : Persistence(com.manydesigns.portofino.persistence.Persistence) Persistence(com.manydesigns.portofino.persistence.Persistence) FileBasedConfigurationBuilder(org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder) CodeBase(com.manydesigns.portofino.code.CodeBase) LoggerFactory(org.slf4j.LoggerFactory) DatabasePlatformsRegistry(com.manydesigns.portofino.model.database.platforms.DatabasePlatformsRegistry) Autowired(org.springframework.beans.factory.annotation.Autowired) AggregateCodeBase(com.manydesigns.portofino.code.AggregateCodeBase) PreDestroy(javax.annotation.PreDestroy) Qualifier(org.springframework.beans.factory.annotation.Qualifier) CacheResetListenerRegistry(com.manydesigns.portofino.cache.CacheResetListenerRegistry) Logger(org.slf4j.Logger) EntityMode(org.hibernate.EntityMode) FileSystemException(org.apache.commons.vfs2.FileSystemException) BeansException(org.springframework.beans.BeansException) ApplicationListener(org.springframework.context.ApplicationListener) FileObject(org.apache.commons.vfs2.FileObject) ApplicationContext(org.springframework.context.ApplicationContext) ConfigurationSource(com.manydesigns.portofino.config.ConfigurationSource) Configuration(org.apache.commons.configuration2.Configuration) MultiTenancyImplementationFactory(com.manydesigns.portofino.persistence.hibernate.multitenancy.MultiTenancyImplementationFactory) Disposable(io.reactivex.disposables.Disposable) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) PortofinoSpringConfiguration(com.manydesigns.portofino.spring.PortofinoSpringConfiguration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) PostConstruct(javax.annotation.PostConstruct) AllFileSelector(org.apache.commons.vfs2.AllFileSelector) ServletContext(javax.servlet.ServletContext) Bean(org.springframework.context.annotation.Bean) NotNull(org.jetbrains.annotations.NotNull) ApplicationContextAware(org.springframework.context.ApplicationContextAware) AllFileSelector(org.apache.commons.vfs2.AllFileSelector) FileObject(org.apache.commons.vfs2.FileObject) Bean(org.springframework.context.annotation.Bean)

Example 4 with DatabasePlatformsRegistry

use of com.manydesigns.portofino.model.database.platforms.DatabasePlatformsRegistry in project Portofino by ManyDesigns.

the class PlatformsAction method listDatabasePlatforms.

@GET
public Map<String, Map<String, String>> listDatabasePlatforms() {
    DatabasePlatformsRegistry manager = persistence.getDatabasePlatformsRegistry();
    DatabasePlatform[] platforms = manager.getDatabasePlatforms();
    Map<String, Map<String, String>> platformMap = new HashMap<>();
    for (DatabasePlatform platform : platforms) {
        Map<String, String> desc = new HashMap<>();
        desc.put("description", platform.getDescription());
        desc.put("standardDriverClassName", platform.getStandardDriverClassName());
        desc.put("status", platform.getStatus());
        desc.put("connectionStringTemplate", platform.getConnectionStringTemplate());
        platformMap.put(platform.getClass().getName(), desc);
    }
    return platformMap;
}
Also used : DatabasePlatformsRegistry(com.manydesigns.portofino.model.database.platforms.DatabasePlatformsRegistry) HashMap(java.util.HashMap) DatabasePlatform(com.manydesigns.portofino.model.database.platforms.DatabasePlatform) Map(java.util.Map) HashMap(java.util.HashMap) GET(javax.ws.rs.GET)

Aggregations

DatabasePlatformsRegistry (com.manydesigns.portofino.model.database.platforms.DatabasePlatformsRegistry)4 ConfigurationSource (com.manydesigns.portofino.config.ConfigurationSource)3 Configuration (org.apache.commons.configuration2.Configuration)3 PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)3 CacheResetListenerRegistry (com.manydesigns.portofino.cache.CacheResetListenerRegistry)2 H2DatabasePlatform (com.manydesigns.portofino.database.platforms.H2DatabasePlatform)2 Persistence (com.manydesigns.portofino.persistence.Persistence)2 AggregateCodeBase (com.manydesigns.portofino.code.AggregateCodeBase)1 CodeBase (com.manydesigns.portofino.code.CodeBase)1 DatabasePlatform (com.manydesigns.portofino.model.database.platforms.DatabasePlatform)1 DatabaseModule (com.manydesigns.portofino.modules.DatabaseModule)1 MultiTenancyImplementationFactory (com.manydesigns.portofino.persistence.hibernate.multitenancy.MultiTenancyImplementationFactory)1 CrudConfiguration (com.manydesigns.portofino.resourceactions.crud.configuration.database.CrudConfiguration)1 PortofinoSpringConfiguration (com.manydesigns.portofino.spring.PortofinoSpringConfiguration)1 Disposable (io.reactivex.disposables.Disposable)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 PostConstruct (javax.annotation.PostConstruct)1 PreDestroy (javax.annotation.PreDestroy)1 ServletContext (javax.servlet.ServletContext)1