Exemple #1
0
  /**
   * Executes query with input stream.
   *
   * @param xquery
   */
  public void executeQueryWithStream(String xquery, InputStream inputStream)
      throws PersistanceException {

    Connection conn = null;
    Statement statement = null;

    List arrayList = new ArrayList(5);

    System.out.println(" runQuery : " + xquery);
    try {
      conn = TLConnectionPool.getTLConnectionPool().borrowConnection();
      statement = conn.createStatement();
      statement.setQueryOption(QueryOption.XMLSPACE, "preserve");
      statement.execute(xquery, inputStream);

    } catch (Exception ex) {
      ex.printStackTrace();
      throw new PersistanceException(ex);
    } finally {
      try {
        if (statement != null) statement.close();
        TLConnectionPool.getTLConnectionPool().returnConnection(conn);
      } catch (Exception ex) {
      }
    }
  }
Exemple #2
0
  public String returnExecuteQueryStringsAsString(String xquery) throws PersistanceException {

    Connection conn = null;
    Statement statement = null;
    ResultSet resultSet = null;
    List list = new ArrayList(5);
    StringBuffer buf = new StringBuffer();
    try {
      conn = TLConnectionPool.getTLConnectionPool().borrowConnection();
      statement = conn.createStatement();
      statement.setQueryOption(QueryOption.XMLSPACE, "preserve");
      resultSet = statement.execute(xquery);
      while (resultSet.next()) {
        String s = resultSet.getString();
        // list.add(resultSet.getString());
        buf.append(s);
        System.out.println("--------TLQR --------->>> " + s);
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      throw new PersistanceException(ex);
    } finally {
      try {
        if (resultSet != null) resultSet.close();
        if (statement != null) statement.close();
        TLConnectionPool.getTLConnectionPool().returnConnection(conn);
      } catch (Exception ex) {
      }
    }
    return buf.toString();
  }
Exemple #3
0
  /**
   * Run the query aganist TL and return result as list of strings.
   *
   * @param xquery
   * @return
   * @throws PersistanceException
   */
  public List returnExecuteQueryStrings(String xquery) throws PersistanceException {

    Connection conn = null;
    Statement statement = null;
    ResultSet resultSet = null;
    List list = new ArrayList(5);
    try {
      conn = TLConnectionPool.getTLConnectionPool().borrowConnection();
      statement = conn.createStatement();
      statement.setQueryOption(QueryOption.XMLSPACE, "preserve");
      resultSet = statement.execute(xquery);
      while (resultSet.next()) {
        list.add(resultSet.getString());
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      throw new PersistanceException(ex);
    } finally {
      try {
        if (resultSet != null) resultSet.close();
        if (statement != null) statement.close();
        TLConnectionPool.getTLConnectionPool().returnConnection(conn);
      } catch (Exception ex) {
      }
    }
    return list;
  }
Exemple #4
0
  /**
   * Returns numbers of documents inside specified collection
   *
   * @param colName
   */
  public int executeCountQuery(String dataBaseName, String colName) throws PersistanceException {

    ResultSet resultSet = null;
    Connection conn = null;
    Statement statement = null;
    int i = 0;

    try {
      conn = TLConnectionPool.getTLConnectionPool().borrowConnection();
      statement = conn.createStatement();
      statement.setQueryOption(QueryOption.XMLSPACE, "preserve");
      String xquery = "count( collection('tig:///" + dataBaseName + "/" + colName + "') )";
      resultSet = statement.execute(xquery);
      // we need to call next before taking
      // out any result from result set
      while (resultSet.next()) {
        i = resultSet.getInt();
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      throw new PersistanceException(ex);
    } finally {
      try {
        if (resultSet != null) resultSet.close();
        if (statement != null) statement.close();
        TLConnectionPool.getTLConnectionPool().returnConnection(conn);
      } catch (Exception e) {
      }
    }

    return i;
  }
Exemple #5
0
 /**
  * Execute specified query in the Tiger Logic.
  *
  * @param xquery
  */
 public void executeUpdate(String xquery) throws PersistanceException {
   Connection conn = null;
   try {
     conn = TLConnectionPool.getTLConnectionPool().borrowConnection();
     executeUpdate(conn, xquery);
   } catch (Exception ex) {
     ex.printStackTrace();
     throw new PersistanceException(ex);
   } finally {
     try {
       TLConnectionPool.getTLConnectionPool().returnConnection(conn);
     } catch (Exception ex) {
     }
   }
 }
Exemple #6
0
  /**
   * Returns result as a list of inputstreams.
   *
   * @param xquery
   */
  public List executeQuery(String xquery) throws PersistanceException {

    InputStream stream = null;
    ResultSet resultSet = null;
    Connection conn = null;
    Statement statement = null;
    byte[] data = null;

    List arrayList = new ArrayList();

    System.out.println(" runQuery : " + xquery);
    try {
      conn = TLConnectionPool.getTLConnectionPool().borrowConnection();
      statement = conn.createStatement();
      statement.setQueryOption(QueryOption.XMLSPACE, "preserve");
      resultSet = statement.execute(xquery);
      // we need to call next before taking
      // out any result from result set
      while (resultSet.next()) {
        data = StreamHelper.copy(resultSet.getStream());
        stream = new ByteArrayInputStream(data);
        arrayList.add(stream);
      }

    } catch (Exception ex) {
      ex.printStackTrace();
      throw new PersistanceException(ex);
    } finally {
      try {
        if (resultSet != null) resultSet.close();
        if (statement != null) statement.close();
        TLConnectionPool.getTLConnectionPool().returnConnection(conn);
      } catch (Exception ex) {
      }
    }

    return arrayList;
  }