use of org.sirix.node.interfaces.Record in project sirix by sirixdb.
the class UnorderedKeyValuePage method getValue.
@Override
public Record getValue(final Long key) {
assert key != null : "key must not be null!";
Record record = mRecords.get(key);
if (record == null) {
byte[] data = null;
try {
final PageReference reference = mReferences.get(key);
if (reference != null && reference.getKey() != Constants.NULL_ID_LONG) {
data = ((OverflowPage) mPageReadTrx.getReader().read(reference, mPageReadTrx)).getData();
} else {
return null;
}
} catch (final SirixIOException e) {
return null;
}
final InputStream in = new ByteArrayInputStream(data);
try {
record = mPersistenter.deserialize(new DataInputStream(in), key, Optional.empty(), null);
} catch (final IOException e) {
return null;
}
mRecords.put(key, record);
}
return record;
}
use of org.sirix.node.interfaces.Record in project sirix by sirixdb.
the class XdmResourceManager method beginNodeWriteTrx.
@Override
public synchronized XdmNodeWriteTrx beginNodeWriteTrx(@Nonnegative final int maxNodeCount, @Nonnull final TimeUnit timeUnit, @Nonnegative final int maxTime) {
// Checks.
assertAccess(mLastCommittedUberPage.get().getRevision());
if (maxNodeCount < 0 || maxTime < 0) {
throw new SirixUsageException("maxNodeCount may not be < 0!");
}
checkNotNull(timeUnit);
// Make sure not to exceed available number of write transactions.
try {
if (!mWriteSemaphore.tryAcquire(20, TimeUnit.SECONDS)) {
throw new SirixUsageException("No write transaction available, please close the write transaction first.");
}
} catch (final InterruptedException e) {
throw new SirixThreadedException(e);
}
// Create new page write transaction (shares the same ID with the node write trx).
final long currentTrxID = mNodeTrxIDCounter.incrementAndGet();
final int lastRev = mLastCommittedUberPage.get().getRevisionNumber();
final PageWriteTrx<Long, Record, UnorderedKeyValuePage> pageWtx = createPageWriteTransaction(currentTrxID, lastRev, lastRev, Abort.NO);
final Node documentNode = getDocumentNode(pageWtx);
// Create new node write transaction.
final XdmNodeWriteTrx wtx = new XdmNodeWriterTrxImpl(currentTrxID, this, pageWtx, maxNodeCount, timeUnit, maxTime, documentNode);
// Remember node transaction for debugging and safe close.
if (mNodeReaderMap.put(currentTrxID, wtx) != null || mNodePageTrxMap.put(currentTrxID, pageWtx) != null) {
throw new SirixThreadedException("ID generation is bogus because of duplicate ID.");
}
return wtx;
}
use of org.sirix.node.interfaces.Record 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.node.interfaces.Record 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.node.interfaces.Record 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