Tony CHEMIT pushed to branch develop at ultreiaio / ird-t3
Commits:
-
3162de0a
by Tony CHEMIT at 2017-04-10T15:02:50+02:00
-
b70063d4
by Tony CHEMIT at 2017-04-10T15:03:17+02:00
10 changed files:
- t3-domain/src/main/java/fr/ird/t3/T3SqlScriptsImporter.java
- t3-domain/src/main/java/fr/ird/t3/entities/T3JdbcHelper.java
- − t3-domain/src/main/java/fr/ird/t3/entities/T3ScriptHelper.java
- t3-domain/src/test/java/fr/ird/t3/entities/AbstractDatabaseTest.java
- t3-domain/src/test/java/fr/ird/t3/entities/conversion/WeightCategoryLogBookConvertorProviderTest.java
- t3-domain/src/test/java/fr/ird/t3/entities/reference/LengthWeightConversionHelperTest.java
- t3-domain/src/test/java/fr/ird/t3/entities/reference/WeightCategoryTreatmentImplTest.java
- t3-installer/src/main/assembly/dist/debug.sh
- t3-installer/src/main/java/fr/ird/t3/tools/T3ApplicationInstaller.java
- t3-installer/src/test/java/fr/ird/t3/tools/db/reference/AbstractReferenceImporterIT.java
Changes:
| ... | ... | @@ -24,7 +24,6 @@ package fr.ird.t3; |
| 24 | 24 |
import com.google.common.base.Preconditions;
|
| 25 | 25 |
import com.google.common.collect.ImmutableSet;
|
| 26 | 26 |
import com.google.common.collect.Lists;
|
| 27 |
-import fr.ird.t3.entities.T3ScriptHelper;
|
|
| 28 | 27 |
import fr.ird.t3.services.T3ServiceContext;
|
| 29 | 28 |
import java.io.File;
|
| 30 | 29 |
import java.io.IOException;
|
| ... | ... | @@ -51,13 +50,13 @@ public class T3SqlScriptsImporter { |
| 51 | 50 |
/** Logger. */
|
| 52 | 51 |
private static final Log log = LogFactory.getLog(T3SqlScriptsImporter.class);
|
| 53 | 52 |
|
| 54 |
- protected final File scriptsDirectory;
|
|
| 53 |
+ private final File scriptsDirectory;
|
|
| 55 | 54 |
|
| 56 |
- protected ImmutableSet<File> scriptsFile;
|
|
| 55 |
+ private ImmutableSet<File> scriptsFile;
|
|
| 57 | 56 |
|
| 58 |
- public static final Predicate<File> SKIP_SPECIES_LENGTH_STEP_FILE = input -> !input.getName().toLowerCase().contains("specieslengthstep.sql");
|
|
| 57 |
+ static final Predicate<File> SKIP_SPECIES_LENGTH_STEP_FILE = input -> !input.getName().toLowerCase().contains("specieslengthstep.sql");
|
|
| 59 | 58 |
|
| 60 |
- public static void importReferential(File buildRootDirectory, T3ServiceContext serviceContext, Predicate<File> filePredicate) throws IOException, TopiaException {
|
|
| 59 |
+ static void importReferential(File buildRootDirectory, T3ServiceContext serviceContext, Predicate<File> filePredicate) throws IOException, TopiaException {
|
|
| 61 | 60 |
|
| 62 | 61 |
Version t3DataVersion = serviceContext.getApplicationConfiguration().getT3DataVersion();
|
| 63 | 62 |
File scriptsZip = Paths.get(buildRootDirectory.getAbsolutePath())
|
| ... | ... | @@ -92,12 +91,14 @@ public class T3SqlScriptsImporter { |
| 92 | 91 |
|
| 93 | 92 |
public void prepare() {
|
| 94 | 93 |
|
| 95 |
- List<String> scriptsName = Lists.newArrayList(scriptsDirectory.list((dir, name) -> name.endsWith(".sql")));
|
|
| 96 |
- Collections.sort(scriptsName);
|
|
| 94 |
+ String[] list = scriptsDirectory.list((dir, name) -> name.endsWith(".sql"));
|
|
| 97 | 95 |
ImmutableSet.Builder<File> filesBuilder = ImmutableSet.builder();
|
| 98 |
- |
|
| 99 |
- for (String ddlScriptName : scriptsName) {
|
|
| 100 |
- filesBuilder.add(new File(scriptsDirectory, ddlScriptName));
|
|
| 96 |
+ if (list != null) {
|
|
| 97 |
+ List<String> scriptsName = Lists.newArrayList(list);
|
|
| 98 |
+ Collections.sort(scriptsName);
|
|
| 99 |
+ for (String ddlScriptName : scriptsName) {
|
|
| 100 |
+ filesBuilder.add(new File(scriptsDirectory, ddlScriptName));
|
|
| 101 |
+ }
|
|
| 101 | 102 |
}
|
| 102 | 103 |
scriptsFile = filesBuilder.build();
|
| 103 | 104 |
}
|
| ... | ... | @@ -113,15 +114,11 @@ public class T3SqlScriptsImporter { |
| 113 | 114 |
log.info(" o Loading sql script ...(" + scriptFile.getName() + ")");
|
| 114 | 115 |
}
|
| 115 | 116 |
if (filePredicate.test(scriptFile)) {
|
| 116 |
- loadScript(serviceContext, scriptFile);
|
|
| 117 |
+ serviceContext.getApplicationContext().newJdbcHelper().executeSql(scriptFile);
|
|
| 117 | 118 |
}
|
| 118 | 119 |
}
|
| 119 | 120 |
|
| 120 | 121 |
}
|
| 121 | 122 |
|
| 122 |
- protected void loadScript(T3ServiceContext serviceContext, File script) throws IOException {
|
|
| 123 |
- |
|
| 124 |
- T3ScriptHelper.loadScript(serviceContext.getApplicationContext(), script);
|
|
| 125 |
- }
|
|
| 126 | 123 |
|
| 127 | 124 |
}
|
| ... | ... | @@ -21,12 +21,20 @@ package fr.ird.t3.entities; |
| 21 | 21 |
* #L%
|
| 22 | 22 |
*/
|
| 23 | 23 |
|
| 24 |
+import java.io.BufferedReader;
|
|
| 24 | 25 |
import java.io.File;
|
| 26 |
+import java.io.IOException;
|
|
| 27 |
+import java.io.InputStream;
|
|
| 28 |
+import java.io.InputStreamReader;
|
|
| 29 |
+import java.io.Reader;
|
|
| 30 |
+import java.nio.charset.StandardCharsets;
|
|
| 31 |
+import java.nio.file.Files;
|
|
| 25 | 32 |
import java.sql.Connection;
|
| 26 |
-import java.sql.PreparedStatement;
|
|
| 27 | 33 |
import java.sql.SQLException;
|
| 34 |
+import java.sql.Statement;
|
|
| 28 | 35 |
import org.nuiton.topia.persistence.jdbc.JdbcConfiguration;
|
| 29 | 36 |
import org.nuiton.topia.persistence.jdbc.JdbcHelper;
|
| 37 |
+import org.nuiton.util.sql.SqlFileReader;
|
|
| 30 | 38 |
|
| 31 | 39 |
/**
|
| 32 | 40 |
* Created by tchemit on 03/04/17.
|
| ... | ... | @@ -35,18 +43,63 @@ import org.nuiton.topia.persistence.jdbc.JdbcHelper; |
| 35 | 43 |
*/
|
| 36 | 44 |
public class T3JdbcHelper extends JdbcHelper {
|
| 37 | 45 |
|
| 38 |
- public T3JdbcHelper(JdbcConfiguration jdbcConfiguration) {
|
|
| 46 |
+ public static final int BUZZER_SIZE = 100;
|
|
| 47 |
+ |
|
| 48 |
+ T3JdbcHelper(JdbcConfiguration jdbcConfiguration) {
|
|
| 39 | 49 |
super(jdbcConfiguration);
|
| 40 | 50 |
}
|
| 41 | 51 |
|
| 42 |
- public void executeSql(String sql) {
|
|
| 52 |
+ public void executeSql(File file) {
|
|
| 53 |
+ |
|
| 54 |
+ try (BufferedReader bufferedReader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
|
|
| 55 |
+ executeSql(bufferedReader);
|
|
| 56 |
+ } catch (IOException e) {
|
|
| 57 |
+ throw new RuntimeException(e);
|
|
| 58 |
+ }
|
|
| 59 |
+ |
|
| 60 |
+ }
|
|
| 61 |
+ |
|
| 62 |
+ public void executeSql(InputStream file) {
|
|
| 63 |
+ |
|
| 64 |
+ try (InputStreamReader bufferedReader = new InputStreamReader(file, StandardCharsets.UTF_8)) {
|
|
| 65 |
+ executeSql(bufferedReader);
|
|
| 66 |
+ } catch (IOException e) {
|
|
| 67 |
+ throw new RuntimeException(e);
|
|
| 68 |
+ }
|
|
| 69 |
+ |
|
| 70 |
+ }
|
|
| 71 |
+ |
|
| 72 |
+ public void executeSql(Reader reader) {
|
|
| 73 |
+ |
|
| 43 | 74 |
try (Connection connection = openConnection()) {
|
| 44 |
- try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
|
| 45 |
- preparedStatement.execute();
|
|
| 75 |
+ try (Statement preparedStatement = connection.createStatement()) {
|
|
| 76 |
+ |
|
| 77 |
+ int currentBuffer = 0;
|
|
| 78 |
+ StringBuilder currentStatement = new StringBuilder();
|
|
| 79 |
+ for (String sqlStatement : new SqlFileReader(reader)) {
|
|
| 80 |
+ if (sqlStatement.startsWith("--")) {
|
|
| 81 |
+ continue;
|
|
| 82 |
+ }
|
|
| 83 |
+ currentStatement.append("\n").append(sqlStatement);
|
|
| 84 |
+ if (sqlStatement.trim().endsWith(";")) {
|
|
| 85 |
+ preparedStatement.addBatch(currentStatement.toString());
|
|
| 86 |
+ currentBuffer++;
|
|
| 87 |
+ currentStatement = new StringBuilder();
|
|
| 88 |
+ }
|
|
| 89 |
+ |
|
| 90 |
+ if (currentBuffer % BUZZER_SIZE == 0) {
|
|
| 91 |
+ preparedStatement.executeBatch();
|
|
| 92 |
+ preparedStatement.clearBatch();
|
|
| 93 |
+ }
|
|
| 94 |
+ }
|
|
| 95 |
+ preparedStatement.executeBatch();
|
|
| 96 |
+ preparedStatement.clearBatch();
|
|
| 46 | 97 |
}
|
| 47 | 98 |
} catch (SQLException e) {
|
| 48 | 99 |
throw new RuntimeException(e);
|
| 49 | 100 |
}
|
| 101 |
+ |
|
| 102 |
+ |
|
| 50 | 103 |
}
|
| 51 | 104 |
|
| 52 | 105 |
public void backup(File file, boolean compress) {
|
| 1 |
-/*
|
|
| 2 |
- * #%L
|
|
| 3 |
- * T3 :: Domain
|
|
| 4 |
- * %%
|
|
| 5 |
- * Copyright (C) 2010 - 2017 IRD, Code Lutin, Ultreia.io
|
|
| 6 |
- * %%
|
|
| 7 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 8 |
- * it under the terms of the GNU Affero General Public License as published by
|
|
| 9 |
- * the Free Software Foundation, either version 3 of the License, or
|
|
| 10 |
- * (at your option) any later version.
|
|
| 11 |
- *
|
|
| 12 |
- * This program is distributed in the hope that it will be useful,
|
|
| 13 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 14 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 15 |
- * GNU General Public License for more details.
|
|
| 16 |
- *
|
|
| 17 |
- * You should have received a copy of the GNU Affero General Public License
|
|
| 18 |
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
| 19 |
- * #L%
|
|
| 20 |
- */
|
|
| 21 |
-package fr.ird.t3.entities;
|
|
| 22 |
- |
|
| 23 |
-import com.google.common.base.Charsets;
|
|
| 24 |
-import java.beans.PropertyChangeEvent;
|
|
| 25 |
-import java.beans.PropertyChangeListener;
|
|
| 26 |
-import java.io.BufferedReader;
|
|
| 27 |
-import java.io.File;
|
|
| 28 |
-import java.io.FileInputStream;
|
|
| 29 |
-import java.io.IOException;
|
|
| 30 |
-import java.io.InputStream;
|
|
| 31 |
-import java.io.InputStreamReader;
|
|
| 32 |
-import java.sql.Connection;
|
|
| 33 |
-import java.sql.SQLException;
|
|
| 34 |
-import java.sql.Statement;
|
|
| 35 |
-import org.apache.commons.io.IOUtils;
|
|
| 36 |
-import org.apache.commons.logging.Log;
|
|
| 37 |
-import org.apache.commons.logging.LogFactory;
|
|
| 38 |
-import org.nuiton.topia.persistence.TopiaException;
|
|
| 39 |
-import org.nuiton.topia.persistence.support.TopiaSqlWork;
|
|
| 40 |
-import org.nuiton.util.sql.SqlFileReader;
|
|
| 41 |
- |
|
| 42 |
-/**
|
|
| 43 |
- * Usefull method to deal with sql scripts.
|
|
| 44 |
- *
|
|
| 45 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 46 |
- * @since 1.0
|
|
| 47 |
- */
|
|
| 48 |
-public class T3ScriptHelper {
|
|
| 49 |
- |
|
| 50 |
- /** Logger. */
|
|
| 51 |
- private static final Log log = LogFactory.getLog(T3ScriptHelper.class);
|
|
| 52 |
- |
|
| 53 |
- public static void exportDatabase(T3TopiaApplicationContext rootTx, File outputFile) throws TopiaException {
|
|
| 54 |
- |
|
| 55 |
- if (log.isInfoEnabled()) {
|
|
| 56 |
- log.info("Export database to file " + outputFile);
|
|
| 57 |
- }
|
|
| 58 |
- rootTx.newJdbcHelper().backup(outputFile, false);
|
|
| 59 |
- }
|
|
| 60 |
- |
|
| 61 |
- public static void loadReferentiel(T3TopiaApplicationContext tx, String location) throws IOException, TopiaException {
|
|
| 62 |
- try (InputStream resourceAsStream = T3EntityHelper.class.getResourceAsStream(location)) {
|
|
| 63 |
- loadScript(tx, resourceAsStream);
|
|
| 64 |
- }
|
|
| 65 |
- }
|
|
| 66 |
- |
|
| 67 |
- public static void loadScript(T3TopiaApplicationContext tx, InputStream resourceAsStream) throws IOException, TopiaException {
|
|
| 68 |
- |
|
| 69 |
- String script = IOUtils.toString(resourceAsStream, Charsets.UTF_8.name());
|
|
| 70 |
- |
|
| 71 |
- tx.newJdbcHelper().executeSql(script);
|
|
| 72 |
- |
|
| 73 |
- }
|
|
| 74 |
- |
|
| 75 |
- public static void loadScript(T3TopiaApplicationContext tx, File file) throws IOException, TopiaException {
|
|
| 76 |
- |
|
| 77 |
- try (InputStream resourceAsStream = new FileInputStream(file)) {
|
|
| 78 |
- loadScript(tx, resourceAsStream);
|
|
| 79 |
- }
|
|
| 80 |
- }
|
|
| 81 |
- |
|
| 82 |
- public static void loadScriptLineByLine(T3TopiaApplicationContext tx, File script, PropertyChangeListener listener) throws TopiaException, IOException {
|
|
| 83 |
- |
|
| 84 |
- try (BufferedReader stream = new BufferedReader(new InputStreamReader(new FileInputStream(script), Charsets.UTF_8))) {
|
|
| 85 |
- |
|
| 86 |
- try (T3TopiaPersistenceContext persistenceContext = tx.newPersistenceContext()) {
|
|
| 87 |
- |
|
| 88 |
- persistenceContext.getSqlSupport().doSqlWork(new TopiaSqlWork() {
|
|
| 89 |
- |
|
| 90 |
- final int batchSize = 100;
|
|
| 91 |
- int lineCount = 0;
|
|
| 92 |
- |
|
| 93 |
- void flushStatement(Statement statement) throws SQLException {
|
|
| 94 |
- |
|
| 95 |
- statement.executeBatch();
|
|
| 96 |
- statement.clearBatch();
|
|
| 97 |
- |
|
| 98 |
- }
|
|
| 99 |
- |
|
| 100 |
- @Override
|
|
| 101 |
- public void execute(Connection connection) throws SQLException {
|
|
| 102 |
- try (Statement statement = connection.createStatement()) {
|
|
| 103 |
- |
|
| 104 |
- int batchSize = 0;
|
|
| 105 |
- |
|
| 106 |
- for (String statementStr : new SqlFileReader(stream)) {
|
|
| 107 |
- |
|
| 108 |
- String trimLine = statementStr.trim();
|
|
| 109 |
- |
|
| 110 |
- if (trimLine.isEmpty() || trimLine.startsWith("--")) {
|
|
| 111 |
- continue;
|
|
| 112 |
- }
|
|
| 113 |
- if (log.isDebugEnabled()) {
|
|
| 114 |
- log.debug("Inject line : " + trimLine);
|
|
| 115 |
- }
|
|
| 116 |
- listener.propertyChange(new PropertyChangeEvent(script, "newLine", null, lineCount++));
|
|
| 117 |
- statement.addBatch(trimLine);
|
|
| 118 |
- batchSize++;
|
|
| 119 |
- |
|
| 120 |
- if (batchSize % this.batchSize == 0) {
|
|
| 121 |
- flushStatement(statement);
|
|
| 122 |
- }
|
|
| 123 |
- |
|
| 124 |
- }
|
|
| 125 |
- |
|
| 126 |
- flushStatement(statement);
|
|
| 127 |
- }
|
|
| 128 |
- }
|
|
| 129 |
- });
|
|
| 130 |
- }
|
|
| 131 |
- }
|
|
| 132 |
- |
|
| 133 |
- }
|
|
| 134 |
- |
|
| 135 |
- protected T3ScriptHelper() {
|
|
| 136 |
- // hide helper constructor
|
|
| 137 |
- }
|
|
| 138 |
-}
|
| ... | ... | @@ -22,6 +22,8 @@ package fr.ird.t3.entities; |
| 22 | 22 |
|
| 23 | 23 |
import fr.ird.t3.T3IOUtil;
|
| 24 | 24 |
import java.io.File;
|
| 25 |
+import java.io.IOException;
|
|
| 26 |
+import java.io.InputStream;
|
|
| 25 | 27 |
import org.junit.Rule;
|
| 26 | 28 |
import org.junit.rules.TestWatcher;
|
| 27 | 29 |
import org.junit.runner.Description;
|
| ... | ... | @@ -29,8 +31,6 @@ import org.nuiton.topia.persistence.TopiaException; |
| 29 | 31 |
|
| 30 | 32 |
public abstract class AbstractDatabaseTest {
|
| 31 | 33 |
|
| 32 |
- public static final long TIMESTAMP = System.nanoTime();
|
|
| 33 |
- |
|
| 34 | 34 |
@Rule
|
| 35 | 35 |
public T3Database db = new T3Database();
|
| 36 | 36 |
|
| ... | ... | @@ -71,16 +71,16 @@ public abstract class AbstractDatabaseTest { |
| 71 | 71 |
T3EntityHelper.releaseRootContext(rootCtxt);
|
| 72 | 72 |
}
|
| 73 | 73 |
|
| 74 |
- public File getTestBasedir() {
|
|
| 75 |
- return testBasedir;
|
|
| 76 |
- }
|
|
| 77 |
- |
|
| 78 |
- public T3TopiaApplicationContext getRootCtxt() {
|
|
| 79 |
- return rootCtxt;
|
|
| 80 |
- }
|
|
| 81 |
- |
|
| 82 | 74 |
public T3TopiaPersistenceContext beginTransaction() throws TopiaException {
|
| 83 | 75 |
return rootCtxt.newPersistenceContext();
|
| 84 | 76 |
}
|
| 77 |
+ |
|
| 78 |
+ public void loadClassPathScript(String location) {
|
|
| 79 |
+ try (InputStream resourceAsStream = getClass().getResourceAsStream(location)) {
|
|
| 80 |
+ rootCtxt.newJdbcHelper().executeSql(resourceAsStream);
|
|
| 81 |
+ } catch (IOException e) {
|
|
| 82 |
+ throw new TopiaException(e);
|
|
| 83 |
+ }
|
|
| 84 |
+ }
|
|
| 85 | 85 |
}
|
| 86 | 86 |
}
|
| ... | ... | @@ -21,7 +21,6 @@ |
| 21 | 21 |
package fr.ird.t3.entities.conversion;
|
| 22 | 22 |
|
| 23 | 23 |
import fr.ird.t3.entities.AbstractDatabaseTest;
|
| 24 |
-import fr.ird.t3.entities.T3ScriptHelper;
|
|
| 25 | 24 |
import fr.ird.t3.entities.T3TopiaPersistenceContext;
|
| 26 | 25 |
import org.junit.Assert;
|
| 27 | 26 |
import org.junit.Test;
|
| ... | ... | @@ -37,13 +36,10 @@ public class WeightCategoryLogBookConvertorProviderTest extends AbstractDatabase |
| 37 | 36 |
@Test
|
| 38 | 37 |
public void newInstance() throws Exception {
|
| 39 | 38 |
|
| 40 |
- T3ScriptHelper.loadReferentiel(
|
|
| 41 |
- db.getRootCtxt(),
|
|
| 42 |
- "/db/WeightCategoryLogBookConvertorProviderTest.sql");
|
|
| 39 |
+ db.loadClassPathScript("/db/WeightCategoryLogBookConvertorProviderTest.sql");
|
|
| 43 | 40 |
|
| 44 |
- try (T3TopiaPersistenceContext tx= beginTransaction()) {
|
|
| 45 |
- WeightCategoryLogBookConvertorProvider provider =
|
|
| 46 |
- WeightCategoryLogBookConvertorProvider.newInstance(tx);
|
|
| 41 |
+ try (T3TopiaPersistenceContext tx = beginTransaction()) {
|
|
| 42 |
+ WeightCategoryLogBookConvertorProvider provider = WeightCategoryLogBookConvertorProvider.newInstance(tx);
|
|
| 47 | 43 |
Assert.assertNotNull(provider);
|
| 48 | 44 |
}
|
| 49 | 45 |
|
| ... | ... | @@ -26,7 +26,6 @@ import com.google.common.collect.Lists; |
| 26 | 26 |
import com.google.common.collect.Range;
|
| 27 | 27 |
import com.google.common.collect.Sets;
|
| 28 | 28 |
import fr.ird.t3.entities.AbstractDatabaseTest;
|
| 29 |
-import fr.ird.t3.entities.T3ScriptHelper;
|
|
| 30 | 29 |
import fr.ird.t3.entities.T3TopiaPersistenceContext;
|
| 31 | 30 |
import fr.ird.t3.entities.type.T3Date;
|
| 32 | 31 |
import java.util.Date;
|
| ... | ... | @@ -49,8 +48,7 @@ public class LengthWeightConversionHelperTest extends AbstractDatabaseTest { |
| 49 | 48 |
@Before
|
| 50 | 49 |
public void setUp() throws Exception {
|
| 51 | 50 |
|
| 52 |
- T3ScriptHelper.loadReferentiel(
|
|
| 53 |
- db.getRootCtxt(), "/db/LengthWeightConversionHelperTest.sql");
|
|
| 51 |
+ db.loadClassPathScript("/db/LengthWeightConversionHelperTest.sql");
|
|
| 54 | 52 |
}
|
| 55 | 53 |
|
| 56 | 54 |
@Test
|
| ... | ... | @@ -23,7 +23,6 @@ package fr.ird.t3.entities.reference; |
| 23 | 23 |
import com.google.common.collect.Lists;
|
| 24 | 24 |
import com.google.common.collect.Maps;
|
| 25 | 25 |
import fr.ird.t3.entities.AbstractDatabaseTest;
|
| 26 |
-import fr.ird.t3.entities.T3ScriptHelper;
|
|
| 27 | 26 |
import fr.ird.t3.entities.T3TopiaPersistenceContext;
|
| 28 | 27 |
import java.util.Comparator;
|
| 29 | 28 |
import java.util.List;
|
| ... | ... | @@ -41,7 +40,7 @@ public class WeightCategoryTreatmentImplTest extends AbstractDatabaseTest { |
| 41 | 40 |
|
| 42 | 41 |
@Test
|
| 43 | 42 |
public void testGetOldCategoryCode() throws Exception {
|
| 44 |
- T3ScriptHelper.loadReferentiel(db.getRootCtxt(), "/db/WeightCategoryTreatmentImplTest.sql");
|
|
| 43 |
+ db.loadClassPathScript("/db/WeightCategoryTreatmentImplTest.sql");
|
|
| 45 | 44 |
|
| 46 | 45 |
try (T3TopiaPersistenceContext tx = beginTransaction()) {
|
| 47 | 46 |
WeightCategoryTreatmentTopiaDao dao = tx.getWeightCategoryTreatmentDao();
|
| ... | ... | @@ -27,7 +27,6 @@ import com.google.common.base.Preconditions; |
| 27 | 27 |
import fr.ird.t3.T3Config;
|
| 28 | 28 |
import fr.ird.t3.T3SqlScriptsImporter;
|
| 29 | 29 |
import fr.ird.t3.entities.T3EntityHelper;
|
| 30 |
-import fr.ird.t3.entities.T3ScriptHelper;
|
|
| 31 | 30 |
import fr.ird.t3.entities.T3TopiaApplicationContext;
|
| 32 | 31 |
import fr.ird.t3.entities.user.JdbcConfiguration;
|
| 33 | 32 |
import fr.ird.t3.services.DefaultT3ServiceContext;
|
| ... | ... | @@ -139,7 +138,7 @@ public class T3ApplicationInstaller { |
| 139 | 138 |
if (log.isInfoEnabled()) {
|
| 140 | 139 |
log.info("3/6 - Create database schema...");
|
| 141 | 140 |
}
|
| 142 |
- boolean schemaFound = createDatabase();
|
|
| 141 |
+ createDatabase();
|
|
| 143 | 142 |
|
| 144 | 143 |
T3SqlScriptsImporter dllScriptsImporter = new T3SqlScriptsImporter(ddlScriptsDirectory);
|
| 145 | 144 |
dllScriptsImporter.prepare();
|
| ... | ... | @@ -148,11 +147,7 @@ public class T3ApplicationInstaller { |
| 148 | 147 |
log.info("4/6 - Loading ddl from " + dllScriptsImporter.getScriptsFile().size() + " scripts.");
|
| 149 | 148 |
}
|
| 150 | 149 |
|
| 151 |
- if (schemaFound) {
|
|
| 152 |
- log.info("4/6 - Loading ddl skip (schema already exists)");
|
|
| 153 |
- } else {
|
|
| 154 |
- dllScriptsImporter.importScripts(serviceContext, file -> true);
|
|
| 155 |
- }
|
|
| 150 |
+ dllScriptsImporter.importScripts(serviceContext, file -> true);
|
|
| 156 | 151 |
|
| 157 | 152 |
T3SqlScriptsImporter referentialScriptsImporter = new T3SqlScriptsImporter(referentialScriptsDirectory);
|
| 158 | 153 |
referentialScriptsImporter.prepare();
|
| ... | ... | @@ -178,7 +173,7 @@ public class T3ApplicationInstaller { |
| 178 | 173 |
if (log.isInfoEnabled()) {
|
| 179 | 174 |
log.info(" o Load postGis data... from " + unzipFile + " script.");
|
| 180 | 175 |
}
|
| 181 |
- loadScriptLineByLine(unzipFile);
|
|
| 176 |
+ serviceContext.getApplicationContext().newJdbcHelper().executeSql(unzipFile);
|
|
| 182 | 177 |
}
|
| 183 | 178 |
}
|
| 184 | 179 |
|
| ... | ... | @@ -240,7 +235,7 @@ public class T3ApplicationInstaller { |
| 240 | 235 |
}
|
| 241 | 236 |
}
|
| 242 | 237 |
|
| 243 |
- private boolean createDatabase() {
|
|
| 238 |
+ private void createDatabase() {
|
|
| 244 | 239 |
|
| 245 | 240 |
|
| 246 | 241 |
try {
|
| ... | ... | @@ -256,7 +251,6 @@ public class T3ApplicationInstaller { |
| 256 | 251 |
rootContext.createSchema();
|
| 257 | 252 |
|
| 258 | 253 |
}
|
| 259 |
- return schemaFound;
|
|
| 260 | 254 |
|
| 261 | 255 |
} catch (TopiaException e) {
|
| 262 | 256 |
throw new IllegalStateException("could not start db", e);
|
| ... | ... | @@ -282,14 +276,6 @@ public class T3ApplicationInstaller { |
| 282 | 276 |
return unzupDirectory;
|
| 283 | 277 |
}
|
| 284 | 278 |
|
| 285 |
- private void loadScriptLineByLine(File script) throws TopiaException, IOException {
|
|
| 286 |
- |
|
| 287 |
- |
|
| 288 |
- T3ScriptHelper.loadScriptLineByLine(serviceContext.getApplicationContext(), script,
|
|
| 289 |
- evt -> log.debug("Sql line " + evt.getNewValue() + " done."));
|
|
| 290 |
- }
|
|
| 291 |
- |
|
| 292 |
- |
|
| 293 | 279 |
private void destroy() {
|
| 294 | 280 |
|
| 295 | 281 |
T3EntityHelper.releaseRootContext(serviceContext.getApplicationContext());
|
| ... | ... | @@ -24,7 +24,6 @@ |
| 24 | 24 |
package fr.ird.t3.tools.db.reference;
|
| 25 | 25 |
|
| 26 | 26 |
import fr.ird.t3.T3IOUtil;
|
| 27 |
-import fr.ird.t3.entities.T3ScriptHelper;
|
|
| 28 | 27 |
import fr.ird.t3.entities.T3TopiaPersistenceContext;
|
| 29 | 28 |
import fr.ird.t3.tools.AbstracToolTest;
|
| 30 | 29 |
import java.io.File;
|
| ... | ... | @@ -95,7 +94,13 @@ public abstract class AbstractReferenceImporterIT<E extends TopiaEntity, T exten |
| 95 | 94 |
|
| 96 | 95 |
// export referentiel
|
| 97 | 96 |
File outputFile = new File(inputFile.getParentFile(), "newReferentiel.sql");
|
| 98 |
- T3ScriptHelper.exportDatabase(serviceContext.getApplicationContext(), outputFile);
|
|
| 97 |
+ |
|
| 98 |
+ if (log.isInfoEnabled()) {
|
|
| 99 |
+ log.info("Export database to file " + outputFile);
|
|
| 100 |
+ }
|
|
| 101 |
+ |
|
| 102 |
+ serviceContext.getApplicationContext().newJdbcHelper().backup(outputFile, false);
|
|
| 103 |
+ |
|
| 99 | 104 |
}
|
| 100 | 105 |
|
| 101 | 106 |
public <T extends TopiaEntity> void deleteEntities(Class<T> entityType) {
|