Skip to content

Commit

Permalink
Merge pull request #110 from keeps/bf-access
Browse files Browse the repository at this point in the history
Microsoft Windows and Microsoft Access support
  • Loading branch information
luis100 committed Nov 30, 2015
2 parents ef2cdf0 + 355e7d1 commit fec2aa6
Show file tree
Hide file tree
Showing 20 changed files with 265 additions and 92 deletions.
2 changes: 1 addition & 1 deletion dbptk-bindings/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>com.databasepreservation</groupId>
<artifactId>dbptk</artifactId>
<version>2.0.0-rc3.1.0</version>
<version>2.0.0-rc3.2.4</version>
<relativePath>..</relativePath>
</parent>
<packaging>pom</packaging>
Expand Down
8 changes: 6 additions & 2 deletions dbptk-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<name>dbptk-core</name>
<groupId>com.databasepreservation</groupId>
<artifactId>dbptk-core</artifactId>
<version>2.0.0-rc3.2.0</version>
<version>2.0.0-rc3.2.4</version>
<parent>
<groupId>com.databasepreservation</groupId>
<artifactId>dbptk</artifactId>
<version>2.0.0-rc3.2.0</version>
<version>2.0.0-rc3.2.4</version>
<relativePath>..</relativePath>
</parent>
<properties>
Expand Down Expand Up @@ -179,6 +179,10 @@
<groupId>com.ibm</groupId>
<artifactId>db2jcc4</artifactId>
</dependency>
<dependency>
<groupId>net.sf.ucanaccess</groupId>
<artifactId>ucanaccess</artifactId>
</dependency>

<!-- test -->
<dependency>
Expand Down
85 changes: 42 additions & 43 deletions dbptk-core/src/main/java/com/databasepreservation/CustomLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
* DEBUG - delegated to log4j
*
* INFO - delegated to log4j
*
* WARN - delegated to log4j
*
* WARN (non-throwable) - delegated to log4j
*
* WARN (message and throwable) - logs twice: first an user-friendly WARN
* message and then logs stack traces and other info as DEBUG
*
* ERROR (non-throwable) - delegated to log4j
*
Expand Down Expand Up @@ -65,6 +68,43 @@ private CustomLogger(Logger logger) {
this.logger = logger;
}

/**
* If message is a throwable object: Logs WARN with throwable message and
* then logs DEBUG with throwable
*
* If message is not a throwable object: delegates method call to log4j
*
* @param message
* the message object to log.
*/
public void warn(Object message) {
if (message instanceof Throwable) {
Throwable throwable = (Throwable) message;
this.warn(throwable, throwable);
} else {
logger.warn(message);
}
}

/**
* Logs WARN with message and then logs DEBUG with message and throwable
*
* @param message
* the message object to log.
* @param t
* the exception to log, including its stack trace.
*/
public void warn(Object message, Throwable t) {
if (message instanceof Throwable) {
Throwable badMessage = (Throwable) message;
message = badMessage.getMessage();
} else {
message = message.toString();
}
logger.warn(message);
logger.debug(message, t);
}

/**
* If message is a throwable object: Logs ERROR with throwable message and
* then logs DEBUG with throwable
Expand Down Expand Up @@ -735,31 +775,6 @@ public void log(String callerFQCN, Priority level, Object message, Throwable t)
logger.log(callerFQCN, level, message, t);
}

/**
* Log a message object with the {@link Level#WARN WARN} Level.
*
* <p>
* This method first checks if this category is <code>WARN</code> enabled by
* comparing the level of this category with {@link Level#WARN WARN} Level. If
* the category is <code>WARN</code> enabled, then it converts the message
* object passed as parameter to a string by invoking the appropriate
* {@link ObjectRenderer}. It proceeds to call all the registered appenders in
* this category and also higher in the hieararchy depending on the value of
* the additivity flag.
*
* <p>
* <b>WARNING</b> Note that passing a {@link Throwable} to this method will
* print the name of the Throwable but no stack trace. To print a stack trace
* use the {@link #warn(Object, Throwable)} form instead.
* <p>
*
* @param message
* the message object to log.
*/
public void warn(Object message) {
logger.warn(message);
}

/**
* @deprecated Please use {@link #getLevel} instead.
*/
Expand Down Expand Up @@ -811,22 +826,6 @@ public void callAppenders(LoggingEvent event) {
logger.callAppenders(event);
}

