Methods Summary |
---|
private void | assertConnectionWait()INTERNAL
Asserts that MsWait and MsInterval are properly configured
if ( msWait < 0 )
{
throw new JDOUserException(I18NHelper.getMessage(messages,
"connection.connectionmanager.mswaitvalue")); // NOI18N
}
else if ( msInterval < 0 || msInterval > msWait || (msWait > 0 && msInterval == 0) )
{
throw new JDOUserException(I18NHelper.getMessage(messages,
"connection.connectionmanager.msintervalvalue")); // NOI18N
}
|
private void | assertNotConfigured()INTERNAL
Asserts that change to the property is allowed
if ( _configured) {
throw new JDOUnsupportedOptionException(I18NHelper.getMessage(messages,
"persistencemanagerfactoryimpl.configured")); //NOI18N
}
|
private void | closeConnection(java.sql.Connection conn)Close a connection
try
{
if (conn != null) conn.close();
}
catch (Exception e)
{
// Recover?
}
conn = null;
|
public void | configured(boolean flag)INTERNAL
Marks Connectionfactory as fully configured
_configured = flag;
|
public boolean | equals(java.lang.Object obj)Determines whether obj is a ConnectionFactoryImpl with the same configuration
if ((obj != null) && (obj instanceof ConnectionFactoryImpl) ) {
ConnectionFactoryImpl cf = (ConnectionFactoryImpl)obj;
return (cf.URL.equals(this.URL) && cf.userName.equals(this.userName) && cf.driverName.equals(this.driverName) && cf.password.equals(this.password));
}
return false;
|
public java.sql.Connection | getConnection()Returns java.sql.Connection
// Delegate to ConnectionManager
try {
if (connectionManager == null)
initialize();
Connection conn = connectionManager.getConnection();
conn.setTransactionIsolation(_txIsolation);
return conn;
} catch (SQLException e) {
String sqlState = e.getSQLState();
int errorCode = e.getErrorCode();
if (sqlState == null)
{
throw new JDODataStoreException(I18NHelper.getMessage(messages,
"connectionefactoryimpl.sqlexception", "null", "" + errorCode), e); //NOI18N
}
else
{
throw new JDODataStoreException(I18NHelper.getMessage(messages,
"connectionefactoryimpl.sqlexception", sqlState, "" + errorCode), e); //NOI18N
}
} catch (Exception e) {
throw new JDOCanRetryException(I18NHelper.getMessage(messages,
"connectionefactoryimpl.getconnection"), e); //NOI18N
}
|
public java.lang.String | getDriverName()Returns JDBC driver name
return driverName;
//return connectionManager.getDriverName();
|
public java.io.PrintWriter | getLogWriter()Returns the LogWriter to which messages should be sent
return logWriter;
|
public int | getLoginTimeout()Returns the number of seconds to wait for a new connection to be
established to the data source
if (connectionManager == null)
return loginTimeout;
try {
return connectionManager.getLoginTimeout();
} catch (Exception e) {
return 0;
}
|
public int | getMaxPool()Returns maximum number of connections in the connection pool
return maxPool;
// return connectionManager.getMaxPool();
|
public int | getMinPool()Returns minimum number of connections in the connection pool
return minPool;
//return connectionManager.getMinPool();
|
public int | getMsInterval()Returns the amount of time, in milliseconds, between the connection
manager's attempts to get a pooled connection.
if (connectionManager == null)
return msInterval;
return connectionManager.getMsInterval();
|
public int | getMsWait()Returns the number of milliseconds to wait for an available connection
from the connection pool before throwing an exception
if (connectionManager == null)
return msWait;
return connectionManager.getMsWait();
|
public int | getTransactionIsolation()Gets this ConnectionFactory's current transaction isolation level.
if (connectionManager == null)
return _txIsolation;
Connection conn = null;
try {
// Delegate to the Connection
if (_txIsolation == -1)
{
synchronized(this)
{
//Double check that it was not set before
if (_txIsolation == -1)
{
conn = connectionManager.getConnection();
_txIsolation = conn.getTransactionIsolation();
}
}
}
return _txIsolation;
} catch (Exception e) {
throw new JDOFatalException(null, e);
}
finally
{
closeConnection(conn);
}
|
public java.lang.String | getURL()Returns connection URL
return URL;
//return connectionManager.getURL();
|
public java.lang.String | getUserName()Returns database user name
return userName;
//return connectionManager.getUserName();
|
public int | hashCode()Computes the hash code of this ConnectionFactoryImpl.
return URL.hashCode() + userName.hashCode() + password.hashCode() + driverName.hashCode();
|
private synchronized void | initialize()INTERNAL
Attempts to create new connectionManager
Throws JDOFatalException
// If connectionManager was already initialized by another thread
if (connectionManager != null)
return;
try {
// Verify msWait/msInterval values
assertConnectionWait();
// need to use this constructor, as it calls internaly startUp() method
// to initialize extra variables and enable pooling
//java.sql.DriverManager.setLogWriter(logWriter);
connectionManager = new ConnectionManager(
driverName,
URL,
userName,
password,
minPool,
maxPool
);
// MsWait MUST be set BEFORE MsInterval
connectionManager.setMsWait(this.msWait);
connectionManager.setMsInterval(this.msInterval);
connectionManager.setLoginTimeout(this.loginTimeout);
if (_txIsolation > 0)
setTransactionIsolation(_txIsolation);
else
_txIsolation = getTransactionIsolation();
// finished all configuration
this.configured(true);
} catch (JDOException e) {
throw e;
} catch (Exception e) {
throw new JDOFatalException(null, e);
}
|
public void | setDriverName(java.lang.String driverName)Sets JDBC driver name
// REMOVE WHEN SUPPORTED:
//unsupported();
assertNotConfigured();
// Delegate to ConnectionManager: this.driverName = driverName;
if(connectionManager == null)
{
this.driverName = driverName;
}
else
{
try {
connectionManager.setDriverName(driverName);
} catch (Exception e) {
throw new JDOFatalException(null, e);
}
}
|
public void | setLogWriter(java.io.PrintWriter logWriter)Sets the LogWriter to which messages should be sent
assertNotConfigured();
this.logWriter = logWriter; //RESOLVE
|
public void | setLoginTimeout(int loginTimeout)Sets the number of seconds to wait for a new connection to be
established to the data source
assertNotConfigured();
if(connectionManager == null) {
// Nothing to do yet
this.loginTimeout = loginTimeout;
return;
}
// Delegate to ConnectionManager: this.loginTimeout = loginTimeout;
try {
connectionManager.setLoginTimeout(loginTimeout);
} catch (Exception e) {
throw new JDOFatalException(null, e);
}
|
public void | setMaxPool(int maxPool)Sets maximum number of connections in the connection pool
assertNotConfigured();
if(connectionManager == null) {
// Nothing to do yet
this.maxPool = maxPool;
return;
}
// Delegate to ConnectionManager: this.maxPool = maxPool;
try {
connectionManager.setMaxPool(maxPool);
} catch (Exception e) {
throw new JDOFatalException(null, e);
}
|
public void | setMinPool(int minPool)Sets minimum number of connections in the connection pool
assertNotConfigured();
if(connectionManager == null) {
// Nothing to do yet
this.minPool = minPool;
return;
}
// Delegate to ConnectionManager: this.minPool = minPool;
try {
connectionManager.setMinPool(minPool);
} catch (Exception e) {
throw new JDOFatalException(null, e);
}
|
public void | setMsInterval(int msInterval)Sets the amount of time, in milliseconds, between the connection
manager's attempts to get a pooled connection.
assertNotConfigured();
if(connectionManager == null) {
// Nothing to do yet
this.msInterval = msInterval;
return;
}
// Delegate to ConnectionManager: this.msInterval = msInterval;
try {
connectionManager.setMsInterval(msInterval);
} catch (Exception e) {
throw new JDOFatalException(null, e);
}
|
public void | setMsWait(int msWait)Sets the number of milliseconds to wait for an available connection
from the connection pool before throwing an exception
assertNotConfigured();
if(connectionManager == null) {
// Nothing to do yet
this.msWait = msWait;
return;
}
// Delegate to ConnectionManager: this.msWait = msWait;
try {
connectionManager.setMsWait(msWait);
} catch (Exception e) {
throw new JDOFatalException(null, e);
}
|
public void | setPassword(java.lang.String password)Sets database user password
// REMOVE WHEN SUPPORTED:
//unsupported();
assertNotConfigured();
// Delegate to ConnectionManager: this.password = password;
if(connectionManager == null)
{
this.password = password;
}
else
{
try {
connectionManager.setPassword(password);
} catch (Exception e) {
throw new JDOFatalException(null, e);
}
}
|
public void | setTransactionIsolation(int level)Sets transaction isolation level for all connections of this ConnectionFactory.
All validation is done by java.sql.Connection itself, so e.g. while Oracle
will not allow to set solation level to TRANSACTION_REPEATABLE_READ, this method
does not have any explicit restrictions
assertNotConfigured();
if(connectionManager == null) {
// Nothing to do yet
_txIsolation = level;
return;
}
// verify that database supports it
Connection conn = null;
try {
conn = connectionManager.getConnection();
DatabaseMetaData dbMetaData = conn.getMetaData();
if(dbMetaData.supportsTransactionIsolationLevel(level))
{
_txIsolation = level;
}
else
{
throw new JDOFatalException(I18NHelper.getMessage(messages,
"connectionefactoryimpl.isolationlevel_notsupported", //NOI18N
level));
}
} catch (Exception e) {
throw new JDOFatalException(null, e);
}
finally
{
closeConnection(conn);
}
|
public void | setURL(java.lang.String URL)Sets JDBC connection URL
// REMOVE WHEN SUPPORTED:
//unsupported();
assertNotConfigured();
// Delegate to ConnectionManager: this.URL = URL;
if(connectionManager == null)
{
this.URL = URL;
}
else
{
try {
connectionManager.setURL(URL);
} catch (Exception e) {
throw new JDOFatalException(null, e);
}
}
|
public void | setUserName(java.lang.String userName)Sets database user
// REMOVE WHEN SUPPORTED:
//unsupported();
assertNotConfigured();
// Delegate to ConnectionManager: this.userName = userName;
if(connectionManager == null)
{
this.userName = userName;
}
else
{
try {
connectionManager.setUserName(userName);
} catch (Exception e) {
throw new JDOFatalException(null, e);
}
}
|
private void | unsupported()INTERNAL
Throws JDOUnsupportedOptionException
throw new JDOUnsupportedOptionException(I18NHelper.getMessage(messages,
"persistencemanagerfactoryimpl.notsupported")); //NOI18N
|