Search in sources :

Example 51 with ObjectStoreException

use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.

the class HornetqObjectStoreAdaptor method allTypes.

/**
 * Obtain all types of objects stored in the object store.
 *
 * @param foundTypes The state in which to store the types.
 * @return <code>true</code> if no errors occurred, <code>false</code>
 *         otherwise.
 */
@Override
public boolean allTypes(InputObjectState foundTypes) throws ObjectStoreException {
    if (tsLogger.logger.isTraceEnabled()) {
        tsLogger.logger.trace("HornetqObjectStore.allTypes()");
    }
    boolean result = true;
    // may contain trailing null elements
    String[] knownTypes = store.getKnownTypes();
    Set<String> typeSet = new HashSet<String>();
    if (knownTypes == null || knownTypes.length == 0)
        return true;
    OutputObjectState buffer = new OutputObjectState();
    try {
        for (String typeName : knownTypes) {
            if (typeName == null) {
                continue;
            }
            if (typeName.startsWith("/")) {
                typeName = typeName.substring(1);
            }
            if (typeName.contains("/")) {
                String value = "";
                String[] parents = typeName.split("/");
                for (String parent : parents) {
                    if (parent.length() == 0) {
                        continue;
                    }
                    if (value.length() > 0) {
                        value = value + "/";
                    }
                    value = value + parent;
                    if (!typeSet.contains(value)) {
                        typeSet.add(value);
                        buffer.packString(value);
                    }
                }
            } else {
                buffer.packString(typeName);
            }
        }
        buffer.packString("");
    } catch (IOException e) {
        throw new ObjectStoreException(e);
    }
    foundTypes.setBuffer(buffer.buffer());
    return result;
}
Also used : ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 52 with ObjectStoreException

use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.

the class JDBCImple_driver method allObjUids.

/**
 * 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) throws ObjectStoreException {
    // Taken this requirement from ObjStoreBrowser
    if (typeName.startsWith("/"))
        typeName = typeName.substring(1);
    try {
        OutputObjectState store = new OutputObjectState();
        Connection connection = jdbcAccess.getConnection();
        Statement stmt = connection.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;
                }
            }
            connection.commit();
        } finally {
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException e) {
                // Ignore
                }
            }
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                // Ignore
                }
            }
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException e) {
                // Ignore
                }
            }
        }
        UidHelper.packInto(Uid.nullUid(), store);
        state.setBuffer(store.buffer());
        store = null;
        return true;
    } catch (Exception e) {
        tsLogger.i18NLogger.warn_objectstore_JDBCImple_4(e);
        return false;
    }
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) IOException(java.io.IOException) IOException(java.io.IOException) NamingException(javax.naming.NamingException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) SQLException(java.sql.SQLException)

Example 53 with ObjectStoreException

use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.

the class JDBCImple_driver method allTypes.

public boolean allTypes(InputObjectState foundTypes) throws ObjectStoreException {
    try {
        OutputObjectState store = new OutputObjectState();
        Connection connection = jdbcAccess.getConnection();
        Statement stmt = connection.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;
                }
            }
            connection.commit();
        } finally {
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException e) {
                // Ignore
                }
            }
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException e) {
                // Ignore
                }
            }
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException e) {
                // Ignore
                }
            }
        }
        store.packString("");
        foundTypes.setBuffer(store.buffer());
        return true;
    } catch (Exception e) {
        tsLogger.i18NLogger.warn_objectstore_JDBCImple_6(e);
        return false;
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) IOException(java.io.IOException) IOException(java.io.IOException) NamingException(javax.naming.NamingException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) SQLException(java.sql.SQLException)

Example 54 with ObjectStoreException

use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.

the class JDBCImple_driver method remove_state.

public boolean remove_state(Uid objUid, String typeName, int stateType) throws ObjectStoreException {
    // Taken this requirement from ObjStoreBrowser
    if (typeName.startsWith("/"))
        typeName = typeName.substring(1);
    boolean result = false;
    if (typeName != null) {
        if ((stateType == StateStatus.OS_COMMITTED) || (stateType == StateStatus.OS_UNCOMMITTED)) {
            Connection connection = null;
            PreparedStatement pstmt = null;
            try {
                connection = jdbcAccess.getConnection();
                pstmt = connection.prepareStatement("DELETE FROM " + tableName + " WHERE TypeName = ? AND UidString = ? AND StateType = ?");
                pstmt.setString(1, typeName);
                pstmt.setString(2, objUid.stringForm());
                pstmt.setInt(3, stateType);
                if (pstmt.executeUpdate() > 0) {
                    result = true;
                }
                connection.commit();
            } catch (Exception e) {
                result = false;
                tsLogger.i18NLogger.warn_objectstore_JDBCImple_8(e);
            } finally {
                if (pstmt != null) {
                    try {
                        pstmt.close();
                    } catch (SQLException e) {
                    // Ignore
                    }
                }
                if (connection != null) {
                    try {
                        connection.close();
                    } catch (SQLException e) {
                    // Ignore
                    }
                }
            }
        } else {
            // can only remove (UN)COMMITTED objs
            tsLogger.i18NLogger.warn_objectstore_JDBCImple_9(Integer.toString(stateType), objUid);
        }
    } else {
        tsLogger.i18NLogger.warn_objectstore_JDBCImple_10(objUid);
    }
    return result;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) NamingException(javax.naming.NamingException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) SQLException(java.sql.SQLException)

Example 55 with ObjectStoreException

use of com.arjuna.ats.arjuna.exceptions.ObjectStoreException in project narayana by jbosstm.

the class JDBCImple_driver method currentState.

/**
 * currentState - determine the current state of an object. State search is
 * ordered OS_UNCOMMITTED, OS_UNCOMMITTED_HIDDEN, OS_COMMITTED,
 * OS_COMMITTED_HIDDEN
 *
 * @throws ObjectStoreException - in case the JDBC store cannot be contacted
 */
