DMManagedConnectionFactorypublic class DMManagedConnectionFactory extends ManagedConnectionFactory Driver Manager ManagedConnectionFactory implementation for Generic JDBC Connector. |
Fields Summary |
---|
Properties | props | private static Logger | _logger | private boolean | debug |
Methods Summary |
---|
public javax.resource.spi.ManagedConnection | createManagedConnection(javax.security.auth.Subject subject, javax.resource.spi.ConnectionRequestInfo cxRequestInfo)Creates a new physical connection to the underlying EIS resource
manager.
if (logWriter != null) {
logWriter.println("In createManagedConnection");
}
PasswordCredential pc = SecurityUtils.getPasswordCredential(this, subject, cxRequestInfo);
try {
Thread.currentThread().getContextClassLoader().loadClass(spec.getDetail(DataSourceSpec.CLASSNAME));
} catch (ClassNotFoundException cnfe) {
_logger.log(Level.SEVERE, "jdbc.exc_cnfe",cnfe);
throw new ResourceException("The driver could not be loaded: " + spec.getDetail(DataSourceSpec.CLASSNAME) );
}
java.sql.Connection dsConn = null;
Properties driverProps = getPropertiesObj();
try {
if (cxRequestInfo != null) {
driverProps.setProperty("user", pc.getUserName());
driverProps.setProperty("password", new String(pc.getPassword()));
}
dsConn = DriverManager.getConnection(spec.getDetail(DataSourceSpec.URL), driverProps);
} catch (java.sql.SQLException sqle) {
_logger.log(Level.SEVERE, "jdbc.exc_create_mc", sqle);
throw new javax.resource.spi.ResourceAllocationException("The connection could not be allocated: " +
sqle.getMessage());
}
com.sun.gjc.spi.ManagedConnection mc = constructManagedConnection(
null, dsConn, pc, this);
//GJCINT
setIsolation(mc);
isValid(mc);
return mc;
| public boolean | equals(java.lang.Object other)Check if this ManagedConnectionFactory is equal to
another ManagedConnectionFactory .
if (logWriter != null) {
logWriter.println("In equals");
}
/**
* The check below means that two ManagedConnectionFactory objects are equal
* if and only if their properties are the same.
*/
if (other instanceof com.sun.gjc.spi.DMManagedConnectionFactory) {
com.sun.gjc.spi.DMManagedConnectionFactory otherMCF =
(com.sun.gjc.spi.DMManagedConnectionFactory) other;
return this.spec.equals(otherMCF.spec);
}
return false;
| public java.lang.String | getConnectionURL()Gets the connection url.
return spec.getDetail(DataSourceSpec.URL);
| public java.lang.Object | getDataSource()
return null;
| private java.util.Properties | getPropertiesObj()This method checks if the properties object is null or not.
If the properties object is null, it creates a new Properties
object and inserts the default "user" and "password" key value
pairs. It checks if any other properties have been set or not
and includes the key value pairs for those properties.
if (props != null) {
return props;
}
props = new Properties();
props.setProperty("user", getUser());
props.setProperty("password", getPassword());
String driverProps = spec.getDetail(DataSourceSpec.DRIVERPROPERTIES);
String delimiter = spec.getDetail(DataSourceSpec.DELIMITER);
if (driverProps != null && driverProps.trim().equals("") == false) {
if (delimiter == null || delimiter.equals("")) {
throw new ResourceException("Invalid driver properties string - " +
"delimiter not properly set!!");
}
StringTokenizer st = new StringTokenizer(driverProps, delimiter);
while (st.hasMoreTokens()) {
String keyValuePair = null;
try {
keyValuePair = st.nextToken();
} catch (NoSuchElementException nsee) {
throw new ResourceException("Invalid driver properties string - " +
"Key value pair not available: " + nsee.getMessage());
}
int indexOfEqualsSign = -1;
try {
indexOfEqualsSign = keyValuePair.indexOf("=");
if (indexOfEqualsSign == -1) {
throw new ResourceException("Invalid driver properties string - " +
"Key value pair should be of the form key = value");
}
} catch (NullPointerException npe) {
if (debug) {
_logger.log(Level.FINE, "jdbc.exc_caught_ign", npe.getMessage());
}
}
String key = null;
try {
key = keyValuePair.substring(0, indexOfEqualsSign).trim();
} catch (IndexOutOfBoundsException iobe) {
if (debug) {
_logger.log(Level.FINE, "jdbc.exc_caught_ign", iobe.getMessage());
}
}
if (key.equals("")) {
throw new ResourceException("Invalid driver properties string - " +
"Key cannot be an empty string");
}
String value = null;
try {
value = keyValuePair.substring(indexOfEqualsSign + 1).trim();
} catch (IndexOutOfBoundsException iobe) {
if (debug) {
_logger.log(Level.FINE, "jdbc.exc_caught_ign", iobe.getMessage());
}
}
props.setProperty(key, value);
}
}
return props;
| public void | setConnectionURL(java.lang.String url)Sets the connection url.
spec.setDetail(DataSourceSpec.URL, url);
| public void | setLoginTimeOut(java.lang.String loginTimeOut)Sets the login timeout.
int timeOut = 0;
try {
timeOut = Integer.valueOf(loginTimeOut);
DriverManager.setLoginTimeout(timeOut);
spec.setDetail(DataSourceSpec.LOGINTIMEOUT, loginTimeOut);
} catch (Exception e) {
if (debug) {
_logger.log(Level.FINE, "jdbc.exc_caught_ign", e.getMessage());
}
}
|
|