package journal.reader; import java.util.Date; import java.util.Map; import java.util.HashMap; public class NoteJournalEntry extends JournalEntry { public enum JournalDBFlags { C0(0x0001) { }, C1(0x0002) { }, C2(0x0004) { }, UNICODE(0x0008) { }; final int flag; JournalDBFlags(int f) { this.flag = f; } } public enum JournalType { CHECKPOINT_HEADER(0) { public String toString(int[] intArrays, String[] stringArrays) { StringBuilder buf = new StringBuilder("CHECKPOINT_HEADER ("); buf.append("Flags = "); buf.append(intArrays[0]); buf.append(" Root = "); buf.append(stringArrays[0]); buf.append(" JournalFile = "); buf.append(stringArrays[1]); buf.append(" )"); return buf.toString(); } }, CHECKPOINT_TRAILER(1) { public String toString(int[] intArrays, String[] stringArrays) { StringBuilder buf = new StringBuilder("CHECKPOINT_TRAILER"); return buf.toString(); } }, JOURNAL_HEADER(2) { public String toString(int[] intArrays, String[] stringArrays) { StringBuilder buf = new StringBuilder("JOURNAL_HEADER ("); buf.append("Flags = "); buf.append(intArrays[0]); switch (intArrays[1]) { case 0: buf.append(" -jc"); break; case 1: buf.append(" -jd"); break; case 2: buf.append(" -jds"); break; default: buf.append(" -j?"); buf.append(intArrays[1]); break; } buf.append(")"); return buf.toString(); } }, JOURNAL_TRAILER(3) { public String toString(int[] intArrays, String[] stringArrays) { StringBuilder buf = new StringBuilder("JOURNAL_TRAILER"); return buf.toString(); } }, TABLE_SUMMARY(4) { public String toString(int[] intArrays, String[] stringArrays) { StringBuilder buf = new StringBuilder("TABLE_SUMMARY ("); buf.append("Version = "); buf.append(intArrays[0]); buf.append(" Old Version = "); buf.append(intArrays[1]); buf.append(" Checksum = "); buf.append(intArrays[2]); buf.append(" Name = "); buf.append(stringArrays[0]); buf.append(" )"); return buf.toString(); } }, SERVER_UPGRADE(5) { public String toString(int[] intArrays, String[] stringArrays) { StringBuilder buf = new StringBuilder("SERVER_UPGRADE ("); buf.append("Start Value = "); buf.append(intArrays[0]); buf.append(" Destination Value = "); buf.append(intArrays[1]); buf.append(" )"); return buf.toString(); } }, TABLE_UPGRADE(6) { public String toString(int[] intArrays, String[] stringArrays) { StringBuilder buf = new StringBuilder("TABLE_UPGRADE ("); buf.append("Upgrade Counter = "); buf.append(intArrays[0]); buf.append(" Upgrade Function = "); buf.append(stringArrays[0]); buf.append(" )"); return buf.toString(); } }, SERVER_STARTUP(7) { public String toString(int[] intArrays, String[] stringArrays) { StringBuilder buf = new StringBuilder("SERVER_STARTUP ("); buf.append("Port = "); buf.append(stringArrays[0]); buf.append(" Root = "); buf.append(stringArrays[1]); buf.append(" Name = "); buf.append(stringArrays[2]); buf.append(")"); return buf.toString(); } }, SERVER_SHUTDOWN(8) { public String toString(int[] intArrays, String[] stringArrays) { StringBuilder buf = new StringBuilder("SERVER_SHUTDOWN ("); buf.append("Port = "); buf.append(stringArrays[0]); buf.append(")"); return buf.toString(); } }, UNICODE_ENABLED(9) { public String toString(int[] intArrays, String[] stringArrays) { StringBuilder buf = new StringBuilder("UNICODE_ENABLED"); return buf.toString(); } }, TABLE_PATCHED(10) { public String toString(int[] intArrays, String[] stringArrays) { StringBuilder buf = new StringBuilder("TABLE_PATCHED"); return buf.toString(); } }, JOURNAL_REPLAYED(11) { public String toString(int[] intArrays, String[] stringArrays) { StringBuilder buf = new StringBuilder("JOURNAL_REPLAYED"); return buf.toString(); } }, JOURNAL_DBCHECKSUMS(12) { public String toString(int[] intArrays, String[] stringArrays) { StringBuilder buf = new StringBuilder("JOURNAL_DBCHECKSUMS"); return buf.toString(); } }; final int type; JournalType(int typeValue) { this.type = typeValue; } public abstract String toString(int[] intArrays, String[] stringArrays); public static Map<Integer, JournalType> types = new HashMap<Integer, JournalType>(); static { for( JournalType t: JournalType.values()) { types.put(t.type, t); } } } private JournalType journalType; private Date timestamp; private String version; private int[] integerFlags = new int[5]; private String[] stringFlags = new String[5]; public NoteJournalEntry(Token startToken, Token typeToken, Token timestampToken, Token versionToken, Token[] intToken, Token[] stringToken) { super(startToken); journalType = JournalType.types.get(Integer.parseInt(typeToken.getValue())); long value = Long.parseLong(timestampToken.getValue()) * 1000; timestamp = new Date(value); version = versionToken.getValue(); for( int i = 0; i < 5; i++ ) { integerFlags[i] = Integer.parseInt(intToken[i].getValue()); } for( int i = 0; i < 5; i++ ) { stringFlags[i] = stringToken[i].getValue(); } } public JournalType getJournalType() { return journalType; } public int[] getIntegerFlags() { return integerFlags; } public String[] getStringFlags() { return stringFlags; } @Override public String toString() { StringBuffer buf = new StringBuffer(actionType.toString()); buf.append(" "); buf.append(journalType.toString(integerFlags, stringFlags)); return buf.toString(); } @Override public boolean equals(Object to) { if (!to.getClass().equals(getClass())) { return false; } NoteJournalEntry toEntry = (NoteJournalEntry) to; return (journalType == toEntry.journalType); } @Override public String toJournalString() { StringBuffer buf = new StringBuffer(super.toJournalString()); buf.append(" "); buf.append(journalType.type); buf.append(" "); buf.append(timestamp.getTime()/1000); buf.append(" @"); buf.append(version); buf.append("@"); for( int i = 0; i < 5; i++) { buf.append(" "); buf.append(integerFlags[i]); } for( int i = 0; i < 5; i++) { buf.append(" @"); buf.append(stringFlags[i]); buf.append("@"); } return buf.toString(); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 8200 | Sven Erik Knop |
JournalReader can now process delete records (@dl@). Also fixed processing of type 12 note records = journaldbchecksum |
||
#2 | 8019 | Sven Erik Knop | Safety checks for case-sensitivity and Unicode, now provided in the checkpoint. | ||
#1 | 7876 | Sven Erik Knop | Added new Journal type for JournalNotes and modified printers to deal with its values. |