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;
}
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());
}
}
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;
}
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");
}
}
}
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;
}
Aggregations