Search in sources :

Example 1 with ValNodeDelegate

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

the class NodeFactoryImpl method createTextNode.

@Override
public TextNode createTextNode(@Nonnegative final long parentKey, @Nonnegative final long leftSibKey, @Nonnegative final long rightSibKey, @Nonnull 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 (TextNode) mPageWriteTrx.createEntry(nodeDel.getNodeKey(), new TextNode(valDel, structDel), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
}
Also used : StructNodeDelegate(org.sirix.node.delegates.StructNodeDelegate) ValNodeDelegate(org.sirix.node.delegates.ValNodeDelegate) TextNode(org.sirix.node.TextNode) 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 2 with ValNodeDelegate

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

the class NodeFactoryImpl method createPINode.

@Override
public PINode createPINode(@Nonnegative final long parentKey, @Nonnegative final long leftSibKey, @Nonnegative final long rightSibKey, final QNm target, final byte[] content, final boolean isCompressed, @Nonnegative final long pathNodeKey, final Optional<SirixDeweyID> id) throws SirixIOException {
    final long revision = mPageWriteTrx.getRevisionNumber();
    final int prefixKey = target.getPrefix() != null && !target.getPrefix().isEmpty() ? mPageWriteTrx.createNameKey(target.getPrefix(), Kind.PROCESSING_INSTRUCTION) : -1;
    final int localNameKey = mPageWriteTrx.createNameKey(target.getLocalName(), Kind.PROCESSING_INSTRUCTION);
    final int uriKey = mPageWriteTrx.createNameKey(target.getNamespaceURI(), Kind.NAMESPACE);
    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);
    final ValNodeDelegate valDel = new ValNodeDelegate(nodeDel, content, false);
    return (PINode) mPageWriteTrx.createEntry(nodeDel.getNodeKey(), new PINode(structDel, nameDel, valDel, mPageWriteTrx), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
}
Also used : StructNodeDelegate(org.sirix.node.delegates.StructNodeDelegate) PINode(org.sirix.node.PINode) 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 3 with ValNodeDelegate

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

the class TextNodeTest method testTextRootNode.

@Test
public void testTextRootNode() throws IOException {
    // Create empty node.
    final byte[] value = { (byte) 17, (byte) 18 };
    final NodeDelegate del = new NodeDelegate(13, 14, 0, 0, Optional.of(SirixDeweyID.newRootID()));
    final ValNodeDelegate valDel = new ValNodeDelegate(del, value, false);
    final StructNodeDelegate strucDel = new StructNodeDelegate(del, Fixed.NULL_NODE_KEY.getStandardProperty(), 16l, 15l, 0l, 0l);
    final TextNode node = new TextNode(valDel, strucDel);
    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 TextNode node2 = (TextNode) Kind.TEXT.deserialize(new DataInputStream(in), node.getNodeKey(), node.getDeweyID(), mPageReadTrx);
    check(node2);
}
Also used : StructNodeDelegate(org.sirix.node.delegates.StructNodeDelegate) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ValNodeDelegate(org.sirix.node.delegates.ValNodeDelegate) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) NodeDelegate(org.sirix.node.delegates.NodeDelegate) StructNodeDelegate(org.sirix.node.delegates.StructNodeDelegate) ValNodeDelegate(org.sirix.node.delegates.ValNodeDelegate) Test(org.junit.Test)

Example 4 with ValNodeDelegate

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

the class AttributeNodeTest method testAttributeNode.

@Test
public void testAttributeNode() throws IOException {
    final byte[] value = { (byte) 17, (byte) 18 };
    final NodeDelegate del = new NodeDelegate(99, 13, 0, 0, Optional.of(SirixDeweyID.newRootID()));
    final NameNodeDelegate nameDel = new NameNodeDelegate(del, 13, 14, 15, 1);
    final ValNodeDelegate valDel = new ValNodeDelegate(del, value, false);
    final AttributeNode node = new AttributeNode(del, nameDel, valDel, new QNm("ns", "a", "p"));
    // Create empty node.
    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 AttributeNode node2 = (AttributeNode) Kind.ATTRIBUTE.deserialize(new DataInputStream(in), node.getNodeKey(), node.getDeweyID(), mPageReadTrx);
    check(node2);
}
Also used : QNm(org.brackit.xquery.atomic.QNm) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ValNodeDelegate(org.sirix.node.delegates.ValNodeDelegate) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) NodeDelegate(org.sirix.node.delegates.NodeDelegate) NameNodeDelegate(org.sirix.node.delegates.NameNodeDelegate) ValNodeDelegate(org.sirix.node.delegates.ValNodeDelegate) NameNodeDelegate(org.sirix.node.delegates.NameNodeDelegate) Test(org.junit.Test)

Example 5 with ValNodeDelegate

use of org.sirix.node.delegates.ValNodeDelegate 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)

Aggregations

NodeDelegate (org.sirix.node.delegates.NodeDelegate)6 ValNodeDelegate (org.sirix.node.delegates.ValNodeDelegate)6 NameNodeDelegate (org.sirix.node.delegates.NameNodeDelegate)5 StructNodeDelegate (org.sirix.node.delegates.StructNodeDelegate)5 UnorderedKeyValuePage (org.sirix.page.UnorderedKeyValuePage)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 Test (org.junit.Test)2 QNm (org.brackit.xquery.atomic.QNm)1 AttributeNode (org.sirix.node.AttributeNode)1 CommentNode (org.sirix.node.CommentNode)1 PINode (org.sirix.node.PINode)1 TextNode (org.sirix.node.TextNode)1