branch feature/7528 updated (f723352 -> aa7fad6)
This is an automated email from the git hooks/post-receive script. New change to branch feature/7528 in repository observe. See http://git.codelutin.com/observe.git from f723352 creation d'un base local (refs #7529) new aa7fad6 chargement de la base de données local au démarage (refs #7528) The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit aa7fad6218a84b3dfe782781ebe559ed44fc736e Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Thu Sep 24 09:46:29 2015 +0200 chargement de la base de données local au démarage (refs #7528) Summary of changes: .../java/fr/ird/observe/ObserveServiceHelper.java | 42 ++++---- .../observe/ObserveSwingApplicationContext.java | 118 ++++++++------------- 2 files changed, 65 insertions(+), 95 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7528 in repository observe. See http://git.codelutin.com/observe.git commit aa7fad6218a84b3dfe782781ebe559ed44fc736e Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Thu Sep 24 09:46:29 2015 +0200 chargement de la base de données local au démarage (refs #7528) --- .../java/fr/ird/observe/ObserveServiceHelper.java | 42 ++++---- .../observe/ObserveSwingApplicationContext.java | 118 ++++++++------------- 2 files changed, 65 insertions(+), 95 deletions(-) diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ObserveServiceHelper.java b/observe-application-swing/src/main/java/fr/ird/observe/ObserveServiceHelper.java index ab50553..bfae457 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ObserveServiceHelper.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ObserveServiceHelper.java @@ -26,11 +26,15 @@ import fr.ird.observe.business.gps.GPSService; import fr.ird.observe.business.validation.ValidationContext; import fr.ird.observe.business.validation.ValidationService; import fr.ird.observe.configuration.ObserveSwingApplicationConfig; +import fr.ird.observe.db.ObserveSwingDataSource; +import fr.ird.observe.services.configuration.ObserveDataSourceConfigurationTopiaH2; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.io.IOException; +import static org.nuiton.i18n.I18n.t; + public class ObserveServiceHelper { /** Logger. */ @@ -97,8 +101,6 @@ public class ObserveServiceHelper { log.debug("Closing service helper..."); } context = null; - //FIXME -// AbstractDataSourceMigration.setApplicationConfigSupplier(null); // application fermée closed = true; @@ -252,26 +254,24 @@ public class ObserveServiceHelper { * @return la service de persistance initialisé (mais non ouvert) * @throws IOException si une erreur d'IO * @throws IllegalStateException si la base locale n'existe pas - * @see DataSource + * @see ObserveSwingDataSource */ - //FIXME -// public static H2DataSource newLocalStorageService(ObserveSwingApplicationConfig config) throws IOException, IllegalStateException { -// -// -// H2DataSourceConfig c = -// config.toH2StorageConfig(n("observe.storage.label.local")); -// -// c.init(); -// -// if (!c.isStorageExists()) { -// throw new IllegalStateException( -// "local base must exist, when using this method (" + -// c.getStorageDirectory() + ')'); -// } -// -// H2DataSource service = DataSourceFactory.newService(c); -// return service; -// } + public static ObserveSwingDataSource newLocalStorageService(ObserveSwingApplicationConfig config) throws IllegalStateException { + + ObserveDataSourceConfigurationTopiaH2 dataSourceConfigurationH2 = config.getDataSourceConfigurationH2(t("observe.storage.label.local")); + + if (! dataSourceConfigurationH2.getDatabaseFile().exists()) { + throw new IllegalStateException( + "local base must exist, when using this method (" + + dataSourceConfigurationH2.getDirectory() + ')'); + } + + ObserveSwingDataSource dataSource = new ObserveSwingDataSource(dataSourceConfigurationH2); + + return dataSource; + } + + /** * Teste si la base locale existe. diff --git a/observe-application-swing/src/main/java/fr/ird/observe/ObserveSwingApplicationContext.java b/observe-application-swing/src/main/java/fr/ird/observe/ObserveSwingApplicationContext.java index 5dc2fd9..ba4b340 100644 --- a/observe-application-swing/src/main/java/fr/ird/observe/ObserveSwingApplicationContext.java +++ b/observe-application-swing/src/main/java/fr/ird/observe/ObserveSwingApplicationContext.java @@ -44,6 +44,8 @@ import fr.ird.observe.services.dto.longline.TripLonglineStubDto; import fr.ird.observe.services.dto.referential.ProgramDto; import fr.ird.observe.services.dto.referential.ProgramDtos; import fr.ird.observe.services.dto.seine.TripSeineStubDto; +import fr.ird.observe.services.service.DatabaseConnexionNotAuthorizedException; +import fr.ird.observe.services.service.DatabaseNotFoundException; import fr.ird.observe.services.service.ReferentialService; import fr.ird.observe.services.service.longline.TripLonglineService; import fr.ird.observe.services.service.seine.TripSeineService; @@ -130,15 +132,6 @@ public class ObserveSwingApplicationContext extends DefaultApplicationContext { public static final JAXXContextEntryDef<GPSService> GPS_SERVICE_ENTRY_DEF = JAXXUtil.newContextEntryDef(GPSService.class); - //FIXME -// /** the jaxx context entry to store the consolidate data service */ -// public static final JAXXContextEntryDef<ConsolidateDataService> CONSOLIDATE_DATA_SERVICE_ENTRY_DEF = -// JAXXUtil.newContextEntryDef(ConsolidateDataService.class); - //FIXME -// /** the jaxx context entry to store the data service */ -// public static final JAXXContextEntryDef<DataService> DATA_SERVICE_ENTRY_DEF = -// JAXXUtil.newContextEntryDef(DataService.class); - /** the jaxx context entry to store the data service */ public static final JAXXContextEntryDef<DataContext> DATA_CONTEXT_ENTRY_DEF = JAXXUtil.newContextEntryDef(DataContext.class); @@ -329,21 +322,18 @@ public class ObserveSwingApplicationContext extends DefaultApplicationContext { } // fermeture du context de données - if (getDataSource() != null) { + ObserveSwingDataSource dataSource = getDataSource(); + if (getDataSource() != null && dataSource.isOpen()) { + dataSource.close(); setDataSource(null); } getValidationContext().closeDataSource(); - // fermeture des services de persistances ouverts - //FIXME -// DataSourceFactory.dispose(); - // fermeture du context principal clear(); - //FIXME -// ObserveServiceHelper.close(); + ObserveServiceHelper.close(); } @@ -481,34 +471,28 @@ public class ObserveSwingApplicationContext extends DefaultApplicationContext { public void initStorage(ObserveSwingApplicationConfig config, ObserveMainUI mainUI, boolean askToCreate) { - try { - if (config.isLocalStorageExist()) { - // une base locale existe, on l'ouvre - loadLocalStorage(); + if (config.isLocalStorageExist()) { + // une base locale existe, on l'ouvre + if (loadLocalStorage()) { // on peut retourner sur cette base mainUI.setMode(ObserveUIMode.DB); - } else { + } + } else { - // on peut retourner sur cette base - mainUI.setMode(ObserveUIMode.NO_DB); + // on peut retourner sur cette base + mainUI.setMode(ObserveUIMode.NO_DB); - if (askToCreate) { + if (askToCreate) { - // demande à l'utilisateur s'il veut créer la base locale - createStorage(config, mainUI.getHandler()); - } - } - if (log.isInfoEnabled()) { - log.info(t("observe.init.storage.done")); - } - } catch (Exception e) { - ErrorDialogUI.showError(e); - if (log.isErrorEnabled()) { - log.error(e.getMessage(), e); + // demande à l'utilisateur s'il veut créer la base locale + createStorage(config, mainUI.getHandler()); } } + if (log.isInfoEnabled()) { + log.info(t("observe.init.storage.done")); + } } protected void createStorage(ObserveSwingApplicationConfig config, @@ -551,48 +535,35 @@ public class ObserveSwingApplicationContext extends DefaultApplicationContext { } } - protected void loadLocalStorage() throws Exception { + protected boolean loadLocalStorage() { + boolean success = false; // chargement de la base locale // création de la source de données sur la base locale - //FIXME -// DataSource service = -// ObserveServiceHelper.newLocalStorageService(getConfig()); -// -// // la source sera utilisée dans les ui -// prepareMainStorage(service); -// -// if (log.isInfoEnabled()) { -// log.info(t("observe.init.local.db.detected", service.getLabel())); -// } -// -// // la base locale existe, on l'ouvre -// try { -// service.doOpen(); -// } catch (Exception eee) { -// // la base n'a pas pu être ouverte -// -// Throwable cause = eee.getCause(); -// while (cause != null && cause.getCause() != null) { -// cause = cause.getCause(); -// } -// if (cause != null) { -// if (cause instanceof JdbcSQLException) { -// JdbcSQLException error = (JdbcSQLException) cause; -// if (error.getMessage().contains("Locked")) { -// JOptionPane.showMessageDialog( -// null, -// t("observe.error.open.first.db"), -// t("observe.title.error.dialog"), -// JOptionPane.ERROR_MESSAGE -// ); -// return; -// } -// } -// } -// throw eee; -// } + ObserveSwingDataSource dataSource = ObserveServiceHelper.newLocalStorageService(getConfig()); + + // la source sera utilisée dans les ui + prepareMainStorage(dataSource); + setDataSource(dataSource); + + if (log.isInfoEnabled()) { + log.info(t("observe.init.local.db.detected", dataSource.getLabel())); + } + + // la base locale existe, on l'ouvre + try { + dataSource.open(); + success = true; + } catch (DatabaseConnexionNotAuthorizedException | DatabaseNotFoundException e) { + JOptionPane.showMessageDialog( + null, + e.getMessage(), + t("observe.title.error.dialog"), + JOptionPane.ERROR_MESSAGE + ); + } + return success; } /** @@ -686,7 +657,6 @@ public class ObserveSwingApplicationContext extends DefaultApplicationContext { } protected void openOnUI(ObserveSwingDataSource source) { - // FIXME // on rend le service disponible dans le service de validation //getValidationContext().setDataSource(source); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
participants (1)
-
codelutin.com scm