Example #1
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();
  }
Example #2
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;
  }
Example #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;
  }
Example #4
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;
  }