Search in sources :

Example 56 with ObjectStoreException

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

the class JDBCImple_driver method hide_state.

public boolean hide_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;
    try {
        connection = jdbcAccess.getConnection();
        pstmt = connection.prepareStatement("UPDATE " + tableName + " SET Hidden = 1 WHERE TypeName = ? AND UidString = ?");
        pstmt.setString(1, typeName);
        pstmt.setString(2, objUid.stringForm());
        int rowcount = pstmt.executeUpdate();
        connection.commit();
        if (rowcount > 0) {
            result = true;
        }
    } catch (Exception e) {
        tsLogger.i18NLogger.warn_objectstore_JDBCImple_1(e);
    } finally {
        if (pstmt != null) {
            try {
                pstmt.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 57 with ObjectStoreException

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

the class AsyncStore method doWork.

private final void doWork() {
    synchronized (_workList) {
        LinkedList list = getList();
        if (list != null) {
            synchronized (list) {
                try {
                    _work = (StoreElement) list.removeLast();
                    _numberOfEntries--;
                    if ((_work.state != null) && !_work.removed)
                        _currentCacheSize -= _work.state.size();
                    if (_work.removed) {
                        _removedItems--;
                    }
                } catch (java.util.NoSuchElementException ex) {
                    _work = null;
                }
            }
        } else
            _work = null;
    }
    if ((_work != null) && !_work.removed) {
        try {
            switch(_work.typeOfWork) {
                case AsyncStore.COMMIT:
                    {
                        if (!_work.store.commitState(_work.objUid, _work.tName)) {
                            tsLogger.i18NLogger.warn_objectstore_CacheStore_1(_work.objUid, _work.tName);
                        }
                    }
                    break;
                case AsyncStore.REMOVE:
                    {
                        if (!_work.store.removeState(_work.objUid, _work.tName, _work.fileType)) {
                            tsLogger.i18NLogger.warn_objectstore_CacheStore_2(_work.objUid, _work.tName, Integer.toString(_work.fileType));
                        }
                    }
                    break;
                case AsyncStore.WRITE:
                    {
                        if (!_work.store.writeState(_work.objUid, _work.tName, _work.state, _work.fileType)) {
                            tsLogger.i18NLogger.warn_objectstore_CacheStore_3(_work.objUid, _work.tName, _work.state.toString(), Integer.toString(_work.fileType));
                        }
                    }
                    break;
                default:
                    tsLogger.i18NLogger.warn_objectstore_CacheStore_4(Integer.toString(_work.typeOfWork));
                    break;
            }
        } catch (ObjectStoreException ex) {
            ex.printStackTrace();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    synchronized (_workList) {
        // Must have the lock to write to _work
        _work = null;
    }
}
Also used : ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) LinkedList(java.util.LinkedList) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

Example 58 with ObjectStoreException

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

the class FileSystemStore method allTypes.

public boolean allTypes(InputObjectState foundTypes) throws ObjectStoreException {
    if (tsLogger.logger.isTraceEnabled()) {
        tsLogger.logger.trace("FileSystemStore.allTypes(" + foundTypes + ")");
    }
    boolean result = true;
    String directory = new String(fullStoreName);
    File f = new File(directory);
    String[] entry = f.list();
    if (entry == null)
        return true;
    OutputObjectState store = new OutputObjectState();
    for (int i = 0; i < entry.length; i++) {
        if (!supressEntry(entry[i])) {
            File tmpFile = new File(directory + File.separator + entry[i]);
            if (tmpFile.isDirectory()) {
                try {
                    store.packString(entry[i]);
                    result = allTypes(store, entry[i]);
                } catch (IOException e) {
                    throw new ObjectStoreException(tsLogger.i18NLogger.get_objectstore_FileSystemStore_4(), e);
                }
            }
            tmpFile = null;
        }
    }
    try {
        store.packString("");
    } catch (IOException e) {
        throw new ObjectStoreException(tsLogger.i18NLogger.get_objectstore_FileSystemStore_5(), e);
    }
    foundTypes.setBuffer(store.buffer());
    return result;
}
Also used : ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) IOException(java.io.IOException) File(java.io.File)

Example 59 with ObjectStoreException

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

the class FileSystemStore method allObjUidsInternal.

private boolean allObjUidsInternal(String tName, InputObjectState state, int match) throws ObjectStoreException {
    if (tsLogger.logger.isTraceEnabled()) {
        tsLogger.logger.trace("FileSystemStore.allObjUids(" + tName + ", " + state + ", " + match + ")");
    }
    String directory = null;
    OutputObjectState store = new OutputObjectState();
    if ((tName != null) && (tName.length() > 0) && (tName.charAt(0) == File.separatorChar)) {
        String s = tName.substring(1, tName.length());
        directory = new String(fullStoreName + s);
    } else
        directory = new String(fullStoreName + tName);
    File f = new File(directory);
    // only return files not dirs
    String[] entry = f.list(new FileFilter());
    if ((entry != null) && (entry.length > 0)) {
        for (int i = 0; i < entry.length; i++) {
            try {
                Uid aUid = new Uid(entry[i], true);
                if (!aUid.valid() || (aUid.equals(Uid.nullUid()))) {
                    String revealed = revealedId(entry[i]);
                    if (present(revealed, entry))
                        aUid = null;
                    else
                        aUid = new Uid(revealed);
                }
                if ((aUid != null) && (aUid.valid())) {
                    if ((aUid.notEquals(Uid.nullUid())) && ((match == StateStatus.OS_UNKNOWN) || (isType(aUid, tName, match)))) {
                        if (scanZeroLengthFiles || new File(f, entry[i]).length() > 0) {
                            UidHelper.packInto(aUid, store);
                        }
                    }
                }
            } catch (NumberFormatException e) {
            /*
                     * Not a number at start of file.
                     */
            } catch (IOException e) {
                throw new ObjectStoreException(tsLogger.i18NLogger.get_objectstore_FileSystemStore_2a(), e);
            }
        }
    }
    try {
        UidHelper.packInto(Uid.nullUid(), store);
    } catch (IOException e) {
        throw new ObjectStoreException(tsLogger.i18NLogger.get_objectstore_FileSystemStore_3(), e);
    }
    state.setBuffer(store.buffer());
    store = null;
    return true;
}
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) File(java.io.File)

Example 60 with ObjectStoreException

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

the class HashedStore method allObjUids.

/**
 * Given a type name initialise <code>state</code> to 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("HashedStore.allObjUids(" + tName + ", " + state + ", " + match + ")");
    }
    /*
         * Directory ALWAYS has a trailing '/'
         */
    String directory = locateStore(getStoreName());
    OutputObjectState store = new OutputObjectState();
    if ((tName != null) && (tName.length() > 0) && (tName.charAt(0) == File.separatorChar))
        directory = directory + tName.substring(1, tName.length());
    else
        directory = directory + tName;
    if (!directory.endsWith(File.separator))
        directory = directory + File.separator;
    File f = new File(directory);
    String[] entry = f.list();
    if ((entry != null) && (entry.length > 0)) {
        for (int i = 0; i < entry.length; i++) {
            if (Character.isDigit(entry[i].charAt(1)) || entry[i].startsWith(HASH_SEPARATOR)) {
                File dir = new File(directory + entry[i]);
                if (dir.isDirectory()) {
                    String[] dirEnt = dir.list();
                    for (int j = 0; j < dirEnt.length; j++) {
                        try {
                            Uid aUid = new Uid(dirEnt[j], true);
                            if (!aUid.valid() || (aUid.equals(Uid.nullUid()))) {
                                String revealed = revealedId(dirEnt[j]);
                                if (present(revealed, dirEnt))
                                    aUid = null;
                                else
                                    aUid = new Uid(revealed);
                            }
                            if ((aUid.notEquals(Uid.nullUid())) && ((match == StateStatus.OS_UNKNOWN) || (isType(aUid, tName, match)))) {
                                if (scanZeroLengthFiles || new File(dir, dirEnt[j]).length() > 0) {
                                    UidHelper.packInto(aUid, store);
                                }
                            }
                        } catch (NumberFormatException e) {
                        /*
                                 * Not a number at start of file.
                                 */
                        } catch (IOException e) {
                            throw new ObjectStoreException(tsLogger.i18NLogger.get_objectstore_HashedStore_5(), e);
                        }
                    }
                }
            } else {
            // ignore
            }
        }
    }
    try {
        UidHelper.packInto(Uid.nullUid(), store);
    } catch (IOException e) {
        throw new ObjectStoreException(tsLogger.i18NLogger.get_objectstore_HashedStore_6(), e);
    }
    state.setBuffer(store.buffer());
    store = null;
    return true;
}
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) File(java.io.File)

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