]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Operations.java
Initial support for concurrency in databoard, bindings and serializers
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / util / Operations.java
1 package org.simantics.db.layer0.util;
2
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;
10
11 public class Operations {
12
13     public static boolean isAllowed(RequestProcessor rp, Resource operation) throws DatabaseException {
14         return true;
15     }
16     
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);
25     }
26     
27 }