use of com.manydesigns.portofino.cache.CacheResetListenerRegistry 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.cache.CacheResetListenerRegistry 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;
}
Aggregations