Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 derbydump.properties


## Continuous integration testing
Expand Down
6 changes: 4 additions & 2 deletions derbydump.properties.sample
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ db.derbyDbPath = ~/databaseFolder
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
Expand All @@ -42,4 +44,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
tableRewritePath = tableRewrite.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -28,10 +31,11 @@ public class Configuration {
private static Configuration configuration;
private Properties prop = new Properties();
private Properties tableRewriteProp = new Properties();
private List<String> tableNames = new ArrayList<String>();

private Configuration() {
private Configuration(String configurationFile) {
try {
FileInputStream file = new FileInputStream("derbydump.properties");
FileInputStream file = new FileInputStream(configurationFile);
prop.load(file);
file.close();

Expand All @@ -45,16 +49,25 @@ private Configuration() {
}
}

String tablesProp = prop.getProperty("db.tableNames");
if (tablesProp != null) {
tableNames = Arrays.asList(tablesProp.split(","));
}

} catch (Exception ignored) {}

}

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();
Expand All @@ -63,6 +76,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();
}
Expand Down Expand Up @@ -97,6 +112,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");
}
Expand Down Expand Up @@ -158,4 +181,12 @@ public boolean getTruncateTables() {
}
return Boolean.valueOf(prop.getProperty("output.truncateTables").trim());
}

public List<String> getTableNames() {
return tableNames;
}

public void setTableNames(List<String> tableNames) {
this.tableNames = tableNames;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand All @@ -72,6 +74,18 @@ void readMetaData(String schema) {

}

private List<Table> getOrderedSubSet(List<Table> tables) {
List<String> tableNames = config.getTableNames();
List<Table> toReturn = new ArrayList<Table>(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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ 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());
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());
Expand Down