Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3

Commits:

1 changed file:

Changes:

  • t3-installer/src/main/java/fr/ird/t3/tools/T3ApplicationInstaller.java
    ... ... @@ -33,11 +33,8 @@ import fr.ird.t3.entities.user.JdbcConfiguration;
    33 33
     import fr.ird.t3.services.DefaultT3ServiceContext;
    
    34 34
     import fr.ird.t3.services.T3ServiceContext;
    
    35 35
     import fr.ird.t3.services.T3ServiceFactory;
    
    36
    -import java.beans.PropertyChangeEvent;
    
    37
    -import java.beans.PropertyChangeListener;
    
    38 36
     import java.io.File;
    
    39 37
     import java.io.FileInputStream;
    
    40
    -import java.io.FilenameFilter;
    
    41 38
     import java.io.IOException;
    
    42 39
     import java.util.List;
    
    43 40
     import java.util.Locale;
    
    ... ... @@ -96,45 +93,39 @@ public class T3ApplicationInstaller {
    96 93
             }
    
    97 94
         }
    
    98 95
     
    
    99
    -    public static void usage() {
    
    100
    -        StringBuilder buffer = new StringBuilder(T3ApplicationInstaller.class.getSimpleName() + " requires 4 parameters :");
    
    101
    -        buffer.append("\n").append("- databse connection properties file");
    
    102
    -        buffer.append("\n").append("- postgis structure script creation");
    
    103
    -        buffer.append("\n").append("- referential scripts directory");
    
    104
    -        buffer.append("\n").append("- postgis data script").append("\n");
    
    105
    -        System.out.println(buffer.toString());
    
    96
    +    private static void usage() {
    
    97
    +        String buffer = T3ApplicationInstaller.class.getSimpleName() + " requires 4 parameters :" + "\n" + "- databse connection properties file" +
    
    98
    +                "\n" + "- postgis structure script creation" +
    
    99
    +                "\n" + "- referential scripts directory" +
    
    100
    +                "\n" + "- postgis data script" + "\n";
    
    101
    +        System.out.println(buffer);
    
    106 102
         }
    
    107 103
     
    
    108
    -    protected final File connectionFile;
    
    104
    +    private final File connectionFile;
    
    109 105
     
    
    110
    -    protected final File[] postgisDataFiles;
    
    106
    +    private final File[] postgisDataFiles;
    
    111 107
     
    
    112
    -    protected final File ddlScriptsDirectory;
    
    108
    +    private final File ddlScriptsDirectory;
    
    113 109
     
    
    114
    -    protected final File referentialScriptsDirectory;
    
    110
    +    private final File referentialScriptsDirectory;
    
    115 111
     
    
    116
    -    protected T3ServiceContext serviceContext;
    
    112
    +    private T3ServiceContext serviceContext;
    
    117 113
     
    
    118
    -    protected JdbcConfiguration jdbcConfiguration;
    
    114
    +    private JdbcConfiguration jdbcConfiguration;
    
    119 115
     
    
    120
    -    protected T3ApplicationInstaller(File connectionFile,
    
    121
    -                                     File ddlScriptsDirectory,
    
    122
    -                                     File referentialScriptsDirectory,
    
    123
    -                                     File postgisDataScript) {
    
    116
    +    private T3ApplicationInstaller(File connectionFile,
    
    117
    +                                   File ddlScriptsDirectory,
    
    118
    +                                   File referentialScriptsDirectory,
    
    119
    +                                   File postgisDataScript) {
    
    124 120
             this.connectionFile = connectionFile;
    
    125 121
             this.ddlScriptsDirectory = ddlScriptsDirectory;
    
    126 122
             this.referentialScriptsDirectory = referentialScriptsDirectory;
    
    127 123
     
    
    128
    -        postgisDataFiles = postgisDataScript.listFiles(new FilenameFilter() {
    
    129
    -            @Override
    
    130
    -            public boolean accept(File dir, String name) {
    
    131
    -                return name.endsWith(".zip");
    
    132
    -            }
    
    133
    -        });
    
    124
    +        postgisDataFiles = postgisDataScript.listFiles((dir, name) -> name.endsWith(".zip"));
    
    134 125
     
    
    135 126
         }
    
    136 127
     
    
    137
    -    public void run() throws Exception {
    
    128
    +    private void run() throws Exception {
    
    138 129
             if (log.isInfoEnabled()) {
    
    139 130
                 log.info("1/6 - Setup installer...");
    
    140 131
             }
    
    ... ... @@ -148,7 +139,7 @@ public class T3ApplicationInstaller {
    148 139
             if (log.isInfoEnabled()) {
    
    149 140
                 log.info("3/6 - Create database schema...");
    
    150 141
             }
    
    151
    -        createDatabase();
    
    142
    +        boolean schemaFound = createDatabase();
    
    152 143
     
    
    153 144
             T3SqlScriptsImporter dllScriptsImporter = new T3SqlScriptsImporter(ddlScriptsDirectory);
    
    154 145
             dllScriptsImporter.prepare();
    
    ... ... @@ -157,7 +148,11 @@ public class T3ApplicationInstaller {
    157 148
                 log.info("4/6 - Loading ddl from " + dllScriptsImporter.getScriptsFile().size() + " scripts.");
    
    158 149
             }
    
    159 150
     
    
    160
    -        dllScriptsImporter.importScripts(serviceContext, file -> true);
    
    151
    +        if (schemaFound) {
    
    152
    +            log.info("4/6 - Loading ddl skip (schema already exists)");
    
    153
    +        } else {
    
    154
    +            dllScriptsImporter.importScripts(serviceContext, file -> true);
    
    155
    +        }
    
    161 156
     
    
    162 157
             T3SqlScriptsImporter referentialScriptsImporter = new T3SqlScriptsImporter(referentialScriptsDirectory);
    
    163 158
             referentialScriptsImporter.prepare();
    
    ... ... @@ -168,7 +163,7 @@ public class T3ApplicationInstaller {
    168 163
             }
    
    169 164
             referentialScriptsImporter.importScripts(serviceContext, file -> true);
    
    170 165
     
    
    171
    -        File unzipDirectory = createUnzipDirectory("postgis-data");
    
    166
    +        File unzipDirectory = createUnzipDirectory();
    
    172 167
     
    
    173 168
             if (log.isInfoEnabled()) {
    
    174 169
                 log.info("6/6 - Import postGis data from " + postgisDataFiles.length + " scripts.");
    
    ... ... @@ -187,7 +182,7 @@ public class T3ApplicationInstaller {
    187 182
             }
    
    188 183
         }
    
    189 184
     
    
    190
    -    protected void setup() throws IOException {
    
    185
    +    private void setup() throws IOException {
    
    191 186
     
    
    192 187
     
    
    193 188
             // initialize configuration
    
    ... ... @@ -232,7 +227,7 @@ public class T3ApplicationInstaller {
    232 227
             );
    
    233 228
         }
    
    234 229
     
    
    235
    -    protected void checkDatabaseConnection() throws IOException {
    
    230
    +    private void checkDatabaseConnection() throws IOException {
    
    236 231
     
    
    237 232
             // check jdbc connection
    
    238 233
             try {
    
    ... ... @@ -245,7 +240,7 @@ public class T3ApplicationInstaller {
    245 240
             }
    
    246 241
         }
    
    247 242
     
    
    248
    -    protected void createDatabase() {
    
    243
    +    private boolean createDatabase() {
    
    249 244
     
    
    250 245
     
    
    251 246
             try {
    
    ... ... @@ -261,12 +256,15 @@ public class T3ApplicationInstaller {
    261 256
                     rootContext.createSchema();
    
    262 257
     
    
    263 258
                 }
    
    259
    +            return schemaFound;
    
    260
    +
    
    264 261
             } catch (TopiaException e) {
    
    265 262
                 throw new IllegalStateException("could not start db", e);
    
    266 263
             }
    
    264
    +
    
    267 265
         }
    
    268 266
     
    
    269
    -    protected File unzipFile(File unzipDirectory, File script) throws IOException {
    
    267
    +    private File unzipFile(File unzipDirectory, File script) throws IOException {
    
    270 268
     
    
    271 269
             List<String>[] lists = ZipUtil.scanAndExplodeZip(script, unzipDirectory, null);
    
    272 270
             ZipUtil.uncompress(script, unzipDirectory);
    
    ... ... @@ -275,30 +273,24 @@ public class T3ApplicationInstaller {
    275 273
             return result;
    
    276 274
         }
    
    277 275
     
    
    278
    -    protected File createUnzipDirectory(String name) throws IOException {
    
    276
    +    private File createUnzipDirectory() throws IOException {
    
    279 277
             String tmpPath = System.getProperty("java.io.tmpdir");
    
    280 278
             File tmpDir = new File(tmpPath);
    
    281
    -        File unzupDirectory = new File(tmpDir, name + "_" + System.nanoTime());
    
    279
    +        File unzupDirectory = new File(tmpDir, "postgis-data" + "_" + System.nanoTime());
    
    282 280
             unzupDirectory.deleteOnExit();
    
    283 281
             FileUtil.createDirectoryIfNecessary(unzupDirectory);
    
    284 282
             return unzupDirectory;
    
    285 283
         }
    
    286 284
     
    
    287
    -    protected void loadScriptLineByLine(File script) throws TopiaException, IOException {
    
    285
    +    private void loadScriptLineByLine(File script) throws TopiaException, IOException {
    
    288 286
     
    
    289 287
     
    
    290
    -            T3ScriptHelper.loadScriptLineByLine(serviceContext.getApplicationContext(), script, new PropertyChangeListener() {
    
    291
    -                @Override
    
    292
    -                public void propertyChange(PropertyChangeEvent evt) {
    
    293
    -                    if (log.isInfoEnabled()) {
    
    294
    -                        log.info("Sql line " + evt.getNewValue() + " done.");
    
    295
    -                    }
    
    296
    -                }
    
    297
    -            });
    
    288
    +        T3ScriptHelper.loadScriptLineByLine(serviceContext.getApplicationContext(), script,
    
    289
    +                                            evt -> log.debug("Sql line " + evt.getNewValue() + " done."));
    
    298 290
         }
    
    299 291
     
    
    300 292
     
    
    301
    -    protected void destroy() {
    
    293
    +    private void destroy() {
    
    302 294
     
    
    303 295
             T3EntityHelper.releaseRootContext(serviceContext.getApplicationContext());
    
    304 296
         }