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

Method replace

basex-core/src/main/java/org/basex/data/Data.java:581–666  ·  view source on GitHub ↗

Rapid Replace implementation. Replaces parts of the database with the specified data instance. @param pre PRE value of the node to be replaced @param source clip with source data @return success flag

(final int pre, final DataClip source)

Source from the content-addressed store, hash-verified

579 * @return success flag
580 */
581 public final boolean replace(final int pre, final DataClip source) {
582 final int sCount = source.size();
583 if(sCount == 0 || !bufferSize(sCount)) return false;
584
585 meta.update();
586
587 // update index structures
588 final int tKind = kind(pre), tSize = size(pre, tKind), tPar = parent(pre, tKind);
589 indexDelete(pre, id(pre), tSize);
590
591 final Data sData = source.data;
592 int sTopPre = source.start;
593 for(int sPre = source.start; sPre < source.end; ++sPre) {
594 // properties of the source node
595 final int sKind = sData.kind(sPre);
596 final int sSize = sData.size(sPre, sKind);
597 final int sPar = sData.parent(sPre, sKind);
598 final int cPre = pre + sPre - source.start;
599
600 // calculate new distance value
601 final int cDist;
602 if(sPre == sTopPre) {
603 // handle top level entry: calculate distance based on target database
604 cDist = cPre - tPar;
605 // calculate PRE value of next top level entry
606 sTopPre += sSize;
607 } else {
608 cDist = sPre - sPar;
609 }
610
611 switch(sKind) {
612 case DOC:
613 // add document
614 doc(sSize, sData.text(sPre, true));
615 ++meta.ndocs;
616 break;
617 case ELEM:
618 // add element
619 final byte[] en = sData.name(sPre, sKind);
620 elem(cDist, elemNames.put(en), sData.attSize(sPre, sKind), sSize,
621 nspaces.uriIdForPrefix(prefix(en), true), false);
622 break;
623 case TEXT:
624 case COMM:
625 case PI:
626 // add text
627 text(cDist, sData.text(sPre, true), sKind);
628 break;
629 case ATTR:
630 // add attribute
631 final byte[] an = sData.name(sPre, sKind);
632 attr(cDist, attrNames.put(an), sData.text(sPre, false),
633 nspaces.uriIdForPrefix(prefix(an), false));
634 break;
635 }
636 }
637
638 // replace table entries, reset buffer size

Callers 11

BaseXMethod · 0.45
compareMethod · 0.45
readMethod · 0.45
parseMethod · 0.45
creditsMethod · 0.45
checkMethod · 0.45
argMethod · 0.45
checkMethod · 0.45
queryMethod · 0.45
tableQueryMethod · 0.45
backupMethod · 0.45

Calls 15

bufferSizeMethod · 0.95
kindMethod · 0.95
sizeMethod · 0.95
parentMethod · 0.95
indexDeleteMethod · 0.95
idMethod · 0.95
docMethod · 0.95
textMethod · 0.95
nameMethod · 0.95
elemMethod · 0.95
attSizeMethod · 0.95
attrMethod · 0.95

Tested by

no test coverage detected