From aff825048a8d8bbc455af1554f8b0515849c0dd3 Mon Sep 17 00:00:00 2001 From: brinn <brinn> Date: Tue, 3 Jul 2007 10:57:34 +0000 Subject: [PATCH] add: separate configuration option for the folder holding data for mass upload fix: mass upload with distribution SVN: 836 --- .../DatabaseConfigurationContext.java | 45 +++++++++++++++---- .../cisd/dbmigration/SqlScriptProvider.java | 15 ++++--- .../dbmigration/SqlScriptExecutorTest.java | 22 +++++++-- 3 files changed, 65 insertions(+), 17 deletions(-) diff --git a/dbmigration/source/java/ch/systemsx/cisd/dbmigration/DatabaseConfigurationContext.java b/dbmigration/source/java/ch/systemsx/cisd/dbmigration/DatabaseConfigurationContext.java index f2785b1fe0a..a2319f5e151 100644 --- a/dbmigration/source/java/ch/systemsx/cisd/dbmigration/DatabaseConfigurationContext.java +++ b/dbmigration/source/java/ch/systemsx/cisd/dbmigration/DatabaseConfigurationContext.java @@ -36,7 +36,7 @@ public class DatabaseConfigurationContext private String driver; private LobHandler lobHandler; - + private ISequencerScriptProvider sequencerScriptProvider; private String adminURL; @@ -51,14 +51,16 @@ public class DatabaseConfigurationContext private String folderOfDataScripts; + private String folderOfMassUploadFiles; + private String databaseKind; - + private String databaseType; private boolean createFromScratch; private DataSource dataSource; - + private DataSource adminDataSource; private String owner; @@ -66,7 +68,7 @@ public class DatabaseConfigurationContext private String basicDatabaseName; private String databaseName; - + public DatabaseConfigurationContext() { owner = System.getProperty("user.name"); @@ -100,7 +102,7 @@ public class DatabaseConfigurationContext myDataSource.setPassword(""); return myDataSource; } - + /** * Returns the {@link DataSource} of this data configuration. */ @@ -409,11 +411,38 @@ public class DatabaseConfigurationContext /** * Sets the folder which contains all Data SQL scripts. * - * @param scriptFolderOfDataScripts New value. Can be <code>null</code>. + * @param folderOfDataScripts New value. Can be <code>null</code>. + */ + public final void setFolderOfDataScripts(String folderOfDataScripts) + { + this.folderOfDataScripts = folderOfDataScripts; + } + + /** + * Returns the folder which contains the files for mass upload to the database. As a default value + * {@link #getFolderOfDataScripts()} will be returned if not definied by a non-<code>null</code> value in + * {@link #setFolderOfMassUploadFiles(String)}. + */ + public String getFolderOfMassUploadFiles() + { + return folderOfMassUploadFiles == null ? getFolderOfDataScripts() : folderOfMassUploadFiles; + } + + /** + * Sets the folder which contains the files for mass uploads. + * + * @param folderOfMassUploadFiles New value. Can be <code>null</code>. An empty value will be interpreted as + * <code>null</code>. */ - public final void setFolderOfDataScripts(String scriptFolderOfDataScripts) + public void setFolderOfMassUploadFiles(String folderOfMassUploadFiles) { - this.folderOfDataScripts = scriptFolderOfDataScripts; + if ("".equals(folderOfMassUploadFiles)) + { + this.folderOfMassUploadFiles = null; + } else + { + this.folderOfMassUploadFiles = folderOfMassUploadFiles; + } } } diff --git a/dbmigration/source/java/ch/systemsx/cisd/dbmigration/SqlScriptProvider.java b/dbmigration/source/java/ch/systemsx/cisd/dbmigration/SqlScriptProvider.java index 39a6b4e2fd9..c63c16ff352 100644 --- a/dbmigration/source/java/ch/systemsx/cisd/dbmigration/SqlScriptProvider.java +++ b/dbmigration/source/java/ch/systemsx/cisd/dbmigration/SqlScriptProvider.java @@ -43,16 +43,19 @@ public class SqlScriptProvider implements ISqlScriptProvider private final String dataScriptFolder; + private final String massUploadDataFolder; + private final String internalScriptFolder; /** * Creates an instance for the specified folders and database type. The database type specifies the resource folder * relative to the package of this class where the scripts with method {@link #getScript(String)} are loaded. */ - public static ISqlScriptProvider create(String schemaScriptFolder, String dataScriptFolder, String databaseType) + public static ISqlScriptProvider create(String schemaScriptFolder, String dataScriptFolder, + String massUploadDataFolder, String databaseType) { String internalFolder = SqlScriptProvider.class.getPackage().getName().replace('.', '/') + "/" + databaseType; - return new SqlScriptProvider(schemaScriptFolder, dataScriptFolder, internalFolder); + return new SqlScriptProvider(schemaScriptFolder, dataScriptFolder, massUploadDataFolder, internalFolder); } /** @@ -63,10 +66,12 @@ public class SqlScriptProvider implements ISqlScriptProvider * @param dataScriptFolder Folder of data scripts. * @param internalScriptFolder Folder for internal scripts. */ - SqlScriptProvider(String schemaScriptFolder, String dataScriptFolder, String internalScriptFolder) + SqlScriptProvider(String schemaScriptFolder, String dataScriptFolder, String massUploadDataFolder, + String internalScriptFolder) { this.schemaScriptFolder = schemaScriptFolder; this.dataScriptFolder = dataScriptFolder; + this.massUploadDataFolder = massUploadDataFolder; this.internalScriptFolder = internalScriptFolder; } @@ -145,7 +150,7 @@ public class SqlScriptProvider implements ISqlScriptProvider */ public File[] getMassUploadFiles(String version) { - final File dataFolder = new File(dataScriptFolder + "/" + version); + final File dataFolder = new File(massUploadDataFolder + "/" + version); if (operationLog.isDebugEnabled()) { operationLog.debug("Searching for mass upload files in directory '" + dataFolder.getAbsolutePath() + "'."); @@ -159,7 +164,7 @@ public class SqlScriptProvider implements ISqlScriptProvider }); if (csvFiles == null) { - operationLog.warn("Path '" + dataFolder.getAbsolutePath() + "' is not a directory."); + operationLog.warn("Path '" + dataFolder.getAbsolutePath() + "' is not a directory."); return new File[0]; } Arrays.sort(csvFiles); diff --git a/dbmigration/sourceTest/java/ch/systemsx/cisd/dbmigration/SqlScriptExecutorTest.java b/dbmigration/sourceTest/java/ch/systemsx/cisd/dbmigration/SqlScriptExecutorTest.java index 15c5f47c2ef..b497fc35d47 100644 --- a/dbmigration/sourceTest/java/ch/systemsx/cisd/dbmigration/SqlScriptExecutorTest.java +++ b/dbmigration/sourceTest/java/ch/systemsx/cisd/dbmigration/SqlScriptExecutorTest.java @@ -17,6 +17,7 @@ package ch.systemsx.cisd.dbmigration; import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertTrue; import java.io.File; import java.io.FileWriter; @@ -37,9 +38,11 @@ public class SqlScriptExecutorTest { private static final String TEMPORARY_DATA_SCRIPT_FOLDER_NAME = "temporaryDataScriptFolder"; private static final String TEMPORARY_SCHEMA_SCRIPT_FOLDER_NAME = "temporarySchemaScriptFolder"; + private static final String TEMPORARY_MASS_DATA_UPLOAD_FOLDER_NAME = "temporaryMassDataUploadFolder"; private static final String TEMPORARY_INTERNAL_SCRIPT_FOLDER_NAME = "temporaryInternalScriptFolder"; private static final File TEMP_SCHEMA_SCRIPT_FOLDER = new File(TEMPORARY_SCHEMA_SCRIPT_FOLDER_NAME); private static final File TEMP_DATA_SCRIPT_FOLDER = new File(TEMPORARY_DATA_SCRIPT_FOLDER_NAME); + private static final File TEMP_MASS_DATA_UPLOAD_FOLDER = new File(TEMPORARY_MASS_DATA_UPLOAD_FOLDER_NAME); private static final File TEMP_INTERNAL_SCRIPT_FOLDER = new File(TEMPORARY_INTERNAL_SCRIPT_FOLDER_NAME); private static final String MIGRATION = "migration"; private static final String VERSION = "042"; @@ -50,21 +53,23 @@ public class SqlScriptExecutorTest @BeforeClass public void setUpTestFiles() throws IOException { - TEMP_SCHEMA_SCRIPT_FOLDER.mkdir(); File schemaVersionFolder = new File(TEMP_SCHEMA_SCRIPT_FOLDER, VERSION); - schemaVersionFolder.mkdir(); + schemaVersionFolder.mkdirs(); write(new File(schemaVersionFolder, "schema-" + VERSION + ".sql"), "code: schema"); File migrationFolder = new File(TEMP_SCHEMA_SCRIPT_FOLDER, MIGRATION); migrationFolder.mkdir(); write(new File(migrationFolder, "migration-" + VERSION + "-" + VERSION2 + ".sql"), "code: migration"); - TEMP_DATA_SCRIPT_FOLDER.mkdir(); File dataVersionFolder = new File(TEMP_DATA_SCRIPT_FOLDER, VERSION); - dataVersionFolder.mkdir(); + dataVersionFolder.mkdirs(); write(new File(dataVersionFolder, "data-" + VERSION + ".sql"), "code: data"); TEMP_INTERNAL_SCRIPT_FOLDER.mkdir(); write(new File(TEMP_INTERNAL_SCRIPT_FOLDER, "hello.script"), "hello world!"); + File massUploaadVersionFolder = new File(TEMP_MASS_DATA_UPLOAD_FOLDER, VERSION); + massUploaadVersionFolder.mkdirs(); + write(new File(massUploaadVersionFolder, "1=test.csv"), "id,code\n1,bla"); sqlScriptProvider = new SqlScriptProvider(TEMPORARY_SCHEMA_SCRIPT_FOLDER_NAME, TEMPORARY_DATA_SCRIPT_FOLDER_NAME, + TEMPORARY_MASS_DATA_UPLOAD_FOLDER_NAME, TEMPORARY_INTERNAL_SCRIPT_FOLDER_NAME); } @@ -90,6 +95,7 @@ public class SqlScriptExecutorTest delete(TEMP_SCHEMA_SCRIPT_FOLDER); delete(TEMP_DATA_SCRIPT_FOLDER); delete(TEMP_INTERNAL_SCRIPT_FOLDER); + delete(TEMP_MASS_DATA_UPLOAD_FOLDER); } private void delete(File file) @@ -127,6 +133,14 @@ public class SqlScriptExecutorTest assertEquals("code: data", script.getCode().trim()); } + @Test void testGetMassUploadFiles() + { + final File[] massUploadFiles = sqlScriptProvider.getMassUploadFiles(VERSION); + assertEquals(1, massUploadFiles.length); + assertEquals("1=test.csv", massUploadFiles[0].getName()); + assertTrue(massUploadFiles[0].exists()); + } + @Test public void testGetNonExistingDataScript() { -- GitLab