1 package org.simantics.db.layer0.util;
3 import org.simantics.db.RequestProcessor;
4 import org.simantics.db.Resource;
5 import org.simantics.db.common.request.AdaptValue;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.db.layer0.exception.OperationNotAllowedException;
8 import org.simantics.db.request.WriteResult;
9 import org.simantics.scl.runtime.function.Function;
11 public class Operations {
13 public static boolean isAllowed(RequestProcessor rp, Resource operation) throws DatabaseException {
17 public static <T> T exec(RequestProcessor rp,
18 Resource operation, Object ... parameters) throws DatabaseException, OperationNotAllowedException {
19 if(!isAllowed(rp, operation))
20 throw new OperationNotAllowedException();
21 Object op = rp.syncRequest(new AdaptValue(operation));
22 if(parameters.length > 0)
23 op = ((Function)op).applyArray(parameters);
24 return rp.syncRequest((WriteResult<T>)op);