Author: tchemit Date: 2012-12-17 08:36:36 +0100 (Mon, 17 Dec 2012) New Revision: 80 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/80 Log: prepare configuration for the adagio persistence module Added: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/TuttiPersistenceAdagioConfig.java trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/TuttiPersistenceAdagioConfigOption.java trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/TuttiPersistenceAdagioProvider.java trunk/tutti-persistence-adagio/src/test/resources/tutti-test.properties Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceAdagioImpl.java trunk/tutti-persistence-adagio/src/test/resources/conf.properties Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceAdagioImpl.java =================================================================== --- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceAdagioImpl.java 2012-12-17 07:32:05 UTC (rev 79) +++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceAdagioImpl.java 2012-12-17 07:36:36 UTC (rev 80) @@ -24,6 +24,7 @@ * #L% */ +import fr.ifremer.tutti.persistence.config.TuttiPersistenceAdagioConfig; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; @@ -46,6 +47,7 @@ import fr.ifremer.tutti.persistence.entities.referential.Vessel; import fr.ifremer.tutti.persistence.entities.referential.WeightCategory; import fr.ifremer.tutti.persistence.entities.referential.Zone; +import org.apache.commons.io.FileUtils; import org.nuiton.util.ApplicationConfig; import java.io.IOException; @@ -57,6 +59,13 @@ */ public class TuttiPersistenceAdagioImpl implements TuttiPersistence { + /** + * Persistence config. + * + * @since 0.2 + */ + protected TuttiPersistenceAdagioConfig config; + @Override public String getImplementationName() { return "Persistence Adagio implementation"; @@ -64,6 +73,12 @@ @Override public void open(ApplicationConfig config) throws IOException { + this.config = new TuttiPersistenceAdagioConfig(config); + try { + FileUtils.forceMkdir(this.config.getDbDirectory()); + } catch (IOException e) { + throw new RuntimeException("Could not create directory", e); + } } @Override Added: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/TuttiPersistenceAdagioConfig.java =================================================================== --- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/TuttiPersistenceAdagioConfig.java (rev 0) +++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/TuttiPersistenceAdagioConfig.java 2012-12-17 07:36:36 UTC (rev 80) @@ -0,0 +1,66 @@ +package fr.ifremer.tutti.persistence.config; + +/* + * #%L + * Tutti :: Persistence Adagio (impl) + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.nuiton.util.ApplicationConfig; + +import java.io.File; + +/** + * Configuration for the persistence driver. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class TuttiPersistenceAdagioConfig { + + protected final ApplicationConfig config; + + public TuttiPersistenceAdagioConfig(ApplicationConfig config) { + this.config = config; + config.loadDefaultOptions(TuttiPersistenceAdagioConfigOption.values()); + } + + public File getDbDirectory() { + return config.getOptionAsFile(TuttiPersistenceAdagioConfigOption.DB_PATH.getKey()); + } + + public File getDbName() { + return config.getOptionAsFile(TuttiPersistenceAdagioConfigOption.DB_NAME.getKey()); + } + + public File getDbConfigurationPath() { + return config.getOptionAsFile(TuttiPersistenceAdagioConfigOption.DB_CONFIGURATION_PATH.getKey()); + } + + public File getDbMappingPath() { + return config.getOptionAsFile(TuttiPersistenceAdagioConfigOption.BB_MAPPING_PATH.getKey()); + } + + public ApplicationConfig getConfig() { + return config; + } + +} \ No newline at end of file Property changes on: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/TuttiPersistenceAdagioConfig.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/TuttiPersistenceAdagioConfigOption.java =================================================================== --- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/TuttiPersistenceAdagioConfigOption.java (rev 0) +++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/TuttiPersistenceAdagioConfigOption.java 2012-12-17 07:36:36 UTC (rev 80) @@ -0,0 +1,141 @@ +package fr.ifremer.tutti.persistence.config; + +/* + * #%L + * Tutti :: Persistence Adagio (impl) + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.nuiton.util.ApplicationConfig; + +import java.io.File; + +/** + * Persistence configuration options. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public enum TuttiPersistenceAdagioConfigOption implements ApplicationConfig.OptionDef { + + DB_PATH("tutti.persistence.dbPath", + "Répertoire où est la base de données", + "${tutti.data.directory}/db", + File.class, + true, + true), + DB_NAME("tutti.persistence.dbName", + "Nom du fichier de la base de données", + "tutti", + String.class, + true, + true), + + DB_CONFIGURATION_PATH("tutti.persistence.dbConfigurationµPath", + "Chemin du fichier de configuration de la base", + "${tutti.data.directory}/dbConfiguration.properties", + File.class, + true, + true), + BB_MAPPING_PATH("tutti.persistence.dbMappingPath", + "Chemin du fichier de mapping des constantes de la base", + "${tutti.data.directory}/dbMapping.properties", + File.class, + true, + true); + + /** Configuration key. */ + private final String key; + + /** I18n key of option description */ + private final String description; + + /** Type of option */ + private final Class<?> type; + + /** Default value of option. */ + private String defaultValue; + + /** Flag to not keep option value on disk */ + private boolean isTransient; + + /** Flag to not allow option value modification */ + private boolean isFinal; + + TuttiPersistenceAdagioConfigOption(String key, + String description, + String defaultValue, + Class<?> type, + boolean isTransient, + boolean isFinal) { + this.key = key; + this.description = description; + this.defaultValue = defaultValue; + this.type = type; + this.isTransient = isTransient; + this.isFinal = isFinal; + } + + @Override + public String getKey() { + return key; + } + + @Override + public Class<?> getType() { + return type; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public String getDefaultValue() { + return defaultValue; + } + + @Override + public boolean isTransient() { + return isTransient; + } + + @Override + public boolean isFinal() { + return isFinal; + } + + @Override + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } + + @Override + public void setTransient(boolean newValue) { + // not used + } + + @Override + public void setFinal(boolean newValue) { + // not used + } +} \ No newline at end of file Property changes on: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/TuttiPersistenceAdagioConfigOption.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/TuttiPersistenceAdagioProvider.java =================================================================== --- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/TuttiPersistenceAdagioProvider.java (rev 0) +++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/TuttiPersistenceAdagioProvider.java 2012-12-17 07:36:36 UTC (rev 80) @@ -0,0 +1,59 @@ +package fr.ifremer.tutti.persistence.config; + +/* + * #%L + * Tutti :: Persistence Adagio (impl) + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.nuiton.util.ApplicationConfig; +import org.nuiton.util.ApplicationConfigProvider; + +import java.util.Locale; + +/** + * Persistence config provider (for site generation). + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class TuttiPersistenceAdagioProvider implements ApplicationConfigProvider { + + @Override + public String getName() { + return "tutti-adagio-persistence"; + } + + @Override + public String getDescription(Locale locale) { + return "Configuration de la persistence de Tutti (Adagio implantation)."; + } + + @Override + public ApplicationConfig.OptionDef[] getOptions() { + return TuttiPersistenceAdagioConfigOption.values(); + } + + @Override + public ApplicationConfig.ActionDef[] getActions() { + return new ApplicationConfig.ActionDef[0]; + } +} Property changes on: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/config/TuttiPersistenceAdagioProvider.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/tutti-persistence-adagio/src/test/resources/conf.properties =================================================================== --- trunk/tutti-persistence-adagio/src/test/resources/conf.properties 2012-12-17 07:32:05 UTC (rev 79) +++ trunk/tutti-persistence-adagio/src/test/resources/conf.properties 2012-12-17 07:36:36 UTC (rev 80) @@ -21,21 +21,6 @@ # <http://www.gnu.org/licenses/gpl-3.0.html>. # #L% ### -#-------------------------------------------------------------------------- -# -# WARNING : For UNIT TEST ONLY -# -------------- -# Configuration file for agadio-persistence -# -# project : ${pom.name} -# version : ${pom.version} for ${pom.env} -# env : ${pom.env} - ${pom.profil} -# date : ${pom.date.fr} -# -# Copyright INRH/Ifremer 2012 -# -# 25/11/12 BL Creation -#-------------------------------------------------------------------------- # dataSource : jndi ou local dataSource.type=local @@ -50,6 +35,7 @@ dataSource.jdbc.username=sa dataSource.jdbc.password= dataSource.jdbc.url=jdbc:hsqldb:file:src/test/db/allegro +#dataSource.jdbc.url=jdbc:hsqldb:file:${tutti.persistence.dbPath}/${tutti.persistence.dbName} #dataSource.jdbc.url=jdbc:hsqldb:hsql://localhost/toto # Hibernate configuration : Added: trunk/tutti-persistence-adagio/src/test/resources/tutti-test.properties =================================================================== --- trunk/tutti-persistence-adagio/src/test/resources/tutti-test.properties (rev 0) +++ trunk/tutti-persistence-adagio/src/test/resources/tutti-test.properties 2012-12-17 07:36:36 UTC (rev 80) @@ -0,0 +1,24 @@ +### +# #%L +# Tutti :: Persistence Adagio (impl) +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2012 Ifremer +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/gpl-3.0.html>. +# #L% +### +tutti.data.directory=${testDirectory} Property changes on: trunk/tutti-persistence-adagio/src/test/resources/tutti-test.properties ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native
participants (1)
-
tchemit@users.forge.codelutin.com