use of org.sirix.exception.SirixUsageException in project sirix by sirixdb.
the class DatabaseImpl method getResourceManager.
// //////////////////////////////////////////////////////////
// END resource name <=> ID handling ////////////////////////
// //////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////
// START DB-Operations //////////////////////////////////////
// //////////////////////////////////////////////////////////
@Override
public synchronized ResourceManager getResourceManager(final ResourceManagerConfiguration resourceManagerConfig) throws SirixException {
final Path resourceFile = mDBConfig.getFile().resolve(DatabaseConfiguration.DatabasePaths.DATA.getFile()).resolve(resourceManagerConfig.getResource());
if (!Files.exists(resourceFile)) {
throw new SirixUsageException("Resource could not be opened (since it was not created?) at location", resourceFile.toString());
}
if (mResourceStore.hasOpenResourceManager(resourceFile))
return mResourceStore.getOpenResourceManager(resourceFile);
final ResourceConfiguration resourceConfig = ResourceConfiguration.deserialize(resourceFile);
// Resource of must be associated to this database.
assert resourceConfig.mPath.getParent().getParent().equals(mDBConfig.getFile());
if (!mBufferManagers.containsKey(resourceFile))
mBufferManagers.put(resourceFile, new BufferManagerImpl());
final ResourceManager resourceManager = mResourceStore.openResource(this, resourceConfig, resourceManagerConfig, mBufferManagers.get(resourceFile), resourceFile);
return resourceManager;
}
use of org.sirix.exception.SirixUsageException in project sirix by sirixdb.
the class Databases method openDatabase.
/**
* Open database. A database can be opened only once (even across JVMs). Afterwards a singleton
* instance bound to the {@link File} is returned.
*
* @param file determines where the database is located sessionConf a
* {@link ResourceManagerConfiguration} object to set up the session
* @return {@link Database} instance.
* @throws SirixIOException if an I/O exception occurs
* @throws SirixUsageException if Sirix is not used properly
* @throws NullPointerException if {@code file} is {@code null}
*/
public static synchronized Database openDatabase(final Path file) throws SirixUsageException, SirixIOException {
checkNotNull(file);
if (!Files.exists(file)) {
throw new SirixUsageException("DB could not be opened (since it was not created?) at location", file.toString());
}
final DatabaseConfiguration config = DatabaseConfiguration.deserialize(file);
if (config == null) {
throw new IllegalStateException("Configuration may not be null!");
}
final Database database = new DatabaseImpl(config);
putDatabase(file, database);
return database;
}
use of org.sirix.exception.SirixUsageException in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method insertTextAsFirstChild.
@Override
public XdmNodeWriteTrx insertTextAsFirstChild(final String value) throws SirixException {
checkNotNull(value);
acquireLock();
try {
if (getCurrentNode() instanceof StructNode && !value.isEmpty()) {
checkAccessAndCommit();
final long pathNodeKey = getCurrentNode().getNodeKey();
final long parentKey = getCurrentNode().getNodeKey();
final long leftSibKey = Fixed.NULL_NODE_KEY.getStandardProperty();
final long rightSibKey = ((StructNode) getCurrentNode()).getFirstChildKey();
// Update value in case of adjacent text nodes.
if (hasNode(rightSibKey)) {
moveTo(rightSibKey);
if (getCurrentNode().getKind() == Kind.TEXT) {
setValue(new StringBuilder(value).append(getValue()).toString());
adaptHashedWithUpdate(getCurrentNode().getHash());
return this;
}
moveTo(parentKey);
}
// Insert new text node if no adjacent text nodes are found.
final byte[] textValue = getBytes(value);
final Optional<SirixDeweyID> id = newFirstChildID();
final TextNode node = mNodeFactory.createTextNode(parentKey, leftSibKey, rightSibKey, textValue, mCompression, id);
// Adapt local nodes and hashes.
mNodeReader.setCurrentNode(node);
adaptForInsert(node, InsertPos.ASFIRSTCHILD, PageKind.RECORDPAGE);
mNodeReader.setCurrentNode(node);
adaptHashesWithAdd();
// Index text value.
mIndexController.notifyChange(ChangeType.INSERT, node, pathNodeKey);
return this;
} else {
throw new SirixUsageException("Insert is not allowed if current node is not an ElementNode or TextNode!");
}
} finally {
unLock();
}
}
use of org.sirix.exception.SirixUsageException in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method setValue.
@Override
public XdmNodeWriteTrx setValue(final String value) throws SirixException {
checkNotNull(value);
acquireLock();
try {
if (getCurrentNode() instanceof ValueNode) {
checkAccessAndCommit();
// XDM).
if (value.isEmpty()) {
remove();
return this;
}
// Remove old value from indexes.
mIndexController.notifyChange(ChangeType.DELETE, getNode(), getPathNodeKey());
final long oldHash = mNodeReader.getCurrentNode().hashCode();
final byte[] byteVal = getBytes(value);
final ValueNode node = (ValueNode) getPageTransaction().prepareEntryForModification(mNodeReader.getCurrentNode().getNodeKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
node.setValue(byteVal);
mNodeReader.setCurrentNode(node);
adaptHashedWithUpdate(oldHash);
// Index new value.
mIndexController.notifyChange(ChangeType.INSERT, getNode(), getPathNodeKey());
return this;
} else {
throw new SirixUsageException("setValue(String) is not allowed if current node is not an IValNode implementation!");
}
} finally {
unLock();
}
}
use of org.sirix.exception.SirixUsageException in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method insertElementAsLeftSibling.
@Override
public XdmNodeWriteTrx insertElementAsLeftSibling(final QNm name) throws SirixException {
if (!XMLToken.isValidQName(checkNotNull(name))) {
throw new IllegalArgumentException("The QName is not valid!");
}
acquireLock();
try {
if (getCurrentNode() instanceof StructNode && getCurrentNode().getKind() != Kind.DOCUMENT) {
checkAccessAndCommit();
final long key = getCurrentNode().getNodeKey();
moveToParent();
final long pathNodeKey = mBuildPathSummary ? mPathSummaryWriter.getPathNodeKey(name, Kind.ELEMENT) : 0;
moveTo(key);
final long parentKey = getCurrentNode().getParentKey();
final long leftSibKey = ((StructNode) getCurrentNode()).getLeftSiblingKey();
final long rightSibKey = getCurrentNode().getNodeKey();
final Optional<SirixDeweyID> id = newLeftSiblingID();
final ElementNode node = mNodeFactory.createElementNode(parentKey, leftSibKey, rightSibKey, 0, name, pathNodeKey, id);
mNodeReader.setCurrentNode(node);
adaptForInsert(node, InsertPos.ASLEFTSIBLING, PageKind.RECORDPAGE);
mNodeReader.setCurrentNode(node);
adaptHashesWithAdd();
return this;
} else {
throw new SirixUsageException("Insert is not allowed if current node is not an StructuralNode (either Text or Element)!");
}
} finally {
unLock();
}
}
Aggregations