/** * */ package journal.schema; import journal.action.sql.SupportedDatabase; import journal.reader.Token; import java.sql.Timestamp; import java.sql.Types; public enum Domain { INT(Number.class, Types.INTEGER, "INTEGER", 10) { public Integer parse(Token token) { return Integer.decode(token.getValue()); } public String toJournalFormat(Object o) { return o.toString(); } protected void initialize() { SupportedDatabase.MySQL.defineMapping(this, "INTEGER"); SupportedDatabase.SQLite.defineMapping(this, "INTEGER"); SupportedDatabase.Oracle.defineMapping(this, "NUMBER(10)"); SupportedDatabase.PostgreSQL.defineMapping(this, "INTEGER"); } }, KEY(String.class, Types.VARCHAR, "VARCHAR(750)", 1024) { public String parse(Token token) { return token.getValue(); } public String toJournalFormat(Object o) { StringBuffer buf = new StringBuffer(); buf.append("@"); buf.append(o.toString().replaceAll("@", "@@")); buf.append("@"); return buf.toString(); } protected void initialize() { SupportedDatabase.MySQL.defineMapping(this, "VARCHAR(400) BINARY"); SupportedDatabase.SQLite.defineMapping(this, "VARCHAR(1024)"); SupportedDatabase.Oracle.defineMapping(this, "VARCHAR2(1024)"); SupportedDatabase.PostgreSQL.defineMapping(this, "VARCHAR(1024)"); } }, TEXT(String.class, Types.LONGVARCHAR, "TEXT", 65536) { public String parse(Token token) { return token.getValue(); } public String toJournalFormat(Object o) { StringBuffer buf = new StringBuffer(); buf.append("@"); buf.append(o.toString().replaceAll("@", "@@")); buf.append("@"); return buf.toString(); } protected void initialize() { SupportedDatabase.MySQL.defineMapping(this, "TEXT"); SupportedDatabase.SQLite.defineMapping(this, "TEXT"); SupportedDatabase.Oracle.defineMapping(this, "CLOB"); SupportedDatabase.PostgreSQL.defineMapping(this, "TEXT"); } }, OCTET(String.class, Types.CHAR, "CHAR(32)", 32) { public String parse(Token token) { return token.getValue(); } public String toJournalFormat(Object o) { return o.toString(); } protected void initialize() { SupportedDatabase.MySQL.defineMapping(this, "CHAR(32)"); SupportedDatabase.SQLite.defineMapping(this, "CHAR(32)"); SupportedDatabase.Oracle.defineMapping(this, "CHAR(32)"); SupportedDatabase.PostgreSQL.defineMapping(this, "CHAR(32)"); } }, OCTETS(String.class, Types.LONGVARCHAR, "TEXT", 65535) { public String parse(Token token) { return token.getValue(); } public String toJournalFormat(Object o) { return o.toString(); } protected void initialize() { SupportedDatabase.MySQL.defineMapping(this, "TEXT"); SupportedDatabase.SQLite.defineMapping(this, "TEXT"); SupportedDatabase.Oracle.defineMapping(this, "CLOB"); SupportedDatabase.PostgreSQL.defineMapping(this, "TEXT"); } }, DATE(java.sql.Timestamp.class, Types.TIMESTAMP, "DATETIME", 0) { public java.util.Date parse(Token token) { return new Timestamp(Long.parseLong(token.getValue()) * 1000); } public String toJournalFormat(Object o) { Timestamp t = (Timestamp) o; return Long.toString(t.getTime()/1000); } protected void initialize() { SupportedDatabase.MySQL.defineMapping(this, "DATETIME"); SupportedDatabase.SQLite.defineMapping(this, "DATETIME"); SupportedDatabase.Oracle.defineMapping(this, "TIMESTAMP"); SupportedDatabase.PostgreSQL.defineMapping(this, "TIMESTAMP"); } }, INT8(Number.class, Types.TINYINT, "INTEGER", 3) { public Short parse(Token token) { return Short.decode(token.getValue()); } public String toJournalFormat(Object o) { return o.toString(); } protected void initialize() { SupportedDatabase.MySQL.defineMapping(this, "SMALLINT"); SupportedDatabase.SQLite.defineMapping(this, "INTEGER"); SupportedDatabase.Oracle.defineMapping(this, "NUMBER(3)"); SupportedDatabase.PostgreSQL.defineMapping(this, "SMALLINT"); } }, INT64(Number.class, Types.BIGINT, "BIGINT", 19) { public Long parse(Token token) { return Long.decode(token.getValue()); } public String toJournalFormat(Object o) { return o.toString(); } protected void initialize() { SupportedDatabase.MySQL.defineMapping(this, "BIGINT"); SupportedDatabase.SQLite.defineMapping(this, "BIGINT"); SupportedDatabase.Oracle.defineMapping(this, "NUMBER(20)"); SupportedDatabase.PostgreSQL.defineMapping(this, "BIGINT"); } }; final Class<?> sqlType; final String jdbcTypeName; final int jdbcType; final long targetPrecision; Domain(Class<?> sqlType, int jdbcType, String jdbcTypeName, long targetPrecision) { this.sqlType = sqlType; this.jdbcType = jdbcType; this.jdbcTypeName = jdbcTypeName; this.targetPrecision = targetPrecision; initialize(); } protected abstract void initialize(); public Class<?> getSqlType() { return sqlType; } public String getJdbcTypeName() { return jdbcTypeName; } public int getJdbcType() { return jdbcType; } public long getTargetPrecision() { return targetPrecision; } abstract public Comparable<? extends Object> parse(Token token); abstract public String toJournalFormat(Object o); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 24773 | Norman Morse |
Moving journalReader from sven's private branch to perforce_software. This is because journalReader is used in the perfsplit test harness, and should be updated over time. Merging //guest/sven_erik_knop/java/JournalReader/... to //guest/perforce_software/journalReader/... |
||
//guest/sven_erik_knop/java/JournalReader/src/journal/schema/Domain.java | |||||
#3 | 8237 | Sven Erik Knop | Adopted Nick Poole's changes to add PostgresSQL support. | ||
#2 | 7871 | Sven Erik Knop | Reduced size of KEY to fit into MySQL database. | ||
#1 | 7527 | Sven Erik Knop |
JournalReader, now in its proper place. Documentation to follow. |