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.CreateGatewayReceiverController.java
@RequestMapping(value = "/creategatewayreceiver", method = RequestMethod.GET) public String createGatewayReceiver(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 Gateway Receiver"); model.addAttribute("gatewayReceiverAttribute", new NewGatewayReceiver()); // This will resolve to /WEB-INF/jsp/create-gatewayreceiver.jsp return "create-gatewayreceiver"; }
From source file:pivotal.au.se.gemfirexdweb.controller.JMXController.java
@RequestMapping(value = "/jmxmbeans", method = RequestMethod.POST) public String performJMXAction(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 w w. j av a 2 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 search for Mbeans"); UserPref userPref = (UserPref) session.getAttribute("prefs"); String jolokiaURL = userPref.getJolokiaURL(); logger.debug("jolokiaURL = " + jolokiaURL); String searchStr = request.getParameter("search"); logger.debug("searchStr = " + searchStr); List<String> mbeanNames = searchMbeans("", jolokiaURL); List<String> returnMbeanList = new ArrayList<String>(); for (String mbean : mbeanNames) { if (mbean.toUpperCase().contains(searchStr.toUpperCase())) { returnMbeanList.add(mbean); } } model.addAttribute("mbeanNames", returnMbeanList); model.addAttribute("records", returnMbeanList.size()); model.addAttribute("search", searchStr); // This will resolve to /WEB-INF/jsp/showmbeans.jsp return "showmbeans"; }
From source file:com.amazonaws.services.kinesis.connectors.redshift.RedshiftManifestEmitter.java
private void closeConnection(Connection conn) { try {//from w ww . java2 s .c o m if ((conn != null) && (!conn.isClosed())) { conn.close(); } } catch (Exception e) { LOG.error("Unable to close Amazon Redshift connection.", e); } }
From source file:com.amazonaws.services.kinesis.connectors.redshift.RedshiftManifestEmitter.java
private void rollbackAndCloseConnection(Connection conn) { try {/*from ww w. j a v a 2 s . c om*/ if ((conn != null) && (!conn.isClosed())) { conn.rollback(); } } catch (Exception e) { LOG.error("Unable to rollback Amazon Redshift transaction.", e); } closeConnection(conn); }
From source file:pivotal.au.se.gemfirexdweb.controller.ReportsController.java
@RequestMapping(value = "/executequeryreport", method = RequestMethod.GET) public String executeQuery(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 ww w.jav 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 execute a query"); javax.servlet.jsp.jstl.sql.Result queryResult = null; QueryBeanReader reader = QueryBeanReader.getInstance(); ConnectionManager cm = ConnectionManager.getInstance(); String beanId = request.getParameter("beanId"); if (beanId != null) { Query qb = reader.getQueryBean(beanId); if (qb instanceof GenericQuery) { logger.debug("Generic Query will be run"); GenericQuery genericQuery = (GenericQuery) qb; queryResult = genericQuery.invoke(cm.getConnection((String) session.getAttribute("user_key"))); model.addAttribute("queryResults", queryResult); model.addAttribute("queryDescription", genericQuery.getQueryDescription()); model.addAttribute("querySQL", genericQuery.getQuery().trim()); model.addAttribute("beanId", beanId); } else if (qb instanceof ParameterQuery) { ParameterQuery paramQuery = (ParameterQuery) qb; model.addAttribute("queryDescription", paramQuery.getQueryDescription()); model.addAttribute("querySQL", paramQuery.getQuery().trim()); model.addAttribute("beanId", beanId); model.addAttribute("paramMap", paramQuery.getParamMap()); if (request.getParameter("pSubmit") != null) { // execute pressed, get param values Map paramValues = new HashMap(); Set<String> keys = paramQuery.getParamMap().keySet(); for (String param : keys) { paramValues.put(param, (String) request.getParameter(param)); } paramQuery.setParamValues(paramValues); queryResult = paramQuery.invoke(cm.getConnection((String) session.getAttribute("user_key"))); request.setAttribute("queryResults", queryResult); } } else { // do nothing here } } // This will resolve to /WEB-INF/jsp/displayquery.jsp return "displayquery"; }
From source file:pivotal.au.se.gemfirexdweb.controller.CreateTypeController.java
@RequestMapping(value = "/createtype", method = RequestMethod.POST) public String createTypeAction(@ModelAttribute("typeAttribute") Type typeAttribute, 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 w w .ja v a2s . 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 action an event for create UDT (Type)"); String schema = typeAttribute.getSchemaName().trim(); if (schema.length() == 0) { schema = (String) session.getAttribute("schema"); } logger.debug("New Type schema name = " + schema); logger.debug("New Type name = " + typeAttribute.getTypeName()); // perform some action here with what we have String submit = request.getParameter("pSubmit"); if (submit != null) { // build create HDFS Store SQL StringBuffer createType = new StringBuffer(); createType.append("CREATE TYPE " + schema + "." + typeAttribute.getTypeName() + " \n"); createType.append("EXTERNAL NAME '" + typeAttribute.getJavaClassName() + "' \n"); createType.append("LANGUAGE JAVA \n"); if (submit.equalsIgnoreCase("create")) { Result result = new Result(); logger.debug("Creating UDT Type as -> " + createType.toString()); result = GemFireXDWebDAOUtil.runCommand(createType.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 -> " + createType.toString()); model.addAttribute("sql", createType.toString()); } else if (submit.equalsIgnoreCase("Save to File")) { response.setContentType(SAVE_CONTENT_TYPE); response.setHeader("Content-Disposition", "attachment; filename=" + String.format(FILENAME, typeAttribute.getTypeName())); ServletOutputStream out = response.getOutputStream(); out.println(createType.toString()); out.close(); return null; } } // This will resolve to /WEB-INF/jsp/create-type.jsp return "create-type"; }
From source file:pivotal.au.se.gemfirexdweb.controller.AddLoaderController.java
@RequestMapping(value = "/addloader", method = RequestMethod.POST) public String createLoaderAction(@ModelAttribute("loaderAttribute") AddLoader loaderAttribute, 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 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 action an event for Table Loader"); // perform some action here with what we have String submit = request.getParameter("pSubmit"); if (submit != null) { // build create HDFS Store SQL StringBuffer addLoader = new StringBuffer(); addLoader.append("CALL SYS.ATTACH_LOADER ('" + loaderAttribute.getSchemaName() + "', \n"); addLoader.append("'" + loaderAttribute.getTableName() + "', \n"); addLoader.append("'" + loaderAttribute.getFunctionName() + "', \n"); if (!checkIfParameterEmpty(request, "initInfoString")) { addLoader.append("'" + loaderAttribute.getInitInfoString() + "') \n"); } else { addLoader.append("NULL) \n"); } if (submit.equalsIgnoreCase("create")) { Result result = new Result(); logger.debug("Creating Table Loader as -> " + addLoader.toString()); result = GemFireXDWebDAOUtil.runStoredCommand(addLoader.toString(), (String) session.getAttribute("user_key")); model.addAttribute("result", result); } else if (submit.equalsIgnoreCase("Show SQL")) { logger.debug("Create Table Loader SQL as follows as -> " + addLoader.toString()); model.addAttribute("sql", addLoader.toString()); } else if (submit.equalsIgnoreCase("Save to File")) { response.setContentType(SAVE_CONTENT_TYPE); response.setHeader("Content-Disposition", "attachment; filename=" + String.format(FILENAME, loaderAttribute.getTableName() + "-Loader")); ServletOutputStream out = response.getOutputStream(); out.println(addLoader.toString()); out.close(); return null; } } // This will resolve to /WEB-INF/jsp/addloader.jsp return "addloader"; }
From source file:pivotal.au.se.gemfirexdweb.controller.JMXController.java
@RequestMapping(value = "/jmxmbeans", method = RequestMethod.GET) public String showJMXMbeans(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 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; } } } UserPref userPref = (UserPref) session.getAttribute("prefs"); String jolokiaURL = userPref.getJolokiaURL(); String mbeanName = request.getParameter("mbeanName"); if (mbeanName != null) { logger.debug("Received request to show Mbean Attributes"); logger.debug("mbeanName = " + mbeanName); String refreshTime = request.getParameter("refreshTime"); if (refreshTime == null) { refreshTime = "none"; } logger.debug("refresh time : " + refreshTime); Map<String, Object> attributes = getMbeanAttributeValues(mbeanName, jolokiaURL); model.addAttribute("refreshTime", refreshTime); model.addAttribute("mbeanName", mbeanName); model.addAttribute("mbeanMap", attributes); model.addAttribute("records", attributes.size()); // This will resolve to /WEB-INF/jsp/viewmbean.jsp return "viewmbean"; } else { logger.debug("Received request to show JMX Mbeans for cluster"); logger.debug("jolokiaURL = " + jolokiaURL); List<String> mbeanNames = searchMbeans("", jolokiaURL); model.addAttribute("mbeanNames", mbeanNames); model.addAttribute("records", mbeanNames.size()); // This will resolve to /WEB-INF/jsp/showmbeans.jsp return "showmbeans"; } }
From source file:org.wso2.carbon.identity.application.common.persistence.IdentityApplicationDBInitializer.java
private String getDatabaseType(Connection conn) throws IdentityApplicationManagementException { String type = null;//w ww. j a v a 2 s .c o m try { if (conn != null && (!conn.isClosed())) { DatabaseMetaData metaData = conn.getMetaData(); String databaseProductName = metaData.getDatabaseProductName(); if (databaseProductName.matches("(?i).*mysql.*")) { type = "mysql"; } else if (databaseProductName.matches("(?i).*oracle.*")) { type = "oracle"; } else if (databaseProductName.matches("(?i).*microsoft.*")) { type = "mssql"; } else if (databaseProductName.matches("(?i).*h2.*")) { type = "h2"; } else if (databaseProductName.matches("(?i).*db2.*")) { type = "db2"; } else if (databaseProductName.matches("(?i).*postgresql.*")) { type = "postgresql"; } } else { String msg = "Illegal arguments: Connection is either \'NULL\' or already closed"; log.debug(msg); throw new IllegalArgumentException(msg); } } catch (SQLException e) { log.error(e.getMessage(), e); String msg = "Failed to create Identity Application Management Database"; throw new IdentityApplicationManagementException(msg); } return type; }
From source file:utils.DatabaseConnection.java
public Connection getConnectionOnlyFromDatabaseManager() { try {//from www .j av a 2s . c o m Connection con = ds.getConnection(); Logger.debug("Connection is : " + con); if (con == null) { initialize(); } else { if (con.isClosed()) { Logger.debug("Connection was closed : " + con); con = null; initialize(); } else { Logger.debug("connection was good"); Statement stmt = con.createStatement(); Logger.debug("connection was good stantement is : " + stmt); if (stmt == null) { //STrnage try { con.close(); } catch (Exception eee) { } con = null; initialize(); } else { stmt.close(); } } } if (con == null) { return ds.getConnection(); } else { return con; } } catch (Exception e) { e.printStackTrace(); Logger.debug("Returning null getConnection... : " + e.getMessage()); initialize(); try { return ds.getConnection(); } catch (Exception ee) { ee.printStackTrace(); Logger.debug("EEE Returning null getConnection... : " + ee.getMessage()); } return null; } }