use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class DBNode method append.
private DBNode append(XdmNodeReadTrx rtx, Node<?> child) throws DocumentException {
try {
SubtreeBuilder builder = null;
if (rtx.hasFirstChild()) {
rtx.moveToLastChild();
builder = new SubtreeBuilder(mCollection, (XdmNodeWriteTrx) rtx, Insert.ASRIGHTSIBLING, Collections.<SubtreeListener<? super AbstractTemporalNode<DBNode>>>emptyList());
} else {
builder = new SubtreeBuilder(mCollection, (XdmNodeWriteTrx) rtx, Insert.ASFIRSTCHILD, Collections.<SubtreeListener<? super AbstractTemporalNode<DBNode>>>emptyList());
}
child.parse(builder);
rtx.moveTo(builder.getStartNodeKey());
} catch (final SirixException e) {
throw new DocumentException(e);
}
return new DBNode(rtx, mCollection);
}
use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class DBNode method getWtx.
private XdmNodeWriteTrx getWtx() {
final ResourceManager resource = mRtx.getResourceManager();
final XdmNodeWriteTrx wtx;
if (resource.getAvailableNodeWriteTrx() == 0) {
wtx = resource.getXdmNodeWriteTrx().get();
} else {
wtx = resource.beginNodeWriteTrx();
}
if (mRtx.getRevisionNumber() < resource.getMostRecentRevisionNumber())
wtx.revertTo(mRtx.getRevisionNumber());
wtx.moveTo(mNodeKey);
return wtx;
}
use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class DBStore method create.
public TemporalCollection<?> create(final String collName, final Optional<String> optResName, final SubtreeParser parser) throws DocumentException {
final DatabaseConfiguration dbConf = new DatabaseConfiguration(mLocation.resolve(collName));
try {
Databases.truncateDatabase(dbConf);
Databases.createDatabase(dbConf);
try (final Database database = Databases.openDatabase(dbConf.getFile())) {
mDatabases.add(database);
final String resName = optResName.isPresent() ? optResName.get() : new StringBuilder(3).append("resource").append(database.listResources().size() + 1).toString();
database.createResource(ResourceConfiguration.newBuilder(resName, dbConf).useDeweyIDs(true).useTextCompression(true).buildPathSummary(true).storageType(mStorageType).build());
final DBCollection collection = new DBCollection(collName, database);
mCollections.put(database, collection);
try (final ResourceManager resource = database.getResourceManager(new ResourceManagerConfiguration.Builder(resName).build());
final XdmNodeWriteTrx wtx = resource.beginNodeWriteTrx()) {
parser.parse(new SubtreeBuilder(collection, wtx, Insert.ASFIRSTCHILD, Collections.<SubtreeListener<? super AbstractTemporalNode<DBNode>>>emptyList()));
wtx.commit();
}
return collection;
}
} catch (final SirixException e) {
throw new DocumentException(e.getCause());
}
}
use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class Commit method execute.
@Override
public Sequence execute(StaticContext sctx, QueryContext ctx, Sequence[] args) throws QueryException {
final DBNode doc = ((DBNode) args[0]);
if (doc.getTrx() instanceof XdmNodeWriteTrx) {
final XdmNodeWriteTrx wtx = (XdmNodeWriteTrx) doc.getTrx();
final long revision = wtx.getRevisionNumber();
wtx.commit();
return new Int64(revision);
} else {
final ResourceManager manager = doc.getTrx().getResourceManager();
final XdmNodeWriteTrx wtx;
if (manager.getAvailableNodeWriteTrx() == 0) {
wtx = manager.getXdmNodeWriteTrx().get();
} else {
wtx = manager.beginNodeWriteTrx();
}
final int revision = doc.getTrx().getRevisionNumber();
if (revision < manager.getMostRecentRevisionNumber()) {
wtx.revertTo(doc.getTrx().getRevisionNumber());
}
wtx.commit();
return new Int64(revision);
}
}
use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class Rollback method execute.
@Override
public Sequence execute(StaticContext sctx, QueryContext ctx, Sequence[] args) throws QueryException {
final DBNode doc = ((DBNode) args[0]);
if (doc.getTrx() instanceof XdmNodeWriteTrx) {
final XdmNodeWriteTrx wtx = (XdmNodeWriteTrx) doc.getTrx();
final long revision = wtx.getRevisionNumber();
wtx.rollback();
return new Int64(revision);
} else {
throw new QueryException(new QNm("The transaction is not a write transaction!"));
}
}
Aggregations