import net.jaekl.cfb.xml.BugCollection;
import net.jaekl.cfb.xml.BugInstance;
import net.jaekl.cfb.xml.LocalVariable;
+import net.jaekl.cfb.xml.Variable;
+import net.jaekl.cfb.xml.messages.BugCategory;
+import net.jaekl.cfb.xml.messages.BugPattern;
import net.jaekl.cfb.xml.messages.MessageCollection;
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;
}
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
Object[][] values = {
{
Long.valueOf(runId),
+ analysis.getProjectName(),
analysis.getBuildNumber(),
analysis.getStart(),
analysis.getEnd()
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;
}
- Location getLoc(Long locId) throws SQLException, TypeMismatchException
+ Location getLoc(Long locId) throws TypeMismatchException, StoreException
{
+ if (null == locId) {
+ return null;
+ }
+
Column[] columns = { CfbSchema.CLASSNAME, CfbSchema.METHODNAME, CfbSchema.METHODROLE, CfbSchema.STARTLINE, CfbSchema.ENDLINE };
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);
- long startLine = row.getLong(3);
- long endLine = row.getLong(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
return null;
}
- List<LocalVariable> vars = bug.getVariables();
+ List<Variable> vars = bug.getVariables();
if ((null == vars) || (0 == vars.size())) {
return null;
}
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;
+ }
+
Column[] columns = { CfbSchema.NAME, CfbSchema.VARROLE };
Table[] tables = { CfbSchema.VARIABLES };
Condition[] conditions = { new Condition(CfbSchema.VARID_PK, varId, Operation.EQUAL) };
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);
return new LocalVariable(varId, varName, varRole);
}
- Long getVarId(LocalVariable var) throws SQLException, TypeMismatchException
+ Long getVarId(Variable var) throws SQLException, TypeMismatchException
{
if (null == var) {
return null;
return storeVar(var);
}
- Long findVarId(LocalVariable var) throws SQLException, TypeMismatchException
+ Long findVarId(Variable var) throws SQLException, TypeMismatchException
{
Column[] columns = { CfbSchema.VARID_PK };
Table[] tables = { CfbSchema.VARIABLES };
return null; // not found
}
- Long storeVar(LocalVariable var) throws SQLException
+ Long storeVar(Variable var) throws SQLException
{
long varId = m_driver.nextVal(m_con, CfbSchema.VARIABLE_SEQ);
{
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;
return rows.get(0).getLong(0);
}
- Analysis getAnalysis(Long priorId) 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, priorId, Operation.EQUAL ) };
+ Condition[] conditions = { new Condition( CfbSchema.RUNID, analysisId, Operation.EQUAL ) };
List<Row> rows = m_driver.select(m_con, columns, tables, conditions);
if (rows.size() < 1) {
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);
- prior.setId(priorId.longValue());
+ Analysis prior = new Analysis(projName, version);
+ prior.setId(analysisId.longValue());
prior.setStart(start);
prior.setEnd(end);
- prior.setBugCollection(getBugCollection(priorId));
+ prior.setBugCollection(getBugCollection(analysisId));
return prior;
}
- BugCollection getBugCollection(Long runId) throws SQLException, TypeMismatchException
+ BugCollection getBugCollection(Long runId) throws SQLException, TypeMismatchException, StoreException
{
Column[] columns = {
CfbSchema.FOUNDID,
for (Row row : rows) {
// long foundId = row.getLong(0);
- long bugId = row.getLong(1);
- long categoryId = row.getLong(2);
- long firstLocId = row.getLong(3);
- long secondLocId = row.getLong(4);
- long thirdLocId = row.getLong(5);
- long varId = row.getLong(6);
+ Long bugId = row.getLong(1);
+ Long categoryId = row.getLong(2);
+ Long firstLocId = row.getLong(3);
+ Long secondLocId = row.getLong(4);
+ Long thirdLocId = row.getLong(5);
+ Long varId = row.getLong(6);
String bugType = getBugType(bugId);
String category = getCategoryName(categoryId);
Location[] locations = { getLoc(firstLocId), getLoc(secondLocId), getLoc(thirdLocId) };
- LocalVariable[] vars = { getVar(Long.valueOf(varId)) };
+ LocalVariable[] vars = { getVar(varId) };
BugInstance bug = new BugInstance(bugId, category, bugType, locations, vars);
- coll.getBugs().add(bug);
+ coll.add(bug);
}
return coll;