public List getIdentityTables() { // delete all the data in the jbpm tables List jbpmTableNames = new ArrayList(); try { createConnection(); ResultSet resultSet = connection.getMetaData().getTables("", "", null, null); while (resultSet.next()) { String tableName = resultSet.getString("TABLE_NAME"); if ((tableName != null) && (tableName.length() > 5) && (IDENTITY_TABLE_PREFIX.equalsIgnoreCase(tableName.substring(0, 5)))) { jbpmTableNames.add(tableName); } } } catch (SQLException e) { throw new RuntimeException("couldn't get the jbpm table names"); } finally { closeConnection(); } return jbpmTableNames; }
/** * 初始化连接池 * * @param props * @param show_sql */ private static final void initDataSource(Properties dbProperties) { try { if (dbProperties == null) { dbProperties = new Properties(); dbProperties.load(DBManager.class.getResourceAsStream(CONFIG_PATH)); } // Class.forName(dbProperties.getProperty("jdbc.driverClass")); for (Object key : dbProperties.keySet()) { String skey = (String) key; if (skey.startsWith("jdbc.")) { String name = skey.substring(5); cp_props.put(name, dbProperties.getProperty(skey)); if ("show_sql".equalsIgnoreCase(name)) { show_sql = "true".equalsIgnoreCase(dbProperties.getProperty(skey)); } } } dataSource = (DataSource) Class.forName(cp_props.getProperty("datasource")).newInstance(); if (dataSource.getClass().getName().indexOf("c3p0") > 0) { // Disable JMX in C3P0 System.setProperty( "com.mchange.v2.c3p0.management.ManagementCoordinator", "com.mchange.v2.c3p0.management.NullManagementCoordinator"); } log.info("Using DataSource : " + dataSource.getClass().getName()); BeanUtils.populate(dataSource, cp_props); Connection conn = getConnection(); DatabaseMetaData mdm = conn.getMetaData(); log.info( "Connected to " + mdm.getDatabaseProductName() + " " + mdm.getDatabaseProductVersion()); closeConnection(); } catch (Exception e) { e.printStackTrace(); throw new DBException(e); } }
// // Find all the methods for java.sql objects in the Connection which raise // SQLFeatureNotSupportedException. // private void connectionWorkhorse( Connection conn, HashSet<String> unsupportedList, HashSet<String> notUnderstoodList) throws Exception { vetSavepoint(conn, unsupportedList, notUnderstoodList); vetLargeObjects(conn, unsupportedList, notUnderstoodList); DatabaseMetaData dbmd = conn.getMetaData(); PreparedStatement ps = conn.prepareStatement("select * from sys.systables where tablename = ?"); ps.setString(1, "foo"); ParameterMetaData parameterMetaData = ps.getParameterMetaData(); ResultSet rs = ps.executeQuery(); ResultSetMetaData rsmd = rs.getMetaData(); Statement stmt = conn.createStatement(); CallableStatement cs = conn.prepareCall("CALL SYSCS_UTIL.SET_RUNTIMESTATISTICS(0)"); ParameterMetaData csmd = cs.getParameterMetaData(); // // The vetObject() method calls all of the methods in these objects // in a deterministic order, calling the close() method last. // Inspect these objects in an order which respects the fact that // the objects are closed as a result of calling vetObject(). // vetObject(dbmd, unsupportedList, notUnderstoodList); vetObject(stmt, unsupportedList, notUnderstoodList); vetObject(csmd, unsupportedList, notUnderstoodList); vetObject(cs, unsupportedList, notUnderstoodList); vetObject(rsmd, unsupportedList, notUnderstoodList); vetObject(rs, unsupportedList, notUnderstoodList); vetObject(parameterMetaData, unsupportedList, notUnderstoodList); vetObject(ps, unsupportedList, notUnderstoodList); vetObject(conn, unsupportedList, notUnderstoodList); // No need to close the objects. They were closed by vetObject(). }
public synchronized Object invoke(Object proxy, Method m, Object[] args) throws Throwable { if (OBJECT_METHODS.contains(m)) return m.invoke(this, args); try { String mname = m.getName(); if (activeConnection != null) { if (mname.equals("rawConnectionOperation")) { ensureOkay(); txn_known_resolved = false; return doRawConnectionOperation((Method) args[0], args[1], (Object[]) args[2]); } else if (mname.equals("setTransactionIsolation")) { ensureOkay(); // don't modify txn_known_resolved m.invoke(activeConnection, args); int lvl = ((Integer) args[0]).intValue(); isolation_lvl_nondefault = (lvl != dflt_txn_isolation); // System.err.println("updated txn isolation to " + lvl + ", nondefault level? " + // isolation_lvl_nondefault); return null; } else if (mname.equals("setCatalog")) { ensureOkay(); // don't modify txn_known_resolved m.invoke(activeConnection, args); String catalog = (String) args[0]; catalog_nondefault = ObjectUtils.eqOrBothNull(catalog, dflt_catalog); return null; } else if (mname.equals("setHoldability")) { ensureOkay(); // don't modify txn_known_resolved m.invoke( activeConnection, args); // will throw an exception if setHoldability() not supported... int holdability = ((Integer) args[0]).intValue(); holdability_nondefault = (holdability != dflt_holdability); return null; } else if (mname.equals("createStatement")) { ensureOkay(); txn_known_resolved = false; Object stmt = m.invoke(activeConnection, args); return createProxyStatement((Statement) stmt); } else if (mname.equals("prepareStatement")) { ensureOkay(); txn_known_resolved = false; Object pstmt; if (scache == null) { pstmt = m.invoke(activeConnection, args); return createProxyStatement((Statement) pstmt); } else { pstmt = scache.checkoutStatement(physicalConnection, m, args); return createProxyStatement(true, (Statement) pstmt); } } else if (mname.equals("prepareCall")) { ensureOkay(); txn_known_resolved = false; Object cstmt; if (scache == null) { cstmt = m.invoke(activeConnection, args); return createProxyStatement((Statement) cstmt); } else { cstmt = scache.checkoutStatement(physicalConnection, m, args); return createProxyStatement(true, (Statement) cstmt); } } else if (mname.equals("getMetaData")) { ensureOkay(); txn_known_resolved = false; // views of tables etc. might be txn dependent DatabaseMetaData innerMd = activeConnection.getMetaData(); if (metaData == null) { // exposedProxy is protected by C3P0PooledConnection.this' lock synchronized (C3P0PooledConnection.this) { metaData = new SetManagedDatabaseMetaData(innerMd, activeMetaDataResultSets, exposedProxy); } } return metaData; } else if (mname.equals("silentClose")) { // the PooledConnection doesn't have to be okay doSilentClose(proxy, ((Boolean) args[0]).booleanValue(), this.txn_known_resolved); return null; } else if (mname.equals("close")) { // the PooledConnection doesn't have to be okay Exception e = doSilentClose(proxy, false, this.txn_known_resolved); if (!connection_error_signaled) ces.fireConnectionClosed(); // System.err.println("close() called on a ProxyConnection."); if (e != null) { // System.err.print("user close exception -- "); // e.printStackTrace(); throw e; } else return null; } // else if ( mname.equals("finalize") ) //REMOVE THIS CASE -- TMP DEBUG // { // System.err.println("Connection apparently finalized!"); // return m.invoke( activeConnection, args ); // } else { ensureOkay(); // we've disabled setting txn_known_resolved to true, ever, because // we failed to deal with the case that clients would work with previously // acquired Statements and ResultSets after a commit(), rollback(), or setAutoCommit(). // the new non-reflective proxies have been modified to deal with this case. // here, with soon-to-be-deprecated in "traditional reflective proxies mode" // we are reverting to the conservative, always-presume-you-have-to-rollback // policy. // txn_known_resolved = ( mname.equals("commit") || mname.equals( "rollback" ) || // mname.equals( "setAutoCommit" ) ); txn_known_resolved = false; return m.invoke(activeConnection, args); } } else { if (mname.equals("close") || mname.equals("silentClose")) return null; else if (mname.equals("isClosed")) return Boolean.TRUE; else { throw new SQLException("You can't operate on " + "a closed connection!!!"); } } } catch (InvocationTargetException e) { Throwable convertMe = e.getTargetException(); SQLException sqle = handleMaybeFatalToPooledConnection(convertMe, proxy, false); sqle.fillInStackTrace(); throw sqle; } }