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:pivotal.au.se.gemfirexdweb.controller.CreateAsyncController.java

@RequestMapping(value = "/createasync", method = RequestMethod.POST)
public String createAsyncAction(@ModelAttribute("asyncAttribute") NewAsync asyncAttribute, 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  2 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;
            }
        }

    }

    logger.debug("Received request to action an event for create Async Event Listener");

    DiskStoreDAO dsDAO = GemFireXDWebDAOFactory.getDiskStoreDAO();

    List<DiskStore> dsks = dsDAO.retrieveDiskStoreForCreateList((String) session.getAttribute("user_key"));

    model.addAttribute("diskstores", dsks);

    String asyncName = asyncAttribute.getAsyncName();
    String listenerClass = asyncAttribute.getListenerClass();

    logger.debug("New Async Event Listener Name = " + asyncName);
    logger.debug("New Async Event Listener Class = " + listenerClass);

    // perform some action here with what we have
    String submit = request.getParameter("pSubmit");
    boolean needCloseBracket = false;

    if (submit != null) {
        // build create HDFS Store SQL
        StringBuffer createAsync = new StringBuffer();

        createAsync.append("CREATE ASYNCEVENTLISTENER " + asyncName + " (\n");
        createAsync.append("LISTENERCLASS '" + listenerClass + "' \n");

        if (!checkIfParameterEmpty(request, "initParams")) {
            createAsync.append("INITPARAMS " + asyncAttribute.getInitParams() + " \n");
        } else {
            createAsync.append("INITPARAMS '' \n");
        }

        if (!checkIfParameterEmpty(request, "manualStart")) {
            createAsync.append("MANUALSTART " + asyncAttribute.getManualStart() + " \n");
        }

        if (!checkIfParameterEmpty(request, "enableBatchConflation")) {
            createAsync.append("ENABLEBATCHCONFLATION " + asyncAttribute.getEnableBatchConflation() + " \n");
        }

        if (!checkIfParameterEmpty(request, "batchSize")) {
            createAsync.append("BATCHSIZE " + asyncAttribute.getBatchSize() + " \n");
        }

        if (!checkIfParameterEmpty(request, "batchTimeInterval")) {
            createAsync.append("BATCHTIMEINTERVAL " + asyncAttribute.getBatchTimeInterval() + " \n");
        }

        if (!checkIfParameterEmpty(request, "enablePersistence")) {
            createAsync.append("ENABLEPERSISTENCE " + asyncAttribute.getEnablePersistence() + " \n");
            if (asyncAttribute.getEnablePersistence().equals("TRUE")) {
                if (!checkIfParameterEmpty(request, "diskStore")) {
                    createAsync.append("DISKSTORENAME " + asyncAttribute.getDiskStore() + " \n");
                }
            }
        }

        if (!checkIfParameterEmpty(request, "maxQueueMemory")) {
            createAsync.append("MAXQUEUEMEMORY " + asyncAttribute.getMaxQueueMemory() + " \n");
        }

        if (!checkIfParameterEmpty(request, "alertThreshold")) {
            createAsync.append("ALERTTHRESHOLD " + asyncAttribute.getAlertThreshold() + " \n");
        }

        createAsync.append(") \n");

        if (!checkIfParameterEmpty(request, "serverGroups")) {
            createAsync.append("SERVER GROUPS (" + asyncAttribute.getServerGroups() + ") \n");
        }

        if (submit.equalsIgnoreCase("create")) {
            Result result = new Result();

            logger.debug("Creating async event listener as -> " + createAsync.toString());

            result = GemFireXDWebDAOUtil.runCommand(createAsync.toString(),
                    (String) session.getAttribute("user_key"));

            model.addAttribute("result", result);

        } else if (submit.equalsIgnoreCase("Show SQL")) {
            logger.debug("Create Async SQL as follows as -> " + createAsync.toString());
            model.addAttribute("sql", createAsync.toString());
        } else if (submit.equalsIgnoreCase("Save to File")) {
            response.setContentType(SAVE_CONTENT_TYPE);
            response.setHeader("Content-Disposition",
                    "attachment; filename=" + String.format(FILENAME, asyncName));

            ServletOutputStream out = response.getOutputStream();
            out.println(createAsync.toString());
            out.close();
            return null;
        }

    }

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

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

