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());
}
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());
}
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);
}
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);
}
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());
}
Aggregations