| Method from org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory Detail: |
public Object createConnectionFactory(ConnectionManager cm) throws ResourceException {
// check some invariants before they come back to haunt us
if(driverClass == null)
throw new JBossResourceException("driverClass is null");
if(connectionURL == null)
throw new JBossResourceException("connectionURL is null");
return super.createConnectionFactory(cm);
}
|
public ManagedConnection createManagedConnection(Subject subject,
ConnectionRequestInfo cri) throws ResourceException {
Properties props = getConnectionProperties(subject, cri);
// Some friendly drivers (Oracle, you guessed right) modify the props you supply.
// Since we use our copy to identify compatibility in matchManagedConnection, we need
// a pristine copy for our own use. So give the friendly driver a copy.
Properties copy = (Properties) props.clone();
boolean trace = log.isTraceEnabled();
if (trace)
{
// Make yet another copy to mask the password
Properties logCopy = copy;
if (copy.getProperty("password") != null)
{
logCopy = (Properties) props.clone();
logCopy.setProperty("password", "--hidden--");
}
log.trace("Using properties: " + logCopy);
}
if(urlSelector!=null)
{
return getHALocalManagedConnection(props,copy);
}
else
{
return getLocalManagedConnection(props,copy);
}
}
|
public boolean equals(Object other) {
if (this == other)
return true;
if (getClass() != other.getClass())
return false;
LocalManagedConnectionFactory otherMcf = (LocalManagedConnectionFactory) other;
return this.connectionURL.equals(otherMcf.connectionURL) && this.driverClass.equals(otherMcf.driverClass)
&& ((this.userName == null) ? otherMcf.userName == null : this.userName.equals(otherMcf.userName))
&& ((this.password == null) ? otherMcf.password == null : this.password.equals(otherMcf.password))
&& this.transactionIsolation == otherMcf.transactionIsolation;
}
|
public String getConnectionProperties() {
return connectionProperties;
}
Get the value of connectionProperties. |
public String getConnectionURL() {
return connectionURL;
}
Get the value of ConnectionURL. |
protected synchronized Driver getDriver(String url) throws ResourceException {
boolean trace = log.isTraceEnabled();
// don't bother if it is loaded already
if (driver != null)
{
return driver;
}
if (trace)
log.trace("Checking driver for URL: " + url);
if (driverClass == null)
{
throw new JBossResourceException("No Driver class specified (url = " + url + ")!");
}
// Check if the driver is already loaded, if not then try to load it
if (isDriverLoadedForURL(url))
{
return driver;
} // end of if ()
try
{
//try to load the class... this should register with DriverManager.
Class clazz = Class.forName(driverClass, true, Thread.currentThread().getContextClassLoader());
if (isDriverLoadedForURL(url))
//return immediately, some drivers (Cloudscape) do not let you create an instance.
return driver;
//We loaded the class, but either it didn't register
//and is not spec compliant, or is the wrong class.
driver = (Driver) clazz.newInstance();
DriverManager.registerDriver(driver);
if (isDriverLoadedForURL(url))
return driver;
//We can even instantiate one, it must be the wrong class for the URL.
}
catch (Exception e)
{
throw new JBossResourceException("Failed to register driver for: " + driverClass, e);
}
throw new JBossResourceException("Apparently wrong driver class specified for URL: class: " + driverClass
+ ", url: " + url);
}
Check the driver for the given URL. If it is not registered already
then register it. |
public String getDriverClass() {
return driverClass;
}
Get the DriverClass value. |
public int hashCode() {
int result = 17;
result = result * 37 + ((connectionURL == null) ? 0 : connectionURL.hashCode());
result = result * 37 + ((driverClass == null) ? 0 : driverClass.hashCode());
result = result * 37 + ((userName == null) ? 0 : userName.hashCode());
result = result * 37 + ((password == null) ? 0 : password.hashCode());
result = result * 37 + transactionIsolation;
return result;
}
|
protected void initUrlSelector() {
boolean trace = log.isTraceEnabled();
List urlsList = new ArrayList();
String urlsStr = getConnectionURL();
String url;
int urlStart = 0;
int urlEnd = urlsStr.indexOf(urlDelimiter);
while(urlEnd > 0)
{
url = urlsStr.substring(urlStart, urlEnd);
urlsList.add(url);
urlStart = ++urlEnd;
urlEnd = urlsStr.indexOf(urlDelimiter, urlEnd);
if (trace)
log.trace("added HA connection url: " + url);
}
if(urlStart != urlsStr.length())
{
url = urlsStr.substring(urlStart, urlsStr.length());
urlsList.add(url);
if (trace)
log.trace("added HA connection url: " + url);
}
if(getUrlSelectorStrategyClassName()==null)
{
this.urlSelector = new URLSelector(urlsList);
log.debug("Default URLSelectorStrategy is being used : "+urlSelector);
}
else
{
this.urlSelector = (URLSelectorStrategy)loadClass(getUrlSelectorStrategyClassName(),urlsList);
log.debug("Customized URLSelectorStrategy is being used : "+urlSelector);
}
}
|
protected String internalGetConnectionURL() {
return connectionURL;
}
|
public ManagedConnection matchManagedConnections(Set mcs,
Subject subject,
ConnectionRequestInfo cri) throws ResourceException {
Properties newProps = getConnectionProperties(subject, cri);
for (Iterator i = mcs.iterator(); i.hasNext();)
{
Object o = i.next();
if (o instanceof LocalManagedConnection)
{
LocalManagedConnection mc = (LocalManagedConnection) o;
//First check the properties
if (mc.getProperties().equals(newProps))
{
//Next check to see if we are validating on matchManagedConnections
if ((getValidateOnMatch() && mc.checkValid()) || !getValidateOnMatch())
{
return mc;
}
}
}
}
return null;
}
|
public void setConnectionProperties(String connectionProperties) {
this.connectionProperties = connectionProperties;
connectionProps.clear();
if (connectionProperties != null)
{
// Map any \ to \\
connectionProperties = connectionProperties.replaceAll("\\\\", "\\\\\\\\");
InputStream is = new ByteArrayInputStream(connectionProperties.getBytes());
try
{
connectionProps.load(is);
}
catch (IOException ioe)
{
throw new NestedRuntimeException("Could not load connection properties", ioe);
}
}
}
Set the value of connectionProperties. |
public void setConnectionURL(String connectionURL) {
this.connectionURL = connectionURL;
if(urlDelimiter!=null)
{
initUrlSelector();
}
}
Set the value of ConnectionURL. |
public synchronized void setDriverClass(String driverClass) {
this.driverClass = driverClass;
driver = null;
}
Set the DriverClass value. |
public void setURLDelimiter(String urlDelimiter) {
super.urlDelimiter = urlDelimiter;
if(getConnectionURL() != null)
{
initUrlSelector();
}
}
|