@RequestMapping(value = "/asyncevent", method = RequestMethod.GET)
public String showAsyncEvents(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    int startAtIndex = 0, endAtIndex = 0;
    javax.servlet.jsp.jstl.sql.Result allAsyncEventInfoResult, asyncTables = null;

    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 {// w  w  w  .  j a  v a2  s  .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;
            }
        }

    }

    logger.debug("Received request to show async events");

    AsynceventDAO asyncDAO = GemFireXDWebDAOFactory.getAsynceventDAO();
    Result result = new Result();

    String asyncAction = request.getParameter("asyncAction");

    if (asyncAction != null) {
        logger.debug("asyncAction = " + asyncAction);
        if (asyncAction.equals("ALLASYNCEVENTINFO")) {
            allAsyncEventInfoResult = asyncDAO.getAsynEventInfo((String) request.getParameter("asyncName"),
                    (String) session.getAttribute("user_key"));

            model.addAttribute("allAsyncEventInfoResult", allAsyncEventInfoResult);
            model.addAttribute("asyncevent", (String) request.getParameter("asyncName"));
        } else if (asyncAction.equals("ASYNCTABLES")) {
            asyncTables = asyncDAO.getAsyncTables((String) request.getParameter("asyncName"),
                    (String) session.getAttribute("user_key"));

            model.addAttribute("asyncTables", asyncTables);
            model.addAttribute("asyncevent", (String) request.getParameter("asyncName"));
        } else {
            result = null;
            result = asyncDAO.simpleasynceventCommand((String) request.getParameter("asyncName"), asyncAction,
                    (String) session.getAttribute("user_key"));

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

    List<Asyncevent> 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:pivotal.au.se.gemfirexdweb.controller.ViewController.java

@RequestMapping(value = "/views", method = RequestMethod.POST)
public String performTableAction(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    String schema = null;//ww w.j  av  a  2  s. 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<View> views = null;

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

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

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

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

    ViewDAO viewDAO = GemFireXDWebDAOFactory.getViewDAO();
    if (request.getParameter("search") != null) {
        views = viewDAO.retrieveViewList(schema, (String) request.getParameter("search"),
                (String) session.getAttribute("user_key"));

        model.addAttribute("search", (String) request.getParameter("search"));
    } else {
        String[] tableList = request.getParameterValues("selected_view[]");
        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 view : tableList) {
                result = null;
                result = viewDAO.simpleviewCommand(schema, view, commandStr,
                        (String) session.getAttribute("user_key"));
                al.add(result);
            }

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

        views = viewDAO.retrieveViewList(schema, null, (String) session.getAttribute("user_key"));
    }

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

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

    if (views.size() <= userPref.getRecordsToDisplay()) {
        model.addAttribute("views", views);
    } 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 > views.size()) {
                endAtIndex = views.size();
            }
        } else {
            endAtIndex = userPref.getRecordsToDisplay();
        }

        List subList = views.subList(startAtIndex, endAtIndex);
        model.addAttribute("views", 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/views.jsp
    return "views";
}

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

