package journal.action.sql; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import journal.reader.DataJournalEntry; import journal.reader.JournalEntry; import journal.reader.Options; import journal.schema.TableVersion; public class SQLAdapter { private Map<TableVersion, SQLTableVersion> cache = new HashMap<TableVersion, SQLTableVersion>(); private Connection cx; private Set<String> dbTables = new HashSet<String>(); private SQLTableVersion activeTableVersion = null; private int batchSize = 1; Options options; public SQLAdapter(Connection cx, Options options) throws SQLException { this.cx = cx; this.options = options; DatabaseMetaData md = cx.getMetaData(); ResultSet rs = md.getTables(null, null, "DB_%", new String[]{"TABLE"}); while (rs.next()) { dbTables.add(rs.getString("TABLE_NAME")); } } public int getBatchSize() { return batchSize; } public void setBatchSize(int batchSize) { this.batchSize = batchSize; } public void putValue(DataJournalEntry entry) throws Exception { activeTableVersion = getSQLTableVersion(entry); activeTableVersion.putValue(entry); } public void replaceValue(DataJournalEntry entry) throws Exception { activeTableVersion = getSQLTableVersion(entry); activeTableVersion.replaceValue(entry); } public void deleteValue(DataJournalEntry entry ) throws Exception { activeTableVersion = getSQLTableVersion(entry); activeTableVersion.deleteValue(entry); } public void verifyValue(DataJournalEntry entry) throws Exception { activeTableVersion = getSQLTableVersion(entry); activeTableVersion.verifyValue(entry); } public void commitMarker(JournalEntry entry) throws Exception { if (activeTableVersion != null) activeTableVersion.flushBatchUpdate(); cx.commit(); } public void flushMarker(JournalEntry entry) throws Exception { // pass } Connection getConnection() { return cx; } boolean tableExists(String tableName) { return dbTables.contains(tableName); } private SQLTableVersion getSQLTableVersion(DataJournalEntry entry) throws SQLException { TableVersion t = entry.getTableVersion(); if (cache.containsKey(t)) { return cache.get(t); } else { SQLTableVersion s = new SQLTableVersion(this, t); cache.put(t, s); return s; } } public void dropTables() throws Exception { Statement stmt = cx.createStatement(); for (String tableName : dbTables) { stmt.executeUpdate("DROP TABLE " + tableName); } dbTables.clear(); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 7529 | Sven Erik Knop |
Deleted the whole JournalReader. It has actually moved to //guest/sven_erik_knop/java/JournalReader/. |
||
#2 | 7427 | Sven Erik Knop |
Major update of the JournalReader: - New help (usage) system, which explains all options - Config file that allows storing of parameters in a file. These are necessary for the SQLLoader and Updater, because classpath, classname and connection parameters need to be set. (see the example *.cfg files provided) - Now tested with MySQL, SQLite and Oracle 10 XE |
||
#1 | 7375 | Sven Erik Knop |
Major update of the JournalReader. Complete rewrite of the command line parsing Change in the options parsing within the journal reader New SQLLoader action. Currently only against MySQL (needs MySQL JDBC driver) with fixed database and user name. This will be replaced by a config file at some stage. |