Search in sources :

Example 11 with PersistencyException

use of org.cristalise.kernel.common.PersistencyException in project kernel by cristal-ise.

the class ProxyLoader method get.

/**
 * retrieve object by path
 */
@Override
public C2KLocalObject get(ItemPath thisItem, String path) throws PersistencyException {
    try {
        Item thisEntity = getIOR(thisItem);
        ClusterType type = getClusterType(path);
        // fetch the xml from the item
        String queryData = thisEntity.queryData(path);
        if (Logger.doLog(8))
            Logger.msg("ProxyLoader.get() - " + thisItem + " : " + path + " = " + queryData);
        if (queryData != null) {
            if (type == ClusterType.OUTCOME)
                return new Outcome(path, queryData);
            else
                return (C2KLocalObject) Gateway.getMarshaller().unmarshall(queryData);
        }
    } catch (ObjectNotFoundException e) {
        return null;
    } catch (Exception e) {
        Logger.error(e);
        throw new PersistencyException(e.getMessage());
    }
    return null;
}
Also used : Item(org.cristalise.kernel.entity.Item) Outcome(org.cristalise.kernel.persistency.outcome.Outcome) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ClusterType(org.cristalise.kernel.persistency.ClusterType) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException)

Example 12 with PersistencyException

use of org.cristalise.kernel.common.PersistencyException in project kernel by cristal-ise.

the class ProxyLoader method getClusterContents.

/**
 * Directory listing
 */
@Override
public String[] getClusterContents(ItemPath thisItem, String path) throws PersistencyException {
    try {
        Item thisEntity = getIOR(thisItem);
        String contents = thisEntity.queryData(path + "/all");
        StringTokenizer tok = new StringTokenizer(contents, ",");
        String[] result = new String[tok.countTokens()];
        for (int i = 0; i < result.length; i++) result[i] = tok.nextToken();
        return result;
    } catch (Exception e) {
        Logger.error(e);
        throw new PersistencyException(e.getMessage());
    }
}
Also used : Item(org.cristalise.kernel.entity.Item) StringTokenizer(java.util.StringTokenizer) PersistencyException(org.cristalise.kernel.common.PersistencyException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException)

Example 13 with PersistencyException

use of org.cristalise.kernel.common.PersistencyException in project kernel by cristal-ise.

the class TransactionManager method getLockingTransaction.

/**
 * Manages the transaction table keyed by the object 'locker'.
 * If this object is null, transaction support is bypassed (so long as no lock exists on that object).
 *
 * @param itemPath
 * @param locker
 * @return the list of transaction corresponds to that lock object
 * @throws PersistencyException
 */
private ArrayList<TransactionEntry> getLockingTransaction(ItemPath itemPath, Object locker) throws PersistencyException {
    ArrayList<TransactionEntry> lockerTransaction;
    synchronized (locks) {
        // look to see if this object is already locked
        if (locks.containsKey(itemPath)) {
            // if it's this locker, get the transaction list
            Object thisLocker = locks.get(itemPath);
            if (// retrieve the transaction list
            thisLocker.equals(locker))
                lockerTransaction = pendingTransactions.get(locker);
            else
                // locked by someone else
                throw new PersistencyException("Access denied: '" + itemPath + "' has been locked for writing by " + thisLocker);
        } else {
            // no locks for this item
            if (locker == null) {
                // lock the item until the non-transactional put/remove is complete :/
                locks.put(itemPath, new Object());
                lockerTransaction = null;
            } else {
                // initialise the transaction
                locks.put(itemPath, locker);
                lockerTransaction = new ArrayList<TransactionEntry>();
                pendingTransactions.put(locker, lockerTransaction);
            }
        }
    }
    return lockerTransaction;
}
Also used : PersistencyException(org.cristalise.kernel.common.PersistencyException) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject)

Example 14 with PersistencyException

use of org.cristalise.kernel.common.PersistencyException in project kernel by cristal-ise.

the class TransactionManager method commit.

/**
 * Writes all pending changes to the backends.
 *
 * @param locker transaction locker
 */
public void commit(Object locker) {
    synchronized (locks) {
        ArrayList<TransactionEntry> lockerTransactions = pendingTransactions.get(locker);
        HashMap<TransactionEntry, Exception> exceptions = new HashMap<TransactionEntry, Exception>();
        // quit if no transactions are present;
        if (lockerTransactions == null)
            return;
        storage.begin(locker);
        for (TransactionEntry thisEntry : lockerTransactions) {
            try {
                if (thisEntry.obj == null)
                    storage.remove(thisEntry.itemPath, thisEntry.path, locker);
                else
                    storage.put(thisEntry.itemPath, thisEntry.obj, locker);
                locks.remove(thisEntry.itemPath);
            } catch (Exception e) {
                exceptions.put(thisEntry, e);
            }
        }
        pendingTransactions.remove(locker);
        if (exceptions.size() > 0) {
            // oh dear
            storage.abort(locker);
            Logger.error("TransactionManager.commit() - Problems during transaction commit of locker " + locker.toString() + ". Database may be in an inconsistent state.");
            for (TransactionEntry entry : exceptions.keySet()) {
                Exception ex = exceptions.get(entry);
                Logger.msg(entry.toString());
                Logger.error(ex);
            }
            dumpPendingTransactions(0);
            Logger.die("Database failure during commit");
        }
        try {
            storage.commit(locker);
        } catch (PersistencyException e) {
            storage.abort(locker);
            Logger.die("Transactional database failure");
        }
    }
}
Also used : HashMap(java.util.HashMap) PersistencyException(org.cristalise.kernel.common.PersistencyException) PersistencyException(org.cristalise.kernel.common.PersistencyException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException)

Example 15 with PersistencyException

use of org.cristalise.kernel.common.PersistencyException in project kernel by cristal-ise.

the class AddC2KObject method runActivityLogic.

// requestdata is xmlstring
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, PersistencyException {
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "AddC2KObject: agent:" + " item:" + item + " params:" + Arrays.toString(params));
    if (params.length != 1)
        throw new InvalidDataException("AddC2KObject: Invalid parameters " + Arrays.toString(params));
    try {
        C2KLocalObject obj = (C2KLocalObject) Gateway.getMarshaller().unmarshall(params[0]);
        Gateway.getStorage().put(item, obj, locker);
    } catch (Exception e) {
        throw new InvalidDataException("AddC2KObject: Could not unmarshall new object: " + params[0]);
    }
    return requestData;
}
Also used : C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException)

Aggregations

PersistencyException (org.cristalise.kernel.common.PersistencyException)43 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)26 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)26 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)10 IOException (java.io.IOException)9 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)9 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)8 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)8 AccessRightsException (org.cristalise.kernel.common.AccessRightsException)6 CannotManageException (org.cristalise.kernel.common.CannotManageException)6 ItemPath (org.cristalise.kernel.lookup.ItemPath)6 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)6 MappingException (org.exolab.castor.mapping.MappingException)6 MarshalException (org.exolab.castor.xml.MarshalException)6 ValidationException (org.exolab.castor.xml.ValidationException)6 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)5 History (org.cristalise.kernel.events.History)5 AgentPath (org.cristalise.kernel.lookup.AgentPath)5 DomainPath (org.cristalise.kernel.lookup.DomainPath)5 ArrayList (java.util.ArrayList)4