@RequestMapping(value = "/indexes", method = RequestMethod.POST)
public String performIndexAction(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    String schema = null;/*  w ww.  java  2s .  co 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<Index> indexes = null;

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

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

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

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

    IndexDAO indexDAO = GemFireXDWebDAOFactory.getIndexDAO();

    if (request.getParameter("search") != null) {
        indexes = indexDAO.retrieveIndexList(schema, (String) request.getParameter("search"),
                (String) session.getAttribute("user_key"));

        model.addAttribute("search", (String) request.getParameter("search"));
    } else {
        String[] tableList = request.getParameterValues("selected_idx[]");
        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 index : tableList) {
                result = null;
                result = indexDAO.simpleindexCommand(schema, index, commandStr,
                        (String) session.getAttribute("user_key"));
                al.add(result);
            }

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

        indexes = indexDAO.retrieveIndexList(schema, null, (String) session.getAttribute("user_key"));
    }

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

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

    if (indexes.size() <= userPref.getRecordsToDisplay()) {
        model.addAttribute("indexes", indexes);
    } 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 > indexes.size()) {
                endAtIndex = indexes.size();
            }
        } else {
            endAtIndex = userPref.getRecordsToDisplay();
        }

        List subList = indexes.subList(startAtIndex, endAtIndex);
        model.addAttribute("indexes", 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/indexes.jsp
    return "indexes";
}

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

@RequestMapping(value = "/creategatewaysender", method = RequestMethod.POST)
public String createGatewaySenderAction(
        @ModelAttribute("gatewaySenderAttribute") NewGatewaySender gatewaySenderAttribute, 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 {// w  ww .  j  a  v a  2s  .  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;
            }
        }

    }

    logger.debug("Received request to action an event for create Gateway Sender");

    DiskStoreDAO dsDAO = GemFireXDWebDAOFactory.getDiskStoreDAO();

    List<DiskStore> dsks = dsDAO.retrieveDiskStoreForCreateList((String) session.getAttribute("user_key"));

    model.addAttribute("diskstores", dsks);

    String gatewaySenderName = gatewaySenderAttribute.getGatewaySenderName();

    logger.debug("New Gateway Sender Name = " + gatewaySenderName);

    // perform some action here with what we have
    String submit = request.getParameter("pSubmit");
    boolean needCloseBracket = false;

    if (submit != null) {
        // build create HDFS Store SQL
        StringBuffer createGatewaySender = new StringBuffer();

        createGatewaySender.append("CREATE GATEWAYSENDER " + gatewaySenderName + " (\n");
        createGatewaySender.append("REMOTEDSID " + gatewaySenderAttribute.getRemoteSID() + " \n");

        if (!checkIfParameterEmpty(request, "socketBufferSize")) {
            createGatewaySender
                    .append("SOCKETBUFFERSIZE " + gatewaySenderAttribute.getSocketBufferSize() + " \n");
        }

        if (!checkIfParameterEmpty(request, "socketReadTimeout")) {
            createGatewaySender
                    .append("SOCKETREADTIMEOUT " + gatewaySenderAttribute.getSocketReadTimeout() + " \n");
        }

        if (!checkIfParameterEmpty(request, "manualStart")) {
            createGatewaySender.append("MANUALSTART " + gatewaySenderAttribute.getManualStart() + " \n");
        }

        if (!checkIfParameterEmpty(request, "enableBatchConflation")) {
            createGatewaySender.append(
                    "ENABLEBATCHCONFLATION " + gatewaySenderAttribute.getEnableBatchConflation() + " \n");
        }

        if (!checkIfParameterEmpty(request, "batchSize")) {
            createGatewaySender.append("BATCHSIZE " + gatewaySenderAttribute.getBatchSize() + " \n");
        }

        if (!checkIfParameterEmpty(request, "batchTimeInterval")) {
            createGatewaySender
                    .append("BATCHTIMEINTERVAL " + gatewaySenderAttribute.getBatchTimeInterval() + " \n");
        }

        if (!checkIfParameterEmpty(request, "enablePersistence")) {
            createGatewaySender
                    .append("ENABLEPERSISTENCE " + gatewaySenderAttribute.getEnablePersistence() + " \n");
            if (gatewaySenderAttribute.getEnablePersistence().equals("TRUE")) {
                if (!checkIfParameterEmpty(request, "diskStore")) {
                    createGatewaySender
                            .append("DISKSTORENAME " + gatewaySenderAttribute.getDiskStore() + " \n");
                }
            }
        }

        if (!checkIfParameterEmpty(request, "maxQueueMemory")) {
            createGatewaySender.append("MAXQUEUEMEMORY " + gatewaySenderAttribute.getMaxQueueMemory() + " \n");
        }

        if (!checkIfParameterEmpty(request, "alertThreshold")) {
            createGatewaySender.append("ALERTTHRESHOLD " + gatewaySenderAttribute.getAlertThreshold() + " \n");
        }

        createGatewaySender.append(") \n");

        if (!checkIfParameterEmpty(request, "serverGroups")) {
            createGatewaySender.append("SERVER GROUPS (" + gatewaySenderAttribute.getServerGroups() + ") \n");
        }

        if (submit.equalsIgnoreCase("create")) {
            Result result = new Result();

            logger.debug("Creating gateway sender as -> " + createGatewaySender.toString());

            result = GemFireXDWebDAOUtil.runCommand(createGatewaySender.toString(),
                    (String) session.getAttribute("user_key"));

            model.addAttribute("result", result);

        } else if (submit.equalsIgnoreCase("Show SQL")) {
            logger.debug("Create Gateway Sender SQL as follows as -> " + createGatewaySender.toString());
            model.addAttribute("sql", createGatewaySender.toString());
        } else if (submit.equalsIgnoreCase("Save to File")) {
            response.setContentType(SAVE_CONTENT_TYPE);
            response.setHeader("Content-Disposition",
                    "attachment; filename=" + String.format(FILENAME, gatewaySenderName));

            ServletOutputStream out = response.getOutputStream();
            out.println(createGatewaySender.toString());
            out.close();
            return null;
        }

    }

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

From source file:com.mnt.base.das.DBFactory.java

private Connection retrieveConnection() {

    Connection connection = null;

    while (connPool.size() > 0 || usingConnPool.size() >= maxPoolSize) {
        connection = connPool.poll();//  www.java  2 s.c  om

        if (connection != null) {
            try {
                if (connection.isValid(0)) {

                    usingConnPool.add(connection);

                    return connection;
                }
            } catch (SQLException e) {
                try {
                    connection.close();
                } catch (SQLException e1) {
                    // ignore
                }
            }
        } else {
            Iterator<Connection> conns = usingConnPool.iterator();
            Connection conn;
            while (conns.hasNext()) {
                conn = conns.next();

                try {
                    if (conn.isClosed()) {
                        usingConnPool.remove(conn);
                    }
                } catch (SQLException e) {

                    try {
                        conn.close();
                    } catch (SQLException e1) {
                        // skip it
                    }

                    usingConnPool.remove(conn);
                }

                if (usingConnPool.size() < maxPoolSize) {
                    break;
                }
            }

            if (usingConnPool.size() >= maxPoolSize) {
                synchronized (connPool) {
                    try {
                        connPool.wait(1000);
                    } catch (InterruptedException e) {
                        log.error("error while wait for the connection.", e);
                    }
                }
            }
        }
    }

    synchronized (connCreationLock) {
        if (usingConnPool.size() < maxPoolSize) {
            try {
                connection = DriverManager.getConnection(prop.getProperty(DB_URL), prop.getProperty(DB_USER),
                        prop.getProperty(DB_PASSWORD));

                usingConnPool.add(connection);
            } catch (SQLException e) {
                log.error("Error when construct the db connection.", e);
                throw new RuntimeException("Error when construct the db connection.", e);
            }
        }
    }

    if (connection == null) {
        synchronized (connPool) {
            try {
                connPool.wait(1000);
            } catch (InterruptedException e) {
                log.error("error while wait for the connection.", e);
            }
        }

        return getConnection();
    }

    return connection;
}

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

@RequestMapping(value = "/types", method = RequestMethod.GET)
public String showTypes(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    int startAtIndex = 0, endAtIndex = 0;
    javax.servlet.jsp.jstl.sql.Result dataLocationResult = null;
    String schema = null;//from  w  w w  . java 2  s.com

    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 types");

    TypeDAO typeDAO = GemFireXDWebDAOFactory.getTypeDAO();
    Result result = new Result();

    String typeAction = request.getParameter("typeAction");
    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 (typeAction != null) {
        logger.debug("typeAction = " + typeAction);

        result = null;
        result = typeDAO.simpletypeCommand(schema, (String) request.getParameter("typeName"), typeAction,
                (String) session.getAttribute("user_key"));
        model.addAttribute("result", result);

    }

    List<Type> types = typeDAO.retrieveTypeList(schema, null, (String) session.getAttribute("user_key"));

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

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

    if (types.size() <= userPref.getRecordsToDisplay()) {
        model.addAttribute("types", types);
    } 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 > types.size()) {
                endAtIndex = types.size();
            }
        } else {
            endAtIndex = userPref.getRecordsToDisplay();
        }

        List subList = types.subList(startAtIndex, endAtIndex);
        model.addAttribute("types", 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/types.jsp
    return "types";
}

From source file:com.frameworkset.commons.dbcp2.PoolableConnectionFactory.java

protected void initializeConnection(Connection conn) throws SQLException {
    Collection<String> sqls = _connectionInitSqls;
    if (conn.isClosed()) {
        throw new SQLException("initializeConnection: connection closed");
    }//ww w.ja va 2  s . c o  m
    if (null != sqls) {
        Statement stmt = null;
        SQLException localThrowable2 = null;
        try {
            stmt = conn.createStatement();
            for (String sql : sqls) {
                if (sql == null) {
                    throw new NullPointerException("null connectionInitSqls element");
                }
                stmt.execute(sql);
            }
        } catch (SQLException localThrowable1) {
            localThrowable2 = localThrowable1;
            throw localThrowable1;
        } catch (Throwable localThrowable1) {

            SQLException localThrowable1_ = new SQLException(localThrowable1);
            localThrowable2 = localThrowable1_;
            throw localThrowable1_;
        } finally {
            if (stmt != null) {
                if (localThrowable2 != null) {
                    try {
                        stmt.close();
                    } catch (Throwable x2) {
                        localThrowable2.addSuppressed(x2);
                    }
                } else {
                    stmt.close();
                }
            }
        }
    }
}

From source file:com.adaptris.jdbc.connection.FailoverDatasourceTest.java

@Test
public void testDataSource() throws Exception {
    FailoverDataSource fds = new FailoverDataSource(createProperties());
    fds.setLoginTimeout(fds.getLoginTimeout());
    fds.setLogWriter(fds.getLogWriter());
    Connection con = fds.getConnection();
    try {/*from   w  w  w .j  av  a 2  s . co  m*/
        assertFalse(con.isClosed());
        createTables(con);
    } finally {
        JdbcUtil.closeQuietly(con);
        fds.destroy();
    }
}

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

