Search in sources :

Example 6 with ObjectStoreException

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

the class VolatileStore method allTypes.

/**
 * Obtain all types of objects stored in the object store.
 *
 * @param buff The state in which to store the types.
 * @return <code>true</code> if no errors occurred, <code>false</code>
 *         otherwise.
 */
public boolean allTypes(InputObjectState buff) throws ObjectStoreException {
    if (stateTypes == null)
        throw new ObjectStoreException("Operation not supported by this implementation");
    Set<String> types = new HashSet<>(stateTypes.values());
    OutputObjectState store = new OutputObjectState();
    for (String type : types) packString(store, type);
    packString(store, "");
    buff.setBuffer(store.buffer());
    return true;
}
Also used : ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) HashSet(java.util.HashSet)

Example 7 with ObjectStoreException

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

the class HornetqJournalStore method write_committed.

/**
 * Write a new copy of the object's committed state.
 *
 * @param uid    The object to work on.
 * @param typeName   The type of the object to work on.
 * @param txData The state to write.
 * @return <code>true</code> if no errors occurred, <code>false</code>
 *         otherwise.
 * @throws ObjectStoreException if things go wrong.
 */
public boolean write_committed(Uid uid, String typeName, OutputObjectState txData) throws ObjectStoreException {
    RecordInfo previousRecord = null;
    try {
        OutputBuffer outputBuffer = new OutputBuffer();
        UidHelper.packInto(uid, outputBuffer);
        outputBuffer.packString(typeName);
        outputBuffer.packBytes(txData.buffer());
        byte[] data = outputBuffer.buffer();
        RecordInfo record = new RecordInfo(getId(uid, typeName), RECORD_TYPE, data, false, (short) 0);
        previousRecord = getContentForType(typeName).putIfAbsent(uid, record);
        if (previousRecord != null) {
            // the packed data may have changed so updated the map with the latest data
            getContentForType(typeName).replace(uid, record);
            journal.appendUpdateRecord(previousRecord.id, RECORD_TYPE, data, syncWrites);
        } else {
            journal.appendAddRecord(record.id, RECORD_TYPE, data, syncWrites);
        }
    } catch (Exception e) {
        if (previousRecord == null) {
            // if appendAddRecord() fails, remove record from map. Leave it there if appendUpdateRecord() fails.
            getContentForType(typeName).remove(uid);
        }
        throw new ObjectStoreException(e);
    }
    return true;
}
Also used : ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) RecordInfo(org.apache.activemq.artemis.core.journal.RecordInfo) OutputBuffer(com.arjuna.ats.arjuna.state.OutputBuffer) IOException(java.io.IOException) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

Example 8 with ObjectStoreException

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

the class HornetqObjectStoreAdaptor method allObjUids.

/**
 * Obtain all of the Uids for a specified type.
 *
 * @param typeName    The type to scan for.
 * @param foundInstances The object state in which to store the Uids
 * @param matchState    The file type to look for (e.g., committed, shadowed). [StateStatus]
 * @return <code>true</code> if no errors occurred, <code>false</code>
 *         otherwise.
 */
@Override
public boolean allObjUids(String typeName, InputObjectState foundInstances, int matchState) throws ObjectStoreException {
    if (tsLogger.logger.isTraceEnabled()) {
        tsLogger.logger.trace("HornetqObjectStore.allObjUids(" + typeName + ", " + matchState + ")");
    }
    boolean result = true;
    typeName = ensureTypenamePrefix(typeName);
    // may contain trailing null elements
    Uid[] uids = store.getUidsForType(typeName);
    OutputObjectState buffer = new OutputObjectState();
    try {
        if (uids != null && (matchState == StateStatus.OS_UNKNOWN || matchState == StateStatus.OS_COMMITTED)) {
            for (Uid uid : uids) {
                if (uid != null) {
                    UidHelper.packInto(uid, buffer);
                }
            }
        }
        UidHelper.packInto(Uid.nullUid(), buffer);
    } catch (IOException e) {
        throw new ObjectStoreException(e);
    }
    foundInstances.setBuffer(buffer.buffer());
    return result;
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) IOException(java.io.IOException)

