Exemplo n.º 1
0
 protected void index(ResultSet rs, ILinguist linguist, long sid, String sent)
     throws LoadException {
   if (rs == null) throw new LoadException("Index ResultSet null");
   try {
     // System.out.println(sent);
     String[] words = linguist.indexkeys(sent);
     if (words.length > 0) {
       Map<String, String> dup = new HashMap<String, String>();
       int i = 0;
       for (String word : words) {
         // System.out.print(word+" ");
         if (!dup.containsKey(word)) {
           dup.put(word, word);
           rs.moveToInsertRow();
           rs.updateString("F_Word", word);
           rs.updateLong("F_SID", sid);
           rs.updateInt("F_Offset", i++);
           rs.insertRow();
         }
       }
       // System.out.println();
     }
   } catch (SQLException se) {
     throw new LoadException("SQLException occurred: " + se.getMessage());
   } catch (LanguageException le) {
     throw new LoadException("LanguageException occurred indexing: " + le.getMessage());
   }
 }
Exemplo n.º 2
0
 public void endDocument() throws SAXException {
   // System.out.println("endDocument()");
   try {
     conn_.commit();
     closeDatabase();
   } catch (SQLException sqle) {
     throw new SAXException(sqle.toString());
   }
 }
Exemplo n.º 3
0
 protected void openDatabase() throws LoadException {
   try {
     conn_ =
         DriverManager.getConnection("jdbc:postgresql://localhost/transmem", "tm", "yi4ku4wh3");
     conn_.setAutoCommit(false);
   } catch (SQLException se) {
     throw new LoadException("SQLException occurred: " + se.getMessage());
   }
 }
Exemplo n.º 4
0
 protected long getNextSid() throws LoadException {
   try {
     String sql = "SELECT nextval('S_ENZH')";
     Statement stmt = this.conn_.createStatement();
     ResultSet rs = stmt.executeQuery(sql);
     long sid = 0;
     if (rs.next()) sid = rs.getLong(1);
     rs.close();
     stmt.close();
     return sid;
   } catch (SQLException se) {
     throw new LoadException("SQLException occurred: " + se.getMessage());
   }
 }
Exemplo n.º 5
0
 protected void saveSource() throws LoadException {
   PreparedStatement ps = null;
   try {
     String sql = "INSERT INTO T_Sources(F_SourceID,F_Name) VALUES(?,?)";
     ps = this.conn_.prepareStatement(sql);
     ps.setInt(1, this.from_);
     String s = (this.sourceName_ == null) ? "" : this.sourceName_;
     ps.setString(2, s);
     ps.executeUpdate();
   } catch (SQLException e) {
     throw new LoadException(e.getMessage());
   } finally {
     if (ps != null)
       try {
         ps.close();
       } catch (SQLException x) {
       }
   }
 }
Exemplo n.º 6
0
  protected long saveUnit(String en, String zh) throws LoadException {
    if (this.rs_ == null) {
      String sql = "SELECT * FROM T_ENZH WHERE F_SID = 0";
      try {
        Statement stmt =
            this.conn_.createStatement(
                ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        this.rs_ = stmt.executeQuery(sql);
        Statement stmt1 =
            this.conn_.createStatement(
                ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        this.rs1_ = stmt1.executeQuery("SELECT * FROM T_ENZHX WHERE F_Word='x'");
        Statement stmt2 =
            this.conn_.createStatement(
                ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        this.rs2_ = stmt2.executeQuery("SELECT * FROM T_ZHENX WHERE F_Word='x'");
      } catch (SQLException se) {
        throw new LoadException("SQLException occurred: " + se.getMessage());
      }
    }
    if (this.rs_ == null) throw new LoadException("ResultSet not ready! ");

    long sid = getNextSid();
    // System.out.println("SID = "+sid);
    try {
      this.rs_.moveToInsertRow();
      this.rs_.updateLong("F_SID", sid);
      this.rs_.updateString("F_Source", en);
      this.rs_.updateString("F_Target", zh);
      this.rs_.updateString("F_Domain", this.domain_);
      this.rs_.updateInt("F_From", this.from_);
      // this.rs_.updateString("F_Permit", "P");	//default
      // this.rs_.updateInt("F_Owner", 0);	//default
      this.rs_.insertRow();
      return sid;
    } catch (SQLException se) {
      throw new LoadException("SQLException occurred: " + se.getMessage());
    }
  }