📄 jdbcconnectionpool.java
字号:
} catch (Exception ex) { log.warning("the 'maxWaitingThreads' plugin-property is not parseable: '" + help + "' will be using the default '" + this.maxWaitingThreads + "'"); } help = pluginProp.getProperty("queryTimeout", "" + this.queryTimeout); try { this.queryTimeout = Integer.parseInt(help); } catch (Exception ex) { log.warning("the 'queryTimeout' plugin-property is not parseable: '" + help + "' will be using the default '" + this.queryTimeout + "'"); } help = pluginProp.getProperty("enableBatchMode", "true"); try { this.enableBatchMode = Boolean.getBoolean(help); } catch (Exception ex) { log.warning("the 'enableBatchMode' plugin-property is not parseable: '" + help + "' will be using the default '" + this.enableBatchMode + "'"); } // these should be handled by the JdbcManager help = pluginProp.getProperty("tableAllocationIncrement", "" + this.tableAllocationIncrement); try { this.tableAllocationIncrement = Integer.parseInt(help); } catch (Exception ex) { log.warning("the 'tableAllocationIncrement' plugin-property is not parseable: '" + help + "' will be using the default '" + this.tableAllocationIncrement + "'"); } this.tableNamePrefix = pluginProp.getProperty("tableNamePrefix", this.tableNamePrefix).trim().toUpperCase(); this.colNamePrefix = pluginProp.getProperty("colNamePrefix", this.colNamePrefix).trim().toUpperCase(); try { this.forceIsoaltionLevel = Integer.valueOf(pluginProp.getProperty("forceIsoaltionLevel", "-1")).intValue(); } catch(NumberFormatException e) { log.warning("Please check your forceIsoaltionLevel:" + e.toString()); } String tmp = pluginProp.getProperty("dbAdmin", "true").trim(); this.dbAdmin = true; if ("false".equalsIgnoreCase(tmp)) this.dbAdmin = false; this.configurationIdentifier = pluginProp.getProperty("configurationIdentifier", null); if (this.configurationIdentifier != null) this.configurationIdentifier = this.configurationIdentifier.trim(); help = pluginProp.getProperty("cascadeDeleteSupported", "true"); try { this.cascadeDeleteSupported = Boolean.getBoolean(help); } catch (Exception ex) { log.warning("the 'cascadeDeleteSupported' plugin-property is not parseable: '" + help + "' will be using the default '" + this.cascadeDeleteSupported + "'"); } help = pluginProp.getProperty("nestedBracketsSupported", "true"); try { this.nestedBracketsSupported = Boolean.getBoolean(help); } catch (Exception ex) { log.warning("the 'nestedBracketsSupported' plugin-property is not parseable: '" + help + "' will be using the default '" + this.nestedBracketsSupported + "'"); } if (log.isLoggable(Level.FINEST)) { log.finest("initialize -url : " + this.url); log.finest("initialize -user : " + this.user); log.finest("initialize -password : " + this.password); log.finest("initialize -max number of conn : " + this.capacity); log.finest("initialize -queryTimeout : " + this.queryTimeout); log.finest("initialize -conn busy timeout : " + this.connectionBusyTimeout); log.finest("initialize -driver list : " + xmlBlasterJdbc); log.finest("initialize -max. waiting Threads :" + this.maxWaitingThreads); log.finest("initialize -tableNamePrefix :" + this.tableNamePrefix); log.finest("initialize -colNamePrefix :" + this.colNamePrefix); log.finest("initialize -dbAdmin :" + this.dbAdmin); log.finest("initialize -cascadeDeleteSupported :" + this.cascadeDeleteSupported); log.finest("initialize -nestedBracketsSupported:" + this.nestedBracketsSupported); log.finest("initialize -debug :" + this.debug); if (this.configurationIdentifier != null) log.finest("initialize -configurationIdentifier:" + this.configurationIdentifier); } // could block quite a long time if the number of connections is big // or if the connection to the DB is slow. this.connections = new BoundedLinkedQueue(); this.connections.setCapacity(this.capacity); try { // initializing and establishing of connections to DB (but first disconnect if already connected) final boolean disconnectFirst = true; connect(disconnectFirst, true); parseMapping(prop); if (log.isLoggable(Level.FINEST)) dumpMetaData(); this.initialized = true; } catch (SQLException ex) { if (firstConnectError) { firstConnectError = false; log.severe(" connecting to DB, error code : '" + ex.getErrorCode() + " : " + ex.getMessage() + "' DB configuration details follow (check if the DB is running)"); log.info("diagnostics: initialize -url : '" + url + "'"); log.info("diagnostics: initialize -user : '" + user + "'"); log.info("diagnostics: initialize -password : '" + password + "'"); log.info("diagnostics: initialize -max number of conn : '" + this.capacity + "'"); log.info("diagnostics: initialize -queryTimeout : '" + this.queryTimeout + "'"); log.info("diagnostics: initialize -conn busy timeout : '" + this.connectionBusyTimeout + "'"); log.info("diagnostics: initialize -driver list : '" + xmlBlasterJdbc + "'"); log.info("diagnostics: initialize -max. waiting Threads: '" + this.maxWaitingThreads + "'"); log.finest("diagnostics: initialize -tableNamePrefix :" + this.tableNamePrefix); log.finest("diagnostics: initialize -colNamePrefix :" + this.colNamePrefix); ex.printStackTrace(); } else { if (log.isLoggable(Level.FINE)) log.fine(" connecting to DB, error code: '" + ex.getErrorCode() + " : " + ex.getMessage() + "' DB configuration details follow (check if the DB is running)"); } // clean up the connections which might have been established // even if it probably won't help that much ... disconnect(-1L, false); throw ex; } log.info("Connections to DB '" + url + "' successfully established."); } /** * @return the prefix for the name of the tables to associate to the queues */ public String getTableNamePrefix() { return this.tableNamePrefix; } /** * @return the prefix for the name of the columns in each DB table */ public String getColNamePrefix() { return this.colNamePrefix; } /** * @return the number of tables to add each time no free tables are available * when creating a new queue. */ public int getTableAllocationIncrement() { return this.tableAllocationIncrement; } /** This method is used in the init method */ private Hashtable parseMapping(org.xmlBlaster.util.property.Property prop) throws XmlBlasterException, SQLException { if (log.isLoggable(Level.FINER)) log.finer("parseMapping"); if (this.isShutdown) connect(false, false); String mappingKey = null; if (this.configurationIdentifier == null) { Connection conn = null; try { conn = this.getConnection(); mappingKey = conn.getMetaData().getDatabaseProductName(); // replace "Microsoft SQL Server" to "MicrosoftSQLServer" // blanks are not allowed, thanks to zhang zhi wei mappingKey = ReplaceVariable.replaceAll(mappingKey, " ", ""); if (log.isLoggable(Level.FINE)) log.fine("parseMapping: the mapping will be done for the keyword (which is here is the DB product name)'" + mappingKey + "'"); } finally { if (conn != null) releaseConnection(conn); } } else { mappingKey = this.configurationIdentifier; if (log.isLoggable(Level.FINE)) log.fine("parseMapping: the mapping will be done for the keyword (name given in the plugin)'" + mappingKey + "'"); } // String mappingText = prop.get("JdbcDriver." + productName + ".mapping", ""); String mappingText = prop.get("JdbcDriver.mapping[" + mappingKey + "]", ""); if (log.isLoggable(Level.FINE)) log.fine("parseMapping: the string to be mapped is '" + mappingText + "'"); this.mapping = new Hashtable(); // StringTokenizer tokenizer = new StringTokenizer(mappingText, ","); Tokenizer tokenizer = new Tokenizer(mappingText, ',', '"'); XmlBlasterException ex = null; while (tokenizer.hasNext()) { String singleMapping = tokenizer.nextToken(); int pos = singleMapping.indexOf("="); if (pos < 0) ex = new XmlBlasterException(this.glob, ErrorCode.RESOURCE_CONFIGURATION_PLUGINFAILED, ME, "syntax in xmlBlaster.properties for " + singleMapping + " is wrong: no equality sign between key and value");// ex = new XmlBlasterException(ME, "syntax in xmlBlaster.properties for " + singleMapping +// " is wrong: no equality sign between key and value"); String key = singleMapping.substring(0, pos); String value = singleMapping.substring(pos + 1, singleMapping.length()); if (log.isLoggable(Level.FINE)) log.fine("parseMapping: mapping " + key + " to " + value); this.mapping.put(key, value); } if (ex != null) { if (log.isLoggable(Level.FINE)) log.fine("parseMapping: Exception occured: " + ex.getMessage()); throw ex; } return this.mapping; } /** * The mapping is taken out of the xmlBlaster.properties file. It is an * Hashtable where the keys are the logical names used for a type in the * JdbcQueuePlugin and the values are the real names to be used in the database used (which may be vendor specific). */ public Hashtable getMapping() { return this.mapping; } synchronized private final void disconnect(long waitTime, boolean silent) { if (waitTime < 5L) waitTime = 5L; Connection conn = null; for (int i=0; i < this.connections.size(); i++) { try { conn = get(waitTime); if (conn == null) break; conn.close(); if (log.isLoggable(Level.FINE)) log.fine("connection " + conn + " disconnected ( object address: " + conn + ")"); } catch (Throwable ex) { if (silent) { if (log.isLoggable(Level.FINE)) log.fine("could not close connection " + conn + " correctly but resource is set to null. reason " + ex.toString()); } else { log.severe("could not close connection " + conn + " correctly but resource is set to null. reason " + ex.toString()); } ex.printStackTrace(); } } } /** * Closes all connections to the Database. It should not throw any * exception. Exceptions coming from the backend or the communication * layer are catched and logged. When this occurs, the affected connections are set to null. */ synchronized public void disconnect() { if (log.isLoggable(Level.FINER)) log.finer("disconnect invoked"); disconnect(-1L, false); } public void finalize() { shutdown(); } /** * returns true if the connection is temporarly lost (and the pool is polling * for new connections) */ public final int getStatus() { return this.status; } /** * informs this pool that the connection to the DB has been lost */ public final void setConnectionLost() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -