MCPcopy Create free account
hub / github.com/BaseXdb/basex / item

Method item

basex-core/src/main/java/org/basex/query/func/db/DbPut.java:27–62  ·  view source on GitHub ↗
(final QueryContext qc, final InputInfo ii)

Source from the content-addressed store, hash-verified

25 */
26public 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}

Callers

nothing calls this directly

Calls 15

inMemoryMethod · 0.95
addMethod · 0.95
getMethod · 0.95
toDataMethod · 0.80
toNodeOrAtomItemMethod · 0.80
toDbPathMethod · 0.80
toOptionsMethod · 0.80
toNewInputMethod · 0.80
getMethod · 0.65
sizeMethod · 0.65
argMethod · 0.45
updatesMethod · 0.45

Tested by

no test coverage detected