From e39cda22382d19e6b794dd73e1d1f5ed355cc6a6 Mon Sep 17 00:00:00 2001 From: Chris Jaekl Date: Sun, 27 Sep 2015 17:51:36 +0900 Subject: [PATCH] Change schema definition mechanism, to simplify references to table columns in SQL code. --- prod/net/jaekl/cfb/analyze/MessageMap.java | 7 +- prod/net/jaekl/cfb/db/CfbSchema.java | 97 +++++++--------------- prod/net/jaekl/cfb/db/Table.java | 2 +- prod/net/jaekl/cfb/store/DbStore.java | 22 ++--- 4 files changed, 37 insertions(+), 91 deletions(-) diff --git a/prod/net/jaekl/cfb/analyze/MessageMap.java b/prod/net/jaekl/cfb/analyze/MessageMap.java index 0db78ba..b0f0b67 100644 --- a/prod/net/jaekl/cfb/analyze/MessageMap.java +++ b/prod/net/jaekl/cfb/analyze/MessageMap.java @@ -52,8 +52,8 @@ public class MessageMap { void loadCategoryIds(Connection con, DbDriver driver) throws SQLException, TypeMismatchException { - Column[] columns = { CfbSchema.CATEGORIES.getColumn(CfbSchema.CATEGORYID), - CfbSchema.CATEGORIES.getColumn(CfbSchema.CATEGORY) }; + Column[] columns = { CfbSchema.CATEGORYID, + CfbSchema.CATEGORY }; Table[] tables = { CfbSchema.CATEGORIES }; Condition[] conditions = { }; List rows = driver.select(con, columns, tables, conditions); @@ -74,8 +74,7 @@ public class MessageMap { void loadBugPatternIds(Connection con, DbDriver driver) throws SQLException, TypeMismatchException { - Column[] columns = { CfbSchema.BUGS.getColumn(CfbSchema.BUGID), - CfbSchema.BUGS.getColumn(CfbSchema.TYPE) }; + Column[] columns = { CfbSchema.BUGID, CfbSchema.TYPE }; Table[] tables = { CfbSchema.BUGS }; Condition[] conditions = { }; List rows = driver.select(con, columns, tables, conditions); diff --git a/prod/net/jaekl/cfb/db/CfbSchema.java b/prod/net/jaekl/cfb/db/CfbSchema.java index 6125393..49adde6 100644 --- a/prod/net/jaekl/cfb/db/CfbSchema.java +++ b/prod/net/jaekl/cfb/db/CfbSchema.java @@ -24,76 +24,35 @@ public class CfbSchema extends Schema { public static final Sequence LOC_SEQ = new Sequence("LOC_SEQ"); public static final Sequence RUN_SEQ = new Sequence("RUN_SEQ"); - public static final String BUGID = "BUGID"; - public static final String CATEGORY = "CATEGORY"; - public static final String CATEGORYID = "CATEGORYID"; - public static final String CLASSNAME = "CLASSNAME"; - public static final String ENDLINE = "ENDLINE"; - public static final String FIRSTLOCID = "FIRSTLOCID"; - public static final String FOUNDID = "FOUNDID"; - public static final String LOCID = "LOCID"; - public static final String METHODNAME = "METHODNAME"; - public static final String RUNID = "RUNID"; - public static final String SECONDLOCID = "SECONDLOCID"; - public static final String STARTLINE = "STARTLINE"; - public static final String THIRDLOCID = "THIRDLOCID"; - public static final String TYPE = "TYPE"; + public static final Column BUGID = new Column("BUGID", INTEGER, -1, NOT_NULL); + public static final Column CATEGORY = new Column("CATEGORY", VARCHAR, 80, NOT_NULL); + public static final Column CATEGORYID = new Column("CATEGORYID", INTEGER, -1, NOT_NULL); + public static final Column CLASSNAME = new Column("CLASSNAME", VARCHAR, 256, NOT_NULL); + public static final Column ENDLINE = new Column("ENDLINE", INTEGER, -1, NULL); + public static final Column ENDTIME = new Column("ENDTIME", TIMESTAMPTZ, -1, NOT_NULL); + public static final Column FIRSTLOCID = new Column("FIRSTLOCID", INTEGER, -1, NOT_NULL); + public static final Column FOUNDID = new Column("FOUNDID", INTEGER, -1, NOT_NULL); + public static final Column LOCID = new Column("LOCID", INTEGER, -1, NOT_NULL); + public static final Column METHODNAME = new Column("METHODNAME", VARCHAR, 256, NULL); + public static final Column RUNID = new Column("RUNID", INTEGER, -1, NOT_NULL); + public static final Column SECONDLOCID = new Column("SECONDLOCID", INTEGER, -1, NULL); + public static final Column STARTLINE = new Column("STARTLINE", INTEGER, -1, NULL); + public static final Column STARTTIME = new Column("STARTTIME", TIMESTAMPTZ, -1, NOT_NULL); + public static final Column THIRDLOCID = new Column("THIRDLOCID", INTEGER, -1, NULL); + public static final Column TYPE = new Column("TYPE", VARCHAR, 80, NOT_NULL ); + public static final Column VERSION = new Column("VERSION", VARCHAR, 32, NULL); - // Define each table as follows: - // { - // { table_name }, - // { column_name, type, width (-1 for default), null/not_null } - // } - private static final Object[][] BUGS_DEFN = - { - // Description of each possible bug - { "BUG" }, - { BUGID, INTEGER, -1, NOT_NULL }, - { TYPE, VARCHAR, 80, NOT_NULL } - }; - private static final Object[][] CATEGORIES_DEFN = - { - // Description of each possible bug category - { "CATEGORIES" }, - { CATEGORYID, INTEGER, -1, NOT_NULL }, - { CATEGORY, VARCHAR, 80, NOT_NULL } - }; - private static final Object[][] FOUND_DEFN = - { - // One BugInstance, found during an analysis - { "FOUND" }, - { FOUNDID, INTEGER, -1, NOT_NULL }, - { BUGID, INTEGER, -1, NOT_NULL }, - { CATEGORYID, INTEGER, -1, NOT_NULL }, - { FIRSTLOCID, INTEGER, -1, NOT_NULL }, - { SECONDLOCID, INTEGER, -1, NULL }, - { THIRDLOCID, INTEGER, -1, NULL } - }; - private static final Object[][] LOCATIONS_DEFN = - { - // Location in the source code referenced by a BugInstance - { "LOCATION" }, - { LOCID, INTEGER, -1, NOT_NULL }, - { CLASSNAME, VARCHAR, 256, NOT_NULL }, - { METHODNAME, VARCHAR, 256, NULL }, - { STARTLINE, INTEGER, -1, NULL }, - { ENDLINE, INTEGER, -1, NULL } - }; - private static final Object[][] RUNS_DEFN = - { - // Runs of FindBugs, normally one per build version - { "RUN" }, - { RUNID, INTEGER, -1, NOT_NULL }, - { "VERSION", VARCHAR, 32, NULL }, - { "STARTTIME", TIMESTAMPTZ, -1, NOT_NULL }, - { "ENDTIME", TIMESTAMPTZ, -1, NOT_NULL } - }; - - public static final Table BUGS = Table.construct(BUGS_DEFN); - public static final Table CATEGORIES = Table.construct(CATEGORIES_DEFN); - public static final Table FOUND = Table.construct(FOUND_DEFN); - public static final Table LOCATIONS = Table.construct(LOCATIONS_DEFN); - public static final Table RUNS = Table.construct(RUNS_DEFN); + private static final Column[] BUGS_COLS = { BUGID, TYPE }; + private static final Column[] CATEGORIES_COLS = { CATEGORYID, CATEGORY }; + private static final Column[] FOUND_COLS = { FOUNDID, BUGID, CATEGORYID, FIRSTLOCID, SECONDLOCID, THIRDLOCID }; + private static final Column[] LOCATIONS_COLS = { LOCID, CLASSNAME, METHODNAME, STARTLINE, ENDLINE }; + private static final Column[] RUNS_COLS = { RUNID, VERSION, STARTTIME, ENDTIME }; + + public static final Table BUGS = new Table("BUGS", BUGS_COLS); + public static final Table CATEGORIES = new Table("CATEGORIES", CATEGORIES_COLS); + public static final Table FOUND = new Table("FOUND", FOUND_COLS); + public static final Table LOCATIONS = new Table("LOCATIONS", LOCATIONS_COLS); + public static final Table RUNS = new Table("RUNS", RUNS_COLS); private static final Sequence[] SEQUENCES = { BUG_SEQ, diff --git a/prod/net/jaekl/cfb/db/Table.java b/prod/net/jaekl/cfb/db/Table.java index e20552d..7e16cd5 100644 --- a/prod/net/jaekl/cfb/db/Table.java +++ b/prod/net/jaekl/cfb/db/Table.java @@ -27,7 +27,7 @@ public class Table { public int getNumColumns() { return m_columns.size(); } public Column getColumn(int idx) { return m_columns.get(idx); } public Column getColumn(String name) { return m_columnsByName.get(name); } - + // Construct a table from an array of objects like this: // { // { table_name }, diff --git a/prod/net/jaekl/cfb/store/DbStore.java b/prod/net/jaekl/cfb/store/DbStore.java index 2238568..6e17cff 100644 --- a/prod/net/jaekl/cfb/store/DbStore.java +++ b/prod/net/jaekl/cfb/store/DbStore.java @@ -115,25 +115,13 @@ public class DbStore { Long findLocId(Location loc) throws SQLException, TypeMismatchException { - Column[] columns = { CfbSchema.LOCATIONS.getColumn(CfbSchema.LOCID) }; + Column[] columns = { CfbSchema.LOCID }; Table[] tables = { CfbSchema.LOCATIONS }; Condition[] conditions = { - new Condition( CfbSchema.LOCATIONS.getColumn(CfbSchema.CLASSNAME), - loc.getClassName(), - Operation.EQUAL - ), - new Condition( CfbSchema.LOCATIONS.getColumn(CfbSchema.METHODNAME), - loc.getMethodName(), - Operation.EQUAL - ), - new Condition( CfbSchema.LOCATIONS.getColumn(CfbSchema.STARTLINE), - loc.getStart(), - Operation.EQUAL - ), - new Condition( CfbSchema.LOCATIONS.getColumn(CfbSchema.ENDLINE), - loc.getEnd(), - Operation.EQUAL - ) + new Condition( CfbSchema.CLASSNAME, loc.getClassName(), Operation.EQUAL ), + new Condition( CfbSchema.METHODNAME, loc.getMethodName(), Operation.EQUAL ), + new Condition( CfbSchema.STARTLINE, loc.getStart(), Operation.EQUAL ), + new Condition( CfbSchema.ENDLINE, loc.getEnd(), Operation.EQUAL ) }; List rows = m_driver.select(m_con, columns, tables, conditions); if (rows.size() > 0) { -- 2.39.2