From 0bddcc2c50415962116a76d34130f2491a56ea32 Mon Sep 17 00:00:00 2001 From: Sebastien Weber Date: Mon, 2 Mar 2015 15:23:21 +0100 Subject: [PATCH 1/5] UNTRACKED: New parameter "db.bootPassword" to access encrypted database files --- derbydump.properties.sample | 4 ++-- .../ish/derbydump/derbydump/config/Configuration.java | 10 ++++++++++ .../au/com/ish/derbydump/derbydump/main/DerbyDump.java | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/derbydump.properties.sample b/derbydump.properties.sample index f9aeba9..d367670 100644 --- a/derbydump.properties.sample +++ b/derbydump.properties.sample @@ -18,7 +18,7 @@ db.derbyDbPath = ~/databaseFolder db.schemaName = databaseName db.userName = root db.password = secret! - +db.bootPassword = topsecret! ## Internal options ## # buffer size in kB. Must be larger than the largest row. defaults to 8912 @@ -42,4 +42,4 @@ output.truncateTables = true # in order to output the Derby table CONTACT as "Contact" # # If the right side is "--exclude--" then this table is not included in the output -tableRewritePath = tableRewrite.txt \ No newline at end of file +tableRewritePath = tableRewrite.txt diff --git a/src/main/java/au/com/ish/derbydump/derbydump/config/Configuration.java b/src/main/java/au/com/ish/derbydump/derbydump/config/Configuration.java index 13d3d0b..0241919 100644 --- a/src/main/java/au/com/ish/derbydump/derbydump/config/Configuration.java +++ b/src/main/java/au/com/ish/derbydump/derbydump/config/Configuration.java @@ -63,6 +63,8 @@ public String getDerbyUrl() { stringBuilder.append(";create=false;"); stringBuilder.append("user=").append(getUserName()).append(";"); stringBuilder.append("password=").append(getPassword()).append(";"); + stringBuilder.append("bootPassword=").append(getBootPassword()).append(";"); + return stringBuilder.toString(); } @@ -97,6 +99,14 @@ public void setPassword(String password) { prop.setProperty("db.password", password); } + public String getBootPassword() { + return prop.getProperty("db.bootPassword"); + } + + public void setBootPassword(String bootPassword) { + prop.setProperty("db.bootPassword", bootPassword); + } + public String getDriverClassName() { return prop.getProperty("db.driverClassName"); } diff --git a/src/main/java/au/com/ish/derbydump/derbydump/main/DerbyDump.java b/src/main/java/au/com/ish/derbydump/derbydump/main/DerbyDump.java index 4954257..d08a073 100644 --- a/src/main/java/au/com/ish/derbydump/derbydump/main/DerbyDump.java +++ b/src/main/java/au/com/ish/derbydump/derbydump/main/DerbyDump.java @@ -31,6 +31,7 @@ public static void main(String[] args) { LOGGER.debug("Configuration:"); LOGGER.debug("\tuser =" + config.getUserName()); LOGGER.debug("\tpassword =" + config.getPassword()); + LOGGER.debug("\tbootPassword =" + config.getBootPassword()); LOGGER.debug("\tderbyDbPath =" + config.getDerbyDbPath()); LOGGER.debug("\tdriverName =" + config.getDriverClassName()); LOGGER.debug("\tschema =" + config.getSchemaName()); From c03da816574f9dbd94d279738d83c41f3be6c2e8 Mon Sep 17 00:00:00 2001 From: Sebastien Weber Date: Mon, 2 Mar 2015 15:34:33 +0100 Subject: [PATCH 2/5] UNTRACKED: Path to built jar is incorrect. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5992aec..5fc08a7 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Derby SQL dump. This project will take a Derby database and export the data in i 4. # cp derbydump.properties.sample derbydump.properties 5. Edit derbydump.properties for your needs 6. # ./gradlew jar -7. # java -jar build/lib/derbydump-1.0-SNAPSHOT.jar +7. # java -jar build/libs/derbydump-*.jar ## Continuous integration testing From 68e0f17ed644c432a41b37cd30dd3e61a2246f4f Mon Sep 17 00:00:00 2001 From: Sebastien Weber Date: Tue, 3 Mar 2015 11:39:53 +0100 Subject: [PATCH 3/5] UNTRACK: Properties file is now given as argument. --- .../derbydump/derbydump/config/Configuration.java | 12 ++++++++---- .../com/ish/derbydump/derbydump/main/DerbyDump.java | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/au/com/ish/derbydump/derbydump/config/Configuration.java b/src/main/java/au/com/ish/derbydump/derbydump/config/Configuration.java index 0241919..73b8e2b 100644 --- a/src/main/java/au/com/ish/derbydump/derbydump/config/Configuration.java +++ b/src/main/java/au/com/ish/derbydump/derbydump/config/Configuration.java @@ -29,9 +29,9 @@ public class Configuration { private Properties prop = new Properties(); private Properties tableRewriteProp = new Properties(); - private Configuration() { + private Configuration(String configurationFile) { try { - FileInputStream file = new FileInputStream("derbydump.properties"); + FileInputStream file = new FileInputStream(configurationFile); prop.load(file); file.close(); @@ -49,12 +49,16 @@ private Configuration() { } - public static synchronized Configuration getConfiguration() { + public static synchronized Configuration getConfiguration(String configurationFile) { if (configuration == null) { - configuration = new Configuration(); + configuration = new Configuration(configurationFile); } return configuration; } + + public static synchronized Configuration getConfiguration() { + return configuration; + } public String getDerbyUrl() { StringBuilder stringBuilder = new StringBuilder(); diff --git a/src/main/java/au/com/ish/derbydump/derbydump/main/DerbyDump.java b/src/main/java/au/com/ish/derbydump/derbydump/main/DerbyDump.java index d08a073..38c2a13 100644 --- a/src/main/java/au/com/ish/derbydump/derbydump/main/DerbyDump.java +++ b/src/main/java/au/com/ish/derbydump/derbydump/main/DerbyDump.java @@ -26,7 +26,7 @@ public class DerbyDump { public static void main(String[] args) { - Configuration config = Configuration.getConfiguration(); + Configuration config = Configuration.getConfiguration(args[0]); LOGGER.debug("Configuration:"); LOGGER.debug("\tuser =" + config.getUserName()); From b8b7b1be5419ddd50597d63dbe21ee2798340636 Mon Sep 17 00:00:00 2001 From: Sebastien Weber Date: Tue, 3 Mar 2015 11:49:54 +0100 Subject: [PATCH 4/5] UNTRACK: README file now contains last valid information. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5fc08a7..92ded17 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Derby SQL dump. This project will take a Derby database and export the data in i 4. # cp derbydump.properties.sample derbydump.properties 5. Edit derbydump.properties for your needs 6. # ./gradlew jar -7. # java -jar build/libs/derbydump-*.jar +7. # java -jar build/libs/derbydump-*.jar derbydump.properties ## Continuous integration testing From b2f1a1d755b3f7100f6020115df9f43511fbd5fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Caillet?= Date: Tue, 3 Mar 2015 13:51:37 +0100 Subject: [PATCH 5/5] UNTRACKED: Extract a subset of tables --- derbydump.properties.sample | 2 ++ .../derbydump/config/Configuration.java | 17 +++++++++++ .../derbydump/main/DatabaseReader.java | 30 ++++++++++++++----- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/derbydump.properties.sample b/derbydump.properties.sample index d367670..4b06aa8 100644 --- a/derbydump.properties.sample +++ b/derbydump.properties.sample @@ -19,6 +19,8 @@ db.schemaName = databaseName db.userName = root db.password = secret! db.bootPassword = topsecret! +# Names of tables ordered to ensure the constraints validity +db.tableNames = BYTE_FILE,PROGRAM,PROGRAM_OS_VERSION,DOMAIN_REF,SECURITYGROUP_REF,SOLUTION,SOLUTION_PROGRAM,PACKAGED_SOLUTION,APPLICATION_DOMAIN,APP_ACCESS_RIGHT,ACCESSRIGHT_PROGRAM,PACKAGED_SOLUTION_BYTE_FILE,PARAMETER,ACL ## Internal options ## # buffer size in kB. Must be larger than the largest row. defaults to 8912 diff --git a/src/main/java/au/com/ish/derbydump/derbydump/config/Configuration.java b/src/main/java/au/com/ish/derbydump/derbydump/config/Configuration.java index 73b8e2b..e90f9de 100644 --- a/src/main/java/au/com/ish/derbydump/derbydump/config/Configuration.java +++ b/src/main/java/au/com/ish/derbydump/derbydump/config/Configuration.java @@ -17,6 +17,9 @@ package au.com.ish.derbydump.derbydump.config; import java.io.FileInputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Properties; /** @@ -28,6 +31,7 @@ public class Configuration { private static Configuration configuration; private Properties prop = new Properties(); private Properties tableRewriteProp = new Properties(); + private List tableNames = new ArrayList(); private Configuration(String configurationFile) { try { @@ -45,6 +49,11 @@ private Configuration(String configurationFile) { } } + String tablesProp = prop.getProperty("db.tableNames"); + if (tablesProp != null) { + tableNames = Arrays.asList(tablesProp.split(",")); + } + } catch (Exception ignored) {} } @@ -172,4 +181,12 @@ public boolean getTruncateTables() { } return Boolean.valueOf(prop.getProperty("output.truncateTables").trim()); } + + public List getTableNames() { + return tableNames; + } + + public void setTableNames(List tableNames) { + this.tableNames = tableNames; + } } diff --git a/src/main/java/au/com/ish/derbydump/derbydump/main/DatabaseReader.java b/src/main/java/au/com/ish/derbydump/derbydump/main/DatabaseReader.java index 044b26a..786ed51 100644 --- a/src/main/java/au/com/ish/derbydump/derbydump/main/DatabaseReader.java +++ b/src/main/java/au/com/ish/derbydump/derbydump/main/DatabaseReader.java @@ -16,19 +16,21 @@ package au.com.ish.derbydump.derbydump.main; -import au.com.ish.derbydump.derbydump.config.Configuration; -import au.com.ish.derbydump.derbydump.config.DBConnectionManager; -import au.com.ish.derbydump.derbydump.metadata.Column; -import au.com.ish.derbydump.derbydump.metadata.Database; -import au.com.ish.derbydump.derbydump.metadata.Table; -import org.apache.log4j.Logger; - import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.ArrayList; import java.util.List; +import org.apache.log4j.Logger; + +import au.com.ish.derbydump.derbydump.config.Configuration; +import au.com.ish.derbydump.derbydump.config.DBConnectionManager; +import au.com.ish.derbydump.derbydump.metadata.Column; +import au.com.ish.derbydump.derbydump.metadata.Database; +import au.com.ish.derbydump.derbydump.metadata.Table; + /** * Logical module representing a reader/producer which reads from a database and * writes to a buffer. @@ -62,7 +64,7 @@ void readMetaData(String schema) { MetadataReader metadata = new MetadataReader(); LOGGER.debug("Resolving database structure..."); Database database = metadata.readDatabase(db.getConnection()); - getInternalData(database.getTables(), db.getConnection(), schema); + getInternalData(getOrderedSubSet(database.getTables()), db.getConnection(), schema); try { db.getConnection().close(); @@ -72,6 +74,18 @@ void readMetaData(String schema) { } + private List getOrderedSubSet(List
tables) { + List tableNames = config.getTableNames(); + List
toReturn = new ArrayList
(tableNames.size()); + for (Table table : tables) { + if (tableNames.contains(table.getTableName())) { + int index = tableNames.indexOf(table.getTableName()); + toReturn.add(index, table); + } + } + return toReturn; + } + /** * Read data from each {@link Table} and add it to * the output.