use of com.manydesigns.portofino.persistence.Persistence in project Portofino by ManyDesigns.
the class SessionCleaner method closeSessions.
static void closeSessions(ApplicationContext applicationContext) {
Persistence persistence = applicationContext.getBean(Persistence.class);
persistence.closeSessions();
}
use of com.manydesigns.portofino.persistence.Persistence in project Portofino by ManyDesigns.
the class CrudAction method saveConfiguration.
@Override
protected boolean saveConfiguration(Object configuration) {
CrudConfiguration crudConfiguration = (CrudConfiguration) configuration;
List<SelectionProviderReference> sps = new ArrayList<>(crudConfiguration.getSelectionProviders());
crudConfiguration.getSelectionProviders().clear();
crudConfiguration.persistence = persistence;
crudConfiguration.init();
sps.forEach(sp -> {
ForeignKey fk = DatabaseLogic.findForeignKeyByName(crudConfiguration.getActualTable(), sp.getSelectionProviderName());
if (fk != null) {
sp.setForeignKeyName(sp.getSelectionProviderName());
sp.setSelectionProviderName(null);
}
if (sp.getSelectionProviderName() != null || sp.getForeignKeyName() != null) {
crudConfiguration.getSelectionProviders().add(sp);
}
});
List<CrudProperty> existingProperties = this.crudConfiguration.getProperties();
List<CrudProperty> configuredProperties = crudConfiguration.getProperties();
List<CrudProperty> newProperties = configuredProperties.stream().map(p1 -> {
Optional<CrudProperty> maybeP2 = existingProperties.stream().filter(p2 -> p1.getName().equals(p2.getName())).findFirst();
CrudProperty p2 = maybeP2.orElse(new CrudProperty());
p2.setName(p1.getName());
p2.setEnabled(p1.isEnabled());
p2.setInsertable(p1.isInsertable());
p2.setInSummary(p1.isInSummary());
p2.setLabel(p1.getLabel());
p2.setSearchable(p1.isSearchable());
p2.setUpdatable(p1.isUpdatable());
return p2;
}).collect(Collectors.toList());
crudConfiguration.setProperties(newProperties);
return super.saveConfiguration(crudConfiguration);
}
use of com.manydesigns.portofino.persistence.Persistence 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.persistence.Persistence 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.persistence.Persistence in project Portofino by ManyDesigns.
the class CloseSessionsFilter method doFilter.
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
try {
chain.doFilter(request, response);
} finally {
MDC.clear();
ServletContext servletContext = request.getServletContext();
WebApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
Persistence persistence = applicationContext.getBean(Persistence.class);
if (persistence.getModel() != null) {
persistence.closeSessions();
}
}
}
Aggregations