Search in sources :

Example 1 with NamePage

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();
    }
}
Also used : NameNode(org.sirix.node.interfaces.NameNode) PageKind(org.sirix.page.PageKind) Kind(org.sirix.node.Kind) NamePage(org.sirix.page.NamePage) SirixUsageException(org.sirix.exception.SirixUsageException)

Example 2 with NamePage

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);
        }
    }
}
Also used : NameNode(org.sirix.node.interfaces.NameNode) PageKind(org.sirix.page.PageKind) Kind(org.sirix.node.Kind) NamePage(org.sirix.page.NamePage)

Example 3 with NamePage

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;
}
Also used : NamePage(org.sirix.page.NamePage)

Example 4 with NamePage

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;
}
Also used : PageContainer(org.sirix.cache.PageContainer) PathSummaryPage(org.sirix.page.PathSummaryPage) CASPage(org.sirix.page.CASPage) NamePage(org.sirix.page.NamePage) PathPage(org.sirix.page.PathPage) KeyValuePage(org.sirix.page.interfaces.KeyValuePage) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) Record(org.sirix.node.interfaces.Record)

Example 5 with NamePage

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);
}
Also used : NamePage(org.sirix.page.NamePage)

Aggregations

NamePage (org.sirix.page.NamePage)5 Kind (org.sirix.node.Kind)2 NameNode (org.sirix.node.interfaces.NameNode)2 PageKind (org.sirix.page.PageKind)2 PageContainer (org.sirix.cache.PageContainer)1 SirixUsageException (org.sirix.exception.SirixUsageException)1 Record (org.sirix.node.interfaces.Record)1 CASPage (org.sirix.page.CASPage)1 PathPage (org.sirix.page.PathPage)1 PathSummaryPage (org.sirix.page.PathSummaryPage)1 UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)1 KeyValuePage (org.sirix.page.interfaces.KeyValuePage)1