Address some edge cases related to bootstrapping a fresh system.
[cfb.git] / prod / net / jaekl / cfb / store / DbStore.java
index 3860ca5637e5c2fd31f93bec95b1d59900dec6d5..bbf2a721340ec3b6792e3d5721009b72fd992671 100644 (file)
@@ -17,6 +17,8 @@ import net.jaekl.cfb.db.driver.DbDriver;
 import net.jaekl.cfb.xml.BugCollection;
 import net.jaekl.cfb.xml.BugInstance;
 import net.jaekl.cfb.xml.LocalVariable;
+import net.jaekl.cfb.xml.messages.BugCategory;
+import net.jaekl.cfb.xml.messages.BugPattern;
 import net.jaekl.cfb.xml.messages.MessageCollection;
 
 public class DbStore {
@@ -30,7 +32,7 @@ public class DbStore {
                m_msgColl = msgColl;
        }
 
-       public Analysis getPrior(Analysis analysis) throws SQLException, TypeMismatchException {
+       public Analysis getPrior(Analysis analysis) throws SQLException, TypeMismatchException, StoreException {
                if (null == analysis) {
                        return null;
                }
@@ -42,11 +44,13 @@ public class DbStore {
                return getAnalysis(priorId);
        }
        
-       public boolean put(Analysis analysis) throws SQLException, TypeMismatchException {
+       public boolean put(Analysis analysis) throws SQLException, TypeMismatchException, StoreException {
                if (null == analysis) {
                        return false;
                }
                
+               assert (null != analysis.getProjectName());
+               
                // ----------------------------------
                // Add a run record for this analysis
                
@@ -82,6 +86,13 @@ public class DbStore {
                        Location secondLoc = (locs.size() > 1) ? locs.get(1) : null;
                        Location thirdLoc  = (locs.size() > 2) ? locs.get(2) : null;
                        
+                       if (BugPattern.UNKNOWN.getId() == bugId) {
+                               throw new StoreException(StoreException.Type.UNKNOWN_PATTERN, ""+bug.getType());
+                       }
+                       if (BugCategory.UNKNOWN.getId() == categoryId) {
+                               throw new StoreException(StoreException.Type.UNKNOWN_CATEGORY, ""+bug.getCategory());
+                       }
+                       
                        values[row][0] = foundId;
                        values[row][1] = runId;
                        values[row][2] = bugId;
@@ -118,7 +129,7 @@ public class DbStore {
        }
        
        
-       Location getLoc(Long locId) throws SQLException, TypeMismatchException
+       Location getLoc(Long locId) throws TypeMismatchException, StoreException
        {
                if (null == locId) {
                        return null;
@@ -128,16 +139,21 @@ public class DbStore {
                Table[] tables = { CfbSchema.LOCATIONS };
                Condition[] conditions = { new Condition(CfbSchema.LOCID, locId, Operation.EQUAL) };
                
-               Row row = m_driver.selectExactlyOne(m_con, columns, tables, conditions);
-               
-               String className = row.getString(0);
-               String methodName = row.getString(1);
-               String methodRole = row.getString(2);
-               Integer startLine = row.getInt(3);
-               Integer endLine = row.getInt(4);
-               
-               Location loc = new Location(locId, className, methodName, methodRole, startLine, endLine);
-               return loc;
+               try {
+                       Row row = m_driver.selectExactlyOne(m_con, columns, tables, conditions);
+
+                       String className = row.getString(0);
+                       String methodName = row.getString(1);
+                       String methodRole = row.getString(2);
+                       Integer startLine = row.getInt(3);
+                       Integer endLine = row.getInt(4);
+                       
+                       Location loc = new Location(locId, className, methodName, methodRole, startLine, endLine);
+                       return loc;
+               }
+               catch (SQLException exc) {
+                       throw new StoreException(exc, StoreException.Type.INVALID_LOC_ID, ""+locId);
+               }
        }
        
        Long getLocId(Location loc) throws SQLException, TypeMismatchException 
@@ -209,7 +225,7 @@ public class DbStore {
                return getVarId(vars.get(0));
        }
        
-       LocalVariable getVar(Long varId) throws SQLException, TypeMismatchException
+       LocalVariable getVar(Long varId) throws SQLException, TypeMismatchException, StoreException
        {
                if (null == varId) {
                        return null;
@@ -221,7 +237,7 @@ public class DbStore {
                
                List<Row> result = m_driver.select(m_con, columns, tables, conditions);
                if (result.size() < 1) {
-                       throw new SQLException("No variable found for ID " + varId);
+                       throw new StoreException(StoreException.Type.INVALID_VAR_ID, ""+varId);
                }
                if (result.size() > 1) {
                        throw new SQLException("Too many matches (" + result.size() + ") found for variable ID " + varId);
@@ -302,7 +318,7 @@ public class DbStore {
                return rows.get(0).getLong(0);
        }
        
-       Analysis getAnalysis(Long analysisId) throws SQLException, TypeMismatchException
+       Analysis getAnalysis(Long analysisId) throws SQLException, TypeMismatchException, StoreException
        {
                Column[] columns = { CfbSchema.PROJNAME, CfbSchema.VERSION, CfbSchema.STARTTIME, CfbSchema.ENDTIME };
                Table[] tables = { CfbSchema.RUNS };
@@ -330,7 +346,7 @@ public class DbStore {
                return prior;
        }
        
-       BugCollection getBugCollection(Long runId) throws SQLException, TypeMismatchException 
+       BugCollection getBugCollection(Long runId) throws SQLException, TypeMismatchException, StoreException 
        {
                Column[] columns = {
                                CfbSchema.FOUNDID,