Example usage for java.sql Connection isClosed

List of usage examples for java.sql Connection isClosed

Introduction

In this page you can find the example usage for java.sql Connection isClosed.

Prototype

boolean isClosed() throws SQLException;

Source Link

Document

Retrieves whether this Connection object has been closed.

Usage

From source file:Classes.Database.java

private boolean DatabaseConnection(String connection) throws SQLException {
    Connection conn = null;
    Statement sta = null;/*from  w w  w.  ja v  a2s.  c  o m*/
    try {
        Class.forName("com.mysql.jdbc.Driver");

        conn = DriverManager.getConnection(connection, username, password);
        sta = conn.createStatement();
        if (conn == null) {
            return false;
        }
        return !conn.isClosed();
    } catch (SQLException e) {
        Logger.getAnonymousLogger().log(Level.WARNING, "SQL Error: " + e.getMessage(), e);
        return false;
    } catch (ClassNotFoundException e) {
        Logger.getAnonymousLogger().log(Level.WARNING, "Class Error: " + e.getMessage(), e);
        return false;
    } finally {
        if (conn != null) {
            conn.close();
        }

        if (sta != null) {
            sta.close();
        }
    }
}

From source file:pivotal.au.se.gemfirexdweb.controller.GatewayReceiverController.java

@RequestMapping(value = "/gatewayreceivers", method = RequestMethod.POST)
public String performGatewayReceiversAction(Model model, HttpServletResponse response,
        HttpServletRequest request, HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {//from w w w  . j  av  a2 s  .c om
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    int startAtIndex = 0, endAtIndex = 0;
    Result result = new Result();
    List<GatewayReceiver> gatewayreceivers = null;
    String ddlString = null;

    logger.debug("Received request to perform an action on the gateway recievers");

    GatewayReceiverDAO grDAO = GemFireXDWebDAOFactory.getGatewayRecieverDAO();

    if (request.getParameter("search") != null) {
        gatewayreceivers = grDAO.retrieveGatewayReceiverList((String) session.getAttribute("schema"),
                (String) request.getParameter("search"), (String) session.getAttribute("user_key"));

        model.addAttribute("search", (String) request.getParameter("search"));
    } else {
        String[] tableList = request.getParameterValues("selected_gatewayreceivers[]");
        String commandStr = request.getParameter("submit_mult");

        logger.debug("tableList = " + Arrays.toString(tableList));
        logger.debug("command = " + commandStr);

        // start actions now if tableList is not null

        if (tableList != null) {
            List al = new ArrayList<Result>();
            List<String> al2 = new ArrayList<String>();

            for (String id : tableList) {
                if (commandStr.equalsIgnoreCase("DDL") || commandStr.equalsIgnoreCase("DDL_FILE")) {
                    ddlString = grDAO.generateDDL(id, (String) session.getAttribute("user_key"));
                    al2.add(ddlString);
                } else {
                    result = null;
                    result = grDAO.simplegatewayReceiverCommand(id, commandStr,
                            (String) session.getAttribute("user_key"));
                    al.add(result);
                }
            }

            if (commandStr.equalsIgnoreCase("DDL")) {
                request.setAttribute("arrayresultddl", al2);
            } else if (commandStr.equalsIgnoreCase("DDL_FILE")) {
                response.setContentType(SAVE_CONTENT_TYPE);
                response.setHeader("Content-Disposition",
                        "attachment; filename=" + String.format(FILENAME, "GatewayReceiverDDL"));

                ServletOutputStream out = response.getOutputStream();
                for (String ddl : al2) {
                    out.println(ddl);
                }

                out.close();
                return null;
            } else {
                model.addAttribute("arrayresult", al);
            }
        }

        gatewayreceivers = grDAO.retrieveGatewayReceiverList((String) session.getAttribute("schema"), null,
                (String) session.getAttribute("user_key"));
    }

    model.addAttribute("records", gatewayreceivers.size());
    model.addAttribute("estimatedrecords", gatewayreceivers.size());

    UserPref userPref = (UserPref) session.getAttribute("prefs");

    if (gatewayreceivers.size() <= userPref.getRecordsToDisplay()) {
        model.addAttribute("gatewayreceivers", gatewayreceivers);
    } else {
        if (request.getParameter("startAtIndex") != null) {
            startAtIndex = Integer.parseInt(request.getParameter("startAtIndex"));
        }

        if (request.getParameter("endAtIndex") != null) {
            endAtIndex = Integer.parseInt(request.getParameter("endAtIndex"));
            if (endAtIndex > gatewayreceivers.size()) {
                endAtIndex = gatewayreceivers.size();
            }
        } else {
            endAtIndex = userPref.getRecordsToDisplay();
        }

        List subList = gatewayreceivers.subList(startAtIndex, endAtIndex);
        model.addAttribute("gatewayreceivers", subList);
    }

    model.addAttribute("startAtIndex", startAtIndex);
    model.addAttribute("endAtIndex", endAtIndex);

    // This will resolve to /WEB-INF/jsp/gatewayreceivers.jsp
    return "gatewayreceivers";

}

From source file:pivotal.au.se.gemfirexdweb.controller.TriggerController.java

@RequestMapping(value = "/triggers", method = RequestMethod.GET)
public String showTriggers(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    int startAtIndex = 0, endAtIndex = 0;
    javax.servlet.jsp.jstl.sql.Result allTriggerInfoResult, tableTriggersResult = null;
    String schema = null;/*  www.  j av a2  s . c  om*/

    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to show triggers");

    TriggerDAO triggerDAO = GemFireXDWebDAOFactory.getTriggerDAO();
    Result result = new Result();

    String triggerAction = request.getParameter("triggerAction");
    String selectedSchema = request.getParameter("selectedSchema");
    logger.debug("selectedSchema = " + selectedSchema);

    if (selectedSchema != null) {
        schema = selectedSchema;
    } else {
        schema = (String) session.getAttribute("schema");
    }

    logger.debug("schema = " + schema);

    if (triggerAction != null) {
        logger.debug("triggerAction = " + triggerAction);

        if (triggerAction.equals("ALLTRIGGERINFO")) {
            allTriggerInfoResult = triggerDAO.getAllTriggerInfo(schema,
                    (String) request.getParameter("triggerId"), (String) session.getAttribute("user_key"));

            model.addAttribute("allTriggerInfoResult", allTriggerInfoResult);
            model.addAttribute("triggername", (String) request.getParameter("triggerName"));

        } else if (triggerAction.equals("TRIGGERTABLE")) {
            tableTriggersResult = triggerDAO.getTriggerTable((String) request.getParameter("triggerId"),
                    (String) session.getAttribute("user_key"));

            model.addAttribute("tableTriggersResult", tableTriggersResult);
            model.addAttribute("triggerName", (String) request.getParameter("triggerName"));
        } else {
            result = null;
            result = triggerDAO.simpletriggerCommand(schema, (String) request.getParameter("triggerName"),
                    triggerAction, (String) session.getAttribute("user_key"));

            model.addAttribute("result", result);
        }

    }

    List<Trigger> triggers = triggerDAO.retrieveTriggerList(schema, null,
            (String) session.getAttribute("user_key"));

    model.addAttribute("records", triggers.size());
    model.addAttribute("estimatedrecords", triggers.size());

    UserPref userPref = (UserPref) session.getAttribute("prefs");

    if (triggers.size() <= userPref.getRecordsToDisplay()) {
        model.addAttribute("triggers", triggers);
    } else {
        if (request.getParameter("startAtIndex") != null) {
            startAtIndex = Integer.parseInt(request.getParameter("startAtIndex"));
        }

        if (request.getParameter("endAtIndex") != null) {
            endAtIndex = Integer.parseInt(request.getParameter("endAtIndex"));
            if (endAtIndex > triggers.size()) {
                endAtIndex = triggers.size();
            }
        } else {
            endAtIndex = userPref.getRecordsToDisplay();
        }

        List subList = triggers.subList(startAtIndex, endAtIndex);
        model.addAttribute("triggers", subList);
    }

    model.addAttribute("startAtIndex", startAtIndex);
    model.addAttribute("endAtIndex", endAtIndex);
    model.addAttribute("schemas", GemFireXDWebDAOUtil.getAllSchemas((String) session.getAttribute("user_key")));

    model.addAttribute("chosenSchema", schema);

    // This will resolve to /WEB-INF/jsp/triggers.jsp
    return "triggers";
}

From source file:pivotal.au.se.gemfirexdweb.controller.TriggerController.java

@RequestMapping(value = "/triggers", method = RequestMethod.POST)
public String performTriggerAction(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    String schema = null;//  ww  w  . ja  v a  2s .c o  m
    int startAtIndex = 0, endAtIndex = 0;

    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    Result result = new Result();
    List<Trigger> triggers = null;

    logger.debug("Received request to perform an action on the riggers");
    String selectedSchema = request.getParameter("selectedSchema");
    logger.debug("selectedSchema = " + selectedSchema);

    if (selectedSchema != null) {
        schema = selectedSchema;
    } else {
        schema = (String) session.getAttribute("schema");
    }

    logger.debug("schema = " + schema);

    TriggerDAO triggerDAO = GemFireXDWebDAOFactory.getTriggerDAO();

    if (request.getParameter("search") != null) {
        triggers = triggerDAO.retrieveTriggerList(schema, (String) request.getParameter("search"),
                (String) session.getAttribute("user_key"));

        model.addAttribute("search", (String) request.getParameter("search"));
    } else {
        String[] tableList = request.getParameterValues("selected_trigger[]");
        String commandStr = request.getParameter("submit_mult");

        logger.debug("tableList = " + Arrays.toString(tableList));
        logger.debug("command = " + commandStr);

        // start actions now if tableList is not null

        if (tableList != null) {
            List al = new ArrayList<Result>();
            for (String trigger : tableList) {
                result = null;
                result = triggerDAO.simpletriggerCommand(schema, trigger, commandStr,
                        (String) session.getAttribute("user_key"));
                al.add(result);
            }

            model.addAttribute("arrayresult", al);
        }

        triggers = triggerDAO.retrieveTriggerList(schema, null, (String) session.getAttribute("user_key"));
    }

    model.addAttribute("records", triggers.size());
    model.addAttribute("estimatedrecords", triggers.size());

    UserPref userPref = (UserPref) session.getAttribute("prefs");

    if (triggers.size() <= userPref.getRecordsToDisplay()) {
        model.addAttribute("triggers", triggers);
    } else {
        if (request.getParameter("startAtIndex") != null) {
            startAtIndex = Integer.parseInt(request.getParameter("startAtIndex"));
        }

        if (request.getParameter("endAtIndex") != null) {
            endAtIndex = Integer.parseInt(request.getParameter("endAtIndex"));
            if (endAtIndex > triggers.size()) {
                endAtIndex = triggers.size();
            }
        } else {
            endAtIndex = userPref.getRecordsToDisplay();
        }

        List subList = triggers.subList(startAtIndex, endAtIndex);
        model.addAttribute("triggers", subList);
    }

    model.addAttribute("startAtIndex", startAtIndex);
    model.addAttribute("endAtIndex", endAtIndex);

    model.addAttribute("schemas", GemFireXDWebDAOUtil.getAllSchemas((String) session.getAttribute("user_key")));

    model.addAttribute("chosenSchema", schema);

    // This will resolve to /WEB-INF/jsp/triggers.jsp
    return "triggers";
}

From source file:com.cws.esolutions.security.dao.reference.impl.SecurityReferenceDAOImpl.java

/**
 * @see com.cws.esolutions.security.dao.reference.interfaces.ISecurityReferenceDAO#listAvailableServices()
 *///from  w ww . j a v  a2s. co  m
public synchronized Map<String, String> listAvailableServices() throws SQLException {
    final String methodName = ISecurityReferenceDAO.CNAME + "#listAvailableServices() throws SQLException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
    }

    Connection sqlConn = null;
    ResultSet resultSet = null;
    CallableStatement stmt = null;
    Map<String, String> serviceMap = null;

    try {
        sqlConn = dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);
        stmt = sqlConn.prepareCall("{CALL retrAvailableServices()}");

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        if (stmt.execute()) {
            resultSet = stmt.getResultSet();

            if (DEBUG) {
                DEBUGGER.debug("ResultSet: {}", resultSet);
            }

            if (resultSet.next()) {
                resultSet.beforeFirst();
                serviceMap = new HashMap<String, String>();

                while (resultSet.next()) {
                    serviceMap.put(resultSet.getString(1), resultSet.getString(2));
                }

                if (DEBUG) {
                    DEBUGGER.debug("Map<String, String>: {}", serviceMap);
                }
            }
        }
    } catch (SQLException sqx) {
        throw new SQLException(sqx.getMessage(), sqx);
    } finally {
        if (resultSet != null) {
            resultSet.close();
        }

        if (stmt != null) {
            stmt.close();
        }

        if ((sqlConn != null) && (!(sqlConn.isClosed()))) {
            sqlConn.close();
        }
    }

    return serviceMap;
}

