List of usage examples for java.sql Connection isClosed
boolean isClosed() throws SQLException;
Connection
object has been closed. From source file:pivotal.au.se.gemfirexdweb.controller.CreateSynonymController.java
@RequestMapping(value = "/createsynonym", method = RequestMethod.POST) public String createSynonymAction(@ModelAttribute("synonymAttribute") NewSynonym synonymAttribute, 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 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 synonym"); String schema = synonymAttribute.getSchemaName().trim(); if (schema.length() == 0) { schema = (String) session.getAttribute("schema"); } logger.debug("New synonym name = " + synonymAttribute.getSynonymName()); TableDAO tableDAO = GemFireXDWebDAOFactory.getTableDAO(); ViewDAO viewDAO = GemFireXDWebDAOFactory.getViewDAO(); List<View> views = viewDAO.retrieveViewList((String) session.getAttribute("schema"), null, (String) session.getAttribute("user_key")); model.addAttribute("views", views); List<Table> tbls = tableDAO.retrieveTableList((String) session.getAttribute("schema"), null, (String) session.getAttribute("user_key"), "ORDINARY"); model.addAttribute("tables", tbls); // perform some action here with what we have String submit = request.getParameter("pSubmit"); if (submit != null) { // build create HDFS Store SQL StringBuffer createSynonym = new StringBuffer(); createSynonym.append("CREATE SYNONYM " + schema + "." + synonymAttribute.getSynonymName() + " \n"); createSynonym.append("FOR " + synonymAttribute.getObjectName() + " \n"); if (submit.equalsIgnoreCase("create")) { Result result = new Result(); logger.debug("Creating synonym as -> " + createSynonym.toString()); result = GemFireXDWebDAOUtil.runCommand(createSynonym.toString(), (String) session.getAttribute("user_key")); model.addAttribute("result", result); } else if (submit.equalsIgnoreCase("Show SQL")) { logger.debug("Create UDT (Type) SQL as follows as -> " + createSynonym.toString()); model.addAttribute("sql", createSynonym.toString()); model.addAttribute("objectName", request.getParameter("objectName")); } else if (submit.equalsIgnoreCase("Save to File")) { response.setContentType(SAVE_CONTENT_TYPE); response.setHeader("Content-Disposition", "attachment; filename=" + String.format(FILENAME, synonymAttribute.getSynonymName())); ServletOutputStream out = response.getOutputStream(); out.println(createSynonym.toString()); out.close(); return null; } } // This will resolve to /WEB-INF/jsp/create-synonym.jsp return "create-synonym"; }
From source file:pivotal.au.se.gemfirexdweb.controller.CreateIndexController.java
@RequestMapping(value = "/createindex", method = RequestMethod.GET) public String createIndex(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 . 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 create a new index"); String tabName = (String) request.getParameter("tabName"); String schema = (String) request.getParameter("schemaName"); logger.debug("Table = " + schema + "." + tabName); IndexDAO indexDAO = GemFireXDWebDAOFactory.getIndexDAO(); List<IndexColumn> columns = indexDAO.retrieveIndexColumns(schema, tabName, (String) session.getAttribute("user_key")); model.addAttribute("tabName", tabName); model.addAttribute("tableSchemaName", schema); model.addAttribute("columns", columns); model.addAttribute("schema", schema); model.addAttribute("indexAttribute", new NewIndex()); // This will resolve to /WEB-INF/jsp/create-index.jsp return "create-index"; }
From source file:net.fender.sql.ManagedConnectionDataSource.java
/** * Tests if managedConnection != null, wrappedConnection != null && * !isClosed(), then runs validation query. Closes the connection on * SQLException.//w ww. ja v a 2 s. c om * * @param managedConnection * @throws InvalidConnectionException */ protected void validateConnection(ManagedConnection managedConnection) throws InvalidConnectionException { if (managedConnection == null) { throw new InvalidConnectionException("managedConnection is null"); } // only validate the base connection if (managedConnection.isValid()) { return; } managedConnection.setValid(false); Connection connection = managedConnection.getConnection(); if (connection == null) { throw new InvalidConnectionException("wrapped connection is null"); } Statement statement = null; ResultSet resultSet = null; try { if (connection.isClosed()) { throw new InvalidConnectionException("wrapped connection is closed"); } // if no validation query, then assume it is ok if (StringUtils.isBlank(validationQuery)) { managedConnection.setValid(true); return; } statement = connection.createStatement(); resultSet = statement.executeQuery(validationQuery); if (resultSet.next()) { log.debug("connection validation returned " + resultSet.getObject(1)); managedConnection.setValid(true); } } catch (SQLException e) { JdbcUtils.close(connection); throw new InvalidConnectionException(e); } finally { JdbcUtils.close(resultSet, statement); } }
From source file:pivotal.au.se.gemfirexdweb.controller.CreateGatewayReceiverController.java
@RequestMapping(value = "/creategatewayreceiver", method = RequestMethod.POST) public String createGatewayReceiverAction( @ModelAttribute("gatewayReceiverAttribute") NewGatewayReceiver gatewayReceiverAttribute, 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 ava 2 s.com*/ 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 Receiver"); String gatewayReceiverName = gatewayReceiverAttribute.getGatewayReceiverName(); logger.debug("New Gateway Receiver Name = " + gatewayReceiverName); // 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 createGatewayReceiver = new StringBuffer(); createGatewayReceiver.append("CREATE GATEWAYRECEIVER " + gatewayReceiverName + " (\n"); if (!checkIfParameterEmpty(request, "bindAddress")) { createGatewayReceiver.append("BINDADDRESS '" + gatewayReceiverAttribute.getBindAddress() + "' \n"); needCloseBracket = true; } if (!checkIfParameterEmpty(request, "startPort")) { createGatewayReceiver.append("STARTPORT " + gatewayReceiverAttribute.getStartPort() + " \n"); needCloseBracket = true; } if (!checkIfParameterEmpty(request, "endPort")) { createGatewayReceiver.append("ENDPORT " + gatewayReceiverAttribute.getEndPort() + " \n"); needCloseBracket = true; } if (!checkIfParameterEmpty(request, "socketBufferSize")) { createGatewayReceiver .append("SOCKETBUFFERSIZE " + gatewayReceiverAttribute.getSocketBufferSize() + " \n"); needCloseBracket = true; } if (!checkIfParameterEmpty(request, "maxTimeBetweenPings")) { createGatewayReceiver .append("MAXTIMEBETWEENPINGS " + gatewayReceiverAttribute.getMaxTimeBetweenPings() + " \n"); needCloseBracket = true; } if (needCloseBracket) { createGatewayReceiver.append(") "); } if (!checkIfParameterEmpty(request, "serverGroups")) { createGatewayReceiver .append("SERVER GROUPS (" + gatewayReceiverAttribute.getServerGroups() + ") \n"); } if (submit.equalsIgnoreCase("create")) { Result result = new Result(); logger.debug("Creating gateway receiver as -> " + createGatewayReceiver.toString()); result = GemFireXDWebDAOUtil.runCommand(createGatewayReceiver.toString(), (String) session.getAttribute("user_key")); model.addAttribute("result", result); } else if (submit.equalsIgnoreCase("Show SQL")) { logger.debug("Create Async SQL as follows as -> " + createGatewayReceiver.toString()); model.addAttribute("sql", createGatewayReceiver.toString()); } else if (submit.equalsIgnoreCase("Save to File")) { response.setContentType(SAVE_CONTENT_TYPE); response.setHeader("Content-Disposition", "attachment; filename=" + String.format(FILENAME, gatewayReceiverName)); ServletOutputStream out = response.getOutputStream(); out.println(createGatewayReceiver.toString()); out.close(); return null; } } // This will resolve to /WEB-INF/jsp/create-gatewayreceiver.jsp return "create-gatewayreceiver"; }
From source file:pivotal.au.se.gemfirexdweb.controller.ConstraintController.java
@RequestMapping(value = "/constraints", method = RequestMethod.GET) public String showConstraints(Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception { int startAtIndex = 0, endAtIndex = 0; javax.servlet.jsp.jstl.sql.Result fkInfoResult; String schema = null;//from w w w. j av a 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 constraints"); ConstraintDAO conDAO = GemFireXDWebDAOFactory.getConstraintDAO(); Result result = new Result(); String conAction = request.getParameter("conAction"); 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 (conAction != null) { logger.debug("conAction = " + conAction); if (conAction.equalsIgnoreCase("FKINFO")) { fkInfoResult = conDAO.getFKInfo(schema, (String) request.getParameter("constraintId"), (String) session.getAttribute("user_key")); model.addAttribute("fkInfoResult", fkInfoResult); model.addAttribute("constraintname", (String) request.getParameter("constraintName")); } else { result = null; result = conDAO.simpleconstraintCommand(schema, (String) request.getParameter("tabName"), (String) request.getParameter("constraintName"), conAction, (String) session.getAttribute("user_key")); model.addAttribute("result", result); } } List<Constraint> cons = conDAO.retrieveConstraintList(schema, null, (String) session.getAttribute("user_key")); model.addAttribute("records", cons.size()); model.addAttribute("estimatedrecords", cons.size()); UserPref userPref = (UserPref) session.getAttribute("prefs"); if (cons.size() <= userPref.getRecordsToDisplay()) { model.addAttribute("cons", cons); } 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 > cons.size()) { endAtIndex = cons.size(); } } else { endAtIndex = userPref.getRecordsToDisplay(); } List subList = cons.subList(startAtIndex, endAtIndex); model.addAttribute("cons", 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/constraints.jsp return "constraints"; }
From source file:com.sshdemo.common.extendds.manage.web.ConnectDSAction.java
public String test() { EwcmsDataSourceServiceable service = null; Connection con = null; String testResults = "?,!"; try {//from w w w . java2 s . c om BaseDS alqcDataSource = baseDSFac.findByBaseDS(id); DataSourceFactoryable factory = (DataSourceFactoryable) ewcmsDataSourceFactory .getBean(alqcDataSource.getClass()); service = factory.createService(alqcDataSource); con = service.openConnection(); if (!con.isClosed()) testResults = "?,???!"; } catch (Exception e) { } finally { try { if (con != null) { con.close(); con = null; } } catch (Exception e) { } try { if (service != null) { service.closeConnection(); service = null; } } catch (Exception e) { } } Struts2Util.renderText(testResults); return NONE; }
From source file:pivotal.au.se.gemfirexdweb.controller.CreateTriggerController.java
@RequestMapping(value = "/createtrigger", method = RequestMethod.POST) public String createTriggerAction(@ModelAttribute("triggerAttribute") NewTrigger triggerAttribute, 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.jav 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; } } } logger.debug("Received request to action an event for create Trigger"); TableDAO tableDAO = GemFireXDWebDAOFactory.getTableDAO(); List<Table> tables = tableDAO.retrieveTableList((String) session.getAttribute("schema"), null, (String) session.getAttribute("user_key"), "tables"); model.addAttribute("tables", tables); String schema = triggerAttribute.getSchemaName().trim(); if (schema.length() == 0) { schema = (String) session.getAttribute("schema"); } logger.debug("New Trigger schema name = " + schema); logger.debug("New Trigger name = " + triggerAttribute.getTriggerName()); // perform some action here with what we have String submit = request.getParameter("pSubmit"); if (submit != null) { // build create HDFS Store SQL StringBuffer createTrigger = new StringBuffer(); createTrigger.append("CREATE TRIGGER " + schema + "." + triggerAttribute.getTriggerName() + " \n"); createTrigger.append(triggerAttribute.getBeforeOrAfter() + " \n"); createTrigger.append(triggerAttribute.getType() + " \n"); if (!checkIfParameterEmpty(request, "columnList")) { createTrigger.append("OF " + triggerAttribute.getColumnList() + " \n"); } createTrigger.append("ON " + triggerAttribute.getTableName() + " \n"); if (!checkIfParameterEmpty(request, "referencingOldClause")) { createTrigger.append("REFERENCING OLD AS " + triggerAttribute.getReferencingOldClause() + " \n"); } if (!checkIfParameterEmpty(request, "referencingNewClause")) { createTrigger.append("REFERENCING NEW AS " + triggerAttribute.getReferencingNewClause() + " \n"); } createTrigger.append(triggerAttribute.getForEachRow() + " \n"); if (!checkIfParameterEmpty(request, "triggerDefinition")) { createTrigger.append(triggerAttribute.getTriggerDefinition() + " \n"); } if (submit.equalsIgnoreCase("create")) { Result result = new Result(); logger.debug("Creating Trigger as -> " + createTrigger.toString()); result = GemFireXDWebDAOUtil.runCommand(createTrigger.toString(), (String) session.getAttribute("user_key")); model.addAttribute("result", result); model.addAttribute("tableName", triggerAttribute.getTableName()); } else if (submit.equalsIgnoreCase("Show SQL")) { logger.debug("Create Trigger SQL as follows as -> " + createTrigger.toString()); model.addAttribute("sql", createTrigger.toString()); model.addAttribute("tableName", triggerAttribute.getTableName()); } else if (submit.equalsIgnoreCase("Save to File")) { response.setContentType(SAVE_CONTENT_TYPE); response.setHeader("Content-Disposition", "attachment; filename=" + String.format(FILENAME, triggerAttribute.getTriggerName())); ServletOutputStream out = response.getOutputStream(); out.println(createTrigger.toString()); out.close(); return null; } } // This will resolve to /WEB-INF/jsp/create-trigger.jsp return "create-trigger"; }
From source file:com.cws.esolutions.security.dao.userauth.impl.SQLAuthenticator.java
/** * @see com.cws.esolutions.security.dao.userauth.interfaces.Authenticator#verifySecurityData(java.lang.String, java.lang.String, java.util.List) *//*from ww w. ja va2 s . co m*/ public synchronized boolean verifySecurityData(final String userId, final String userGuid, final List<String> attributes) throws AuthenticatorException { final String methodName = SQLAuthenticator.CNAME + "#verifySecurityData(final String userId, final String userGuid, final List<String> attributes) throws AuthenticatorException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", userId); DEBUGGER.debug("Value: {}", userGuid); } Connection sqlConn = null; CallableStatement stmt = null; try { sqlConn = SQLAuthenticator.dataSource.getConnection(); if (sqlConn.isClosed()) { throw new SQLException("Unable to obtain application datasource connection"); } sqlConn.setAutoCommit(true); stmt = sqlConn.prepareCall("{CALL verifySecurityQuestions(?, ?, ?, ?)}"); stmt.setString(1, userGuid); // guid stmt.setString(2, userId); stmt.setString(3, attributes.get(0)); // username stmt.setString(4, attributes.get(1)); // username if (DEBUG) { DEBUGGER.debug("Statement: {}", stmt.toString()); } return stmt.execute(); } catch (SQLException sqx) { throw new AuthenticatorException(sqx.getMessage(), sqx); } finally { try { if (stmt != null) { stmt.close(); } if (!(sqlConn == null) && (!(sqlConn.isClosed()))) { sqlConn.close(); } } catch (SQLException sqx) { throw new AuthenticatorException(sqx.getMessage(), sqx); } } }
From source file:org.executequery.datasource.ConnectionPoolImpl.java
public void setTransactionIsolationLevel(int isolationLevel) { if (!isTransactionSupported()) { return;/*from w w w. ja v a2 s . c o m*/ } int isolationLevelToApply = isolationLevel; if (isolationLevelToApply == -1) { isolationLevelToApply = defaultTxIsolation; } Log.debug("Setting transaction isolation level to open connections as [ " + nameForTransactionIsolationLevel(isolationLevelToApply) + " ]"); try { synchronized (openConnections) { for (Connection connection : openConnections) { if (!connection.isClosed()) { connection.setTransactionIsolation(isolationLevelToApply); } } } } catch (SQLException e) { throw new DataSourceException(e); } }
From source file:org.silverpeas.core.test.rule.DbSetupRule.java
/** * Closes quietly all unclosed database connections opened by {@link #openSafeConnection()} or * {@link #getSafeConnection()}.// w w w. j ava 2 s . c o m */ private void closeConnectionsQuietly(Description description) { if (safeConnectionPool.isEmpty()) { Logger.getLogger(DbSetupRule.class.getName()).info("No database safe connection to close."); return; } Iterator<Connection> connectionIterator = safeConnectionPool.iterator(); int total = safeConnectionPool.size(); int nbAlreadyClosed = 0; int nbCloseErrors = 0; int nbCloseSuccessfully = 0; while (connectionIterator.hasNext()) { Connection connection = connectionIterator.next(); try { if (!connection.isClosed()) { connection.close(); nbCloseSuccessfully++; } else { nbAlreadyClosed++; } } catch (Exception e) { nbCloseErrors++; Logger.getLogger(DbSetupRule.class.getName()).log(Level.WARNING, "Close connection error...", e); } connectionIterator.remove(); } Logger.getLogger(DbSetupRule.class.getName()).log(Level.INFO, "# Quiet database connection close report #\n" + "On {0} opened safe {0,choice, 1#connection| 1<connections }:\n" + " - {1} closed successfully (could be the user of getActualDataSet or something wrong),\n" + " - {2} already closed,\n" + " - {3} closed in error", new Object[] { total, nbCloseSuccessfully, nbAlreadyClosed, nbCloseErrors }); if (nbCloseSuccessfully > 0) { fail(nbCloseSuccessfully + " connection(s) not closed, please review the test performed by: " + description.getTestClass() + "#" + description.getMethodName()); } }