X-Git-Url: http://jaekl.net/gitweb/?p=cfb.git;a=blobdiff_plain;f=prod%2Fnet%2Fjaekl%2Fcfb%2Fdb%2FCfbSchema.java;h=d80be57940a084ebeb81dbe17844f7d5cde4c103;hp=1b989ff5e3ba6a91c372d06dd32e29b86715d9ff;hb=58107a0cbb49652e7772ce80fb73d2c027590eb1;hpb=083fb5094456d37fa4765400a461625635fbf77d diff --git a/prod/net/jaekl/cfb/db/CfbSchema.java b/prod/net/jaekl/cfb/db/CfbSchema.java index 1b989ff..d80be57 100644 --- a/prod/net/jaekl/cfb/db/CfbSchema.java +++ b/prod/net/jaekl/cfb/db/CfbSchema.java @@ -7,9 +7,12 @@ import static net.jaekl.cfb.db.Column.Type.*; import java.sql.Connection; import java.sql.SQLException; +import java.util.Collection; import net.jaekl.cfb.analyze.MessageMap; import net.jaekl.cfb.db.driver.DbDriver; +import net.jaekl.cfb.xml.messages.BugCategory; +import net.jaekl.cfb.xml.messages.BugPattern; public class CfbSchema extends Schema { @@ -115,8 +118,51 @@ public class CfbSchema extends Schema { boolean postCreationInit(Connection con) throws SQLException { assert(null != m_msgMap); - + if (! insertCategories(con)) { + return false; + } + if (! insertPatterns(con)) { + return false; + } return true; } + + boolean insertCategories(Connection con) throws SQLException { + Collection categories = m_msgMap.getColl().getCategories(); + + Object[][] values = new Object[categories.size()][CATEGORIES.getNumColumns()]; + + int row = 0; + for (BugCategory cat : categories) { + long categoryId = m_driver.nextVal(con, CATEGORY_SEQ); + + values[row][0] = Long.valueOf(categoryId); + values[row][1] = cat.getCategory(); + row++; + } + + int count = m_driver.insert(con, CATEGORIES, values); + + return (categories.size() == count); + } + + boolean insertPatterns(Connection con) throws SQLException { + Collection patterns = m_msgMap.getColl().getPatterns(); + + Object[][] values = new Object[patterns.size()][BUGS.getNumColumns()]; + + int row = 0; + for (BugPattern bug : patterns) { + long bugId = m_driver.nextVal(con, BUG_SEQ); + + values[row][0] = Long.valueOf(bugId); + values[row][1] = bug.getType(); + row++; + } + + int count = m_driver.insert(con, BUGS, values); + + return (patterns.size() == count); + } }