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.AddListenerController.java

@RequestMapping(value = "/addlistener", method = RequestMethod.POST)
public String createListenerAction(@ModelAttribute("listenerAttribute") AddListener listenerAttribute,
        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  a 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 add listener");

    logger.debug("Listener ID = " + listenerAttribute.getId());

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

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

        addListener.append("CALL SYS.ADD_LISTENER ('" + listenerAttribute.getId() + "', \n");
        addListener.append("'" + listenerAttribute.getSchemaName() + "', \n");
        addListener.append("'" + listenerAttribute.getTableName() + "', \n");
        addListener.append("'" + listenerAttribute.getFunctionName() + "', \n");

        if (!checkIfParameterEmpty(request, "initString")) {
            addListener.append("'" + listenerAttribute.getInitString() + "', \n");
        } else {
            addListener.append("'', \n");
        }

        if (!checkIfParameterEmpty(request, "serverGroups")) {
            addListener.append("'" + listenerAttribute.getServerGroups() + "')");
        } else {
            addListener.append("''), \n");
        }

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

            logger.debug("Creating Listener as -> " + addListener.toString());

            result = GemFireXDWebDAOUtil.runStoredCommand(addListener.toString(),
                    (String) session.getAttribute("user_key"));

            model.addAttribute("result", result);
            model.addAttribute("tableName", listenerAttribute.getTableName());

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

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

    }

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

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

@RequestMapping(value = "/createprocedure", method = RequestMethod.GET)
public String createProcedure(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  a 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 create a new Procedure");

    session.setAttribute("numParams", "0");
    model.addAttribute("numParams", "0");
    model.addAttribute("procedureAttribute", new NewProcedure());

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

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

@RequestMapping(value = "/jars", method = RequestMethod.GET)
public String showJars(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() + "/gemfirexdweb/login");
        return null;
    } else {//from w  w w .ja  v 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;
            }
        }

    }

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

    int startAtIndex = 0, endAtIndex = 0;
    String schema = null;

    JarDAO jarDAO = GemFireXDWebDAOFactory.getJarStoreDAO();
    Result result = new Result();

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

    if (jarAction != null) {
        logger.debug("jarAction = " + jarAction);
        result = null;
        result = jarDAO.simpleJarCommand((String) request.getParameter("schemaName"),
                (String) request.getParameter("alias"), jarAction, (String) session.getAttribute("user_key"));

        model.addAttribute("result", result);

    }

    List<Jar> jars = jarDAO.retrieveJarList("", null, (String) session.getAttribute("user_key"));

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

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

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

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

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

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

From source file:com.sf.ddao.shards.ShardedDaoTest.java

