@SuppressWarnings("unchecked")
protected void setupStore(String jdbcAccessClassName, String tableName)
throws Exception
{
if (jdbcAccessClassName == null || jdbcAccessClassName.length() == 0)
throw new ObjectStoreException();
final JDBCAccess jdbcAccess;
synchronized (_theAccesses)
{
final Object jdbcAccessObject = _theAccesses
.get(jdbcAccessClassName);
if (jdbcAccessObject != null)
{
jdbcAccess = (JDBCAccess) jdbcAccessObject;
}
else
{
try
{
final Class jdbcAccessClass = Thread.currentThread()
.getContextClassLoader().loadClass(
jdbcAccessClassName);
jdbcAccess = (JDBCAccess) jdbcAccessClass.newInstance();
}
catch (final Exception ex)
{
if (tsLogger.arjLoggerI18N.isFatalEnabled())
{
tsLogger.arjLoggerI18N
.fatal(
"com.arjuna.ats.internal.arjuna.objectstore.JDBCStore_2",
new Object[]
{ ex, jdbcAccessClassName });
}
throw ex;
}
_theAccesses.put(jdbcAccessClassName, jdbcAccess);
}
}
setJDBCAccess(jdbcAccess);
final String impleTableName;
if ((tableName != null) && (tableName.length() > 0))
{
impleTableName = tableName;
}
else
{
final String jdbcAccessTableName = jdbcAccess.tableName();
if ((jdbcAccessTableName != null)
&& (jdbcAccessTableName.length() > 0))
{
impleTableName = jdbcAccessTableName;
}
else
{
impleTableName = getDefaultTableName();
}
}
setTableName(impleTableName);
final String impleKey = jdbcAccessClassName + ":" + impleTableName;
synchronized (_theImples)
{
final Object currentImple = _theImples.get(impleKey);
if (currentImple != null)
{
_theImple = (JDBCImple) currentImple;
}
else
{
try
{
/*
* This had better not be an Arjuna jdbc connection!
*/
final Connection connection;
try
{
connection = jdbcAccess.getConnection();
}
catch (final SQLException sqle)
{
if (tsLogger.arjLoggerI18N.isFatalEnabled())
{
tsLogger.arjLoggerI18N
.fatal(
"com.arjuna.ats.internal.arjuna.objectstore.JDBCStore_2",
new Object[]
{ sqle, "getConnection()" });
}
throw sqle;
}
if (connection == null)
{
if (tsLogger.arjLoggerI18N.isFatalEnabled())
{
tsLogger.arjLoggerI18N
.fatal(
"com.arjuna.ats.internal.arjuna.objectstore.JDBCStore_1",
new Object[]
{ getJDBCAccess(), getTableName() });
}
throw new SQLException("getConnection returned null");
}
boolean success = false;
try
{
connection.setAutoCommit(true);
final JDBCImple jdbcImple;
try
{
final Class jdbcImpleClass = getJDBCClass(connection);
jdbcImple = (JDBCImple) jdbcImpleClass
.newInstance();
jdbcImple.setShareStatus(shareStatus);
}
catch (final Exception ex)
{
if (tsLogger.arjLoggerI18N.isFatalEnabled())
{
tsLogger.arjLoggerI18N
.fatal(
"com.arjuna.ats.internal.arjuna.objectstore.JDBCStore_2",
new Object[]
{ ex, getJDBCAccess() });
}
throw ex;
}
if (!jdbcImple.initialise(connection, jdbcAccess,
impleTableName))
{
if (tsLogger.arjLoggerI18N.isWarnEnabled())
tsLogger.arjLoggerI18N
.warn("com.arjuna.ats.internal.arjuna.objectstore.JDBCStore_3");
throw new ObjectStoreException();
}
else
{
_theImples.put(impleKey, jdbcImple);
_theImple = jdbcImple;