Search in sources :

Example 11 with NodeDelegate

use of org.sirix.node.delegates.NodeDelegate in project sirix by sirixdb.

the class ElementNodeTest method testElementNode.

@Test
public void testElementNode() throws IOException {
    final NodeDelegate del = new NodeDelegate(13, 14, 0, 0, Optional.of(SirixDeweyID.newRootID()));
    final StructNodeDelegate strucDel = new StructNodeDelegate(del, 12l, 17l, 16l, 1l, 0);
    final NameNodeDelegate nameDel = new NameNodeDelegate(del, 17, 18, 19, 1);
    final ElementNode node = new ElementNode(strucDel, nameDel, new ArrayList<Long>(), HashBiMap.<Long, Long>create(), new ArrayList<Long>(), new QNm("ns", "a", "p"));
    // Create empty node.
    node.insertAttribute(97, 100);
    node.insertAttribute(98, 101);
    node.insertNamespace(99);
    node.insertNamespace(100);
    check(node);
    // Serialize and deserialize node.
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    node.getKind().serialize(new DataOutputStream(out), node, mPageReadTrx);
    final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    final ElementNode node2 = (ElementNode) Kind.ELEMENT.deserialize(new DataInputStream(in), node.getNodeKey(), node.getDeweyID(), mPageReadTrx);
    check(node2);
}
Also used : QNm(org.brackit.xquery.atomic.QNm) StructNodeDelegate(org.sirix.node.delegates.StructNodeDelegate) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) NodeDelegate(org.sirix.node.delegates.NodeDelegate) StructNodeDelegate(org.sirix.node.delegates.StructNodeDelegate) NameNodeDelegate(org.sirix.node.delegates.NameNodeDelegate) NameNodeDelegate(org.sirix.node.delegates.NameNodeDelegate) Test(org.junit.Test)

Example 12 with NodeDelegate

use of org.sirix.node.delegates.NodeDelegate in project sirix by sirixdb.

the class PageUtils method createTree.

/**
 * Create the initial tree structure.
 *
 * @param reference reference from revision root
 * @param pageKind the page kind
 */
public static void createTree(@Nonnull PageReference reference, final PageKind pageKind, final int index, final PageReadTrx pageReadTrx, final TransactionIntentLog log) {
    Page page = null;
    // Level page count exponent from the configuration.
    final int[] levelPageCountExp = pageReadTrx.getUberPage().getPageCountExp(pageKind);
    // Remaining levels.
    for (int i = 0, l = levelPageCountExp.length; i < l; i++) {
        page = new IndirectPage();
        log.put(reference, new PageContainer(page, page));
        reference = page.getReference(0);
    }
    // Create new record page.
    final UnorderedKeyValuePage ndp = new UnorderedKeyValuePage(Fixed.ROOT_PAGE_KEY.getStandardProperty(), pageKind, Constants.NULL_ID_LONG, pageReadTrx);
    // Create a {@link DocumentRootNode}.
    final Optional<SirixDeweyID> id = pageReadTrx.getResourceManager().getResourceConfig().mDeweyIDsStored ? Optional.of(SirixDeweyID.newRootID()) : Optional.empty();
    final NodeDelegate nodeDel = new NodeDelegate(Fixed.DOCUMENT_NODE_KEY.getStandardProperty(), Fixed.NULL_NODE_KEY.getStandardProperty(), Fixed.NULL_NODE_KEY.getStandardProperty(), 0, id);
    final StructNodeDelegate strucDel = new StructNodeDelegate(nodeDel, Fixed.NULL_NODE_KEY.getStandardProperty(), Fixed.NULL_NODE_KEY.getStandardProperty(), Fixed.NULL_NODE_KEY.getStandardProperty(), 0, 0);
    ndp.setEntry(0L, new DocumentRootNode(nodeDel, strucDel));
    log.put(reference, new PageContainer(ndp, ndp));
}
Also used : PageContainer(org.sirix.cache.PageContainer) DocumentRootNode(org.sirix.node.DocumentRootNode) StructNodeDelegate(org.sirix.node.delegates.StructNodeDelegate) Page(org.sirix.page.interfaces.Page) SirixDeweyID(org.sirix.node.SirixDeweyID) NodeDelegate(org.sirix.node.delegates.NodeDelegate) StructNodeDelegate(org.sirix.node.delegates.StructNodeDelegate)