/**
* Log a message with the <code>WARN</code> level including the stack trace of
* the {@link Throwable} <code>t</code> passed as parameter.
*
* <p>
* See {@link #warn(Object)} for more detailed information.
*
* @param message
* the message object to log.
* @param t
* the exception to log, including its stack trace.
*/
public void warn(Object message, Throwable t) {
logger.warn(message, t);
}

/**
* Set the resource bundle to be used with localized logging methods
* {@link #l7dlog(Priority, String, Throwable)} and
Expand Down
10 changes: 6 additions & 4 deletions dbptk-core/src/main/java/com/databasepreservation/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.databasepreservation.model.modules.DatabaseExportModule;
import com.databasepreservation.model.modules.DatabaseImportModule;
import com.databasepreservation.modules.jdbc.JDBCModuleFactory;
import com.databasepreservation.modules.msAccess.MsAccessUCanAccessModuleFactory;
import com.databasepreservation.modules.mySql.MySQLModuleFactory;
import com.databasepreservation.modules.oracle.Oracle12cModuleFactory;
import com.databasepreservation.modules.postgreSql.PostgreSQLModuleFactory;
Expand Down Expand Up @@ -55,22 +56,23 @@ public static int internal_main(String... args) {
final DatabaseImportModule importModule;
final DatabaseExportModule exportModule;

CLI cli = new CLI(Arrays.asList(args), new JDBCModuleFactory(), new MySQLModuleFactory(),
new Oracle12cModuleFactory(), new PostgreSQLModuleFactory(), new SIARD1ModuleFactory(),
new SIARD2ModuleFactory(), new SIARDDKModuleFactory(),
new SQLServerJDBCModuleFactory());
CLI cli = new CLI(Arrays.asList(args), new JDBCModuleFactory(), new MsAccessUCanAccessModuleFactory(),
new MySQLModuleFactory(), new Oracle12cModuleFactory(), new PostgreSQLModuleFactory(), new SIARD1ModuleFactory(),
new SIARD2ModuleFactory(), new SIARDDKModuleFactory(), new SQLServerJDBCModuleFactory());
try {
importModule = cli.getImportModule();
exportModule = cli.getExportModule();
} catch (ParseException e) {
System.err.println("Error: " + e.getMessage() + "\n");
cli.printHelp();
logProgramFinish(EXIT_CODE_COMMAND_PARSE_ERROR);
return EXIT_CODE_COMMAND_PARSE_ERROR;
} catch (LicenseNotAcceptedException e) {
System.err.println("Error: The license must be accepted to use this module.");
System.err.println("==================================================");
cli.printLicense(e.getLicense());
System.err.println("==================================================");
logProgramFinish(EXIT_CODE_LICENSE_NOT_ACCEPTED);
return EXIT_CODE_LICENSE_NOT_ACCEPTED;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class SQLHelper {

private String endQuote = "";

private String separatorSchemaTable = ".";

public String getName() {
return name;
}
Expand All @@ -58,11 +60,15 @@ public String getEndQuote() {
return endQuote;
}

public String getSeparatorSchemaTable() {
return separatorSchemaTable;
}

/**
* SQL to get all rows from a table
*
* @param tableName
* the table name
* @param tableId
* the table ID
* @return the SQL
* @throws ModuleException
*/
Expand Down Expand Up @@ -244,8 +250,8 @@ protected Integer getNumericExactScale(Type type, Integer max) {
/**
* SQL to create the primary key, altering the already created table
*
* @param tableName
* the name of the table
* @param tableId
* the ID of the table
* @param pkey
* the primary key
* @return the SQL
Expand Down Expand Up @@ -279,8 +285,8 @@ public String createPrimaryKeySQL(String tableId, PrimaryKey pkey) throws Module
/**
* SQL to create a foreign key (relation), altering the already created table
*
* @param tableName
* the name of the table
* @param table
* the table structure
* @param fkey
* the foreign key
* @return the SQL
Expand Down Expand Up @@ -436,8 +442,9 @@ public String getTriggersSQL(String schemaName, String tableName) {
* The table name
* @return the SQL to get table triggers
*/
public String getRowsSQL(String tableName) {
StringBuilder sb = new StringBuilder("SELECT COUNT(*) FROM ").append(escapeTableName(tableName));
public String getRowsSQL(String schemaName, String tableName) {
StringBuilder sb = new StringBuilder("SELECT COUNT(*) FROM ").append(escapeSchemaName(schemaName))
.append(getSeparatorSchemaTable()).append(escapeTableName(tableName));
return sb.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,12 @@ protected List<ViewStructure> getViews(String schemaName) throws SQLException, C
ViewStructure view = new ViewStructure();
view.setName(viewName);
view.setColumns(getColumns(schemaName, viewName));
views.add(view);

if (view.getColumns().isEmpty()) {
logger.info("View " + viewName + " in schema " + schemaName + " was ignored because it contains no columns.");
} else {
views.add(view);
}
}
return views;
}
Expand Down Expand Up @@ -458,13 +463,13 @@ protected TableStructure getTableStructure(SchemaStructure schema, String tableN
table.setCheckConstraints(getCheckConstraints(schema.getName(), tableName));
table.setTriggers(getTriggers(schema.getName(), tableName));

table.setRows(getRows(tableName));
table.setRows(getRows(schema.getName(), tableName));

return table;
}

private int getRows(String tableName) throws ClassNotFoundException, SQLException {
String query = sqlHelper.getRowsSQL(tableName);
private int getRows(String schemaName, String tableName) throws ClassNotFoundException, SQLException {
String query = sqlHelper.getRowsSQL(schemaName, tableName);
logger.debug("count query: " + query);
ResultSet rs = getStatement().executeQuery(query);

Expand Down Expand Up @@ -801,6 +806,7 @@ protected Type getType(String schemaName, String tableName, String columnName, i
case Types.CHAR:
type = new SimpleTypeString(columnSize, false);
type.setSql99TypeName("CHARACTER", columnSize);
type.setSql2003TypeName("CHARACTER", columnSize);
type.setOriginalTypeName("CHARACTER", columnSize);
break;
case Types.NCHAR:
Expand Down Expand Up @@ -1466,11 +1472,21 @@ protected Cell convertRawToCell(String tableName, String columnName, int columnI
} else if (cellType instanceof SimpleTypeBinary) {
cell = rawToCellSimpleTypeBinary(id, columnName, cellType, rawData);
} else if (cellType instanceof UnsupportedDataType) {
cell = new SimpleCell(id, rawData.getString(columnName));
try {
cell = new SimpleCell(id, rawData.getString(columnName));
} catch (SQLException e) {
logger.warn("Could not export cell of unsupported datatype: OTHER", e);
cell = new SimpleCell(id);
}
} else if (cellType instanceof SimpleTypeNumericExact) {
cell = rawToCellSimpleTypeNumericExact(id, columnName, cellType, rawData);
} else {
cell = new SimpleCell(id, rawData.getString(columnName));
try {
cell = new SimpleCell(id, rawData.getString(columnName));
} catch (SQLException e) {
logger.warn("Could not export cell of unknown/undefined datatype", e);
cell = new SimpleCell(id);
}
}
return cell;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public Connection getConnection() throws ModuleException {
logger.debug("Loading JDBC Driver " + driverClassName);
Class.forName(driverClassName);
logger.debug("Getting connection");
logger.debug("Connection URL: " + connectionURL);
//logger.debug("Connection URL: " + connectionURL);
connection = DriverManager.getConnection(connectionURL);
connection.setAutoCommit(true);
logger.debug("Connected");
Expand Down Expand Up @@ -166,7 +166,7 @@ public Connection getConnection(String databaseName, String connectionURL) throw
logger.debug("Loading JDBC Driver " + driverClassName);
Class.forName(driverClassName);
logger.debug("Getting admin connection");
logger.debug("Connection URL: " + connectionURL);
//logger.debug("Connection URL: " + connectionURL);
connection = DriverManager.getConnection(connectionURL);
connection.setAutoCommit(true);
logger.debug("Connected");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,28 @@
*/
package com.databasepreservation.modules.msAccess;

import com.databasepreservation.model.exception.ModuleException;
import com.databasepreservation.modules.SQLHelper;

/**
* @author Luis Faria
* @author Bruno Ferreira <[email protected]>
* @author Luis Faria <[email protected]>
*/
public class MsAccessHelper extends SQLHelper {
private String startQuote = "[";

public String selectTableSQL(String tableName) {
return "SELECT * FROM [" + tableName + "]";
private String endQuote = "]";

@Override
public String selectTableSQL(String tableId) throws ModuleException {
return "SELECT * FROM " + escapeTableId(tableId);
}

@Override public String getStartQuote() {
return startQuote;
}

@Override public String getEndQuote() {
return endQuote;
}
}
Loading

0 comments on commit fec2aa6

Please sign in to comment.