Example 9 with ObjectStoreException

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

the class JDBCImple_driver method commit_state.

public boolean commit_state(Uid objUid, String typeName) throws ObjectStoreException {
    // Taken this requirement from ObjStoreBrowser
    if (typeName.startsWith("/"))
        typeName = typeName.substring(1);
    boolean result = false;
    Connection connection = null;
    PreparedStatement pstmt = null;
    PreparedStatement pstmt2 = null;
    try {
        connection = jdbcAccess.getConnection();
        // Delete any previously committed state
        pstmt = connection.prepareStatement("DELETE FROM " + tableName + " WHERE TypeName = ? AND UidString = ? AND StateType = " + StateStatus.OS_COMMITTED);
        pstmt.setString(1, typeName);
        pstmt.setString(2, objUid.stringForm());
        int rowcount = pstmt.executeUpdate();
        if (rowcount > 0) {
            tsLogger.i18NLogger.trace_JDBCImple_previouslycommitteddeleted(rowcount);
        }
        // now do the commit itself:
        pstmt2 = connection.prepareStatement("UPDATE " + tableName + " SET StateType = " + StateStatus.OS_COMMITTED + " WHERE TypeName = ? AND UidString = ? AND StateType = " + StateStatus.OS_UNCOMMITTED);
        pstmt2.setString(1, typeName);
        pstmt2.setString(2, objUid.stringForm());
        int rowcount2 = pstmt2.executeUpdate();
        if (rowcount2 > 0) {
            connection.commit();
            result = true;
        } else {
            tsLogger.i18NLogger.warn_objectstore_JDBCImple_nothingtocommit(objUid.stringForm());
            connection.rollback();
        }
    } catch (Exception e) {
        tsLogger.i18NLogger.warn_objectstore_JDBCImple_writefailed(e);
    } finally {
        if (pstmt != null) {
            try {
                pstmt.close();
            } catch (SQLException e) {
            // Ignore
            }
        }
        if (pstmt2 != null) {
            try {
                pstmt2.close();
            } catch (SQLException e) {
            // Ignore
            }
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
            // Ignore
            }
        }
    }
    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 10 with ObjectStoreException

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

the class JDBCImple_driver method read_state.

public InputObjectState read_state(Uid objUid, String typeName, int stateType) throws ObjectStoreException {
    InputObjectState result = null;
    // Taken this requirement from ObjStoreBrowser
    if (typeName.startsWith("/"))
        typeName = typeName.substring(1);
    if ((stateType == StateStatus.OS_COMMITTED) || (stateType == StateStatus.OS_UNCOMMITTED)) {
        ResultSet rs = null;
        Connection connection = null;
        PreparedStatement pstmt = null;
        try {
            connection = jdbcAccess.getConnection();
            pstmt = connection.prepareStatement("SELECT ObjectState FROM " + tableName + " WHERE TypeName = ? AND UidString = ? AND StateType = ?");
            pstmt.setString(1, typeName);
            pstmt.setString(2, objUid.stringForm());
            pstmt.setInt(3, stateType);
            rs = pstmt.executeQuery();
            if (rs.next()) {
                byte[] buffer = rs.getBytes(1);
                if (buffer != null) {
                    result = new InputObjectState(objUid, typeName, buffer);
                } else {
                    tsLogger.i18NLogger.warn_objectstore_JDBCImple_readfailed();
                    throw new ObjectStoreException(tsLogger.i18NLogger.warn_objectstore_JDBCImple_readfailed_message());
                }
            }
            connection.commit();
        } catch (Exception e) {
            tsLogger.i18NLogger.warn_objectstore_JDBCImple_14(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
                }
            }
        }
    } else {
        throw new ObjectStoreException(tsLogger.i18NLogger.unexpected_state_type(stateType));
    }
    return result;
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) 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