public void testTx() throws Exception {
    final long id = 7;
    final String testName = "testName";

    // execute dao method
    final TestUserDao dao = injector.getInstance(TestUserDao.class);
    final TestUserBean user = new TestUserBean(true);
    user.setName(testName);/*from  w w  w .  j a v a2 s.  co  m*/
    TxHelper.execInTx(dao, new Runnable() {
        public void run() {
            try {
                createResultSet(testModule1, "nextval", new Object[] { id });
                final long res = dao.addUser(user);
                final Connection connection1 = TxHelper.getConnectionOnHold();
                assertNotNull(connection1);
                assertFalse(connection1.isClosed());
                testModule1.verifyNotCommitted();
                getUserOnce(testModule1, dao, 11, "user11", true);
                final Connection connection2 = TxHelper.getConnectionOnHold();
                assertSame(connection1, connection2);
                assertFalse(connection2.isClosed());
                testModule1.verifyNotCommitted();
                assertEquals(id, res);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }, id);
    final Connection connection = TxHelper.getConnectionOnHold();
    assertNull(connection);
    testModule1.verifyCommitted();
    testModule1.verifySQLStatementExecuted("select nextval from userIdSequence");
    testModule1.verifySQLStatementExecuted("insert into user(id,name) values(?, ?)");
    testModule1.verifyPreparedStatementParameter(1, 1, id);
    testModule1.verifyPreparedStatementParameter(1, 2, testName);
    testModule1.verifyAllResultSetsClosed();
    testModule1.verifyAllStatementsClosed();
    testModule1.verifyConnectionClosed();
}

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

@RequestMapping(value = "/createfunction", method = RequestMethod.GET)
public String createFunction(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 a va2s .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 create a new Function");

    session.setAttribute("numParams", "0");
    model.addAttribute("numParams", "0");
    model.addAttribute("functionAttribute", new NewFunction());

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

From source file:com.sf.ddao.JDBCDaoTest.java

public void testTx() throws Exception {
    final int id = 77;
    final String testName = "testName";

    // execute dao method
    final TestUserDao dao = injector.getInstance(TestUserDao.class);
    final TestUserBean user = new TestUserBean(true);
    user.setName(testName);/*from w  w w .j  a  v a2s .co  m*/
    //noinspection unchecked
    TxHelper.execInTx(dao, new Runnable() {
        public void run() {
            try {
                createResultSet("nextval", new Object[] { id });
                final int res = dao.addUser(user);
                final Connection connection1 = TxHelper.getConnectionOnHold();
                assertNotNull(connection1);
                assertFalse(connection1.isClosed());
                verifyNotCommitted();
                getUserOnce(dao, 11, "user11", false);
                final Connection connection2 = TxHelper.getConnectionOnHold();
                assertSame(connection1, connection2);
                assertFalse(connection2.isClosed());
                verifyNotCommitted();
                assertEquals(id, res);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
    });
    final Connection connection = TxHelper.getConnectionOnHold();
    assertNull(connection);
    verifyCommitted();
    verifySQLStatementExecuted("select nextval from userIdSequence");
    verifySQLStatementExecuted("insert into user(id,name) values(?, ?)");
    verifyPreparedStatementParameter(1, 1, id);
    verifyPreparedStatementParameter(1, 2, testName);
    verifyAllResultSetsClosed();
    verifyAllStatementsClosed();
    verifyConnectionClosed();
}

From source file:com.viettel.logistic.wms.service.SerialInventoryServiceImpl.java

private void commit(Session session, Transaction transaction, Connection con) {
    try {//w  w  w .  j a  v a  2  s .co m
        if (transaction != null) {
            transaction.commit();
        }
        if (con != null) {
            con.commit();
        }
        if (session != null && session.isOpen()) {
            session.close();
        }

        if (con != null && !con.isClosed()) {
            con.close();
        }
    } catch (SQLException ex) {
        Logger.getLogger(StockImportServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.opensymphony.module.propertyset.database.JDBCPropertySet.java

private void closeConnection(Connection conn) {
    try {/* w  ww .  j  av a2s.  co m*/
        if ((conn != null) && !conn.isClosed()) {
            conn.close();
        }
    } catch (SQLException e) {
        log.error("Could not close connection");
    }
}

From source file:org.fcrepo.server.storage.ConnectionPool.java

/**
 * <p>//from  w w  w. j av  a 2  s  .  com
 * Releases the specified connection and returns it to the pool.
 * </p>
 *
 * @param connection
 *        A JDBC connection.
 */
public void free(Connection connection) {
    try {
        // ensure connections returned to pool as read-only
        setConnectionReadOnly(connection, true);
        if (!connection.isClosed())
            connection.close();
    } catch (SQLException sqle) {
        logger.warn("Unable to close connection", sqle);
    } finally {
        if (logger.isDebugEnabled()) {
            logger.debug("Returned connection to pool (" + toString() + ")");
        }
    }
}

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

@RequestMapping(value = "/creatediskstore", method = RequestMethod.POST)
public String createHDFSStoreAction(@ModelAttribute("diskStoreAttribute") NewDiskStore diskStoreAttribute,
        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  . ja  va 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 Disk Store");

    String diskStoreName = diskStoreAttribute.getDiskStoreName();

    logger.debug("New Disk Store Name = " + diskStoreName);

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

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

        createDiskStore.append("create DISKSTORE " + diskStoreName + " \n");

        if (!checkIfParameterEmpty(request, "maxLogSize")) {
            createDiskStore.append("MAXLOGSIZE " + diskStoreAttribute.getMaxLogSize() + " \n");
        }

        if (!checkIfParameterEmpty(request, "autoCompact")) {
            createDiskStore.append("AUTOCOMPACT " + diskStoreAttribute.getAutoCompact() + " \n");
        }

        if (!checkIfParameterEmpty(request, "allowForceCompaction")) {
            createDiskStore
                    .append("ALLOWFORCECOMPACTION " + diskStoreAttribute.getAllowForceCompaction() + " \n");
        }

        if (!checkIfParameterEmpty(request, "compactionThreshold")) {
            createDiskStore
                    .append("COMPACTIONTHRESHOLD " + diskStoreAttribute.getCompactionThreshold() + " \n");
        }

        if (!checkIfParameterEmpty(request, "timeInterval")) {
            createDiskStore.append("TIMEINTERVAL " + diskStoreAttribute.getTimeInterval() + " \n");
        }

        if (!checkIfParameterEmpty(request, "writeBufferSize")) {
            createDiskStore.append("WRITEBUFFERSIZE " + diskStoreAttribute.getWriteBufferSize() + " \n");
        }

        if (!checkIfParameterEmpty(request, "additionalParams")) {
            createDiskStore.append(diskStoreAttribute.getAdditionalParams());
        }

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

            logger.debug("Creating disk store as -> " + createDiskStore.toString());

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

            model.addAttribute("result", result);

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

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

    }

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