Example 13 with NodeDelegate

use of org.sirix.node.delegates.NodeDelegate in project sirix by sirixdb.

the class NodeFactoryImpl method createCommentNode.

@Override
public CommentNode createCommentNode(@Nonnegative final long parentKey, @Nonnegative final long leftSibKey, @Nonnegative final long rightSibKey, final byte[] value, final boolean isCompressed, final Optional<SirixDeweyID> id) throws SirixIOException {
    final long revision = mPageWriteTrx.getRevisionNumber();
    final NodeDelegate nodeDel = new NodeDelegate(mPageWriteTrx.getActualRevisionRootPage().getMaxNodeKey() + 1, parentKey, 0, revision, id);
    final boolean compression = isCompressed && value.length > 10;
    final byte[] compressedValue = compression ? Compression.compress(value, Deflater.HUFFMAN_ONLY) : value;
    final ValNodeDelegate valDel = new ValNodeDelegate(nodeDel, compressedValue, compression);
    final StructNodeDelegate structDel = new StructNodeDelegate(nodeDel, Fixed.NULL_NODE_KEY.getStandardProperty(), rightSibKey, leftSibKey, 0, 0);
    return (CommentNode) mPageWriteTrx.createEntry(nodeDel.getNodeKey(), new CommentNode(valDel, structDel), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
}
Also used : StructNodeDelegate(org.sirix.node.delegates.StructNodeDelegate) ValNodeDelegate(org.sirix.node.delegates.ValNodeDelegate) CommentNode(org.sirix.node.CommentNode) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) NodeDelegate(org.sirix.node.delegates.NodeDelegate) StructNodeDelegate(org.sirix.node.delegates.StructNodeDelegate) NameNodeDelegate(org.sirix.node.delegates.NameNodeDelegate) ValNodeDelegate(org.sirix.node.delegates.ValNodeDelegate)

Example 14 with NodeDelegate

use of org.sirix.node.delegates.NodeDelegate in project sirix by sirixdb.

the class NodeFactoryImpl method createAttributeNode.

@Override
public AttributeNode createAttributeNode(@Nonnegative final long parentKey, @Nonnull final QNm name, @Nonnull final byte[] value, @Nonnegative final long pathNodeKey, final Optional<SirixDeweyID> id) throws SirixIOException {
    final long revision = mPageWriteTrx.getRevisionNumber();
    final int uriKey = mPageWriteTrx.createNameKey(name.getNamespaceURI(), Kind.NAMESPACE);
    final int prefixKey = name.getPrefix() != null && !name.getPrefix().isEmpty() ? mPageWriteTrx.createNameKey(name.getPrefix(), Kind.ATTRIBUTE) : -1;
    final int localNameKey = mPageWriteTrx.createNameKey(name.getLocalName(), Kind.ATTRIBUTE);
    final NodeDelegate nodeDel = new NodeDelegate(mPageWriteTrx.getActualRevisionRootPage().getMaxNodeKey() + 1, parentKey, 0, revision, id);
    final NameNodeDelegate nameDel = new NameNodeDelegate(nodeDel, uriKey, prefixKey, localNameKey, pathNodeKey);
    final ValNodeDelegate valDel = new ValNodeDelegate(nodeDel, value, false);
    return (AttributeNode) mPageWriteTrx.createEntry(nodeDel.getNodeKey(), new AttributeNode(nodeDel, nameDel, valDel, name), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
}
Also used : AttributeNode(org.sirix.node.AttributeNode) ValNodeDelegate(org.sirix.node.delegates.ValNodeDelegate) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) NodeDelegate(org.sirix.node.delegates.NodeDelegate) StructNodeDelegate(org.sirix.node.delegates.StructNodeDelegate) NameNodeDelegate(org.sirix.node.delegates.NameNodeDelegate) ValNodeDelegate(org.sirix.node.delegates.ValNodeDelegate) NameNodeDelegate(org.sirix.node.delegates.NameNodeDelegate)

