Add ability to load previously found bugs back out of the database.
[cfb.git] / prod / net / jaekl / cfb / db / driver / DbDriver.java
index eea3e22c44c8d89f8fa79d21a52089b87e05555b..a756ab2d39f673b225eee46a4adcfef17bd2b219 100644 (file)
@@ -80,6 +80,22 @@ public abstract class DbDriver {
                }
        }
        
+       public Row selectExactlyOne(Connection con, Column[] columns, Table[] tables, Condition[] conditions) 
+               throws SQLException
+       {
+               Sort[] sorts = new Sort[0];
+               int limit = 2;
+               List<Row> rows = select(con, columns, tables, conditions, sorts, limit);
+               if (rows.size() < 1) {
+                       throw new SQLException("Expected one result, but found none:  ", selectSql(columns, tables, conditions, sorts, limit));
+               }
+               if (rows.size() > 1) {
+                       throw new SQLException("Expected one result, but found more than one:  " + selectSql(columns, tables, conditions, sorts, limit));
+               }
+               
+               return rows.get(0);
+       }
+       
        public List<Row> select(Connection con, Column[] columns, Table[] tables, Condition[] conditions)
                throws SQLException
        {
@@ -131,6 +147,8 @@ public abstract class DbDriver {
                int count = 0;
                int pendingValues = 0;
                
+               assert( isValidInsert(table, values));
+               
                String sql = insertSql(table);
                
                try (PreparedStatement ps = con.prepareStatement(sql))
@@ -372,4 +390,21 @@ public abstract class DbDriver {
        }
        
        abstract protected String nextValSql(Sequence seq);
+       
+       boolean isValidInsert(Table table, Object[][] values)
+       {
+               if (null == table) return false;
+               if (null == values) return false;
+               
+               for (Object[] rowValues : values) {
+                       if (rowValues.length != table.getNumColumns()) {
+                               return false;
+                       }
+                       for (int idx = 0; idx < rowValues.length; ++idx) {
+                               
+                       }
+               }
+               
+               return true;
+       }
 }