package journal.action; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import journal.action.sql.SQLAdapter; import journal.reader.DataJournalEntry; import journal.reader.JournalEntry; import journal.reader.Options; public class SQLUpdater extends BaseAction { protected Connection cx; protected SQLAdapter sf; protected void handleSQLException(SQLException ex) throws Exception { StringBuffer err = new StringBuffer(); err.append( "SQLException: " + ex.getMessage() ); err.append( " SQLState: " + ex.getSQLState() ); err.append( " VendorError: " + ex.getErrorCode() ); Exception newEx = new Exception(err.toString()); newEx.setStackTrace(ex.getStackTrace()); throw newEx; } @Override public void start(Options options) throws Exception { super.start(options); Class.forName("com.mysql.jdbc.Driver").newInstance(); try { cx = DriverManager.getConnection("jdbc:mysql://localhost/perforce?"+ "user=perforce&password=p4"); cx.setAutoCommit(false); sf = new SQLAdapter(cx, options); } catch (SQLException ex) { handleSQLException(ex); } System.out.println("Connected to " + cx); } @Override public void finish() throws Exception { try { cx.close(); } catch (SQLException ex) { handleSQLException(ex); } System.out.println("Disconnected from SQL Database."); } @Override public void commitMarker(JournalEntry entry) throws Exception { try { cx.commit(); } catch (SQLException ex) { handleSQLException(ex); } } @Override public void flushMarker(JournalEntry entry) { // flush is ignored } @Override public void putValue(JournalEntry entry) throws Exception { try { DataJournalEntry dataEntry = (DataJournalEntry) entry; sf.putValue(dataEntry); } catch (SQLException ex) { handleSQLException(ex); } } @Override public void replaceValue(JournalEntry entry) throws Exception { try { DataJournalEntry dataEntry = (DataJournalEntry) entry; sf.replaceValue(dataEntry); } catch (SQLException ex) { handleSQLException(ex); } } @Override public void deleteValue(JournalEntry entry) throws Exception { try { DataJournalEntry dataEntry = (DataJournalEntry) entry; sf.deleteValue(dataEntry); } catch (SQLException ex) { handleSQLException(ex); } } @Override public void verifyValue(JournalEntry entry) throws Exception { try { DataJournalEntry dataEntry = (DataJournalEntry) entry; sf.verifyValue(dataEntry); } catch (SQLException ex) { handleSQLException(ex); } } }
# | 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. |