]> jaekl.net Git - cfb.git/commitdiff
Change schema definition mechanism, to simplify references to table columns in SQL...
authorChris Jaekl <cejaekl@yahoo.com>
Sun, 27 Sep 2015 08:51:36 +0000 (17:51 +0900)
committerChris Jaekl <cejaekl@yahoo.com>
Sun, 27 Sep 2015 08:51:36 +0000 (17:51 +0900)
prod/net/jaekl/cfb/analyze/MessageMap.java
prod/net/jaekl/cfb/db/CfbSchema.java
prod/net/jaekl/cfb/db/Table.java
prod/net/jaekl/cfb/store/DbStore.java

index 0db78babfdaa2974a0c4d366841ed10c5a71f33f..b0f0b67fac525ce3e3343c1eb993f381f33ca3a0 100644 (file)
@@ -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<Row> 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<Row> rows = driver.select(con, columns, tables, conditions);
index 6125393a3331eb8b6f04ec2366143fc3aa99cc2f..49adde6c5a224c6cee2dad0952e82af671dc29e2 100644 (file)
@@ -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,
index e20552daa109e4af9133618b95b8502cb151b5bb..7e16cd5a839c6b3ce16ff1a367177a7398ffbdf6 100644 (file)
@@ -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 },
index 2238568c001bec9d9207419eb36806055a8d0abd..6e17cffef5605c5a358fcfeb01d70e9c73c7011e 100644 (file)
@@ -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<Row> rows = m_driver.select(m_con, columns, tables, conditions);
                if (rows.size() > 0) {