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

Method put

basex-core/src/main/java/org/basex/core/cmd/Put.java:71–113  ·  view source on GitHub ↗

Puts (adds or replaces) resources in the specified database. @param data database @param bin binary file (can be null) @param path target path @return success flag

(final Data data, final IOFile bin, final String path)

Source from the content-addressed store, hash-verified

69 * @return success flag
70 */
71 private boolean put(final Data data, final IOFile bin, final String path) {
72 final IntList docs = data.resources.docs(path);
73 final int ds = docs.size();
74 int bs = 0;
75
76 if(options.get(MainOptions.REPLACE) || docs.isEmpty() && (bin == null || !bin.exists())) {
77 final AtomicUpdateCache auc = new AtomicUpdateCache(data);
78 final IntConsumer exec = start -> {
79 for(int d = start; d < ds; d++) auc.addDelete(docs.get(d));
80 auc.execute(false);
81 };
82
83 if(bin != null && bin.exists()) {
84 // replace binary file if it already exists
85 final BinaryPut put = new BinaryPut(path);
86 put.setInput(in);
87 put.lock = false;
88 if(!put.run(context)) return error(put.info());
89 bs = 1;
90 exec.accept(0);
91 } else {
92 // otherwise, add new document as xml
93 add = new Add(path);
94 try {
95 add.setInput(in);
96 add.init(context, out);
97 if(!add.build()) return error(add.info());
98
99 final DataClip clip = new DataClip(add.tmpData);
100 int d = 0;
101 if(docs.isEmpty()) {
102 auc.addInsert(data.meta.size, -1, clip);
103 } else {
104 auc.addReplace(docs.get(d++), clip);
105 }
106 exec.accept(d);
107 } finally {
108 add.finish();
109 }
110 }
111 }
112 return info(RES_REPLACED_X_X, ds + bs, jc().performance);
113 }
114
115 @Override
116 public void build(final CmdBuilder cb) {

Callers 11

runMethod · 0.95
readMethod · 0.45
addMethod · 0.45
alterMethod · 0.45
UserMethod · 0.45
passwordMethod · 0.45
permissionMethod · 0.45
QueryJobMethod · 0.45
registerMethod · 0.45
acquireMethod · 0.45
bindMethod · 0.45

Calls 15

addDeleteMethod · 0.95
getMethod · 0.95
executeMethod · 0.95
runMethod · 0.95
addInsertMethod · 0.95
addReplaceMethod · 0.95
setInputMethod · 0.80
jcMethod · 0.80
sizeMethod · 0.65
getMethod · 0.65
infoMethod · 0.65
acceptMethod · 0.65

Tested by

no test coverage detected