@RequestMapping(value = "/createhdfsstore", method = RequestMethod.POST)
public String createHDFSStoreAction(@ModelAttribute("hdfsStoreAttribute") NewHDFSStore hdfsStoreAttribute,
        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 {//ww w . j  a  va2s. 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;
            }
        }

    }

    logger.debug("Received request to action an event for create HDFS Store");

    String storeName = hdfsStoreAttribute.getStoreName();
    String nameNode = hdfsStoreAttribute.getNameNode();
    String homeDir = hdfsStoreAttribute.getHomeDir();

    logger.debug("New HDFS Store Name = " + storeName);

    // perform some action here with what we have
    String submit = request.getParameter("pSubmit");

    if (submit != null) {
        // build create HDFS Store SQL
        StringBuffer createHDFSStore = new StringBuffer();

        createHDFSStore.append("create HDFSSTORE " + storeName + " \n");
        createHDFSStore.append("NAMENODE '" + nameNode + "' \n");
        createHDFSStore.append("HOMEDIR '" + homeDir + "' \n");

        if (!checkIfParameterEmpty(request, "batchSize")) {
            createHDFSStore.append("BatchSize " + hdfsStoreAttribute.getBatchSize() + " \n");
        }

        if (!checkIfParameterEmpty(request, "batchTimeInterval")) {
            createHDFSStore.append("BatchTimeInterval " + hdfsStoreAttribute.getBatchTimeInterval() + " \n");
        }

        if (!checkIfParameterEmpty(request, "maxQueueMemory")) {
            createHDFSStore.append("MaxQueueMemory " + hdfsStoreAttribute.getMaxQueueMemory() + " \n");
        }

        if (!checkIfParameterEmpty(request, "minorCompact")) {
            createHDFSStore.append("MinorCompact " + hdfsStoreAttribute.getMinorCompact() + " \n");
        }

        if (!checkIfParameterEmpty(request, "maxInputFileSize")) {
            createHDFSStore.append("MaxInputFileSize " + hdfsStoreAttribute.getMaxInputFileSize() + " \n");
        }

        if (!checkIfParameterEmpty(request, "minInputFileCount")) {
            createHDFSStore.append("MinInputFileCount " + hdfsStoreAttribute.getMinInputFileCount() + " \n");
        }

        if (!checkIfParameterEmpty(request, "maxInputFileCount")) {
            createHDFSStore.append("MaxInputFileCount " + hdfsStoreAttribute.getMaxInputFileCount() + " \n");
        }

        if (!checkIfParameterEmpty(request, "minorCompactionThreads")) {
            createHDFSStore
                    .append("MinorCompactionThreads " + hdfsStoreAttribute.getMinorCompactionThreads() + " \n");
        }

        if (!checkIfParameterEmpty(request, "majorCompact")) {
            createHDFSStore.append("MajorCompact " + hdfsStoreAttribute.getMajorCompact() + " \n");
        }

        if (!checkIfParameterEmpty(request, "majorCompactionInterval")) {
            createHDFSStore.append(
                    "MajorCompactionInterval " + hdfsStoreAttribute.getMajorCompactionInterval() + " \n");
        }

        if (!checkIfParameterEmpty(request, "majorCompactionThreads")) {
            createHDFSStore
                    .append("MajorCompactionThreads " + hdfsStoreAttribute.getMajorCompactionThreads() + " \n");
        }

        if (!checkIfParameterEmpty(request, "maxWriteOnlyFileSize")) {
            createHDFSStore
                    .append("MaxWriteOnlyFileSize " + hdfsStoreAttribute.getMaxWriteOnlyFileSize() + " \n");
        }

        if (!checkIfParameterEmpty(request, "writeOnlyRolloverInterval")) {
            createHDFSStore.append("WriteOnlyFileRolloverInterval "
                    + hdfsStoreAttribute.getWriteOnlyRolloverInterval() + " \n");
        }

        if (!checkIfParameterEmpty(request, "additionalParams")) {
            createHDFSStore.append(hdfsStoreAttribute.getAdditionalParams());
        }

        if (submit.equalsIgnoreCase("create")) {
            Result result = new Result();

            logger.debug("Creating hdfs store as -> " + createHDFSStore.toString());

            result = GemFireXDWebDAOUtil.runCommand(createHDFSStore.toString(),
                    (String) session.getAttribute("user_key"));

            model.addAttribute("result", result);

        } else if (submit.equalsIgnoreCase("Show SQL")) {
            logger.debug("Create HDFS Store SQL as follows as -> " + createHDFSStore.toString());
            model.addAttribute("sql", createHDFSStore.toString());
        } else if (submit.equalsIgnoreCase("Save to File")) {
            response.setContentType(SAVE_CONTENT_TYPE);
            response.setHeader("Content-Disposition",
                    "attachment; filename=" + String.format(FILENAME, storeName));

            ServletOutputStream out = response.getOutputStream();
            out.println(createHDFSStore.toString());
            out.close();
            return null;
        }

    }

    // This will resolve to /WEB-INF/jsp/create-table.jsp
    return "create-hdfsstore";
}