use of org.sirix.exception.SirixException 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.exception.SirixException in project sirix by sirixdb.
the class SubtreeBuilder method attribute.
@Override
public void attribute(final QNm name, final Atomic value) throws DocumentException {
try {
mWtx.insertAttribute(name, value.stringValue());
mWtx.moveToParent();
mSubtreeProcessor.notifyAttribute(new DBNode(mWtx, mCollection));
} catch (final SirixException e) {
throw new DocumentException(e.getCause());
}
}
use of org.sirix.exception.SirixException in project sirix by sirixdb.
the class SubtreeBuilder method startElement.
@Override
public void startElement(final QNm name) throws DocumentException {
try {
processStartTag(name);
if (mFirst) {
mFirst = false;
mStartNodeKey = mWtx.getNodeKey();
}
final DBNode node = new DBNode(mWtx, mCollection);
mParents.push(node);
mSubtreeProcessor.notifyStartElement(node);
} catch (final SirixException e) {
throw new DocumentException(e.getCause());
}
}
use of org.sirix.exception.SirixException in project sirix by sirixdb.
the class SubtreeBuilder method processingInstruction.
@Override
public void processingInstruction(final QNm target, final Atomic content) throws DocumentException {
try {
processPI(content.asStr().stringValue(), target.getLocalName());
mSubtreeProcessor.notifyProcessingInstruction(new DBNode(mWtx, mCollection));
} catch (final SirixException e) {
throw new DocumentException(e.getCause());
}
}
use of org.sirix.exception.SirixException in project sirix by sirixdb.
the class SubtreeBuilder method comment.
@Override
public void comment(final Atomic content) throws DocumentException {
try {
processComment(content.asStr().stringValue());
if (mFirst) {
mFirst = false;
mStartNodeKey = mWtx.getNodeKey();
}
mSubtreeProcessor.notifyComment(new DBNode(mWtx, mCollection));
} catch (final SirixException e) {
throw new DocumentException(e.getCause());
}
}
Aggregations