From source file:com.cws.esolutions.security.dao.reference.impl.SecurityReferenceDAOImpl.java

/**
 * @see com.cws.esolutions.security.dao.reference.interfaces.ISecurityReferenceDAO#obtainApprovedServers()
 *//*from  w w w  .  ja v  a 2  s  . c o m*/
public synchronized List<String> obtainApprovedServers() throws SQLException {
    final String methodName = ISecurityReferenceDAO.CNAME + "#obtainApprovedServers() throws SQLException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
    }

    Connection sqlConn = null;
    ResultSet resultSet = null;
    CallableStatement stmt = null;
    List<String> securityList = null;

    try {
        sqlConn = dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);
        stmt = sqlConn.prepareCall("{CALL retrApprovedServers()}");

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        if (stmt.execute()) {
            resultSet = stmt.getResultSet();

            if (DEBUG) {
                DEBUGGER.debug("ResultSet: {}", resultSet);
            }

            if (resultSet.next()) {
                resultSet.beforeFirst();

                securityList = new ArrayList<String>();

                while (resultSet.next()) {
                    if (DEBUG) {
                        DEBUGGER.debug(resultSet.getString(1));
                    }

                    // check if column is null
                    securityList.add(resultSet.getString(1));
                }

                if (DEBUG) {
                    DEBUGGER.debug("securityList: {}", securityList);
                }
            }
        }
    } catch (SQLException sqx) {
        throw new SQLException(sqx.getMessage(), sqx);
    } finally {
        if (resultSet != null) {
            resultSet.close();
        }

        if (stmt != null) {
            stmt.close();
        }

        if ((sqlConn != null) && (!(sqlConn.isClosed()))) {
            sqlConn.close();
        }
    }

    return securityList;
}

