use of org.sirix.page.UnorderedKeyValuePage 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.page.UnorderedKeyValuePage 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());
}
use of org.sirix.page.UnorderedKeyValuePage in project sirix by sirixdb.
the class PageReadTrxImpl method getRecord.
@Override
public Optional<Record> getRecord(final long nodeKey, final PageKind pageKind, @Nonnegative final int index) {
checkNotNull(pageKind);
assertNotClosed();
if (nodeKey == Fixed.NULL_NODE_KEY.getStandardProperty()) {
return Optional.empty();
}
final long recordPageKey = pageKey(nodeKey);
final PageContainer cont;
try {
switch(pageKind) {
case RECORDPAGE:
case PATHSUMMARYPAGE:
case PATHPAGE:
case CASPAGE:
case NAMEPAGE:
cont = mNodeCache.get(new IndexLogKey(pageKind, recordPageKey, index));
break;
default:
throw new IllegalStateException();
}
} catch (final ExecutionException | UncheckedExecutionException e) {
throw new SirixIOException(e.getCause());
}
if (PageContainer.emptyInstance().equals(cont)) {
return Optional.empty();
}
final Record retVal = ((UnorderedKeyValuePage) cont.getComplete()).getValue(nodeKey);
return checkItemIfDeleted(retVal);
}
use of org.sirix.page.UnorderedKeyValuePage in project sirix by sirixdb.
the class PageWriteTrxImpl method prepareEntryForModification.
@Override
public Record prepareEntryForModification(@Nonnegative final Long recordKey, final PageKind pageKind, final int index, final Optional<UnorderedKeyValuePage> keyValuePage) throws SirixIOException {
mPageRtx.assertNotClosed();
checkNotNull(recordKey);
checkArgument(recordKey >= 0, "recordKey must be >= 0!");
checkNotNull(pageKind);
checkNotNull(keyValuePage);
final long recordPageKey = mPageRtx.pageKey(recordKey);
final PageContainer cont = prepareRecordPage(recordPageKey, index, pageKind);
Record record = ((UnorderedKeyValuePage) cont.getModified()).getValue(recordKey);
if (record == null) {
final Record oldRecord = ((UnorderedKeyValuePage) cont.getComplete()).getValue(recordKey);
if (oldRecord == null) {
throw new SirixIOException("Cannot retrieve record from cache!");
}
record = oldRecord;
((UnorderedKeyValuePage) cont.getModified()).setEntry(record.getNodeKey(), record);
}
return record;
}
use of org.sirix.page.UnorderedKeyValuePage in project sirix by sirixdb.
the class PageWriteTrxImpl method createEntry.
@Override
public Record createEntry(final Long key, final Record record, final PageKind pageKind, final int index, final Optional<UnorderedKeyValuePage> keyValuePage) throws SirixIOException {
mPageRtx.assertNotClosed();
// Allocate record key and increment record count.
long recordKey;
switch(pageKind) {
case RECORDPAGE:
recordKey = mNewRoot.incrementAndGetMaxNodeKey();
break;
case PATHSUMMARYPAGE:
final PathSummaryPage pathSummaryPage = ((PathSummaryPage) mNewRoot.getPathSummaryPageReference().getPage());
recordKey = pathSummaryPage.incrementAndGetMaxNodeKey(index);
break;
case CASPAGE:
final CASPage casPage = ((CASPage) mNewRoot.getCASPageReference().getPage());
recordKey = casPage.incrementAndGetMaxNodeKey(index);
break;
case PATHPAGE:
final PathPage pathPage = ((PathPage) mNewRoot.getPathPageReference().getPage());
recordKey = pathPage.incrementAndGetMaxNodeKey(index);
break;
case NAMEPAGE:
final NamePage namePage = ((NamePage) mNewRoot.getNamePageReference().getPage());
recordKey = namePage.incrementAndGetMaxNodeKey(index);
break;
default:
throw new IllegalStateException();
}
final long recordPageKey = mPageRtx.pageKey(recordKey);
final PageContainer cont = prepareRecordPage(recordPageKey, index, pageKind);
@SuppressWarnings("unchecked") final KeyValuePage<Long, Record> modified = (KeyValuePage<Long, Record>) cont.getModified();
modified.setEntry(record.getNodeKey(), record);
return record;
}
Aggregations