示例#1
0
 public void closeDB() {
   cliDB.closeScript();
   log.dbg(2, "processOneFile", "storing in DB");
   cliDB.runSQL(cached.dbName);
   log.dbg(2, "processOneFile", "finished");
   cliDB = null;
 }
示例#2
0
  protected void initialScript(String dbName, String prefix) {
    if (checkMisprog(cliDB == null, "cliDB")) return;
    if (checkMisprog(cached == null, "cached")) return;

    // (o) listix_sql_schemas XMELON schema creation

    if (cached.dbName == null
        || !cached.dbName.equals(dbName)
        || cached.tabPrefix == null
        || !cached.tabPrefix.equals(prefix)) {
      cached.tabPrefix = prefix;
      cached.dbName = dbName;
      log.dbg(
          2,
          "initialScript",
          "ensure tables creation for prefix "
              + cached.tabPrefix
              + " in database "
              + cached.dbName);
      cliDB.openScript();

      //
      //   table: xmelon_files    (fileID, timeParse, fullPath)
      //   table: xmelon_tagDef   (tagID, tagStr, tagStrNormal)
      //   table: xmelon_pathDef  (patID, parentPatID, pathStr, pathStrNormal, lastNode, level)
      //   table: xmelon_data     (fileID, dataCnt, patCnt, parentPatCnt, patID, tagID, dataPlace,
      // value)
      //
      String tTAG = cached.tabPrefix + "_tagDef";
      String tPATH = cached.tabPrefix + "_pathDef";
      String tFILE = cached.tabPrefix + "_files";
      String tDATA = cached.tabPrefix + "_data";
      String tLOG = cached.tabPrefix + "_log";

      cliDB.writeScript(
          "CREATE TABLE IF NOT EXISTS "
              + tTAG
              + " (tagID int, tagStr text, tagStrNormal text, UNIQUE(tagID));");
      cliDB.writeScript(
          "CREATE TABLE IF NOT EXISTS "
              + tPATH
              + " (patID int, parentPatID int, pathStr text, pathStrNormal text, lastNode text, level int, UNIQUE(patID));");
      cliDB.writeScript(
          "CREATE TABLE IF NOT EXISTS "
              + tFILE
              + " (fileID int, timeParse text, fullPath text, UNIQUE(fileID));");
      cliDB.writeScript(
          "CREATE TABLE IF NOT EXISTS "
              + tDATA
              + " (fileID int, dataCnt int, patCnt int, parentPatCnt int, patID int, tagID int, dataPlace text, value text, UNIQUE(fileID, dataCnt));");

      cliDB.writeScript(
          "CREATE INDEX IF NOT EXISTS " + tDATA + "_indx1 ON " + tDATA + " (fileID, patCnt);");
      cliDB.writeScript(
          "CREATE INDEX IF NOT EXISTS "
              + tDATA
              + "_indx2 ON "
              + tDATA
              + " (fileID, parentPatCnt);");
      cliDB.writeScript(
          "CREATE INDEX IF NOT EXISTS "
              + tDATA
              + "_indx3 ON "
              + tDATA
              + " (patID, tagID);"); // relevant for <SQL calc_PathTag> in util.lsx
      cliDB.writeScript(
          "CREATE INDEX IF NOT EXISTS "
              + tDATA
              + "_indx4 ON "
              + tDATA
              + " (fileID, patID, patCnt);");

      cliDB.writeScript("CREATE TABLE IF NOT EXISTS " + tLOG + " (fileID int, logMessage text);");

      // o-o  Add dbMore connections info
      //
      // connexiones directas
      //
      //   conn, srcTab, srcKey, targTab, targKey
      //
      //   file  , xmelon_data, fileID, xmelon_files, fileID
      //   path  , xmelon_data, patID, xmelon_pathDef, patID
      //   tag   , xmelon_data, tagID, xmelon_tagDef, tagID
      //   parent, xmelon_data, parentPatCnt, xmelon_data, patCnt
      //
      cliDB.writeScript(deepSqlUtil.getSQL_CreateTableConnections());
      cliDB.writeScript(
          deepSqlUtil.getSQL_InsertConnection("parentPath", tPATH, "parentPatID", tPATH, "patID"));
      cliDB.writeScript(
          deepSqlUtil.getSQL_InsertConnection("file", tDATA, "fileID", tFILE, "fileID"));
      cliDB.writeScript(
          deepSqlUtil.getSQL_InsertConnection("path", tDATA, "patID", tPATH, "patID"));
      cliDB.writeScript(deepSqlUtil.getSQL_InsertConnection("tag", tDATA, "tagID", tTAG, "tagID"));
      // NO! es N->N !
      // cliDB.writeScript (deepSqlUtil.getSQL_InsertConnection("parent"    , tDATA, "parentPatCnt",
      //  tDATA,  "patCnt"));

      cliDB.closeScript();
      cliDB.runSQL(cached.dbName);

      // reset patIDList cache
      cached.patIDList = null;
      cached.tagIDList = null;

      // get last fileID
      cached.fileID =
          sqlUtil.getNextID(cached.dbName, cached.tabPrefix + "_files", "fileID", MIN_FILE_ID);
    } else cached.fileID++;

    if (cached.patIDList != null) return;

    // ok, need the list if given

    // get the list id path ID's
    //
    cached.patIDList =
        cliDB.getSQL(
            dbName,
            ".headers off\nSELECT pathStr FROM " + cached.tabPrefix + "_pathDef ORDER BY patID;");
    log.dbg(
        2, "initialScript", "obtained pathDef list of " + cached.patIDList.size() + " elements");

    // get the list id tag ID's
    //
    cached.tagIDList =
        cliDB.getSQL(
            dbName,
            ".headers off\nSELECT tagStr FROM " + cached.tabPrefix + "_tagDef ORDER BY tagID;");
    log.dbg(2, "initialScript", "obtained tagDef list of " + cached.tagIDList.size() + " elements");
  }