Skip to content
Snippets Groups Projects
Commit 29ffe2d4 authored by brinn's avatar brinn
Browse files

fix: NPE

improve: logging

SVN: 827
parent e9fbd847
No related branches found
No related tags found
No related merge requests found
...@@ -28,22 +28,23 @@ import ch.systemsx.cisd.common.utilities.FileUtilities; ...@@ -28,22 +28,23 @@ import ch.systemsx.cisd.common.utilities.FileUtilities;
/** /**
* Implementation of {@link ISqlScriptProvider} based on files in classpath or working directory. This provider tries * Implementation of {@link ISqlScriptProvider} based on files in classpath or working directory. This provider tries
* first to load a resource. If this isn't successful the provider tries to look for files relative to the * first to load a resource. If this isn't successful the provider tries to look for files relative to the working
* working directory. * directory.
* *
* @author Franz-Josef Elmer * @author Franz-Josef Elmer
*/ */
public class SqlScriptProvider implements ISqlScriptProvider public class SqlScriptProvider implements ISqlScriptProvider
{ {
private static final String SQL_FILE_TYPE = ".sql"; private static final String SQL_FILE_TYPE = ".sql";
private static final Logger operationLog private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION, SqlScriptProvider.class);
= LogFactory.getLogger(LogCategory.OPERATION, SqlScriptProvider.class);
private final String schemaScriptFolder; private final String schemaScriptFolder;
private final String dataScriptFolder; private final String dataScriptFolder;
private final String internalScriptFolder; private final String internalScriptFolder;
/** /**
* Creates an instance for the specified folders and database type. The database type specifies the resource folder * 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. * relative to the package of this class where the scripts with method {@link #getScript(String)} are loaded.
...@@ -53,7 +54,7 @@ public class SqlScriptProvider implements ISqlScriptProvider ...@@ -53,7 +54,7 @@ public class SqlScriptProvider implements ISqlScriptProvider
String internalFolder = SqlScriptProvider.class.getPackage().getName().replace('.', '/') + "/" + databaseType; String internalFolder = SqlScriptProvider.class.getPackage().getName().replace('.', '/') + "/" + databaseType;
return new SqlScriptProvider(schemaScriptFolder, dataScriptFolder, internalFolder); return new SqlScriptProvider(schemaScriptFolder, dataScriptFolder, internalFolder);
} }
/** /**
* Creates an instance for the specified script folders. They are either resource folders or folders relative to the * Creates an instance for the specified script folders. They are either resource folders or folders relative to the
* working directory. * working directory.
...@@ -70,9 +71,11 @@ public class SqlScriptProvider implements ISqlScriptProvider ...@@ -70,9 +71,11 @@ public class SqlScriptProvider implements ISqlScriptProvider
} }
/** /**
* Returns the data script for the specified version. * Returns the data script for the specified version. The name of the script is expected to be
* The name of the script is expected to be *
* <pre>&lt;data script folder&gt;/&lt;version&gt;/data-&lt;version&gt;.sql</pre> * <pre>
* &lt;data script folder&gt;/&lt;version&gt;/data-&lt;version&gt;.sql
* </pre>
*/ */
public Script getDataScript(String version) public Script getDataScript(String version)
{ {
...@@ -80,9 +83,11 @@ public class SqlScriptProvider implements ISqlScriptProvider ...@@ -80,9 +83,11 @@ public class SqlScriptProvider implements ISqlScriptProvider
} }
/** /**
* Returns the migration script for the specified versions. * Returns the migration script for the specified versions. The name of the script is expected to be
* The name of the script is expected to be *
* <pre>&lt;schema script folder&gt;/migration/migration-&lt;fromVersion&gt;-&lt;toVersion&gt;.sql</pre> * <pre>
* &lt;schema script folder&gt;/migration/migration-&lt;fromVersion&gt;-&lt;toVersion&gt;.sql
* </pre>
*/ */
public Script getMigrationScript(String fromVersion, String toVersion) public Script getMigrationScript(String fromVersion, String toVersion)
{ {
...@@ -91,9 +96,11 @@ public class SqlScriptProvider implements ISqlScriptProvider ...@@ -91,9 +96,11 @@ public class SqlScriptProvider implements ISqlScriptProvider
} }
/** /**
* Returns the schema script for the specified version. * Returns the schema script for the specified version. The name of the script is expected to be
* The name of the script is expected to be *
* <pre>&lt;schema script folder&gt;/&lt;version&gt;/schema-&lt;version&gt;.sql</pre> * <pre>
* &lt;schema script folder&gt;/&lt;version&gt;/schema-&lt;version&gt;.sql
* </pre>
*/ */
public Script getSchemaScript(String version) public Script getSchemaScript(String version)
{ {
...@@ -139,18 +146,27 @@ public class SqlScriptProvider implements ISqlScriptProvider ...@@ -139,18 +146,27 @@ public class SqlScriptProvider implements ISqlScriptProvider
public File[] getMassUploadFiles(String version) public File[] getMassUploadFiles(String version)
{ {
final File dataFolder = new File(dataScriptFolder + "/" + version); final File dataFolder = new File(dataScriptFolder + "/" + version);
String[] csvFiles = dataFolder.list(new FilenameFilter() if (operationLog.isDebugEnabled())
{ {
public boolean accept(File dir, String name) operationLog.debug("Searching for mass upload files in directory '" + dataFolder.getAbsolutePath() + "'.");
}
String[] csvFiles = dataFolder.list(new FilenameFilter()
{ {
return name.endsWith(".csv"); public boolean accept(File dir, String name)
} {
}); return name.endsWith(".csv");
Arrays.sort(csvFiles); }
});
if (csvFiles == null) if (csvFiles == null)
{ {
operationLog.warn("Path '" + dataFolder.getAbsolutePath() + "' is not a directory.");
return new File[0]; return new File[0];
} }
Arrays.sort(csvFiles);
if (operationLog.isInfoEnabled())
{
operationLog.info("Found " + csvFiles.length + " files for mass uploading.");
}
final File[] csvPaths = new File[csvFiles.length]; final File[] csvPaths = new File[csvFiles.length];
for (int i = 0; i < csvFiles.length; ++i) for (int i = 0; i < csvFiles.length; ++i)
{ {
...@@ -159,5 +175,4 @@ public class SqlScriptProvider implements ISqlScriptProvider ...@@ -159,5 +175,4 @@ public class SqlScriptProvider implements ISqlScriptProvider
return csvPaths; return csvPaths;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment