use of org.sirix.service.xml.shredder.XMLShredder in project sirix by sirixdb.
the class DiffTestHelper method initializeData.
private static void initializeData(final Holder holder, final Path... files) throws SirixException, IOException, XMLStreamException {
int i = 0;
for (final Path file : files) {
if (i == 0) {
final XMLShredder init = new XMLShredder.Builder(holder.getWriter(), XMLShredder.createFileReader(file), Insert.ASFIRSTCHILD).commitAfterwards().build();
init.call();
} else {
final XMLUpdateShredder init = new XMLUpdateShredder(holder.getWriter(), XMLShredder.createFileReader(file), Insert.ASFIRSTCHILD, file, ShredderCommit.COMMIT);
init.call();
}
i++;
}
}
use of org.sirix.service.xml.shredder.XMLShredder in project sirix by sirixdb.
the class FMSEImport method shredder.
/**
* Shredder new revision as temporal resource.
*
* @param resNewRev {@link File} reference for new revision (XML resource)
* @param newRev {@link File} reference for shreddered new revision (sirix resource)
* @throws SirixException if sirix fails to shredder the file
* @throws IOException if file couldn't be read
* @throws XMLStreamException if XML document isn't well formed
* @throws NullPointerException if {@code resNewRev} or {@code newRev} is {@code null}
*/
private void shredder(final Path resNewRev, @Nonnull Path newRev) throws SirixException, IOException, XMLStreamException {
assert resNewRev != null;
assert newRev != null;
final DatabaseConfiguration conf = new DatabaseConfiguration(newRev);
Databases.truncateDatabase(conf);
Databases.createDatabase(conf);
try (final Database db = Databases.openDatabase(newRev)) {
db.createResource(new ResourceConfiguration.Builder("shredded", conf).build());
try (final ResourceManager resMgr = db.getResourceManager(new ResourceManagerConfiguration.Builder("shredded").build());
final XdmNodeWriteTrx wtx = resMgr.beginNodeWriteTrx()) {
final XMLEventReader fileReader = XMLShredder.createFileReader(resNewRev);
final XMLShredder shredder = new XMLShredder.Builder(wtx, fileReader, Insert.ASFIRSTCHILD).commitAfterwards().build();
shredder.call();
}
}
}
use of org.sirix.service.xml.shredder.XMLShredder in project sirix by sirixdb.
the class BookShredding method shredder.
private static void shredder(final File pBooks) throws Exception {
final DatabaseConfiguration config = new DatabaseConfiguration(TestHelper.PATHS.PATH1.getFile());
Databases.truncateDatabase(config);
Databases.createDatabase(config);
final Database database = Databases.openDatabase(config.getFile());
database.createResource(new ResourceConfiguration.Builder(TestHelper.RESOURCE, PATHS.PATH1.getConfig()).build());
final Session session = database.getSession(new SessionConfiguration.Builder(TestHelper.RESOURCE).build());
final NodeWriteTrx wtx = session.beginNodeWriteTrx();
final XMLEventReader reader = XMLShredder.createFileReader(pBooks);
final XMLShredder shredder = new XMLShredder.Builder(wtx, reader, Insert.ASFIRSTCHILD).commitAfterwards().build();
shredder.call();
wtx.close();
session.close();
}
use of org.sirix.service.xml.shredder.XMLShredder in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method insertSubtree.
private XdmNodeWriteTrx insertSubtree(final XMLEventReader reader, final Insert insert) throws SirixException {
checkNotNull(reader);
assert insert != null;
acquireLock();
try {
if (getCurrentNode() instanceof StructNode) {
checkAccessAndCommit();
mBulkInsert = true;
long nodeKey = getCurrentNode().getNodeKey();
final XMLShredder shredder = new XMLShredder.Builder(this, reader, insert).commitAfterwards().build();
shredder.call();
moveTo(nodeKey);
switch(insert) {
case ASFIRSTCHILD:
moveToFirstChild();
break;
case ASRIGHTSIBLING:
moveToRightSibling();
break;
case ASLEFTSIBLING:
moveToLeftSibling();
break;
}
nodeKey = getCurrentNode().getNodeKey();
postOrderTraversalHashes();
final ImmutableNode startNode = getCurrentNode();
moveToParent();
while (getCurrentNode().hasParent()) {
moveToParent();
addParentHash(startNode);
}
moveTo(nodeKey);
mBulkInsert = false;
}
} finally {
unLock();
}
return this;
}
use of org.sirix.service.xml.shredder.XMLShredder in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method replaceNode.
@Override
public XdmNodeWriteTrx replaceNode(final String xml) throws SirixException, IOException, XMLStreamException {
checkNotNull(xml);
acquireLock();
try {
checkAccessAndCommit();
final XMLEventReader reader = XMLShredder.createStringReader(checkNotNull(xml));
ImmutableNode insertedRootNode = null;
if (getCurrentNode() instanceof StructNode) {
final StructNode currentNode = mNodeReader.getStructuralNode();
if (xml.startsWith("<")) {
while (reader.hasNext()) {
final XMLEvent event = reader.peek();
if (event.isStartDocument()) {
reader.nextEvent();
continue;
}
switch(event.getEventType()) {
case XMLStreamConstants.START_ELEMENT:
Insert pos = Insert.ASFIRSTCHILD;
if (currentNode.hasLeftSibling()) {
moveToLeftSibling();
pos = Insert.ASRIGHTSIBLING;
} else {
moveToParent();
}
final XMLShredder shredder = new XMLShredder.Builder(this, reader, pos).build();
shredder.call();
if (reader.hasNext()) {
// End document.
reader.nextEvent();
}
insertedRootNode = mNodeReader.getCurrentNode();
moveTo(currentNode.getNodeKey());
remove();
moveTo(insertedRootNode.getNodeKey());
break;
}
}
} else {
insertedRootNode = replaceWithTextNode(xml);
}
if (insertedRootNode != null) {
moveTo(insertedRootNode.getNodeKey());
}
} else {
}
} finally {
unLock();
}
return this;
}
Aggregations