Exemplo n.º 1
0
  public static String createSynonym(
      JDCConnection oConn, String sGuMainTerm, String sTxTerm, String sTxTermPlural, String sDeTerm)
      throws SQLException {
    Term oMain = new Term();

    if (DebugFile.trace) {
      DebugFile.writeln(
          "Begin Thesauri.createSynonym([Connection],"
              + sGuMainTerm
              + ","
              + sTxTerm
              + ","
              + sTxTermPlural
              + ","
              + sDeTerm);
      DebugFile.incIdent();
    }

    oMain.load(oConn, new Object[] {sGuMainTerm});

    int iLevel = oMain.level();

    oMain.replace(DB.gu_term, Gadgets.generateUUID());
    oMain.replace(DB.gu_synonym, sGuMainTerm);
    oMain.replace(DB.id_term + String.valueOf(iLevel - 1), DBBind.nextVal(oConn, "seq_thesauri"));
    oMain.replace(DB.tx_term, sTxTerm);
    oMain.replace(DB.tx_term + "2", sTxTermPlural);
    oMain.replace(DB.de_term, sDeTerm);

    oMain.store(oConn);

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End Thesauri.createSynonym() : " + oMain.getString(DB.gu_term));
    }

    return oMain.getString(DB.gu_term);
  }
Exemplo n.º 2
0
  /**
   * Create Root Term
   *
   * @param oConn Database Connection
   * @param sTxTerm Term Text Singular
   * @param sTxTerm Term Text Plural
   * @param sDeTerm Term Contextual Description
   * @param sIdLanguage Language
   * @param sIdScope Scope
   * @param iIdDomain Domain Numeric Identifier (from k_domains)
   * @param sGuWorkArea WorkArea GUID
   * @return GUID for new term
   * @throws SQLException
   */
  public static String createRootTerm(
      JDCConnection oConn,
      String sTxTerm,
      String sTxTermPlural,
      String sDeTerm,
      String sIdLanguage,
      String sIdScope,
      int iIdDomain,
      String sGuWorkArea)
      throws SQLException {
    PreparedStatement oStmt;
    String sGuRootTerm = Gadgets.generateUUID();
    int iNextVal;

    if (DebugFile.trace) {
      DebugFile.writeln(
          "Begin Thesauri.createRootTerm([Connection],"
              + sTxTerm
              + ","
              + sTxTermPlural
              + ","
              + sDeTerm
              + ","
              + sIdLanguage
              + ","
              + sIdScope
              + String.valueOf(iIdDomain)
              + ","
              + sGuWorkArea
              + ")");
      DebugFile.incIdent();
      DebugFile.writeln(
          "Connection.prepareStatement(INSERT INTO "
              + DB.k_thesauri_root
              + " ("
              + DB.gu_rootterm
              + ","
              + DB.tx_term
              + ","
              + DB.tx_term
              + "2,"
              + DB.id_domain
              + ","
              + DB.gu_workarea
              + ","
              + DB.id_scope
              + ") VALUES ('"
              + sGuRootTerm
              + "','"
              + sTxTerm
              + "',"
              + String.valueOf(iIdDomain)
              + ",'"
              + sGuWorkArea
              + "','"
              + sIdScope
              + "'))");
    }

    oStmt =
        oConn.prepareStatement(
            "INSERT INTO "
                + DB.k_thesauri_root
                + " ("
                + DB.gu_rootterm
                + ","
                + DB.tx_term
                + ","
                + DB.id_domain
                + ","
                + DB.gu_workarea
                + ","
                + DB.id_scope
                + ") VALUES (?,?,?,?,?)");
    oStmt.setString(1, sGuRootTerm);
    oStmt.setString(2, sTxTerm);
    oStmt.setInt(3, iIdDomain);
    oStmt.setString(4, sGuWorkArea);
    oStmt.setString(5, sIdScope);
    oStmt.executeUpdate();
    oStmt.close();

    iNextVal = DBBind.nextVal(oConn, "seq_thesauri");

    if (DebugFile.trace)
      DebugFile.writeln(
          "Connection.prepareStatement(INSERT INTO "
              + DB.k_thesauri
              + " ("
              + DB.gu_rootterm
              + ","
              + DB.gu_term
              + ","
              + DB.tx_term
              + ","
              + DB.tx_term
              + "2,"
              + DB.id_language
              + ","
              + DB.de_term
              + ","
              + DB.id_scope
              + ","
              + DB.id_domain
              + ","
              + DB.id_term
              + "0) VALUES ('"
              + sGuRootTerm
              + "','"
              + sGuRootTerm
              + "','"
              + sTxTerm
              + "','"
              + sIdLanguage
              + "','"
              + sDeTerm
              + "','"
              + sIdScope
              + "',"
              + String.valueOf(iIdDomain)
              + ","
              + String.valueOf(iNextVal)
              + "))");

    oStmt =
        oConn.prepareStatement(
            "INSERT INTO "
                + DB.k_thesauri
                + " ("
                + DB.gu_rootterm
                + ","
                + DB.gu_term
                + ","
                + DB.tx_term
                + ","
                + DB.tx_term
                + "2,"
                + DB.id_language
                + ","
                + DB.de_term
                + ","
                + DB.id_scope
                + ","
                + DB.id_domain
                + ","
                + DB.id_term
                + "0) VALUES (?,?,?,?,?,?,?,?,?)");
    oStmt.setString(1, sGuRootTerm);
    oStmt.setString(2, sGuRootTerm);
    oStmt.setString(3, sTxTerm);
    oStmt.setString(4, sTxTermPlural);
    oStmt.setString(5, sIdLanguage);
    if (sDeTerm == null) oStmt.setNull(6, Types.VARCHAR);
    else oStmt.setString(6, sDeTerm);
    oStmt.setString(7, sIdScope);
    oStmt.setInt(8, iIdDomain);
    oStmt.setInt(9, iNextVal);
    oStmt.executeUpdate();
    oStmt.close();

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End Thesauri.createRootTerm() : " + sGuRootTerm);
    }

    return sGuRootTerm;
  } // createRootTerm
