use of org.sirix.node.delegates.NameNodeDelegate 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.NameNodeDelegate 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);
}
use of org.sirix.node.delegates.NameNodeDelegate 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());
}
use of org.sirix.node.delegates.NameNodeDelegate 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());
}
Aggregations