예제 #1
0
 /**
  * Recursive method to include a tree of groups.
  *
  * @param cursor The current GroupTreeNode in the GroupsTree
  * @param parentID The integer ID associated with the cursors's parent node
  * @param currentID The integer value to associate with the cursor
  * @param out The output (PrintStream or Connection) object to which the DML should be written.
  * @param database_id Id of jabref database to which the group is part of
  */
 private int populateEntryGroupsTable(
     GroupTreeNode cursor, int parentID, int currentID, Object out, int database_id)
     throws SQLException {
   // if this group contains entries...
   if (cursor.getGroup() instanceof ExplicitGroup) {
     ExplicitGroup grp = (ExplicitGroup) cursor.getGroup();
     for (BibtexEntry be : grp.getEntries()) {
       SQLUtil.processQuery(
           out,
           "INSERT INTO entry_group (entries_id, groups_id) "
               + "VALUES ("
               + "(SELECT entries_id FROM entries WHERE jabref_eid="
               + '\''
               + be.getId()
               + "' AND database_id = "
               + database_id
               + "), "
               + "(SELECT groups_id FROM groups WHERE database_id="
               + '\''
               + database_id
               + "' AND parent_id="
               + '\''
               + parentID
               + "' AND label="
               + '\''
               + grp.getName()
               + "')"
               + ");");
     }
   }
   // recurse on child nodes (depth-first traversal)
   Object response =
       SQLUtil.processQueryWithResults(
           out,
           "SELECT groups_id FROM groups WHERE label='"
               + cursor.getGroup().getName()
               + "' AND database_id='"
               + database_id
               + "' AND parent_id='"
               + parentID
               + "';");
   // setting values to ID and myID to be used in case of textual SQL
   // export
   ++currentID;
   int myID = currentID;
   if (response instanceof Statement) {
     ResultSet rs = ((Statement) response).getResultSet();
     rs.next();
     myID = rs.getInt("groups_id");
   }
   for (Enumeration<GroupTreeNode> e = cursor.children(); e.hasMoreElements(); ) {
     currentID = populateEntryGroupsTable(e.nextElement(), myID, currentID, out, database_id);
   }
   return currentID;
 }