[jboss-svn-commits] JBL Code SVN: r35092 - labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/objectstore.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Sep 9 10:29:41 EDT 2010
Author: jhalliday
Date: 2010-09-09 10:29:41 -0400 (Thu, 09 Sep 2010)
New Revision: 35092
Removed:
labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/objectstore/JDBCActionStore.java
labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/objectstore/JDBCImple.java
labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/objectstore/JDBCStore.java
Log:
Move JDBC store files to new dir. JBTM-788
Deleted: labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/objectstore/JDBCActionStore.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/objectstore/JDBCActionStore.java 2010-09-09 14:28:08 UTC (rev 35091)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/objectstore/JDBCActionStore.java 2010-09-09 14:29:41 UTC (rev 35092)
@@ -1,195 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * (C) 2005-2006,
- * @author JBoss Inc.
- */
-/*
- * Copyright (C) 2000, 2001,
- *
- * Arjuna Solutions Limited,
- * Newcastle upon Tyne,
- * Tyne and Wear,
- * UK.
- *
- * $Id: JDBCActionStore.java 2342 2006-03-30 13:06:17Z $
- */
-
-package com.arjuna.ats.internal.arjuna.objectstore;
-
-import com.arjuna.ats.arjuna.state.*;
-
-import com.arjuna.ats.arjuna.logging.tsLogger;
-
-import com.arjuna.ats.arjuna.objectstore.StateStatus;
-import com.arjuna.ats.arjuna.objectstore.jdbc.JDBCAccess;
-import com.arjuna.ats.arjuna.common.*;
-
-import com.arjuna.ats.arjuna.exceptions.ObjectStoreException;
-
-/**
- * The transaction log implementation.
-*/
-
-public class JDBCActionStore extends JDBCStore
-{
- /**
- * The following operation commits a previous write_state operation which
- * was made with the SHADOW StateType argument. This is achieved by
- * renaming the shadow and removing the hidden version.
- */
-
- public synchronized boolean commit_state (Uid objUid,
- String tName) throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("JDBCActionStore.commit_state(" + objUid + ", " + tName + ")");
- }
-
- boolean result = false;
-
- /* Bail out if the object store is not set up */
-
- if (!storeValid())
- return false;
-
- if (currentState(objUid, tName) == StateStatus.OS_COMMITTED)
- result = true;
-
- return result;
- }
-
- public boolean hide_state (Uid u, String tn) throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("JDBCActionStore.hide_state(" + u + ", " + tn + ")");
- }
-
- return false;
- }
-
- public boolean reveal_state (Uid u, String tn) throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("JDBCActionStore.reveal_state(" + u + ", " + tn + ")");
- }
-
- return false;
- }
-
- public InputObjectState read_committed (Uid storeUid, String tName) throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("JDBCActionStore.read_committed(" + storeUid + ", " + tName + ")");
- }
-
- return super.read_committed(storeUid, tName);
- }
-
- public InputObjectState read_uncommitted (Uid u, String tn) throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("JDBCActionStore.read_uncommitted(" + u + ", " + tn + ")");
- }
-
- return null;
- }
-
- public boolean remove_committed (Uid storeUid, String tName) throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("JDBCActionStore.remove_committed(" + storeUid + ", " + tName + ")");
- }
-
- return super.remove_committed(storeUid, tName);
- }
-
- public boolean remove_uncommitted (Uid u, String tn) throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("JDBCActionStore.remove_uncommitted(" + u + ", " + tn + ")");
- }
-
- return false;
- }
-
- public boolean write_committed (Uid storeUid, String tName, OutputObjectState state) throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("JDBCActionStore.write_committed(" + storeUid + ", " + tName + ")");
- }
-
- return super.write_committed(storeUid, tName, state);
- }
-
- public boolean write_uncommitted (Uid u, String tn, OutputObjectState s) throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("JDBCActionStore.write_uncommitted(" + u + ", " + tn + ", " + s + ")");
- }
-
- return false;
- }
-
- public JDBCActionStore(ObjectStoreEnvironmentBean objectStoreEnvironmentBean) throws ObjectStoreException
- {
- super(objectStoreEnvironmentBean);
- }
-
- protected String getAccessClassName()
- {
- if (_txClassName == null)
- _txClassName = arjPropertyManager.getObjectStoreEnvironmentBean().getJdbcTxDbAccess();
- return _txClassName;
- }
-
- protected void setAccessClassName(String txClassName)
- {
- _txClassName = txClassName;
- }
-
- protected String getDefaultTableName()
- {
- return _defaultTxTableName;
- }
-
- protected JDBCAccess getJDBCAccess()
- {
- return _txJDBCAccess;
- }
-
- protected void setJDBCAccess(JDBCAccess jdbcAccess)
- {
- _txJDBCAccess = jdbcAccess ;
- }
-
- protected String getTableName()
- {
- return _txTableName;
- }
-
- protected void setTableName(String tableName)
- {
- _txTableName = tableName ;
- }
-
- private JDBCAccess _txJDBCAccess;
- private String _txClassName;
- private String _txTableName;
- private static String _defaultTxTableName = "JBossTSTxTable";
-
-}
Deleted: labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/objectstore/JDBCImple.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/objectstore/JDBCImple.java 2010-09-09 14:28:08 UTC (rev 35091)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/objectstore/JDBCImple.java 2010-09-09 14:29:41 UTC (rev 35092)
@@ -1,1275 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * (C) 2005-2006,
- * @author JBoss Inc.
- */
-/*
- * Copyright (C) 2000, 2001,
- *
- * Arjuna Solutions Limited,
- * Newcastle upon Tyne,
- * Tyne and Wear,
- * UK.
- *
- * $Id: JDBCImple.java 2342 2006-03-30 13:06:17Z $
- */
-
-package com.arjuna.ats.internal.arjuna.objectstore;
-
-import com.arjuna.ats.arjuna.state.*;
-import com.arjuna.ats.arjuna.logging.tsLogger;
-import com.arjuna.ats.arjuna.objectstore.StateStatus;
-import com.arjuna.ats.arjuna.objectstore.StateType;
-import com.arjuna.ats.arjuna.common.*;
-
-import com.arjuna.ats.arjuna.objectstore.jdbc.JDBCAccess;
-
-import java.sql.*;
-import java.util.Hashtable;
-
-import com.arjuna.ats.arjuna.exceptions.ObjectStoreException;
-import com.arjuna.ats.internal.arjuna.common.UidHelper;
-
-import java.io.IOException;
-
-/**
- * An object store implementation which uses a JDBC database for maintaining
- * object states. All states are maintained within a single table.
- */
-
-public abstract class JDBCImple
-{
-
- public final boolean storeValid()
- {
- return _isValid;
- }
-
- public boolean commit_state(Uid objUid, String typeName, String tableName)
- throws ObjectStoreException
- {
- boolean result = false;
- boolean cleanup = true;
-
- /* Bail out if the object store is not set up */
-
- if (!storeValid())
- return false;
-
- if (typeName != null)
- {
- int currState = currentState(objUid, typeName, tableName);
- int pool = getPool();
-
- try
- {
- // remove the old committed state, if any:
- PreparedStatement pstmt = _preparedStatements[pool][PRECOMMIT_CLEANUP];
- if (pstmt == null)
- {
- pstmt = _theConnection[pool]
- .prepareStatement("DELETE FROM "
- + tableName
- + " WHERE UidString = ? AND TypeName = ? AND StateType = "
- + StateStatus.OS_COMMITTED);
- _preparedStatements[pool][PRECOMMIT_CLEANUP] = pstmt;
- }
- pstmt.setString(1, objUid.stringForm());
- pstmt.setString(2, typeName);
- pstmt.executeUpdate();
- // done cleanup
-
- // now do the commit itself:
- pstmt = _preparedStatements[pool][COMMIT_STATE];
- if (pstmt == null)
- {
- pstmt = _theConnection[pool]
- .prepareStatement("UPDATE "
- + tableName
- + " SET StateType = ? WHERE UidString = ? AND TypeName = ? AND StateType = ?");
- _preparedStatements[pool][COMMIT_STATE] = pstmt;
- }
-
- if (currState == StateStatus.OS_UNCOMMITTED)
- {
- pstmt.setInt(1, StateStatus.OS_COMMITTED);
- }
- else if (currState == StateStatus.OS_UNCOMMITTED_HIDDEN)
- {
- pstmt.setInt(1, StateStatus.OS_COMMITTED_HIDDEN);
- }
- else
- {
- throw new ObjectStoreException("can't commit object "
- + objUid + " in state " + currState);
- }
-
- pstmt.setString(2, objUid.stringForm());
- pstmt.setString(3, typeName);
- pstmt.setInt(4, currState);
-
- int rowcount = pstmt.executeUpdate();
-
- if (rowcount > 0)
- {
- result = true;
- }
- }
- catch (Throwable e)
- {
- e.printStackTrace();
-
- if (true)
- return false;
-
- cleanup = false;
- if (retryConnection(e, pool))
- {
- return commit_state(objUid, typeName, tableName);
- }
- else
- {
- throw new ObjectStoreException(e.toString(), e);
- }
- }
- finally
- {
- if (cleanup)
- freePool(pool);
- }
- }
- else
- throw new ObjectStoreException("commit_state - object with uid "
- + objUid + " has no TypeName");
-
- return result;
- }
-
- public boolean hide_state(Uid objUid, String typeName, String tableName)
- throws ObjectStoreException
- {
- boolean hiddenOk = true;
- boolean cleanup = true;
-
- /* Bail out if the object store is not set up */
-
- if (storeValid())
- {
- int state = currentState(objUid, typeName, tableName);
- int pool = getPool();
- PreparedStatement pstmt = null;
-
- try
- {
- pstmt = _preparedStatements[pool][HIDE_STATE];
-
- if (pstmt == null)
- {
- pstmt = _theConnection[pool]
- .prepareStatement("UPDATE "
- + tableName
- + " SET StateType = ? WHERE UidString = ? AND TypeName = ? AND StateType = ?");
-
- _preparedStatements[pool][HIDE_STATE] = pstmt;
- }
- }
- catch (Exception e) {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_1(e);
-
- freePool(pool);
- return false;
- }
-
- try
- {
- switch (state)
- {
- case StateStatus.OS_UNCOMMITTED_HIDDEN:
- case StateStatus.OS_COMMITTED_HIDDEN:
- break;
- case StateStatus.OS_UNCOMMITTED:
- {
- pstmt.setInt(1, StateStatus.OS_UNCOMMITTED_HIDDEN);
- pstmt.setString(2, objUid.stringForm());
- pstmt.setString(3, typeName);
- pstmt.setInt(4, state);
- pstmt.executeUpdate();
- }
- break;
- case StateStatus.OS_COMMITTED:
- {
- pstmt.setInt(1, StateStatus.OS_COMMITTED_HIDDEN);
- pstmt.setString(2, objUid.stringForm());
- pstmt.setString(3, typeName);
- pstmt.setInt(4, state);
- pstmt.executeUpdate();
- }
- break;
- default:
- hiddenOk = false;
- }
- }
- catch (Throwable e)
- {
- cleanup = false;
- if (retryConnection(e, pool))
- {
- hide_state(objUid, typeName, tableName);
- }
- else
- {
- throw new ObjectStoreException(e.toString(), e);
- }
- }
- finally
- {
- if (cleanup)
- freePool(pool);
- }
- }
- else
- {
- hiddenOk = false;
- }
-
- return hiddenOk;
- }
-
- public boolean reveal_state(Uid objUid, String typeName, String tableName)
- throws ObjectStoreException
- {
- boolean revealedOk = true;
- boolean cleanup = true;
-
- if (storeValid())
- {
- int state = currentState(objUid, typeName, tableName);
-
- int pool = getPool();
-
- PreparedStatement pstmt = null;
- try
- {
- pstmt = _preparedStatements[pool][REVEAL_STATE];
-
- if (pstmt == null)
- {
- pstmt = _theConnection[pool]
- .prepareStatement("UPDATE "
- + tableName
- + " SET StateType = ? WHERE UidString = ? AND AND TypeName = ? StateType = ?");
- _preparedStatements[pool][REVEAL_STATE] = pstmt;
- }
- }
- catch (Exception e) {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_2(e);
-
- freePool(pool);
- return false;
- }
-
- try
- {
- switch (state)
- {
- case StateStatus.OS_UNCOMMITTED_HIDDEN:
- {
- pstmt.setInt(1, StateStatus.OS_UNCOMMITTED);
- pstmt.setString(2, objUid.stringForm());
- pstmt.setString(3, typeName);
- pstmt.setInt(4, state);
- pstmt.executeUpdate();
- }
- break;
- case StateStatus.OS_COMMITTED_HIDDEN:
- {
- pstmt.setInt(1, StateStatus.OS_COMMITTED);
- pstmt.setString(2, objUid.stringForm());
- pstmt.setString(3, typeName);
- pstmt.setInt(4, state);
- pstmt.executeUpdate();
- }
- break;
- case StateStatus.OS_COMMITTED:
- case StateStatus.OS_UNCOMMITTED:
- break;
- default:
- revealedOk = false;
- }
- }
- catch (Throwable e)
- {
- cleanup = false;
- if (retryConnection(e, pool))
- {
- reveal_state(objUid, typeName, tableName);
- }
- else
- {
- throw new ObjectStoreException(e.toString(), e);
- }
- }
- finally
- {
- if (cleanup)
- freePool(pool);
- }
- }
- else
- {
- revealedOk = false;
- }
-
- return revealedOk;
- }
-
- /**
- * currentState - determine the current state of an object. State search is
- * ordered OS_UNCOMMITTED, OS_UNCOMMITTED_HIDDEN, OS_COMMITTED,
- * OS_COMMITTED_HIDDEN
- */
- public int currentState(Uid objUid, String typeName, String tableName)
- throws ObjectStoreException
- {
- int theState = StateStatus.OS_UNKNOWN;
- ResultSet rs = null;
- boolean cleanup = true;
-
- if (storeValid())
- {
- int pool = getPool();
- try
- {
- PreparedStatement pstmt = _preparedStatements[pool][CURRENT_STATE];
-
- if (pstmt == null)
- {
- pstmt = _theConnection[pool]
- .prepareStatement("SELECT StateType, UidString FROM "
- + tableName
- + " WHERE UidString = ? AND TypeName = ?");
- _preparedStatements[pool][CURRENT_STATE] = pstmt;
- }
-
- pstmt.setString(1, objUid.stringForm());
- pstmt.setString(2, typeName);
-
- rs = pstmt.executeQuery();
-
- // we may have multiple states. need to sort out the order of
- // precedence
- // without making multiple round trips out to the db. this gets
- // a bit messy:
-
- boolean have_OS_UNCOMMITTED = false;
- boolean have_OS_UNCOMMITTED_HIDDEN = false;
- boolean have_OS_COMMITTED = false;
- boolean have_OS_COMMITTED_HIDDEN = false;
-
- while (rs.next())
- {
- int stateStatus = rs.getInt(1);
-
- switch (stateStatus)
- {
- case StateStatus.OS_UNCOMMITTED:
- have_OS_UNCOMMITTED = true;
- break;
- case StateStatus.OS_COMMITTED:
- have_OS_COMMITTED = true;
- break;
- case StateStatus.OS_COMMITTED_HIDDEN:
- have_OS_COMMITTED_HIDDEN = true;
- break;
- case StateStatus.OS_UNCOMMITTED_HIDDEN:
- have_OS_UNCOMMITTED_HIDDEN = true;
- break;
- }
- }
-
- // examine in reverse order:
- if (have_OS_COMMITTED_HIDDEN)
- {
- theState = StateStatus.OS_COMMITTED_HIDDEN;
- }
- if (have_OS_COMMITTED)
- {
- theState = StateStatus.OS_COMMITTED;
- }
- if (have_OS_UNCOMMITTED_HIDDEN)
- {
- theState = StateStatus.OS_UNCOMMITTED_HIDDEN;
- }
- if (have_OS_UNCOMMITTED)
- {
- theState = StateStatus.OS_UNCOMMITTED;
- }
- }
- catch (Throwable e)
- {
- cleanup = false;
- try
- {
- if (rs != null)
- rs.close();
- }
- catch (SQLException re)
- {
- // Just in case it's already closed
- }
- if (retryConnection(e, pool))
- {
- return currentState(objUid, typeName, tableName);
- }
- else
- {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_3(e);
-
- return StateStatus.OS_UNKNOWN;
- }
- }
- finally
- {
- if (cleanup)
- {
- try
- {
- if (rs != null)
- rs.close();
- }
- catch (SQLException e)
- {
- // Just in case it's already closed
- }
- freePool(pool);
- }
- }
- }
-
- return theState;
- }
-
- /**
- * allObjUids - Given a type name, return an ObjectState that contains all
- * of the uids of objects of that type.
- */
- public boolean allObjUids(String typeName, InputObjectState state,
- int match, String tableName) throws ObjectStoreException
- {
- int pool = getPool();
-
- try
- {
- OutputObjectState store = new OutputObjectState();
- Statement stmt = _theConnection[pool].createStatement();
- ResultSet rs = null;
-
- try
- {
- /*
- * Not used enough to warrant a PreparedStatement.
- */
- rs = stmt.executeQuery("SELECT DISTINCT UidString FROM "
- + tableName + " WHERE TypeName = '" + typeName + "'");
-
- boolean finished = false;
-
- while (!finished && rs.next())
- {
- Uid theUid = null;
-
- try
- {
- theUid = new Uid(rs.getString(1));
- UidHelper.packInto(theUid, store);
- }
- catch (IOException ex) {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_5(ex);
-
- return false;
- }
- catch (Exception e) {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_4(e);
-
- finished = true;
- }
- }
- }
- catch (Exception e) {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_4(e);
- }
- finally
- {
- try
- {
- if (rs != null)
- rs.close();
- }
- catch (SQLException e)
- {
- // Just in case it's already closed
- }
- try
- {
- if (stmt != null)
- stmt.close();
- }
- catch (SQLException e)
- {
- // Just in case it's already closed
- }
- }
-
- try
- {
- UidHelper.packInto(Uid.nullUid(), store);
- }
- catch (IOException e)
- {
- throw new ObjectStoreException("allObjUids - could not pack end of list Uid.", e);
- }
-
- state.setBuffer(store.buffer());
-
- store = null;
-
- return true;
- }
- catch (Exception e) {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_4(e);
- }
- finally
- {
- freePool(pool);
- }
-
- return false;
- }
-
- public boolean allTypes(InputObjectState foundTypes, String tableName)
- throws ObjectStoreException
- {
- int pool = getPool();
-
- try
- {
- OutputObjectState store = new OutputObjectState();
- Statement stmt = _theConnection[pool].createStatement();
- ResultSet rs = null;
-
- try
- {
- /*
- * Not used enough to warrant a PreparedStatement.
- */
- rs = stmt.executeQuery("SELECT DISTINCT TypeName FROM "
- + tableName);
-
- boolean finished = false;
-
- while (!finished && rs.next())
- {
- try
- {
- String type = rs.getString(1);
- store.packString(type);
- }
- catch (IOException ex) {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_7(ex);
-
- return false;
- }
- catch (Exception e) {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_6(e);
-
- finished = true;
- }
- }
- }
- catch (Exception e) {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_6(e);
- }
- finally
- {
- try
- {
- if (rs != null)
- rs.close();
- }
- catch (SQLException e)
- {
- // Just in case it's already closed
- }
- try
- {
- if (stmt != null)
- stmt.close();
- }
- catch (SQLException e)
- {
- // Just in case it's already closed
- }
- }
-
- try
- {
- store.packString("");
- }
- catch (IOException e)
- {
- throw new ObjectStoreException(tsLogger.i18NLogger.get_objectstore_packProblem(), e);
- }
-
- foundTypes.setBuffer(store.buffer());
-
- return true;
- }
- catch (Exception e) {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_6(e);
- }
- finally
- {
- freePool(pool);
- }
-
- return false;
- }
-
- public boolean remove_state(Uid objUid, String name, int ft,
- String tableName) throws ObjectStoreException
- {
- boolean removeOk = false;
- boolean cleanup = true;
-
- if (!storeValid())
- return false;
-
- if (name != null)
- {
- if ((ft == StateStatus.OS_COMMITTED)
- || (ft == StateStatus.OS_UNCOMMITTED))
- {
- int pool = getPool();
-
- try
- {
- PreparedStatement pstmt = _preparedStatements[pool][REMOVE_STATE];
-
- if (pstmt == null)
- {
- pstmt = _theConnection[pool]
- .prepareStatement("DELETE FROM "
- + tableName
- + " WHERE UidString = ? AND TypeName = ? AND StateType = ?");
-
- _preparedStatements[pool][REMOVE_STATE] = pstmt;
- }
-
- pstmt.setString(1, objUid.stringForm());
- pstmt.setString(2, name);
- pstmt.setInt(3, ft);
- if (pstmt.executeUpdate() > 0)
- {
- removeOk = true;
- }
- }
- catch (Throwable e)
- {
- cleanup = false;
- if (retryConnection(e, pool))
- {
- return remove_state(objUid, name, ft, tableName);
- }
- else {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_8(e);
-
- removeOk = false;
- }
- }
- finally
- {
- if (cleanup)
- freePool(pool);
- }
- }
- else {
- removeOk = false;
- // can only remove (UN)COMMITTED objs
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_9(Integer.toString(ft), objUid);
- }
- }
- else {
- removeOk = false;
-
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_10(objUid);
- }
-
- return removeOk;
- }
-
- public InputObjectState read_state (Uid objUid, String tName, int ft, String tableName) throws ObjectStoreException
- {
- InputObjectState newImage = null;
-
- if (!storeValid())
- return newImage;
-
- if (tName != null)
- {
- if ((ft == StateStatus.OS_COMMITTED) || (ft == StateStatus.OS_UNCOMMITTED))
- {
- int pool = getPool();
- ResultSet rs = null;
-
- try
- {
- PreparedStatement pstmt = _preparedStatements[pool][READ_STATE];
-
- if (pstmt == null)
- {
- pstmt = _theConnection[pool].prepareStatement("SELECT ObjectState FROM "+tableName+" WHERE UidString = ? AND TypeName = ? AND StateType = ?");
-
- _preparedStatements[pool][READ_STATE] = pstmt;
- }
-
- pstmt.setString(1, objUid.stringForm());
- pstmt.setString(2, tName);
- pstmt.setInt(3, ft);
-
- rs = pstmt.executeQuery();
-
- if(! rs.next()) {
- return null; // no matching state in db
- }
-
- byte[] buffer = rs.getBytes(1);
-
- if (buffer != null)
- {
- newImage = new InputObjectState(objUid, tName, buffer);
- }
- else {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_readfailed();
- }
- }
- catch (Throwable e)
- {
- e.printStackTrace();
-
- if(retryConnection(e, pool)) {
- return read_state(objUid, tName, ft, tableName);
- } else {
- throw new ObjectStoreException(e.toString(), e);
- }
- }
- finally
- {
- try
- {
- rs.close();
- }
- // Ignore
- catch (Exception re) {}
- freePool(pool);
- }
- }
- }
- else
- throw new ObjectStoreException("JDBCImple.read_state - object with uid "+objUid+" has no TypeName");
-
- return newImage;
- }
-
- public boolean write_state (Uid objUid, String tName, OutputObjectState state, int s, String tableName) throws ObjectStoreException
- {
- boolean result = false;
-
- int imageSize = (int) state.length();
-
- if (imageSize > getMaxStateSize())
- throw new ObjectStoreException("Object state is too large - maximum size allowed: " + getMaxStateSize());
-
- byte[] b = state.buffer();
-
- if (imageSize > 0 && storeValid())
- {
- int pool = getPool();
- ResultSet rs = null;
-
- try
- {
- PreparedStatement pstmt = _preparedStatements[pool][READ_WRITE_SHORTCUT];
-
- if (pstmt == null)
- {
- pstmt = _theConnection[pool].prepareStatement("SELECT ObjectState FROM "+tableName+" WHERE UidString = ? AND StateType = ? AND TypeName = ?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
-
- _preparedStatements[pool][READ_WRITE_SHORTCUT] = pstmt;
- }
-
- pstmt.setString(1, objUid.stringForm());
- pstmt.setInt(2, s);
- pstmt.setString(3, tName);
-
- rs = pstmt.executeQuery();
-
- if( rs.next() ) {
-
- rs.updateBytes(1, b);
- rs.updateRow();
-
- } else {
- // not in database, do insert:
- PreparedStatement pstmt2 = _preparedStatements[pool][WRITE_STATE_NEW];
-
- if (pstmt2 == null)
- {
- pstmt2 = _theConnection[pool].prepareStatement("INSERT INTO "+tableName+" (StateType,TypeName,UidString,ObjectState) VALUES (?,?,?,?)");
-
- _preparedStatements[pool][WRITE_STATE_NEW] = pstmt2;
- }
-
- pstmt2.setInt(1, s);
- pstmt2.setString(2, tName);
- pstmt2.setString(3, objUid.stringForm());
- pstmt2.setBytes(4, b);
-
- pstmt2.executeUpdate();
- }
-
- result = true;
- }
- catch(Throwable e)
- {
- if(retryConnection(e, pool)) {
- return write_state(objUid, tName, state, s, tableName);
- } else {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_writefailed(e);
- }
- }
- finally
- {
- try
- {
- rs.close();
- }
- // Ignore
- catch (Exception re) {}
- freePool(pool);
- }
- }
- return result;
- }
-
- /**
- * Set up the store for use.
- */
- public boolean initialise(Connection conn, JDBCAccess jdbcAccess,
- String tableName) throws SQLException
- {
- _poolSizeInit = arjPropertyManager.getObjectStoreEnvironmentBean().getJdbcPoolSizeInitial();
- if (_poolSizeInit < 1) {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_11(Integer.toString(_poolSizeInit));
- _poolSizeInit = 1;
- }
-
- _poolSizeMax = arjPropertyManager.getObjectStoreEnvironmentBean().getJdbcPoolSizeMaximum();
- if (_poolSizeMax < _poolSizeInit) {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_12(Integer.toString(_poolSizeMax));
- _poolSizeMax = _poolSizeInit;
- }
-
- _poolPutConn = arjPropertyManager.getObjectStoreEnvironmentBean().isJdbcPoolPutConnections();
-
- _jdbcAccess = jdbcAccess;
- _theConnection = new Connection[_poolSizeMax];
- _theConnection[0] = conn;
- conn.setAutoCommit(true);
-
- try
- {
- for (int i = 1; i < _poolSizeInit; i++)
- {
- _theConnection[i] = _jdbcAccess.getConnection();
- _theConnection[i].setAutoCommit(true);
- }
- }
- catch (Exception e) {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_13(e);
-
- _isValid = false;
- return _isValid;
- }
-
- for (int i = _poolSizeInit; i < _poolSizeMax; i++)
- {
- _theConnection[i] = null;
- }
- if (_inUse == null)
- {
- _inUse = new boolean[_poolSizeMax];
- }
-
- _preparedStatements = new PreparedStatement[_poolSizeMax][];
-
- for (int i = 0; i < _poolSizeMax; i++)
- {
- _preparedStatements[i] = new PreparedStatement[STATEMENT_SIZE];
-
- for (int j = 0; j < STATEMENT_SIZE; j++)
- {
- _preparedStatements[i][j] = null;
- }
- }
-
- try
- {
- Statement stmt = _theConnection[0].createStatement();
-
- // table [type, object UID, format, blob]
-
- // Need some management interface to delete the table!
-
- if (jdbcAccess.dropTable())
- {
- try
- {
- stmt.executeUpdate("DROP TABLE " + tableName);
- }
- catch (SQLException ex)
- {
- // don't want to print error - chances are it
- // just reports that the table does not exist
- // ex.printStackTrace();
- }
- }
-
- try
- {
- createTable(stmt, tableName);
- }
- catch (SQLException ex)
- {
- // assume this is reporting that the table already exists:
- }
-
- _isValid = true;
- }
- catch (Exception e) {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_13(e);
-
- _isValid = false;
- }
-
- return _isValid;
- }
-
- /**
- * Add a new table to an existing implementation.
- *
- */
- protected void addTable(String tableName) throws Exception
- {
- int pool = getPool();
- Statement stmt = _theConnection[pool].createStatement();
-
- try
- {
- createTable(stmt, tableName);
- }
- catch (SQLException ex)
- {
- // assume this is reporting that the table already exists:
- }
- finally
- {
- freePool(pool);
- }
-
- }
-
- /**
- * Use implementation-specific code to create the store table. Called from
- * initialise() and addTable(), above.
- */
- protected abstract void createTable(Statement stmt, String tableName)
- throws SQLException;
-
- public abstract String name();
-
- protected abstract int getMaxStateSize();
-
- // protected abstract boolean exists (String state);
-
- protected final int getState(String state)
- {
- try
- {
- Integer st = (Integer) stateCache.get(state);
-
- if (st != null)
- {
- return st.intValue();
- }
- }
- catch (Exception ex) {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_14(ex);
- }
-
- return StateStatus.OS_UNKNOWN;
- }
-
- protected final void addToCache(Uid state, int status)
- {
- if (shareStatus == StateType.OS_UNSHARED)
- {
- stateCache.put(state, new Integer(status));
- }
- }
-
- protected final void removeFromCache(String state)
- {
- removeFromCache(state, true);
- }
-
- /**
- * Print a warning if the file to be removed is not in the cache.
- */
- protected final void removeFromCache(String state, boolean warn)
- {
- if (shareStatus == StateType.OS_UNSHARED)
- {
- if ((stateCache.remove(state) == null) && warn) {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_15(state);
- }
- }
- }
-
- final void setShareStatus(int status)
- {
- shareStatus = status;
- }
-
- /**
- * retryConnection. Called in exeption handlers where the problem may be due
- * to use of a stale (broken) cached connection. If this is the case, we
- * re-establish the connection before returning.
- *
- * @param e
- * The exception, which may be due to a bad connection.
- * @param pool
- * The pooled connection which was in use when the exception was
- * thrown and which is therfore suspect.
- * @return true if the connection was reestablished (in which case it is
- * worth retrying the calling function), false is a broken
- * connection was unlikely to be the problem.
- */
- protected boolean retryConnection(Throwable e, int pool)
- {
- if (e instanceof SQLException)
- {
- // To do: Look for specific driver error codes here...
- try
- {
- reconnect(pool);
- }
- catch (Exception e1)
- {
- return false;
- }
- synchronized (_inUse)
- {
- _inUse[pool] = true;
- }
- freePool(pool);
- return true;
- }
-
- return false;
- }
-
- /**
- * reconnect(int pool): re-establish a potentially failed cached connection.
- */
- protected void reconnect(int pool) throws SQLException
- {
- Connection newConnection = _theConnection[pool];
- _theConnection[pool] = null;
-
- // just in case the connection is still live,
- // attempt to clean it up nicely:
- try
- {
- newConnection.close();
- }
- catch (SQLException e)
- {
- }
- _jdbcAccess.putConnection(newConnection);
-
- // release the statements associated with the closed
- // connection so they dont get used by mistake...
- for (int i = 0; i < STATEMENT_SIZE; i++)
- {
- _preparedStatements[pool][i] = null;
- }
-
- // re-establish the connection:
- newConnection = _jdbcAccess.getConnection();
- try
- {
- newConnection.setAutoCommit(true);
- }
- catch (SQLException e)
- {
- newConnection = null;
- throw e;
- }
- _theConnection[pool] = newConnection;
- }
-
- /**
- * Allocate a database connection from the pool: Walks the array and
- * allocates the first available connection. If non are free, waits before
- * trying again.
- */
- protected int getPool()
- {
- int i = 0;
- int rtn = -1;
-
- synchronized (_inUse)
- {
- while (true)
- {
- if (!_inUse[i])
- {
- if (_theConnection[i] == null) /*
- * i >= _poolSizeInit && i <
- * _poolSizeMax
- */
- {
- try
- {
- _theConnection[i] = _jdbcAccess.getConnection();
- _inUse[i] = true;
- rtn = i;
- break;
- }
- catch (Exception e) {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_16(e);
- }
- }
- else
- {
- _inUse[i] = true;
- rtn = i;
- break;
- }
- }
-
- i++;
- if (i == _poolSizeMax)
- {
- i = 0;
- try
- {
- _inUse.wait();
- }
- catch (InterruptedException ie)
- {
- tsLogger.i18NLogger.info_objectstore_JDBCImple_17();
- }
- }
- }
- }
-
- return rtn;
- }
-
- /**
- * return a connection to the free pool, optionally closing it.
- */
- protected void freePool(int pool)
- {
- /*
- * try { _theConnection[pool].commit(); } catch(Exception e) {}
- */
-
- synchronized (_inUse)
- {
- if (_inUse[pool] == false) {
- tsLogger.i18NLogger.warn_objectstore_JDBCImple_18();
- }
- _inUse[pool] = false;
- _inUse.notifyAll();
- }
- }
-
- private int shareStatus;
-
- private Hashtable stateCache = new Hashtable();
-
- protected JDBCAccess _jdbcAccess = null;
-
- protected Connection[] _theConnection = null;
-
- protected boolean _isValid = false;
-
- protected PreparedStatement[][] _preparedStatements = null;
-
- /*
- * IMPORTANT: remember to update if we add more prepared statements!
- */
- protected static final int COMMIT_STATE = 0;
-
- protected static final int HIDE_STATE = 1;
-
- protected static final int REVEAL_STATE = 2;
-
- protected static final int CURRENT_STATE = 3;
-
- protected static final int READ_STATE = 4;
-
- protected static final int REMOVE_STATE = 5;
-
- protected static final int WRITE_STATE_NEW = 6;
-
- protected static final int WRITE_STATE_EXISTING = 7;
-
- protected static final int SELECT_FOR_WRITE_STATE = 8;
-
- protected static final int READ_WRITE_SHORTCUT = 9;
-
- protected static final int PRECOMMIT_CLEANUP = 10;
-
- // size:
- protected static final int STATEMENT_SIZE = 11;
-
- // record the status of each connection in the pool:
- protected boolean[] _inUse = null;
-
- protected int _poolSizeInit = 1; /* Initial pool size */
-
- protected int _poolSizeMax = 1; /* Maximum pool size */
-
- protected boolean _poolPutConn = false; /*
- * Return (putConnection()) after
- * use?
- */
-}
Deleted: labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/objectstore/JDBCStore.java
===================================================================
--- labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/objectstore/JDBCStore.java 2010-09-09 14:28:08 UTC (rev 35091)
+++ labs/jbosstm/trunk/ArjunaCore/arjuna/classes/com/arjuna/ats/internal/arjuna/objectstore/JDBCStore.java 2010-09-09 14:29:41 UTC (rev 35092)
@@ -1,640 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * (C) 2005-2006,
- * @author JBoss Inc.
- */
-/*
- * Copyright (C) 2000, 2001,
- *
- * Arjuna Solutions Limited,
- * Newcastle upon Tyne,
- * Tyne and Wear,
- * UK.
- *
- * $Id: JDBCStore.java 2342 2006-03-30 13:06:17Z $
- */
-
-package com.arjuna.ats.internal.arjuna.objectstore;
-
-import com.arjuna.ats.arjuna.state.*;
-
-import com.arjuna.ats.arjuna.logging.tsLogger;
-
-import com.arjuna.ats.arjuna.objectstore.ObjectStore;
-import com.arjuna.ats.arjuna.objectstore.StateStatus;
-import com.arjuna.ats.arjuna.objectstore.StateType;
-import com.arjuna.ats.arjuna.objectstore.jdbc.JDBCAccess;
-import com.arjuna.ats.arjuna.common.*;
-
-import java.sql.*;
-import java.util.HashMap;
-
-import com.arjuna.ats.arjuna.exceptions.ObjectStoreException;
-import com.arjuna.ats.arjuna.exceptions.FatalError;
-
-import java.io.IOException;
-
-/**
- * An object store implementation which uses a JDBC database for maintaining
- * object states. All states are maintained within a single table.
- *
- * It is assumed that only one object will use a given instance of the
- * JDBCStore. Hence, there is no need for synchronizations.
- */
-
-public class JDBCStore extends ObjectStore
-{
-
- public String getStoreName()
- {
- if (storeValid())
- return getAccessClassName() + ":" + getTableName();
- else
- return "Invalid";
- }
-
- public boolean commit_state(Uid objUid, String tName)
- throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("JDBCStore.commit_state(" + objUid + ", " + tName + ")");
- }
-
- /* Bail out if the object store is not set up */
-
- if (!storeValid())
- return false;
- else
- return _theImple.commit_state(objUid, tName, getTableName());
- }
-
- public boolean hide_state(Uid objUid, String tName)
- throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("ShadowingStore.hide_state(" + objUid + ", " + tName + ")");
- }
-
- /* Bail out if the object store is not set up */
-
- if (storeValid())
- return _theImple.hide_state(objUid, tName, getTableName());
- else
- return false;
- }
-
- public boolean reveal_state(Uid objUid, String tName)
- throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("ShadowingStore.reveal_state(" + objUid + ", " + tName
- + ")");
- }
-
- if (storeValid())
- return _theImple.reveal_state(objUid, tName, getTableName());
- else
- return false;
- }
-
- /*
- * Determine current state of object. State search is ordered
- * OS_UNCOMMITTED, OS_UNCOMMITTED_HIDDEN, OS_COMMITTED, OS_COMMITTED_HIDDEN
- */
-
- public int currentState(Uid objUid, String tName)
- throws ObjectStoreException
- {
- if (storeValid())
- return _theImple.currentState(objUid, tName, getTableName());
- else
- return StateStatus.OS_UNKNOWN;
- }
-
- /**
- * Read an uncommitted instance of State out of the object store. The
- * instance is identified by the unique id and type
- */
-
- public InputObjectState read_committed(Uid storeUid, String tName)
- throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("JDBCStore.read_committed(" + storeUid + ", "
- + tName + ")");
- }
-
- return read_state(storeUid, tName, StateStatus.OS_COMMITTED);
- }
-
- public InputObjectState read_uncommitted(Uid storeUid, String tName)
- throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("JDBCStore.read_uncommitted(" + storeUid + ", " + tName
- + ")");
- }
-
- return read_state(storeUid, tName, StateStatus.OS_UNCOMMITTED);
- }
-
- public boolean remove_committed(Uid storeUid, String tName)
- throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("JDBCStore.remove_committed(" + storeUid + ", " + tName
- + ")");
- }
-
- return remove_state(storeUid, tName, StateStatus.OS_COMMITTED);
- }
-
- public boolean remove_uncommitted(Uid storeUid, String tName)
- throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("JDBCStore.remove_uncommitted(" + storeUid + ", " + tName
- + ")");
- }
-
- return remove_state(storeUid, tName, StateStatus.OS_UNCOMMITTED);
- }
-
- public boolean write_committed(Uid storeUid, String tName,
- OutputObjectState state) throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("JDBCStore.write_committed(" + storeUid + ", " + tName
- + ")");
- }
-
- return write_state(storeUid, tName, state, StateStatus.OS_COMMITTED);
- }
-
- public boolean write_uncommitted(Uid storeUid, String tName,
- OutputObjectState state) throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("JDBCStore.write_uncommitted(" + storeUid + ", " + tName
- + ", " + state + ")");
- }
-
- return write_state(storeUid, tName, state, StateStatus.OS_UNCOMMITTED);
- }
-
- public final boolean storeValid()
- {
- return _isValid;
- }
-
- /*
- * Given a type name return an ObjectState that contains all of the uids of
- * objects of that type
- */
-
- public boolean allObjUids(String tName, InputObjectState state, int match)
- throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("JDBCStore.allObjUids(" + tName + ", " + state + ", "
- + match + ")");
- }
-
- if (storeValid())
- return _theImple.allObjUids(tName, state, match, getTableName());
- else
- return false;
- }
-
- public boolean allTypes(InputObjectState foundTypes)
- throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("JDBCStore.allTypes(" + foundTypes + ")");
- }
-
- if (storeValid())
- return _theImple.allTypes(foundTypes, getTableName());
- else
- return false;
- }
-
- public synchronized void packInto(OutputBuffer buff) throws IOException
- {
- buff.packString(getAccessClassName());
- buff.packString(getTableName());
- }
-
- public synchronized void unpackFrom(InputBuffer buff) throws IOException
- {
- setAccessClassName(buff.unpackString());
- setTableName(buff.unpackString());
- }
-
- protected InputObjectState read_state(Uid objUid, String tName, int ft)
- throws ObjectStoreException
- {
- if (!storeValid())
- return null;
- else
- return _theImple.read_state(objUid, tName, ft, getTableName());
- }
-
- /**
- * We don't actually delete the state entry, only change its type.
- */
-
- protected boolean remove_state(Uid objUid, String name, int ft)
- throws ObjectStoreException
- {
- if (tsLogger.logger.isTraceEnabled()) {
- tsLogger.logger.trace("JDBCStore.remove_state("
- + objUid + ", " + name + ", "
- + StateType.stateTypeString(ft) + ")");
- }
-
- if (!storeValid())
- return false;
- else
- return _theImple.remove_state(objUid, name, ft, getTableName());
- }
-
- protected boolean write_state(Uid objUid, String tName,
- OutputObjectState state, int s) throws ObjectStoreException
- {
- if (!storeValid())
- return false;
- else
- return _theImple.write_state(objUid, tName, state, s,
- getTableName());
- }
-
- protected JDBCStore(ObjectStoreEnvironmentBean objectStoreEnvironmentBean) throws ObjectStoreException
- {
- super(objectStoreEnvironmentBean);
-
- _jdbcAccessClassName = objectStoreEnvironmentBean.getJdbcUserDbAccess();
-
- if(_jdbcAccessClassName == null) {
- throw new ObjectStoreException(tsLogger.i18NLogger.get_objectstore_JDBCStore_5());
- }
-
- setTableName(_defaultTableName);
-
- try
- {
- setupStore(_jdbcAccessClassName, getTableName());
- }
- catch (Exception e)
- {
- tsLogger.i18NLogger.fatal_objectstore_JDBCStore_1(getJDBCAccess().toString(), getTableName());
- throw new ObjectStoreException(e);
- }
-
- _isValid = true;
- }
-
- /**
- * Get the JDBC access class name.
- *
- * @return The access class name.
- */
- protected String getAccessClassName()
- {
- return _jdbcAccessClassName;
- }
-
- /**
- * Set the JDBC access class name.
- *
- * @param jdbcAccessClassName access class name.
- */
- protected void setAccessClassName(String jdbcAccessClassName)
- {
- _jdbcAccessClassName = jdbcAccessClassName;
- }
-
- /**
- * Get the JDBC default table name.
- *
- * @return The default table name.
- */
- protected String getDefaultTableName()
- {
- return _defaultTableName;
- }
-
- /**
- * Get the JDBC access class.
- *
- * @return The jdbc access variable.
- */
- protected JDBCAccess getJDBCAccess()
- {
- return _jdbcAccess;
- }
-
- /**
- * Set the JDBC access class.
- *
- * @param jdbcAccess
- * The jdbc access variable.
- */
- protected void setJDBCAccess(JDBCAccess jdbcAccess)
- {
- _jdbcAccess = jdbcAccess;
- }
-
- /**
- * Get the JDBC table name.
- *
- * @return The table name.
- */
- protected String getTableName()
- {
- return _jdbcTableName;
- }
-
- /**
- * Set the JDBC table name.
- *
- * @param tableName
- * The table name.
- */
- protected void setTableName(String tableName)
- {
- _jdbcTableName = tableName;
- }
-
- protected void initialise(String tableName) throws Exception
- {
- String jdbcAccessClassName = getAccessClassName();
-
- if (jdbcAccessClassName == null)
- {
- throw new FatalError(tsLogger.i18NLogger.get_objectstore_JDBCStore_5());
- }
-
- try
- {
- setupStore(jdbcAccessClassName, tableName);
- }
- catch (Exception e)
- {
- tsLogger.i18NLogger.fatal_objectstore_JDBCStore_1(getJDBCAccess().toString(), getTableName());
- throw e;
- }
-
- _isValid = true;
- }
-
- /*
- * Try to create the original and shadow/hidden tables. If this fails, then
- * we will exit.
- */
- @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)
- {
- tsLogger.i18NLogger.fatal_objectstore_JDBCStore_2(jdbcAccessClassName, ex);
- 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)
- {
- tsLogger.i18NLogger.fatal_objectstore_JDBCStore_2("getConnection()", sqle);
- throw sqle;
- }
-
- if (connection == null)
- {
- tsLogger.i18NLogger.fatal_objectstore_JDBCStore_1(getJDBCAccess().toString(), 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)
- {
- tsLogger.i18NLogger.fatal_objectstore_JDBCStore_2(getJDBCAccess().toString(), ex);
- throw ex;
- }
-
- if (!jdbcImple.initialise(connection, jdbcAccess,
- impleTableName)) {
- tsLogger.i18NLogger.warn_objectstore_JDBCStore_3();
- throw new ObjectStoreException();
- }
- else
- {
- _theImples.put(impleKey, jdbcImple);
- _theImple = jdbcImple;
- success = true;
- }
- }
- finally
- {
- if (!success)
- {
- try
- {
- connection.close();
- }
- catch (final SQLException sqle)
- {
- } // Ignore exception
- }
- }
- }
- catch (Exception e)
- {
- tsLogger.logger.warn(e);
- throw e;
- }
- }
- _isValid = true;
- }
- }
-
- /**
- * Attempt to load the database class. This method searches for a
- * class called <name>_<major>_<minor>, then <name>_<major> and finally
- * <dbName>
- *
- * @param conn
- * A database connection.
- * @return The database class.
- * @throws ClassNotFoundException
- * If no database class can be found.
- * @throws SQLException
- * If the database connection cannot be interrogated.
- */
- @SuppressWarnings("unchecked")
- protected Class getJDBCClass(Connection conn)
- throws ClassNotFoundException, SQLException
- {
- DatabaseMetaData md = conn.getMetaData();
-
- String name = md.getDriverName();
- int major = md.getDriverMajorVersion();
- int minor = md.getDriverMinorVersion();
-
- /*
- * Check for spaces in the name - our implementation classes are always
- * just the first part of such names.
- */
-
- int index = name.indexOf(' ');
-
- if (index != -1)
- name = name.substring(0, index);
-
- name = name.replaceAll("-", "_");
-
- name = name.toLowerCase();
-
- final ClassLoader classLoader = Thread.currentThread()
- .getContextClassLoader();
- final String packageName = getClass().getPackage().getName() + ".jdbc.";
- try
- {
- return classLoader.loadClass(packageName + name + "_" + major + "_"
- + minor + "_driver");
- }
- catch (final ClassNotFoundException cnfe)
- {
- }
- try
- {
- return classLoader.loadClass(packageName + name + "_" + major
- + "_driver");
- }
- catch (final ClassNotFoundException cnfe)
- {
- }
- return classLoader.loadClass(packageName + name + "_driver");
- }
-
- protected boolean supressEntry(String name)
- {
- return true;
- }
-
- /*
- * Instance specific data.
- */
-
- protected boolean _isValid;
-
- protected JDBCImple _theImple;
-
- private JDBCAccess _jdbcAccess;
-
- private String _jdbcAccessClassName;
-
- private String _jdbcTableName;
-
- private static String _defaultTableName = "JBossTSTable";
-
- /*
- * Class data.
- */
-
- protected static final HashMap _theImples = new HashMap();
-
- protected static final HashMap _theAccesses = new HashMap();
-}
More information about the jboss-svn-commits
mailing list