X-Git-Url: http://jaekl.net/gitweb/?p=cfb.git;a=blobdiff_plain;f=prod%2Fnet%2Fjaekl%2Fcfb%2Fstore%2FDbStore.java;h=37a389801ca5ced85bf4246de05a012ae68e4a2a;hp=315ade579272e91cb8d91b22bd8b5d1d58fca54c;hb=538190e8467a555615fbaf1ada3eed44631e10b4;hpb=358d80a86ac7c79cd57b81a4f1708da80db2f0ec diff --git a/prod/net/jaekl/cfb/store/DbStore.java b/prod/net/jaekl/cfb/store/DbStore.java index 315ade5..37a3898 100644 --- a/prod/net/jaekl/cfb/store/DbStore.java +++ b/prod/net/jaekl/cfb/store/DbStore.java @@ -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 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 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"); + } }