From source file:pivotal.au.se.gemfirexdweb.controller.DiskStoreController.java

@RequestMapping(value = "/diskstores", method = RequestMethod.POST)
public String performDiskStoreAction(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {//from w  w  w .  ja  v a 2s .  co m
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    int startAtIndex = 0, endAtIndex = 0;
    Result result = new Result();
    List<DiskStore> dsks = null;
    String ddlString = null;

    logger.debug("Received request to perform an action on the disk stores");

    DiskStoreDAO dsDAO = GemFireXDWebDAOFactory.getDiskStoreDAO();

    if (request.getParameter("search") != null) {
        dsks = dsDAO.retrieveDiskStoreList("", (String) request.getParameter("search"),
                (String) session.getAttribute("user_key"));

        model.addAttribute("search", (String) request.getParameter("search"));
    } else {
        String[] tableList = request.getParameterValues("selected_ds[]");
        String commandStr = request.getParameter("submit_mult");

        logger.debug("tableList = " + Arrays.toString(tableList));
        logger.debug("command = " + commandStr);

        // start actions now if tableList is not null

        if (tableList != null) {
            List al = new ArrayList<Result>();
            List<String> al2 = new ArrayList<String>();

            for (String table : tableList) {
                if (commandStr.equalsIgnoreCase("DDL") || commandStr.equalsIgnoreCase("DDL_FILE")) {
                    ddlString = dsDAO.generateDDL(table, (String) session.getAttribute("user_key"));
                    al2.add(ddlString);
                } else {
                    result = null;
                    result = dsDAO.simplediskStoreCommand(table, commandStr,
                            (String) session.getAttribute("user_key"));
                    al.add(result);
                }
            }

            if (commandStr.equalsIgnoreCase("DDL")) {
                request.setAttribute("arrayresultddl", al2);
            } else if (commandStr.equalsIgnoreCase("DDL_FILE")) {
                response.setContentType(SAVE_CONTENT_TYPE);
                response.setHeader("Content-Disposition",
                        "attachment; filename=" + String.format(FILENAME, "DiskStoreDDL"));

                ServletOutputStream out = response.getOutputStream();
                for (String ddl : al2) {
                    out.println(ddl);
                }

                out.close();
                return null;
            } else {
                model.addAttribute("arrayresult", al);
            }
        }

        dsks = dsDAO.retrieveDiskStoreList("", null, (String) session.getAttribute("user_key"));
    }

    model.addAttribute("records", dsks.size());
    model.addAttribute("estimatedrecords", dsks.size());

    UserPref userPref = (UserPref) session.getAttribute("prefs");

    if (dsks.size() <= userPref.getRecordsToDisplay()) {
        model.addAttribute("diskstores", dsks);
    } else {
        if (request.getParameter("startAtIndex") != null) {
            startAtIndex = Integer.parseInt(request.getParameter("startAtIndex"));
        }

        if (request.getParameter("endAtIndex") != null) {
            endAtIndex = Integer.parseInt(request.getParameter("endAtIndex"));
            if (endAtIndex > dsks.size()) {
                endAtIndex = dsks.size();
            }
        } else {
            endAtIndex = userPref.getRecordsToDisplay();

        }

        List subList = dsks.subList(startAtIndex, endAtIndex);
        model.addAttribute("diskstores", subList);
    }

    model.addAttribute("startAtIndex", startAtIndex);
    model.addAttribute("endAtIndex", endAtIndex);

    // This will resolve to /WEB-INF/jsp/diskstores.jsp
    return "diskstores";

}

From source file:pivotal.au.se.gemfirexdweb.controller.HdfsStoreController.java

@RequestMapping(value = "/hdfsstores", method = RequestMethod.POST)
public String performHdfsStoreAction(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {/*from w  ww .  j a  v a2  s.  c o m*/
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    int startAtIndex = 0, endAtIndex = 0;
    Result result = new Result();
    List<HdfsStore> hdfsStores = null;
    String ddlString = null;

    logger.debug("Received request to perform an action on the hdfs stores");

    HdfsStoreDAO hdfsDAO = GemFireXDWebDAOFactory.getHdfsStoreDAO();

    if (request.getParameter("search") != null) {
        hdfsStores = hdfsDAO.retrieveHdfsStoreList("", (String) request.getParameter("search"),
                (String) session.getAttribute("user_key"));

        model.addAttribute("search", (String) request.getParameter("search"));
    } else {
        String[] tableList = request.getParameterValues("selected_hdfs[]");
        String commandStr = request.getParameter("submit_mult");

        logger.debug("tableList = " + Arrays.toString(tableList));
        logger.debug("command = " + commandStr);

        // start actions now if tableList is not null

        if (tableList != null) {
            List al = new ArrayList<Result>();
            List<String> al2 = new ArrayList<String>();

            for (String table : tableList) {
                if (commandStr.equalsIgnoreCase("DDL") || commandStr.equalsIgnoreCase("DDL_FILE")) {
                    ddlString = hdfsDAO.generateDDL(table, (String) session.getAttribute("user_key"));
                    al2.add(ddlString);
                } else {
                    result = null;
                    result = hdfsDAO.simplehdfsStoreCommand(table, commandStr,
                            (String) session.getAttribute("user_key"));
                    al.add(result);
                }
            }

            if (commandStr.equalsIgnoreCase("DDL")) {
                request.setAttribute("arrayresultddl", al2);
            } else if (commandStr.equalsIgnoreCase("DDL_FILE")) {
                response.setContentType(SAVE_CONTENT_TYPE);
                response.setHeader("Content-Disposition",
                        "attachment; filename=" + String.format(FILENAME, "HDFSStoreDDL"));

                ServletOutputStream out = response.getOutputStream();
                for (String ddl : al2) {
                    out.println(ddl);
                }

                out.close();
                return null;
            } else {
                model.addAttribute("arrayresult", al);
            }
        }

        hdfsStores = hdfsDAO.retrieveHdfsStoreList("", null, (String) session.getAttribute("user_key"));
    }

    model.addAttribute("records", hdfsStores.size());
    model.addAttribute("estimatedrecords", hdfsStores.size());

    UserPref userPref = (UserPref) session.getAttribute("prefs");

    if (hdfsStores.size() <= userPref.getRecordsToDisplay()) {
        model.addAttribute("hdfsstores", hdfsStores);
    } else {
        if (request.getParameter("startAtIndex") != null) {
            startAtIndex = Integer.parseInt(request.getParameter("startAtIndex"));
        }

        if (request.getParameter("endAtIndex") != null) {
            endAtIndex = Integer.parseInt(request.getParameter("endAtIndex"));
            if (endAtIndex > hdfsStores.size()) {
                endAtIndex = hdfsStores.size();
            }
        } else {
            endAtIndex = userPref.getRecordsToDisplay();

        }

        List subList = hdfsStores.subList(startAtIndex, endAtIndex);
        model.addAttribute("hdfsstores", subList);
    }

    model.addAttribute("startAtIndex", startAtIndex);
    model.addAttribute("endAtIndex", endAtIndex);

    // This will resolve to /WEB-INF/jsp/hdfsstores.jsp
    return "hdfsstores";

}

From source file:pivotal.au.se.gemfirexdweb.controller.AsyncController.java

@RequestMapping(value = "/asyncevent", method = RequestMethod.POST)
public String performAsyncAction(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {/*from w  ww . j a  v  a 2s . co m*/
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    int startAtIndex = 0, endAtIndex = 0;
    Result result = new Result();
    List<Asyncevent> asyncevents = null;
    String ddlString = null;

    logger.debug("Received request to perform an action on the async events");

    AsynceventDAO asyncDAO = GemFireXDWebDAOFactory.getAsynceventDAO();

    if (request.getParameter("search") != null) {
        asyncevents = asyncDAO.retrieveAsynceventList((String) session.getAttribute("schema"),
                (String) request.getParameter("search"), (String) session.getAttribute("user_key"));

        model.addAttribute("search", (String) request.getParameter("search"));
    } else {
        String[] tableList = request.getParameterValues("selected_async[]");
        String commandStr = request.getParameter("submit_mult");

        logger.debug("tableList = " + Arrays.toString(tableList));
        logger.debug("command = " + commandStr);

        // start actions now if tableList is not null

        if (tableList != null) {
            List al = new ArrayList<Result>();
            List<String> al2 = new ArrayList<String>();

            for (String asyncName : tableList) {
                if (commandStr.equalsIgnoreCase("DDL") || commandStr.equalsIgnoreCase("DDL_FILE")) {
                    ddlString = asyncDAO.generateDDL(asyncName, (String) session.getAttribute("user_key"));
                    al2.add(ddlString);
                } else {
                    result = null;
                    result = asyncDAO.simpleasynceventCommand(asyncName, commandStr,
                            (String) session.getAttribute("user_key"));
                    al.add(result);
                }
            }

            if (commandStr.equalsIgnoreCase("DDL")) {
                request.setAttribute("arrayresultddl", al2);
            } else if (commandStr.equalsIgnoreCase("DDL_FILE")) {
                response.setContentType(SAVE_CONTENT_TYPE);
                response.setHeader("Content-Disposition",
                        "attachment; filename=" + String.format(FILENAME, "AsyncEventListenerDDL"));

                ServletOutputStream out = response.getOutputStream();
                for (String ddl : al2) {
                    out.println(ddl);
                }

                out.close();
                return null;
            } else {
                model.addAttribute("arrayresult", al);
            }
        }

        asyncevents = asyncDAO.retrieveAsynceventList((String) session.getAttribute("schema"), null,
                (String) session.getAttribute("user_key"));
    }

    model.addAttribute("records", asyncevents.size());
    model.addAttribute("estimatedrecords", asyncevents.size());

    UserPref userPref = (UserPref) session.getAttribute("prefs");

    if (asyncevents.size() <= userPref.getRecordsToDisplay()) {
        model.addAttribute("asyncevents", asyncevents);
    } else {
        if (request.getParameter("startAtIndex") != null) {
            startAtIndex = Integer.parseInt(request.getParameter("startAtIndex"));
        }

        if (request.getParameter("endAtIndex") != null) {
            endAtIndex = Integer.parseInt(request.getParameter("endAtIndex"));
            if (endAtIndex > asyncevents.size()) {
                endAtIndex = asyncevents.size();
            }
        } else {
            endAtIndex = userPref.getRecordsToDisplay();
        }

        List subList = asyncevents.subList(startAtIndex, endAtIndex);
        model.addAttribute("asyncevents", subList);
    }

    model.addAttribute("startAtIndex", startAtIndex);
    model.addAttribute("endAtIndex", endAtIndex);

    // This will resolve to /WEB-INF/jsp/async.jsp
    return "async";
}

From source file:com.cws.esolutions.security.dao.reference.impl.SecurityReferenceDAOImpl.java

/**
 * @see com.cws.esolutions.security.dao.reference.interfaces.ISecurityReferenceDAO#obtainSecurityQuestionList()
 *///from w  w  w  . j a  v a  2  s . c  o m
public synchronized List<String> obtainSecurityQuestionList() throws SQLException {
    final String methodName = ISecurityReferenceDAO.CNAME + "#obtainSecurityQuestionList() throws SQLException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
    }

    Connection sqlConn = null;
    ResultSet resultSet = null;
    CallableStatement stmt = null;
    List<String> questionList = null;

    try {
        sqlConn = dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);
        stmt = sqlConn.prepareCall("{CALL retrieve_user_questions()}");

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        if (stmt.execute()) {
            resultSet = stmt.getResultSet();
            resultSet.last();
            int iRowCount = resultSet.getRow();

            if (iRowCount == 0) {
                throw new SQLException("No security questions are currently configured.");
            }

            resultSet.first();
            ResultSetMetaData resultData = resultSet.getMetaData();

            int iColumns = resultData.getColumnCount();

            questionList = new ArrayList<String>();

            for (int x = 1; x < iColumns + 1; x++) {
                if (DEBUG) {
                    DEBUGGER.debug("resultSet.getObject: {}", resultSet.getObject(resultData.getColumnName(x)));
                }

                // check if column is null
                resultSet.getObject(resultData.getColumnName(x));

                // if the column was null, insert n/a, otherwise, insert the column's contents
                questionList.add((String) (resultSet.wasNull() ? "N/A"
                        : resultSet.getObject(resultData.getColumnName(x))));
            }
        }
    } catch (SQLException sqx) {
        throw new SQLException(sqx.getMessage(), sqx);
    } finally {
        if (resultSet != null) {
            resultSet.close();
        }

        if (stmt != null) {
            stmt.close();
        }

        if ((sqlConn != null) && (!(sqlConn.isClosed()))) {
            sqlConn.close();
        }
    }

    return questionList;
}