📄 torqueclassicdatasource.java
字号:
* internal purpose. * * @return value of description. */ public String getDescription() { return description; } /** * Set the description. This property is defined by jdbc as for use with * GUI (or other) tools that might deploy the datasource. It serves no * internal purpose. * * @param v Value to assign to description. */ public void setDescription(String v) { this.description = v; } /** * Get the value of jndiEnvironment which is used when instantiating * a jndi InitialContext. This InitialContext is used to locate the * backend ConnectionPoolDataSource. * * @param key environment key * @return value of jndiEnvironment. */ public String getJndiEnvironment(String key) { String value = null; if (jndiEnvironment != null) { value = jndiEnvironment.getProperty(key); } return value; } /** * Set the value of jndiEnvironment which is used when instantiating * a jndi InitialContext. This InitialContext is used to locate the * backend ConnectionPoolDataSource. * * @param key environment key * @param value Value to assign to jndiEnvironment. */ public void setJndiEnvironment(String key, String value) { if (jndiEnvironment == null) { jndiEnvironment = new Properties(); } jndiEnvironment.setProperty(key, value); } /** * Get the value of connectionPoolDataSource. This method will return * null, if the backing datasource is being accessed via jndi. * * @return value of connectionPoolDataSource. */ public ConnectionPoolDataSource getConnectionPoolDataSource() { return cpds; } /** * Set the backend ConnectionPoolDataSource. This property should not be * set if using jndi to access the datasource. * * @param v Value to assign to connectionPoolDataSource. */ public void setConnectionPoolDataSource(ConnectionPoolDataSource v) { if (v == null) { throw new IllegalArgumentException( "Null argument value is not allowed."); } if (getDataSourceName() != null) { throw new IllegalStateException("dataSourceName property" + " already has a value. Both dataSourceName and " + "connectionPoolDataSource properties cannot be set."); } this.cpds = v; // set the dataSourceName to a unique value dataSourceName = v.hashCode() + " internal cpds name " + cpdsCounter++; } /** * Attempt to establish a database connection. * * @return A database connection. * @throws SQLException */ public Connection getConnection() throws SQLException { return getConnection(null, null); } /** * Attempt to establish a database connection. * * @param username The name of the database user. * @param password The password of the database user. * @return A database connection. * @throws SQLException */ public synchronized Connection getConnection(String username, String password) throws SQLException { String key = getKey(username); ConnectionPool pool = (ConnectionPool) pools.get(key); if (pool == null) { try { registerPool(username, password); pool = (ConnectionPool) pools.get(key); } catch (Exception e) { throw new SQLException(e.getMessage()); } } Connection con = pool.getConnection(username, password).getConnection(); con.setAutoCommit(defaultAutoCommit); con.setReadOnly(defaultReadOnly); return con; } /** * * @param suffix * @return */ private String getKey(String suffix) { String key = getDataSourceName(); if (key == null) { throw new IllegalStateException("Attempted to use DataSource " + "without a backend ConnectionPoolDataSource defined."); } if (suffix != null) { key += suffix; } return key; } /** * * @param username The name of the database user. * @param password The password of the database user. * @throws javax.naming.NamingException */ synchronized private void registerPool(String username, String password) throws javax.naming.NamingException { String key = getKey(username); if (!pools.containsKey(key)) { ConnectionPoolDataSource cpds = this.cpds; if (cpds == null) { Context ctx = null; if (jndiEnvironment == null) { ctx = new InitialContext(); } else { ctx = new InitialContext(jndiEnvironment); } cpds = (ConnectionPoolDataSource) ctx.lookup(dataSourceName); } int maxConnections = getDefaultMaxConnections(); if (username != null) { String userMaxCon = (String) getPerUserMaxConnections().get(username); if (userMaxCon != null) { maxConnections = Integer.parseInt(userMaxCon); } } ConnectionPool pool = new ConnectionPool(cpds, username, password, maxConnections, getMaxExpiryTime(), getConnectionWaitTimeout(), getLogInterval()); // avoid ConcurrentModificationException Map newPools = new HashMap(pools); newPools.put(key, pool); pools = newPools; } } /** * Gets the maximum time in seconds that this data source can wait * while attempting to connect to a database. * * @return the login timeout */ public int getLoginTimeout() { return loginTimeout; } /** * Get the log writer for this data source. * * @return the log writer * @deprecated Use correct debugging and logging code from Log4j */ public PrintWriter getLogWriter() { if (logWriter == null) { logWriter = new PrintWriter(System.out); } return logWriter; } /** * Sets the maximum time in seconds that this data source will wait * while attempting to connect to a database. NOT USED. * * @param seconds the login timeout */ public void setLoginTimeout(int seconds) { loginTimeout = seconds; } /** * Set the log writer for this data source. * * @param out the log writer to use * @deprecated Use correct debugging and logging code from Log4j */ public void setLogWriter(java.io.PrintWriter out) { logWriter = out; } /** * <CODE>Referenceable</CODE> implementation. * * @return a reference * @throws NamingException */ public Reference getReference() throws NamingException { String factory = getClass().getName(); Reference ref = new Reference(getClass().getName(), factory, null); ref.add(new StringRefAddr("defaultMaxConnections", String.valueOf(getDefaultMaxConnections()))); ref.add(new StringRefAddr("maxExpiryTime", String.valueOf(getMaxExpiryTime()))); ref.add(new StringRefAddr("connectionWaitTimeout", String.valueOf(getConnectionWaitTimeout()))); ref.add(new StringRefAddr("logInterval", String.valueOf(getLogInterval()))); ref.add(new StringRefAddr("dataSourceName", getDataSourceName())); ref.add(new StringRefAddr("description", getDescription())); byte[] serJndiEnv = null; // BinaryRefAddr does not allow null byte[]. if (jndiEnvironment != null) { serJndiEnv = SerializationUtils.serialize(jndiEnvironment); ref.add(new BinaryRefAddr("jndiEnvironment", serJndiEnv)); } byte[] serPUMC = null; // BinaryRefAddr does not allow null byte[]. if (getPerUserMaxConnections() != null) { serPUMC = SerializationUtils.serialize(getPerUserMaxConnections()); ref.add(new BinaryRefAddr("perUserMaxConnections", serPUMC)); } return ref; } /** * implements ObjectFactory to create an instance of this class * * @param refObj * @param name * @param context * @param env * @return an instance of this class * @throws Exception */ public Object getObjectInstance(Object refObj, Name name, Context context, Hashtable env) throws Exception { Reference ref = (Reference) refObj; if (ref.getClassName().equals(getClass().getName())) { setDefaultMaxConnections(Integer.parseInt( (String) ref.get("defaultMaxConnections").getContent())); setMaxExpiryTime(Integer.parseInt( (String) ref.get("maxExpiryTime").getContent())); setConnectionWaitTimeout(Integer.parseInt( (String) ref.get("connectionWaitTimeout").getContent())); setLogInterval(Integer.parseInt( (String) ref.get("logInterval").getContent())); setDataSourceName((String) ref.get("dataSourceName").getContent()); setDescription((String) ref.get("description").getContent()); RefAddr refAddr = ref.get("jndiEnvironment"); if (refAddr != null) { byte[] serialized = (byte[]) refAddr.getContent(); jndiEnvironment = (Properties) SerializationUtils.deserialize(serialized); } refAddr = ref.get("perUserMaxConnections"); if (refAddr != null) { byte[] serialized = (byte[]) refAddr.getContent(); setPerUserMaxConnections( (Properties) SerializationUtils.deserialize(serialized)); } return this; } else { // We can't create an instance of the reference return null; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -