Partial implemenation of load-Analysis code.
[cfb.git] / prod / net / jaekl / cfb / store / DbStore.java
index 315ade579272e91cb8d91b22bd8b5d1d58fca54c..37a389801ca5ced85bf4246de05a012ae68e4a2a 100644 (file)
@@ -11,10 +11,12 @@ import net.jaekl.cfb.db.Column;
 import net.jaekl.cfb.db.Condition;
 import net.jaekl.cfb.db.Operation;
 import net.jaekl.cfb.db.Row;
+import net.jaekl.cfb.db.Sort;
 import net.jaekl.cfb.db.Table;
 import net.jaekl.cfb.db.TypeMismatchException;
 import net.jaekl.cfb.db.driver.DbDriver;
 import net.jaekl.cfb.xml.BugClass;
+import net.jaekl.cfb.xml.BugCollection;
 import net.jaekl.cfb.xml.BugInstance;
 import net.jaekl.cfb.xml.BugMethod;
 import net.jaekl.cfb.xml.LocalVariable;
@@ -31,6 +33,18 @@ public class DbStore {
                m_driver = driver;
                m_msgColl = msgColl;
        }
+
+       public Analysis getPrior(Analysis analysis) throws SQLException, TypeMismatchException {
+               if (null == analysis) {
+                       return null;
+               }
+               Long priorId = getPriorId(analysis);
+               if (null == priorId) {
+                       return null;
+               }
+               
+               return getAnalysis(priorId);
+       }
        
        public boolean put(Analysis analysis) throws SQLException, TypeMismatchException {
                if (null == analysis) {
@@ -261,4 +275,51 @@ public class DbStore {
                
                return Long.valueOf(varId);
        }
+       
+       Long getPriorId(Analysis analysis) throws SQLException, TypeMismatchException
+       {
+               Column[] columns = { CfbSchema.RUNID };
+               Table[] tables = { CfbSchema.RUNS };
+               Condition[] conditions = { new Condition( CfbSchema.STARTTIME, analysis.getStart(), Operation.LESS_THAN ) };
+               Sort[] sorts = { new Sort( CfbSchema.STARTTIME, Sort.Direction.DESCENDING ) };
+               int limit = 1;
+               
+               List<Row> rows = m_driver.select(m_con, columns, tables, conditions, sorts, limit);
+               if (rows.size() < 1) {
+                       return null;
+               }
+               return rows.get(0).getLong(0);
+       }
+       
+       Analysis getAnalysis(Long priorId) throws SQLException, TypeMismatchException
+       {
+               Column[] columns = { CfbSchema.VERSION, CfbSchema.STARTTIME, CfbSchema.ENDTIME };
+               Table[] tables = { CfbSchema.RUNS };
+               Condition[] conditions = { new Condition( CfbSchema.RUNID, priorId, Operation.EQUAL ) };
+               
+               List<Row> rows = m_driver.select(m_con, columns, tables, conditions);
+               if (rows.size() < 1) {
+                       return null;
+               }
+               
+               Row row = rows.get(0);
+               
+               String version = row.getString(0);
+               java.util.Date start= row.getDate(1);
+               java.util.Date end = row.getDate(2);
+               
+               Analysis prior = new Analysis(version);
+               prior.setId(priorId.longValue());
+               prior.setStart(start);
+               prior.setEnd(end);
+               
+               prior.setBugCollection(getBugCollection(priorId));
+               
+               return prior;
+       }
+       
+       BugCollection getBugCollection(Long priorId) throws SQLException, TypeMismatchException 
+       {
+               throw new UnsupportedOperationException("Not yet implemented");
+       }
 }