X-Git-Url: http://jaekl.net/gitweb/?a=blobdiff_plain;f=prod%2Fnet%2Fjaekl%2Fcfb%2Fstore%2FDbStore.java;h=1ab20222db35ba68b0fa837599463d3637b383d9;hb=e6448f6cf67e5a5409f24b531c2443b3bed53b52;hp=6c2097925f3d78a3c14fb91e6325643d66578be1;hpb=769f0f2e9b90516e68246b551a4c68f953018c72;p=cfb.git diff --git a/prod/net/jaekl/cfb/store/DbStore.java b/prod/net/jaekl/cfb/store/DbStore.java index 6c20979..1ab2022 100644 --- a/prod/net/jaekl/cfb/store/DbStore.java +++ b/prod/net/jaekl/cfb/store/DbStore.java @@ -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,14 @@ 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()); + assert (null != analysis.getBuildNumber()); + // ---------------------------------- // Add a run record for this analysis @@ -54,6 +59,7 @@ public class DbStore { Object[][] values = { { Long.valueOf(runId), + analysis.getProjectName(), analysis.getBuildNumber(), analysis.getStart(), analysis.getEnd() @@ -81,6 +87,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; @@ -117,7 +130,7 @@ public class DbStore { } - Location getLoc(Long locId) throws SQLException, TypeMismatchException + Location getLoc(Long locId) throws TypeMismatchException, StoreException { if (null == locId) { return null; @@ -127,16 +140,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 @@ -208,7 +226,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; @@ -220,7 +238,7 @@ public class DbStore { List 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); @@ -287,7 +305,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; @@ -298,9 +319,9 @@ 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.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 +332,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); @@ -325,7 +347,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,