package journal.reader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.text.ParseException; public class JournalComparer { private String file1; private String file2; private DataProvider provider1; private DataProvider provider2; private int lineCounter; public JournalComparer(String file1, String file2, int lineCounter) { this.file1 = file1; this.file2 = file2; this.lineCounter = lineCounter; } static class DataProvider { private String filename; private JournalParser parser; private int lineCounter; private int line = 0; public DataProvider(String filename, int lineCounter) throws FileNotFoundException { this.filename = filename; this.lineCounter = lineCounter; parser = new JournalParser(new FileReader(filename)); } public DataJournalEntry next() throws ParseException, IOException { JournalEntry entry = parser.parseNext(); line++; if (lineCounter > 0 && line > 0 && line % lineCounter == 0) { System.err.println(filename + " : " + line); } if (entry instanceof TransactionJournalEntry) { entry = parser.parseNext(); line++; if (entry == null) { return null; } } return (DataJournalEntry) entry; } } public void run() throws ParseException, IOException { provider1 = new DataProvider(file1, lineCounter); provider2 = new DataProvider(file2, lineCounter); DataJournalEntry data1 = provider1.next(); DataJournalEntry data2 = provider2.next(); while (data1 != null && data2 != null) { int compare = data1.compareTo(data2); if (compare == 0) { if (! data1.equals(data2)) { System.out.println("Entries differ : "); System.out.println("1 : " + data1); System.out.println("2 : " + data2); } data1 = provider1.next(); data2 = provider2.next(); continue; } else if (compare < 0) { System.out.println("1 : " + data1); data1 = provider1.next(); } else { // compare > 0 System.out.println("2 : " + data2); data2 = provider2.next(); } } while (data1 != null) { System.out.println("1 : " + data1); data1 = provider1.next(); } while (data2 != null) { System.out.println("2 : " + data2); data2 = provider2.next(); } } public static void main(String[] args) { if (args.length < 2) { System.out.println("Usage : journal.reader.JournalComparer <file1> <file2> [linecounter]"); System.exit(1); } String file1 = args[0]; String file2 = args[1]; int lineCounter = 0; if (args.length == 3) { lineCounter = Integer.parseInt(args[2]); } JournalComparer comp = new JournalComparer(file1, file2, lineCounter); try { comp.run(); } catch (Exception e) { e.printStackTrace(); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 7529 | Sven Erik Knop |
Deleted the whole JournalReader. It has actually moved to //guest/sven_erik_knop/java/JournalReader/. |
||
#4 | 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 |
||
#3 | 7380 | Sven Erik Knop |
Moved journalReader.jar into a dist directory. This will match it up with the build.xml file that can generate this file now. The jar builder target in Eclipse puts this file in the same place now. Also updated the generics definition of the Comparable<? extends <? extends Comparable>> to the much saner Comparable<Object>, which solves my compiler problems (and hopefully everyone elses as well). |
||
#2 | 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. |
||
#1 | 7374 | Sven Erik Knop | Rename/move file(s) - correct location for Eclipse project | ||
//guest/sven_erik_knop/JournalReader/journal/reader/JournalComparer.java | |||||
#1 | 6467 | Sven Erik Knop |
Added JournalReader, a Java library of useful tools to read and process checkpoints and journals. Added are a readme.txt to explain some details, and a jar file that contains the compiled class files. The programs will need Java 1.6 to run. |