Avoid unit test failures when cfb.properties is not found in the classpath.
[cfb.git] / prod / net / jaekl / cfb / store / DbStore.java
index 6c2097925f3d78a3c14fb91e6325643d66578be1..e50f7403910830d798e7cd8ca1b3296f056f42bc 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 {
@@ -42,7 +44,7 @@ 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;
                }
@@ -54,6 +56,7 @@ public class DbStore {
                Object[][] values = { 
                                                                {
                                                                        Long.valueOf(runId),
+                                                                       analysis.getProjectName(),
                                                                        analysis.getBuildNumber(),
                                                                        analysis.getStart(),
                                                                        analysis.getEnd() 
@@ -81,6 +84,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;
@@ -287,7 +297,10 @@ public class DbStore {
        {
                Column[] columns = { CfbSchema.RUNID };
                Table[] tables = { CfbSchema.RUNS };
-               Condition[] conditions = { new Condition( CfbSchema.STARTTIME, analysis.getStart(), Operation.LESS_THAN ) };
+               Condition[] conditions = {
+                       new Condition( CfbSchema.PROJNAME, analysis.getProjectName(), Operation.EQUAL ),
+                       new Condition( CfbSchema.STARTTIME, analysis.getStart(), Operation.LESS_THAN ) 
+               };
                Sort[] sorts = { new Sort( CfbSchema.STARTTIME, Sort.Direction.DESCENDING ) };
                int limit = 1;
                
@@ -300,7 +313,7 @@ public class DbStore {
        
        Analysis getAnalysis(Long analysisId) throws SQLException, TypeMismatchException
        {
-               Column[] columns = { CfbSchema.VERSION, CfbSchema.STARTTIME, CfbSchema.ENDTIME };
+               Column[] columns = { CfbSchema.PROJNAME, CfbSchema.VERSION, CfbSchema.STARTTIME, CfbSchema.ENDTIME };
                Table[] tables = { CfbSchema.RUNS };
                Condition[] conditions = { new Condition( CfbSchema.RUNID, analysisId, Operation.EQUAL ) };
                
@@ -311,11 +324,12 @@ public class DbStore {
                
                Row row = rows.get(0);
                
-               String version = row.getString(0);
-               java.util.Date start= row.getDate(1);
-               java.util.Date end = row.getDate(2);
+               String projName = row.getString(0);
+               String version = row.getString(1);
+               java.util.Date start= row.getDate(2);
+               java.util.Date end = row.getDate(3);
                
-               Analysis prior = new Analysis(version);
+               Analysis prior = new Analysis(projName, version);
                prior.setId(analysisId.longValue());
                prior.setStart(start);
                prior.setEnd(end);