(final QueryContext qc, final InputInfo ii)
| 25 | */ |
| 26 | public final class DbPut extends DbNew { |
| 27 | @Override |
| 28 | public Item item(final QueryContext qc, final InputInfo ii) throws QueryException { |
| 29 | final Data data = toData(qc); |
| 30 | final Item input = toNodeOrAtomItem(arg(1), false, qc); |
| 31 | final String path = toDbPath(arg(2), qc); |
| 32 | final HashMap<String, String> options = toOptions(arg(3), qc); |
| 33 | |
| 34 | final Updates updates = qc.updates(); |
| 35 | final IntList docs = data.resources.docs(path); |
| 36 | int d = 0; |
| 37 | |
| 38 | if(put(docs, data, path, options)) { |
| 39 | if(input instanceof Bin) { |
| 40 | // store binary resource |
| 41 | if(data.inMemory()) throw DB_MAINMEM_X.get(info, data.meta.name); |
| 42 | updates.add(new DBPutBinary(data, input, path, info), qc); |
| 43 | } else { |
| 44 | // store XML document: replace existing document or add new one |
| 45 | final NewInput ni = toNewInput(input, path); |
| 46 | final Update update = docs.isEmpty() ? |
| 47 | new DBAdd(data, options, true, qc, info, ni) : |
| 48 | new ReplaceDoc(docs.get(d++), data, ni, options, qc, info); |
| 49 | updates.add(update, qc); |
| 50 | |
| 51 | // delete file resources |
| 52 | for(final ResourceType type : Resources.BINARIES) { |
| 53 | final IOFile bin = data.meta.file(path, type); |
| 54 | if(bin != null) updates.add(new DBDelete(data, bin, info), qc); |
| 55 | } |
| 56 | } |
| 57 | // delete spare documents |
| 58 | final int ds = docs.size(); |
| 59 | for(; d < ds; d++) updates.add(new DeleteNode(docs.get(d), data, info), qc); |
| 60 | } |
| 61 | return Empty.VALUE; |
| 62 | } |
| 63 | } |
nothing calls this directly
no test coverage detected