Examples of QueryRunner


Examples of org.apache.commons.dbutils.QueryRunner

    String primaryKeyName,
    Map columnMap)
    throws ControllerException, UpdaterException {

    Connection conn = null;
    QueryRunner queryRunner = new QueryRunner(dataSource);
    ResultSetHandler rsh = new MapHandler();
    String sql = null;

    try {
      conn = dataSource.getConnection();
      conn.setAutoCommit(false); // Start transaction

      sql = "select * from " + tableName;
      sql += " where (" + primaryKeyName + "=?)";
      Map columnMapTemp =
        (Map) queryRunner.query(
          sql,
          columnMap.get(primaryKeyName),
          rsh);

      if (columnMapTemp == null) {
        conn.rollback();
        throw new ControllerException("GenericController: Cannot find record.");
      }

      Date oldDate = (java.util.Date) columnMap.get("date_updated");
      Date newDate = (java.util.Date) columnMapTemp.get("date_updated");
      if (!oldDate.equals(newDate)) {
        conn.rollback();
        throw new UpdaterException();
        // Signal that record has already been changed
      }

      sql = "update " + tableName;
      String parameter = null;
      String columnName = null;
      List columnNameList = null;
      List paramList = new ArrayList();
      // Iterate over columns
      Set columnSet = columnMapTemp.keySet();
      Iterator iterator = columnSet.iterator();
      int i = 0;
      while (iterator.hasNext()) {
        columnName = (String) iterator.next();

        if (columnName.equals("date_updated")) {
          parameter = "CURRENT_TIMESTAMP";
        } else {
          parameter = "?";
          paramList.add(columnMap.get(columnName));
        }

        if (i++ == 0) {
          sql += " set " + columnName + " = " + parameter;
        } else {
          sql += " ," + columnName + " = " + parameter;
        }
      }

      sql += " where (" + primaryKeyName + "=?)";
      paramList.add(columnMap.get(primaryKeyName));
      // Add primaryKey value to paramList
      int result = queryRunner.update(sql, paramList.toArray());

      if (result == 0) {
        conn.rollback();
      } else {
        conn.commit();
View Full Code Here

Examples of org.apache.commons.dbutils.QueryRunner

        return keyID;
      }
    }

    // Add new record
    QueryRunner queryRunner = new QueryRunner(dataSource);
    columnMap = new HashMap();
    columnMap.put(primaryKeyName, null); // Have key
    // generated
    columnMap.put(displayColumnName, displayColumnValue);
    //columnMap.put("date_created", null);
View Full Code Here

Examples of org.apache.commons.dbutils.QueryRunner

    // If this record is no default, return
    if (!isDefault) {
      return;
    }

    QueryRunner queryRunner = new QueryRunner(dataSource);
    ResultSetHandler rsh = new MapHandler();
    String sql = null;
    sql = "select * from " + tableName;
    sql += " where (";
    sql += " (is_default=true)";

    if (primaryKeyValue != null) {
      sql += " and ("
        + primaryKeyName
        + "!="
        + primaryKeyValue.intValue()
        + ")";
    }

    sql += ")";

    try {
      Map recordMap = (Map) queryRunner.query(sql, rsh);

      if (recordMap == null) {
        return;
      }

View Full Code Here

Examples of org.apache.commons.dbutils.QueryRunner

    String databaseObject,
    String userName,
    boolean withGrantOption)
    throws ControllerException {

    QueryRunner queryRunner = new QueryRunner(dataSource);
    String sql =
      "grant " + permission + " on " + databaseObject + " to " + userName;

    if (withGrantOption) {
      sql += " with grant option";
    }

    try {
      queryRunner.update(sql);
    } catch (SQLException se) {
      log.warning("GenericController: " + se.getMessage());
      throw new ControllerException(se);
    }
  }
View Full Code Here

Examples of org.apache.commons.dbutils.QueryRunner

    String permission,
    String databaseObject,
    String userName)
    throws ControllerException {

    QueryRunner queryRunner = new QueryRunner(dataSource);
    String sql =
      "revoke "
        + permission
        + " on "
        + databaseObject
        + " from "
        + userName;

    try {
      queryRunner.update(sql);
    } catch (SQLException se) {
      log.warning("GenericController: " + se.getMessage());
      throw new ControllerException(se);
    }
  }
