Abstract class for performing REST operations. @author BaseX Team, BSD License @author Christian Gruen
| 20 | * @author Christian Gruen |
| 21 | */ |
| 22 | abstract class RESTCmd extends Command { |
| 23 | /** REST session. */ |
| 24 | final RESTSession session; |
| 25 | |
| 26 | /** Response status (can be {@code null}). */ |
| 27 | HTTPStatus status; |
| 28 | |
| 29 | /** |
| 30 | * Constructor. |
| 31 | * @param session REST session |
| 32 | */ |
| 33 | RESTCmd(final RESTSession session) { |
| 34 | // permissions will be tested if single commands are run |
| 35 | super(Perm.NONE); |
| 36 | this.session = session; |
| 37 | jc().type(RESTText.REST); |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public void addLocks() { |
| 42 | final Locks locks = jc().locks; |
| 43 | final LockList reads = locks.reads, writes = locks.writes; |
| 44 | |
| 45 | for(final Command cmd : session) { |
| 46 | cmd.addLocks(); |
| 47 | // if command updates the context, it may affect any database that has been opened before. |
| 48 | // hence, all read locks will be added to list of write locks |
| 49 | final Locks cmdLocks = cmd.jc().locks; |
| 50 | if(cmdLocks.writes.contains(Locking.CONTEXT)) writes.add(reads); |
| 51 | // merge lock lists |
| 52 | reads.add(cmdLocks.reads); |
| 53 | writes.add(cmdLocks.writes); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public boolean updating(final Context ctx) { |
| 59 | boolean up = false; |
| 60 | for(final Command cmd : session) up |= cmd.updating(ctx); |
| 61 | updating = up; |
| 62 | return up; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | protected final boolean run() { |
| 67 | try { |
| 68 | run0(); |
| 69 | return true; |
| 70 | } catch(final IOException ex) { |
| 71 | return error(ex.getMessage()); |
| 72 | } finally { |
| 73 | Close.close(context); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Runs the command. |
| 79 | * @throws IOException I/O exception |
nothing calls this directly
no outgoing calls
no test coverage detected