示例#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) {
      }
    }
  }
示例#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();
  }
示例#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;
  }
示例#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;
  }
示例#5
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;
  }
示例#6
0
  /**
   * Executes update query aganist Tiger Logic.
   *
   * @param conn
   * @param xquery
   */
  public void executeUpdate(Connection conn, String xquery) throws PersistanceException {

    //	System.out.println(" UpdateQuery : " + xquery);
    Statement statement = null;
    try {
      statement = conn.createStatement();
      statement.setQueryOption(QueryOption.XMLSPACE, "preserve");
      statement.executeUpdate(xquery);
    } catch (XQLException ex) {
      ex.printFullLog();
      throw new PersistanceException(ex.getCause());
    } finally {
      try {
        if (statement != null) statement.close();
      } catch (Exception e) {
      }
    }
  }