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