@Override
  public String renameItem(String connectionToken, int item, ITEM_TYPE type, String newName)
      throws IllegalArgumentException, DatabaseConnectionException, PostgreSQLException {
    ConnectionManager connMgr = new ConnectionManager();
    HttpServletRequest request = this.getThreadLocalRequest();

    String clientIP = ConnectionInfo.remoteAddr(request);
    String userAgent = request.getHeader("User-Agent");

    try {
      switch (type) {
        case FOREIGN_TABLE:
          ForeignTables fTables =
              new ForeignTables(connMgr.getConnection(connectionToken, clientIP, userAgent));
          return fTables.rename(item, type, q.addQuote(newName));
        case TABLE:
          Tables tables = new Tables(connMgr.getConnection(connectionToken, clientIP, userAgent));
          return tables.rename(item, type, q.addQuote(newName));
        case VIEW:
        case MATERIALIZED_VIEW:
          Views views = new Views(connMgr.getConnection(connectionToken, clientIP, userAgent));
          return views.rename(item, type, newName);
        default:
          return "";
      }
    } catch (SQLException e) {
      throw new PostgreSQLException(e.getMessage());
    }
  }
  @Override
  public String createColumn(
      String connectionToken,
      int item,
      String columnName,
      String datatype,
      String comment,
      boolean not_null,
      String defaultval)
      throws DatabaseConnectionException, PostgreSQLException {
    ConnectionManager connMgr = new ConnectionManager();
    HttpServletRequest request = this.getThreadLocalRequest();

    String clientIP = ConnectionInfo.remoteAddr(request);
    String userAgent = request.getHeader("User-Agent");

    Columns columns;

    columns = new Columns(connMgr.getConnection(connectionToken, clientIP, userAgent));

    try {
      return columns.create(item, q.addQuote(columnName), datatype, comment, not_null, defaultval);
    } catch (SQLException e) {
      throw new PostgreSQLException(e.getMessage());
    }
  }
  @Override
  public String createTable(
      String connectionToken,
      int schema,
      String tableName,
      boolean unlogged,
      boolean temporary,
      String fill,
      ArrayList<String> col_list,
      HashMap<Integer, String> commentLog,
      ArrayList<String> col_index)
      throws DatabaseConnectionException, PostgreSQLException {

    ConnectionManager connMgr = new ConnectionManager();
    HttpServletRequest request = this.getThreadLocalRequest();

    String clientIP = ConnectionInfo.remoteAddr(request);
    String userAgent = request.getHeader("User-Agent");

    Tables tables = new Tables(connMgr.getConnection(connectionToken, clientIP, userAgent));

    try {
      return tables.create(
          schema,
          q.addQuote(tableName),
          unlogged,
          temporary,
          fill,
          col_list,
          commentLog,
          col_index);
    } catch (SQLException e) {
      throw new PostgreSQLException(e.getMessage());
    }
  }
  @Override
  public String dropItemObject(
      String connectionToken, int item, ITEM_TYPE type, String objectName, ITEM_OBJECT_TYPE objType)
      throws DatabaseConnectionException, PostgreSQLException {

    ConnectionManager connMgr = new ConnectionManager();
    HttpServletRequest request = this.getThreadLocalRequest();

    String clientIP = ConnectionInfo.remoteAddr(request);
    String userAgent = request.getHeader("User-Agent");

    try {
      switch (objType) {
        case COLUMN:
          Columns columns =
              new Columns(connMgr.getConnection(connectionToken, clientIP, userAgent));
          return columns.drop(item, q.addQuote(objectName));

        case CONSTRAINT:
          Constraints constraints =
              new Constraints(connMgr.getConnection(connectionToken, clientIP, userAgent));
          return constraints.drop(item, q.addQuote(objectName));
        case INDEX:
          Indexes indexes =
              new Indexes(connMgr.getConnection(connectionToken, clientIP, userAgent));
          return indexes.drop(item, q.addQuote(objectName));
        case RULE:
          Rules rules = new Rules(connMgr.getConnection(connectionToken, clientIP, userAgent));
          return rules.drop(item, q.addQuote(objectName));
        case TRIGGER:
          Triggers triggers =
              new Triggers(connMgr.getConnection(connectionToken, clientIP, userAgent));
          return triggers.drop(item, q.addQuote(objectName));

        default:
          return "";
      }
    } catch (SQLException e) {
      throw new PostgreSQLException(e.getMessage());
    }
  }
  /**
   * ********************************************************************************************
   */
  @Override
  public String refreshMaterializedView(String connectionToken, String schema, String viewName)
      throws DatabaseConnectionException {

    ConnectionManager connMgr = new ConnectionManager();
    HttpServletRequest request = this.getThreadLocalRequest();

    String clientIP = ConnectionInfo.remoteAddr(request);
    String userAgent = request.getHeader("User-Agent");

    Views views = new Views(connMgr.getConnection(connectionToken, clientIP, userAgent));

    return views.refreshMaterializedView(schema, q.addQuote(viewName));
  }