Package se.rupy.pool

Examples of se.rupy.pool.Connection


    return NO;
  }

  public static long max(short type) throws Exception {
    Connection conn = Sprout.connection(false);
    PreparedStatement stmt = null;
    ResultSet result = null;
    String sql = null;
    try {
      sql = "SELECT count(*) AS count FROM poll WHERE type = " + type;
     
      if(Sprout.SQL.driver().equals("org.postgresql.Driver") ||
          Sprout.SQL.driver().equals("oracle.jdbc.OracleDriver")) {
        sql = "SELECT count(*) AS count FROM poll_table WHERE poll_type = " + type;
      }
     
      stmt = conn.prepareStatement(sql);
      result = stmt.executeQuery();
      if(result.next()) {
        return result.getLong("count");
      }
    } catch(SQLException e) {
      throw e;
    } finally {
      if(result != null) {
        result.close();
      }
      if(stmt != null) {
        stmt.close();
      }
      if(conn != null && conn.getAutoCommit()) {
        conn.close();
      }
    }

    return 0;
  }
View Full Code Here


    return most(type, start, limit, Sprout.SQL.driver().equals("com.mysql.jdbc.Driver") ? "ORDER BY value DESC" : "ORDER BY poll_value DESC");
  }

  public static LinkedList most(short type, int start, int limit, String order) throws SQLException {
    LinkedList list = new LinkedList();
    Connection conn = Sprout.connection(false);
    PreparedStatement stmt = null;
    ResultSet result = null;
    String sql = null;
    try {
      sql = "SELECT node FROM poll WHERE type = " + type + " " + order + " LIMIT " + start * limit + ", " + limit;
     
      if(Sprout.SQL.driver().equals("org.postgresql.Driver")) {
        sql = "SELECT poll_node FROM poll_table WHERE poll_type = " + type + " " + order + " OFFSET " + start * limit + " LIMIT " + limit;
      }
     
      if(Sprout.SQL.driver().equals("oracle.jdbc.OracleDriver")) {
        sql = "SELECT poll_node FROM poll_table WHERE poll_type = " + type + " AND ROWNUM BETWEEN " + start * limit + " AND " + (start * limit + limit) + " " + order;
      }
     
      stmt = conn.prepareStatement(sql);
      result = stmt.executeQuery();
      while(result.next()) {
        list.add(find(result.getLong(Sprout.SQL.driver().equals("com.mysql.jdbc.Driver") ? "node" : "poll_node")));
      }
    } catch(SQLException e) {
      throw e;
    } finally {
      if(result != null) {
        result.close();
      }
      if(stmt != null) {
        stmt.close();
      }
      if(conn != null && conn.getAutoCommit()) {
        conn.close();
      }
    }

    return list;
  }
View Full Code Here

    "(n.id = m1.node AND m1.data = d1.id AND m1.data = d2.id AND n.id = l1.parent AND l1.type = " +
    (ARTICLE | USER) + " AND l1.child = n2.id AND n2.id = m2.node AND m2.data = d3.id)";
  }

  public static long max(String query) throws Exception {
    Connection conn = Sprout.connection(false);
    PreparedStatement stmt = null;
    ResultSet result = null;
    String sql = null;
    try {
      sql = "SELECT count(DISTINCT n.id) AS count " + from(query);
     
      if(Sprout.SQL.driver().equals("org.postgresql.Driver") ||
          Sprout.SQL.driver().equals("oracle.jdbc.OracleDriver")) {
        sql = "SELECT count(DISTINCT n.node_id) AS count " + from(query);
      }
     
      stmt = conn.prepareStatement(sql);
     
      byte[] data = ("%" + query + "%").getBytes("UTF-8");

      if(Sprout.SQL.driver().equals("oracle.jdbc.OracleDriver")) {
        data = query.getBytes("UTF-8");
      }
     
      stmt.setBytes(1, data);
      stmt.setBytes(2, data);
      stmt.setBytes(3, data);
     
      result = stmt.executeQuery();
      if(result.next()) {
        return result.getLong("count");
      }
    } catch(SQLException e) {
      throw e;
    } finally {
      if(result != null) {
        result.close();
      }
      if(stmt != null) {
        stmt.close();
      }
      if(conn != null && conn.getAutoCommit()) {
        conn.close();
      }
    }

    return 0;
  }
View Full Code Here

    return 0;
  }

  public static LinkedList query(String query, int start, int limit) throws Exception {
    LinkedList list = new LinkedList();
    Connection conn = Sprout.connection(false);
    PreparedStatement stmt = null;
    ResultSet result = null;
    String sql = null;
    try {
      sql = "SELECT DISTINCT n.id " + from(query) + " ORDER BY n.date DESC LIMIT " + start * limit + ", " + limit;
     
      if(Sprout.SQL.driver().equals("org.postgresql.Driver")) {
        sql = "SELECT DISTINCT n.node_date, n.node_id " + from(query) + " ORDER BY n.node_date DESC OFFSET " + start * limit + " LIMIT " + limit;
      }
     
      if(Sprout.SQL.driver().equals("oracle.jdbc.OracleDriver")) {
        sql = "SELECT DISTINCT n.node_date, n.node_id " + from(query) + " AND ROWNUM BETWEEN " + start * limit + " AND " + (start * limit + limit) + " ORDER BY n.node_date DESC";
      }
     
      stmt = conn.prepareStatement(sql);
     
      byte[] data = ("%" + query + "%").getBytes("UTF-8");

      if(Sprout.SQL.driver().equals("oracle.jdbc.OracleDriver")) {
        data = query.getBytes("UTF-8");
      }
     
      stmt.setBytes(1, data);
      stmt.setBytes(2, data);
      stmt.setBytes(3, data);
     
      result = stmt.executeQuery();
      while(result.next()) {
        list.add(find(result.getLong(Sprout.SQL.driver().equals("com.mysql.jdbc.Driver") ? "id" : "node_id")));
      }
    } catch(SQLException e) {
      throw e;
    } finally {
      if(result != null) {
        result.close();
      }
      if(stmt != null) {
        stmt.close();
      }
      if(conn != null && conn.getAutoCommit()) {
        conn.close();
      }
    }

    return list;
  }
View Full Code Here

TOP

Related Classes of se.rupy.pool.Connection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.