View Full Code Here

Examples of org.apache.commons.dbutils.QueryRunner

   * @throws ControllerException
   */
  public void revokeAllPermissions(String userName)
    throws ControllerException {

    QueryRunner queryRunner = new QueryRunner(dataSource);
    String sql =
      "delete from SYS_INFO.sUSRGrant where (grantee='" + userName + "')";

    try {
      queryRunner.update(sql);
    } catch (SQLException se) {
      log.warning("GenericController: " + se.getMessage());
      throw new ControllerException(se);
    }
  }
View Full Code Here

Examples of org.apache.commons.dbutils.QueryRunner

    String permission,
    String databaseObject,
    String userName)
    throws ControllerException {

    QueryRunner queryRunner = new QueryRunner(dataSource);
    String sql =
      "revoke grant option for "
        + permission
        + " on "
        + databaseObject
        + " from "
        + userName;

    try {
      queryRunner.update(sql);
    } catch (SQLException se) {
      log.warning("GenericController: " + se.getMessage());
      throw new ControllerException(se);
    }
  }
View Full Code Here

Examples of org.apache.commons.dbutils.QueryRunner

  }
 
  public void go() {
   
    DataSource dataSource= DataSourceHandler.getDataSource();
    QueryRunner runner = new QueryRunner(dataSource);
    ResultSetHandler rsh = new MapHandler();
    String sql = "select * from Client where (ClientID=1)";
    Map clientMap = null;
    try {
      clientMap = (Map) runner.query(sql, null, rsh);
    } catch (SQLException se) {
      System.out.println(se.getMessage());
      return;
    }
   
    Set fieldSet = clientMap.keySet();
    Iterator iterator = fieldSet.iterator();
    String fieldName = null;
   
    while (iterator.hasNext()) {
      fieldName = (String) iterator.next();
      System.out.println("Field name = " + fieldName);
      System.out.println("Field value = " + clientMap.get(fieldName));
    }
   
    clientMap = null;
    try {
      clientMap = (Map) runner.query(sql, null, rsh);
      DataSourceHandler.closeDataSource();
    } catch (ControllerException ce) {
      System.out.println(ce.getMessage());
      return;
    } catch (SQLException se) {
View Full Code Here

Examples of org.apache.commons.dbutils.QueryRunner

   * @throws ControllerException
   */
  public List findAllWhere(String tableName, String orderClause, String whereClause)
  throws ControllerException  {

    QueryRunner queryRunner = new QueryRunner();
    ResultSetHandler rsh = new MapListHandler();
    String sql = null;

    try {
      sql = "SELECT * FROM " + tableName;
     
      if (whereClause != null) {
        sql += " WHERE " + whereClause;
      }
     
      if (orderClause != null) {
        sql += " ORDER BY " + orderClause;
      }
     
      return (List) queryRunner.query(conn, sql, rsh);
    } catch (SQLException se) {
      log.warning("GenericController SQLException: " + se.getMessage());
      throw new ControllerException(se);
    }
  }
View Full Code Here

Examples of org.apache.commons.dbutils.QueryRunner

   * @throws FinderException If there are no results a FinderException is thrown
   */
  public Map findWhere(String tableName, String whereClause)
  throws ControllerException, FinderException  {

    QueryRunner queryRunner = new QueryRunner();
    ResultSetHandler rsh = new MapListHandler();
    String sql = null;

    try {
      sql = "SELECT * FROM " + tableName;
     
      if (whereClause != null) {
        sql += " WHERE " + whereClause;
      }
     
      List mapList = (List) queryRunner.query(conn, sql, rsh);
      if (mapList.size() == 0l) {
        throw new FinderException();
      }
     
      Iterator iterator = mapList.iterator();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.