Exemplo n.º 3
0
  /**
   * Create Term
   *
   * @param oConn Database Connection
   * @param sGuParent Parent Term
   * @param sTxTerm Term Text Singular
   * @param sTxTermPlural Term Text Plural
   * @param sDeTerm Term Contextual Description
   * @param sIdLanguage Language
   * @param sIdScope Scope
   * @param iIdDomain Domain Numeric Identifier (from k_domains)
   * @return GUID for new term
   * @throws SQLException
   */
  public static String createTerm(
      JDCConnection oConn,
      String sGuParent,
      String sTxTerm,
      String sTxTermPlural,
      String sDeTerm,
      String sIdLanguage,
      String sIdScope,
      int iIdDomain)
      throws SQLException {
    ResultSet oRSet;
    PreparedStatement oStmt;
    String sGuTerm = Gadgets.generateUUID();
    String sGuRootTerm;
    Object[] oTerm = new Object[10];
    int iTerm;
    int iNext;

    if (DebugFile.trace) {
      DebugFile.writeln(
          "Begin Thesauri.createTerm([Connection],"
              + sGuParent
              + ","
              + sTxTerm
              + ","
              + sTxTermPlural
              + ","
              + sDeTerm
              + ","
              + sIdLanguage
              + ","
              + sIdScope
              + String.valueOf(iIdDomain)
              + ")");
      DebugFile.incIdent();
      DebugFile.writeln(
          "Connection.prepareStatement(SELECT "
              + DB.gu_rootterm
              + ","
              + DB.id_term
              + "0,"
              + DB.id_term
              + "1,"
              + DB.id_term
              + "2,"
              + DB.id_term
              + "3,"
              + DB.id_term
              + "4,"
              + DB.id_term
              + "5,"
              + DB.id_term
              + "6,"
              + DB.id_term
              + "7,"
              + DB.id_term
              + "8,"
              + DB.id_term
              + "9 FROM "
              + DB.k_thesauri
              + " WHERE "
              + DB.gu_term
              + "='"
              + sGuParent
              + "'");
    }

    oStmt =
        oConn.prepareStatement(
            "SELECT "
                + DB.gu_rootterm
                + ","
                + DB.id_term
                + "0,"
                + DB.id_term
                + "1,"
                + DB.id_term
                + "2,"
                + DB.id_term
                + "3,"
                + DB.id_term
                + "4,"
                + DB.id_term
                + "5,"
                + DB.id_term
                + "6,"
                + DB.id_term
                + "7,"
                + DB.id_term
                + "8,"
                + DB.id_term
                + "9 FROM "
                + DB.k_thesauri
                + " WHERE "
                + DB.gu_term
                + "=?",
            ResultSet.TYPE_FORWARD_ONLY,
            ResultSet.CONCUR_READ_ONLY);
    oStmt.setString(1, sGuParent);
    oRSet = oStmt.executeQuery();
    boolean bParentExists = oRSet.next();
    if (bParentExists) {
      sGuRootTerm = oRSet.getString(1);
      oTerm[0] = oRSet.getObject(2);
      oTerm[1] = oRSet.getObject(3);
      oTerm[2] = oRSet.getObject(4);
      oTerm[3] = oRSet.getObject(5);
      oTerm[4] = oRSet.getObject(6);
      oTerm[5] = oRSet.getObject(7);
      oTerm[6] = oRSet.getObject(8);
      oTerm[7] = oRSet.getObject(9);
      oTerm[8] = oRSet.getObject(10);
      oTerm[9] = oRSet.getObject(11);
    } else {
      sGuRootTerm = null;
    }
    oRSet.close();
    oStmt.close();

    if (!bParentExists) {
      if (DebugFile.trace) {
        DebugFile.writeln("Parent term \"" + sGuParent + "\" not found");
        DebugFile.decIdent();
      }
      throw new SQLException("Thesauri.createTerm() Parent term \"" + sGuParent + "\" not found");
    }

    if (DebugFile.trace)
      DebugFile.writeln(
          "Connection.prepareStatement(INSERT INTO "
              + DB.k_thesauri
              + " ("
              + DB.gu_rootterm
              + ","
              + DB.gu_term
              + ","
              + DB.tx_term
              + ","
              + DB.tx_term
              + "2,"
              + DB.id_language
              + ","
              + DB.de_term
              + ","
              + DB.id_scope
              + ","
              + DB.id_domain
              + ","
              + DB.id_term
              + "0,"
              + DB.id_term
              + "1,"
              + DB.id_term
              + "2,"
              + DB.id_term
              + "3,"
              + DB.id_term
              + "4,"
              + DB.id_term
              + "5,"
              + DB.id_term
              + "6,"
              + DB.id_term
              + "7,"
              + DB.id_term
              + "8,"
              + DB.id_term
              + "9) VALUES ('"
              + sGuRootTerm
              + "','"
              + sGuTerm
              + "','"
              + sTxTerm
              + "','"
              + sTxTermPlural
              + "','"
              + sIdLanguage
              + "','"
              + sDeTerm
              + "','"
              + sIdScope
              + "',"
              + String.valueOf(iIdDomain)
              + ",?,?,?,?,?,?,?,?,?,?))");

    oStmt =
        oConn.prepareStatement(
            "INSERT INTO "
                + DB.k_thesauri
                + " ("
                + DB.gu_rootterm
                + ","
                + DB.gu_term
                + ","
                + DB.tx_term
                + ","
                + DB.tx_term
                + "2,"
                + DB.id_language
                + ","
                + DB.de_term
                + ","
                + DB.id_scope
                + ","
                + DB.id_domain
                + ","
                + DB.id_term
                + "0,"
                + DB.id_term
                + "1,"
                + DB.id_term
                + "2,"
                + DB.id_term
                + "3,"
                + DB.id_term
                + "4,"
                + DB.id_term
                + "5,"
                + DB.id_term
                + "6,"
                + DB.id_term
                + "7,"
                + DB.id_term
                + "8,"
                + DB.id_term
                + "9) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
    oStmt.setString(1, sGuRootTerm);
    oStmt.setString(2, sGuTerm);
    oStmt.setString(3, sTxTerm);
    oStmt.setString(4, sTxTermPlural);
    oStmt.setString(5, sIdLanguage);
    if (sDeTerm == null) oStmt.setNull(6, Types.VARCHAR);
    else oStmt.setString(6, sDeTerm);
    oStmt.setString(7, sIdScope);
    oStmt.setInt(8, iIdDomain);

    iTerm = 0;
    do {
      if (null == oTerm[iTerm]) break;

      if (DebugFile.trace)
        DebugFile.writeln(
            "PreparedStatement.setObject("
                + String.valueOf(iTerm + 9)
                + ", "
                + oTerm[iTerm]
                + ", java.sql.Types.INTEGER)");

      oStmt.setObject(iTerm + 9, oTerm[iTerm], java.sql.Types.INTEGER);
    } while (++iTerm <= 9);

    if (10 == iTerm)
      throw new SQLException("Thesauri maximum number of hierarchical levels exceeded");

    iNext = DBBind.nextVal(oConn, "seq_thesauri");

    if (DebugFile.trace)
      DebugFile.writeln(
          "PreparedStatement.setInt ("
              + String.valueOf(iTerm + 9)
              + ","
              + String.valueOf(iNext)
              + ")");

    oStmt.setInt(iTerm + 9, iNext);

    while (++iTerm <= 9) {
      if (DebugFile.trace)
        DebugFile.writeln(
            "PreparedStatement.setObject("
                + String.valueOf(iTerm + 9)
                + ", null, java.sql.Types.INTEGER)");

      oStmt.setObject(iTerm + 9, null, java.sql.Types.INTEGER);
    } // wend

    if (DebugFile.trace) DebugFile.writeln("PreparedStatement.executeUpdate();");

    oStmt.executeUpdate();
    oStmt.close();

    if (DebugFile.trace) {
      DebugFile.decIdent();
      DebugFile.writeln("End Thesauri.createTerm() : " + sGuTerm);
    }

    return sGuTerm;
  } // createTerm