use of org.sirix.page.NamePage in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method setName.
@Override
public XdmNodeWriteTrx setName(final QNm name) throws SirixException {
checkNotNull(name);
acquireLock();
try {
if (getCurrentNode() instanceof NameNode) {
if (!getName().equals(name)) {
checkAccessAndCommit();
NameNode node = (NameNode) mNodeReader.getCurrentNode();
final long oldHash = node.hashCode();
// Create new keys for mapping.
final int prefixKey = name.getPrefix() != null && !name.getPrefix().isEmpty() ? getPageTransaction().createNameKey(name.getPrefix(), node.getKind()) : -1;
final int localNameKey = name.getLocalName() != null && !name.getLocalName().isEmpty() ? getPageTransaction().createNameKey(name.getLocalName(), node.getKind()) : -1;
final int uriKey = name.getNamespaceURI() != null && !name.getNamespaceURI().isEmpty() ? getPageTransaction().createNameKey(name.getNamespaceURI(), Kind.NAMESPACE) : -1;
// Adapt path summary.
if (mBuildPathSummary) {
mPathSummaryWriter.adaptPathForChangedNode(node, name, uriKey, prefixKey, localNameKey, OPType.SETNAME);
}
// Remove old keys from mapping.
final Kind nodeKind = node.getKind();
final int oldPrefixKey = node.getPrefixKey();
final int oldLocalNameKey = node.getLocalNameKey();
final int oldUriKey = node.getURIKey();
final NamePage page = ((NamePage) getPageTransaction().getActualRevisionRootPage().getNamePageReference().getPage());
page.removeName(oldPrefixKey, nodeKind);
page.removeName(oldLocalNameKey, nodeKind);
page.removeName(oldUriKey, Kind.NAMESPACE);
// Set new keys for current node.
node = (NameNode) getPageTransaction().prepareEntryForModification(node.getNodeKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
node.setLocalNameKey(localNameKey);
node.setURIKey(uriKey);
node.setPrefixKey(prefixKey);
node.setPathNodeKey(mBuildPathSummary ? mPathSummaryWriter.getNodeKey() : 0);
mNodeReader.setCurrentNode(node);
adaptHashedWithUpdate(oldHash);
}
return this;
} else {
throw new SirixUsageException("setName is not allowed if current node is not an INameNode implementation!");
}
} finally {
unLock();
}
}
use of org.sirix.page.NamePage in project sirix by sirixdb.
the class XdmNodeWriterTrxImpl method removeName.
/**
* Remove a name from the {@link NamePage} reference and the path summary if needed.
*
* @throws SirixException if Sirix fails
*/
private void removeName() throws SirixException {
if (getCurrentNode() instanceof NameNode) {
final NameNode node = ((NameNode) getCurrentNode());
final Kind nodeKind = node.getKind();
final NamePage page = ((NamePage) getPageTransaction().getActualRevisionRootPage().getNamePageReference().getPage());
page.removeName(node.getPrefixKey(), nodeKind);
page.removeName(node.getLocalNameKey(), nodeKind);
page.removeName(node.getURIKey(), Kind.NAMESPACE);
assert nodeKind != Kind.DOCUMENT;
if (mBuildPathSummary) {
mPathSummaryWriter.remove(node, nodeKind, page);
}
}
}
use of org.sirix.page.NamePage in project sirix by sirixdb.
the class PageWriteTrxImpl method createNameKey.
@Override
public int createNameKey(@Nullable final String name, final Kind nodeKind) throws SirixIOException {
mPageRtx.assertNotClosed();
checkNotNull(nodeKind);
final String string = (name == null ? "" : name);
final int nameKey = NamePageHash.generateHashForString(string);
final NamePage namePage = getNamePage(mNewRoot);
namePage.setName(nameKey, string, nodeKind);
return nameKey;
}
use of org.sirix.page.NamePage in project sirix by sirixdb.
the class PageWriteTrxImpl method createEntry.
@Override
public Record createEntry(final Long key, final Record record, final PageKind pageKind, final int index, final Optional<UnorderedKeyValuePage> keyValuePage) throws SirixIOException {
mPageRtx.assertNotClosed();
// Allocate record key and increment record count.
long recordKey;
switch(pageKind) {
case RECORDPAGE:
recordKey = mNewRoot.incrementAndGetMaxNodeKey();
break;
case PATHSUMMARYPAGE:
final PathSummaryPage pathSummaryPage = ((PathSummaryPage) mNewRoot.getPathSummaryPageReference().getPage());
recordKey = pathSummaryPage.incrementAndGetMaxNodeKey(index);
break;
case CASPAGE:
final CASPage casPage = ((CASPage) mNewRoot.getCASPageReference().getPage());
recordKey = casPage.incrementAndGetMaxNodeKey(index);
break;
case PATHPAGE:
final PathPage pathPage = ((PathPage) mNewRoot.getPathPageReference().getPage());
recordKey = pathPage.incrementAndGetMaxNodeKey(index);
break;
case NAMEPAGE:
final NamePage namePage = ((NamePage) mNewRoot.getNamePageReference().getPage());
recordKey = namePage.incrementAndGetMaxNodeKey(index);
break;
default:
throw new IllegalStateException();
}
final long recordPageKey = mPageRtx.pageKey(recordKey);
final PageContainer cont = prepareRecordPage(recordPageKey, index, pageKind);
@SuppressWarnings("unchecked") final KeyValuePage<Long, Record> modified = (KeyValuePage<Long, Record>) cont.getModified();
modified.setEntry(record.getNodeKey(), record);
return record;
}
use of org.sirix.page.NamePage in project sirix by sirixdb.
the class PageWriteTrxImpl method getName.
@Override
public String getName(final int nameKey, final Kind nodeKind) {
mPageRtx.assertNotClosed();
final NamePage currentNamePage = getNamePage(mNewRoot);
return (currentNamePage == null || currentNamePage.getName(nameKey, nodeKind) == null) ? mPageRtx.getName(nameKey, nodeKind) : currentNamePage.getName(nameKey, nodeKind);
}
Aggregations