public int currentState(Uid objUid, String typeName) throws ObjectStoreException {
    // Taken this requirement from ObjStoreBrowser
    if (typeName.startsWith("/"))
        typeName = typeName.substring(1);
    int theState = StateStatus.OS_UNKNOWN;
    ResultSet rs = null;
    Connection connection = null;
    PreparedStatement pstmt = null;
    try {
        connection = jdbcAccess.getConnection();
        pstmt = connection.prepareStatement("SELECT StateType, Hidden FROM " + tableName + " WHERE TypeName = ? AND UidString = ?");
        pstmt.setString(1, typeName);
        pstmt.setString(2, objUid.stringForm());
        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_COMMITTED = false;
        boolean have_OS_UNCOMMITTED_HIDDEN = false;
        boolean have_OS_COMMITTED_HIDDEN = false;
        while (rs.next()) {
            int stateStatus = rs.getInt(1);
            int hidden = rs.getInt(2);
            switch(stateStatus) {
                case StateStatus.OS_UNCOMMITTED:
                    if (hidden == 0)
                        have_OS_UNCOMMITTED = true;
                    else
                        have_OS_UNCOMMITTED_HIDDEN = true;
                    break;
                case StateStatus.OS_COMMITTED:
                    if (hidden == 0)
                        have_OS_COMMITTED = true;
                    else
                        have_OS_COMMITTED_HIDDEN = true;
                    break;
            }
        }
        connection.commit();
        // 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 (Exception e) {
        tsLogger.i18NLogger.warn_objectstore_JDBCImple_3(e);
        throw new ObjectStoreException(e);
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
            // ignore
            }
        }
        if (pstmt != null) {
            try {
                pstmt.close();
            } catch (SQLException e) {
            // Ignore
            }
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
            // Ignore
            }
        }
    }
    return theState;
}
Also used : ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) NamingException(javax.naming.NamingException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) SQLException(java.sql.SQLException)

Aggregations

ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)87 IOException (java.io.IOException)44 Uid (com.arjuna.ats.arjuna.common.Uid)35 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)34 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)23 File (java.io.File)11 Connection (java.sql.Connection)9 PreparedStatement (java.sql.PreparedStatement)9 SQLException (java.sql.SQLException)9 NamingException (javax.naming.NamingException)9 Enumeration (java.util.Enumeration)8 RecoveryStore (com.arjuna.ats.arjuna.objectstore.RecoveryStore)6 FileNotFoundException (java.io.FileNotFoundException)5 ResultSet (java.sql.ResultSet)5 ArrayList (java.util.ArrayList)5 ParticipantStore (com.arjuna.ats.arjuna.objectstore.ParticipantStore)4 XidImple (com.arjuna.ats.jta.xa.XidImple)4 RandomAccessFile (java.io.RandomAccessFile)3 SyncFailedException (java.io.SyncFailedException)3 Statement (java.sql.Statement)3