use of org.sirix.node.delegates.StructNodeDelegate in project sirix by sirixdb.
the class NodePageTest method testSerializeDeserialize.
@Test
public void testSerializeDeserialize() throws IOException {
final UnorderedKeyValuePage page1 = new UnorderedKeyValuePage(0L, PageKind.RECORDPAGE, Constants.NULL_ID_LONG, mPageReadTrx);
assertEquals(0L, page1.getPageKey());
final NodeDelegate del = new NodeDelegate(0, 1, 0, 0, Optional.of(SirixDeweyID.newRootID()));
final StructNodeDelegate strucDel = new StructNodeDelegate(del, 12l, 4l, 3l, 1l, 0l);
final NameNodeDelegate nameDel = new NameNodeDelegate(del, 5, 6, 7, 1);
final ElementNode node1 = new ElementNode(strucDel, nameDel, new ArrayList<Long>(), HashBiMap.<Long, Long>create(), new ArrayList<Long>(), new QNm("a", "b", "c"));
node1.insertAttribute(88L, 100);
node1.insertAttribute(87L, 101);
node1.insertNamespace(99L);
node1.insertNamespace(98L);
assertEquals(0L, node1.getNodeKey());
page1.setEntry(node1.getNodeKey(), node1);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final DataOutputStream dataOut = new DataOutputStream(out);
PagePersistenter.serializePage(dataOut, page1, SerializationType.DATA);
final ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
final UnorderedKeyValuePage page2 = (UnorderedKeyValuePage) PagePersistenter.deserializePage(new DataInputStream(in), mPageReadTrx, SerializationType.DATA);
// assertEquals(position, out.position());
final ElementNode element = (ElementNode) page2.getValue(0l);
assertEquals(0L, page2.getValue(0l).getNodeKey());
assertEquals(1L, element.getParentKey());
assertEquals(12L, element.getFirstChildKey());
assertEquals(3L, element.getLeftSiblingKey());
assertEquals(4L, element.getRightSiblingKey());
assertEquals(1, element.getChildCount());
assertEquals(2, element.getAttributeCount());
assertEquals(2, element.getNamespaceCount());
assertEquals(88L, element.getAttributeKey(0));
assertEquals(87L, element.getAttributeKey(1));
assertEquals(99L, element.getNamespaceKey(0));
assertEquals(98L, element.getNamespaceKey(1));
assertEquals(5, ((NameNode) page2.getValue(0l)).getURIKey());
assertEquals(6, ((NameNode) page2.getValue(0l)).getPrefixKey());
assertEquals(7, ((NameNode) page2.getValue(0l)).getLocalNameKey());
assertEquals(NamePageHash.generateHashForString("xs:untyped"), element.getTypeKey());
}
use of org.sirix.node.delegates.StructNodeDelegate in project sirix by sirixdb.
the class NodeFactoryImpl method createPathNode.
@Override
public PathNode createPathNode(@Nonnegative final long parentKey, @Nonnegative final long leftSibKey, final long rightSibKey, final long hash, @Nonnull final QNm name, @Nonnull final Kind kind, @Nonnegative final int level) throws SirixIOException {
final int uriKey = NamePageHash.generateHashForString(name.getNamespaceURI());
final int prefixKey = name.getPrefix() != null && !name.getPrefix().isEmpty() ? NamePageHash.generateHashForString(name.getPrefix()) : -1;
final int localName = name.getLocalName() != null && !name.getLocalName().isEmpty() ? NamePageHash.generateHashForString(name.getLocalName()) : -1;
final long revision = mPageWriteTrx.getRevisionNumber();
final NodeDelegate nodeDel = new NodeDelegate(((PathSummaryPage) mPageWriteTrx.getActualRevisionRootPage().getPathSummaryPageReference().getPage()).getMaxNodeKey(0) + 1, parentKey, 0, revision, Optional.<SirixDeweyID>empty());
final StructNodeDelegate structDel = new StructNodeDelegate(nodeDel, Fixed.NULL_NODE_KEY.getStandardProperty(), rightSibKey, leftSibKey, 0, 0);
final NameNodeDelegate nameDel = new NameNodeDelegate(nodeDel, uriKey, prefixKey, localName, 0);
return (PathNode) mPageWriteTrx.createEntry(nodeDel.getNodeKey(), new PathNode(nodeDel, structDel, nameDel, kind, 1, level), PageKind.PATHSUMMARYPAGE, 0, Optional.<UnorderedKeyValuePage>empty());
}
use of org.sirix.node.delegates.StructNodeDelegate 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.StructNodeDelegate 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.StructNodeDelegate 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);
}
Aggregations