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();
}
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();
}
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;
}
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;
}
Aggregations