Example 15 with NodeDelegate

use of org.sirix.node.delegates.NodeDelegate in project sirix by sirixdb.

the class NodeFactoryImpl method createElementNode.

@Override
public ElementNode createElementNode(@Nonnegative final long parentKey, @Nonnegative final long leftSibKey, @Nonnegative final long rightSibKey, final long hash, @Nonnull final QNm name, @Nonnegative final long pathNodeKey, final Optional<SirixDeweyID> id) throws SirixIOException {
    final int uriKey = name.getNamespaceURI() != null && !name.getNamespaceURI().isEmpty() ? mPageWriteTrx.createNameKey(name.getNamespaceURI(), Kind.NAMESPACE) : -1;
    final int prefixKey = name.getPrefix() != null && !name.getPrefix().isEmpty() ? mPageWriteTrx.createNameKey(name.getPrefix(), Kind.ELEMENT) : -1;
    final int localNameKey = mPageWriteTrx.createNameKey(name.getLocalName(), Kind.ELEMENT);
    final long revision = mPageWriteTrx.getRevisionNumber();
    final NodeDelegate nodeDel = new NodeDelegate(mPageWriteTrx.getActualRevisionRootPage().getMaxNodeKey() + 1, parentKey, 0, revision, id);
    final StructNodeDelegate structDel = new StructNodeDelegate(nodeDel, Fixed.NULL_NODE_KEY.getStandardProperty(), rightSibKey, leftSibKey, 0, 0);
    final NameNodeDelegate nameDel = new NameNodeDelegate(nodeDel, uriKey, prefixKey, localNameKey, pathNodeKey);
    return (ElementNode) mPageWriteTrx.createEntry(nodeDel.getNodeKey(), new ElementNode(structDel, nameDel, new ArrayList<Long>(), HashBiMap.<Long, Long>create(), new ArrayList<Long>(), name), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
}
Also used : StructNodeDelegate(org.sirix.node.delegates.StructNodeDelegate) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) ElementNode(org.sirix.node.ElementNode) NodeDelegate(org.sirix.node.delegates.NodeDelegate) StructNodeDelegate(org.sirix.node.delegates.StructNodeDelegate) NameNodeDelegate(org.sirix.node.delegates.NameNodeDelegate) ValNodeDelegate(org.sirix.node.delegates.ValNodeDelegate) NameNodeDelegate(org.sirix.node.delegates.NameNodeDelegate)

Aggregations

NodeDelegate (org.sirix.node.delegates.NodeDelegate)16 StructNodeDelegate (org.sirix.node.delegates.StructNodeDelegate)12 NameNodeDelegate (org.sirix.node.delegates.NameNodeDelegate)11 ValNodeDelegate (org.sirix.node.delegates.ValNodeDelegate)9 UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)9 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DataInputStream (java.io.DataInputStream)6 DataOutputStream (java.io.DataOutputStream)6 Test (org.junit.Test)6 QNm (org.brackit.xquery.atomic.QNm)4 SirixDeweyID (org.sirix.node.SirixDeweyID)3 PageContainer (org.sirix.cache.PageContainer)2 DocumentRootNode (org.sirix.node.DocumentRootNode)2 ElementNode (org.sirix.node.ElementNode)2 PathNode (org.sirix.index.path.summary.PathNode)1 AttributeNode (org.sirix.node.AttributeNode)1 CommentNode (org.sirix.node.CommentNode)1 DeletedNode (org.sirix.node.DeletedNode)1 NamespaceNode (org.sirix.node.NamespaceNode)1