コード例 #1
0
ファイル: xmelonSchema.java プロジェクト: axaharman/gastona
 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
ファイル: xmelonSchema.java プロジェクト: axaharman/gastona
  public TextFile openDBforFile(String dbName, String fileName, String tablePrefix) {
    perFile = new perFileStruc();

    cliDB = new sqlSolver();
    initialScript(dbName, tablePrefix);

    if (checkMisprog(cliDB == null, "cliDB")) return null;
    if (checkMisprog(cached == null, "cached")) return null;

    cliDB.openScript();
    out(
        "INSERT INTO "
            + cached.tabPrefix
            + "_files VALUES ("
            + cached.fileID
            + ", '"
            + cliDB.escapeString(DateFormat.getTodayStr())
            + "', '"
            + fileName
            + "');");

    log.dbg(2, "processOneFile", "start parsing [" + fileName + "]");
    TextFile tf = new TextFile();
    if (!tf.fopen(fileName, "rb")) // mode "rb" to be able to get the InputStream!
    {
      log.err("processOneFile", "file to parse [" + fileName + "] cannot be openned!");
      return null;
    }
    return tf;
  }
コード例 #3
0
ファイル: xmelonSchema.java プロジェクト: axaharman/gastona
 public boolean checkMisprog(boolean sayAgain, String varName) {
   if (sayAgain)
     log.severe("out", varName + " is null during operation, is xmelonSchema misprogrammed?");
   return sayAgain;
 }
コード例 #4
0
ファイル: xmelonSchema.java プロジェクト: axaharman/gastona
 public void clearCache() {
   cached = new cacheableStruct();
   log.dbg(2, "clearCache", "cache cleared");
 }
コード例 #5
0
ファイル: xmelonSchema.java プロジェクト: axaharman/gastona
  /**
   * NOTE: Only call this function if a record is going to be stored
   *
   * <p>When calling this function with the current path WE KNOW that there is data to be stored
   * using this pathID, therefore we set HASDATA = 1 for this path
   */
  public long getPathTypeIdentifier() {
    if (checkMisprog(perFile == null, "perFile")) return -1;
    if (checkMisprog(cached == null, "cached")) return -1;

    // form path and search for its index
    //
    int currentPathIndx = perFile.currentPath.rows() - 1;
    String pathStr = "";
    String lastNode = perFile.currentPath.getValue(currentPathIndx, cNODE);
    for (int ii = 0; ii <= currentPathIndx; ii++) {
      pathStr += "/" + perFile.currentPath.getValue(ii, cNODE);
    }
    long indx = cached.patIDList.indexOf(pathStr);

    log.dbg(
        2,
        "getPathTypeIdentifier pathStr ["
            + pathStr
            + "] currentPathIndx = "
            + currentPathIndx
            + " index = "
            + indx);

    // SET has data flag
    if (currentPathIndx >= 0) {
      perFile.currentPath.setValue("1", currentPathIndx, cHASDATA);
    }

    if (indx == -1) {
      cached.patIDList.add(pathStr);
      indx = cached.patIDList.size() - 1;

      // (o) TOSEE_XMeLon is this record convenient ? 14.02.2010 02:46
      if (indx == 0) {
        // first one, insert path root (one per file)
        out("INSERT OR IGNORE INTO " + cached.tabPrefix + "_pathDef VALUES (0, 0, '', '', '', 0);");
      }

      long parentIndx = getPathParentIndex(pathStr);

      log.dbg(2, "getPathTypeIdentifier a insert con parentIndx = " + parentIndx);
      out(
          "INSERT INTO "
              + cached.tabPrefix
              + "_pathDef VALUES ("
              + (MIN_PAT_ID + indx)
              + ", "
              + (parentIndx != -1 ? (MIN_PAT_ID + parentIndx) : 0)
              + ", '"
              + utilEscapeStr.escapeStr(pathStr)
              + "', '"
              + utilEscapeStr.escapeStr(naming.toVariableName(pathStr))
              + "', '"
              + utilEscapeStr.escapeStr(lastNode)
              + "', "
              + perFile.currentPath.rows()
              + ");");
    }

    return MIN_PAT_ID + indx;
  }
コード例 #6
0
ファイル: xmelonSchema.java プロジェクト: axaharman/gastona
  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");
  }