private static RelationList findRelationList(Cons<Pair<String, RelationList>> allLists, Object lastList, String attrName) { while (allLists != lastList) { Pair<String, RelationList> list = allLists.first(); // it is not safe to use == instead of equals(Object) to // compare Strings here because this method may be // called with non-interned strings (when reading the changelogs from DB) if (list.first.equals(attrName)) { return list.second; } allLists = allLists.rest(); } return null; }
public E get(int index) { if (index > (size - 1)) { throw new NoSuchElementException(); } else { Cons<E> iter = elems; while (index-- > 0) { iter = iter.rest(); } return iter.first(); } }
private static VBox[] borrowFromPool() { Cons<VBox[]> available = pool.get(); if (available.isEmpty()) { VBox[] newArray = new VBox[1000]; return newArray; } else { pool.set(available.rest()); return available.first(); } }
protected <T> void addToReadSet(VBox<T> vbox) { VBox[] readset = null; if (next < 0) { readset = borrowFromPool(); next = readset.length - 1; bodiesRead = bodiesRead.cons(readset); } else { readset = bodiesRead.first(); } readset[next--] = vbox; }
@Override @Atomic(readOnly = true) public E element() { Cons<E> frontElems = front.get(); if (frontElems.isEmpty()) { throw new NoSuchElementException(); } else { return frontElems.first(); } }
protected <T> T readGlobal(VBox<T> vbox) { VBoxBody<T> body = vbox.body; if (body.version > number) { TransactionSignaller.SIGNALLER.signalEarlyAbort(); } ReadBlock readBlock = null; if (next < 0) { if (blocksFree.get().get() > 0) { for (ReadBlock poolBlock : blocksPool.get()) { if (poolBlock.free) { poolBlock.free = false; readBlock = poolBlock; blocksFree.get().decrementAndGet(); break; } } } else { readBlock = new ReadBlock(blocksFree.get()); } next = 999; globalReads = globalReads.cons(readBlock); } else { readBlock = globalReads.first(); } readBlock.entries[next--] = vbox; return body.value; }
private SimpleReadSet makeSimpleReadSet() { HashSet<String> vboxIds = new HashSet<String>(); if (!this.bodiesRead.isEmpty()) { // the first may not be full jvstm.VBox[] array = this.bodiesRead.first(); for (int i = next + 1; i < array.length; i++) { String vboxId = ((VBox) array[i]).getId(); vboxIds.add(vboxId); } // the rest are full for (jvstm.VBox[] ar : bodiesRead.rest()) { for (int i = 0; i < ar.length; i++) { String vboxId = ((VBox) array[i]).getId(); vboxIds.add(vboxId); } } } return new SimpleReadSet(vboxIds.toArray(new String[vboxIds.size()])); }
@Override @Atomic(readOnly = true) public E peek() { Cons<E> frontElems = front.get(); if (frontElems.isEmpty()) { return null; } else { return frontElems.first(); } }
Cons<VBox[]> myArrays = this.bodiesRead; while (myArrays != parentArrays) { returnToPool(myArrays.first()); myArrays = myArrays.rest();
@Override protected void deleteDomainObject() { super.deleteDomainObject(); // Mark the VState as deleted obj$state.markAsDeleted(); // Ensure that all RelationLists exist... create$allLists(); Cons<Pair<String, RelationList>> lists = relationLists; while (lists != (Object) Cons.empty()) { // ... and mark them as deleted lists.first().second.markAsDeleted(); lists = lists.rest(); } } }
protected boolean isSnapshotValidationWorthIt(ActiveTransactionsRecord lastRecord) { if (this.bodiesRead.isEmpty()) { return false; } int numberOfReadsToCheck = this.bodiesRead.first().length - (next + 1); // if there are more arrays the rest are full, for sure for (VBox[] array : bodiesRead.rest()) { numberOfReadsToCheck += array.length; } int numberOfWritesToCheck = 0; for (ActiveTransactionsRecord rec = this.activeTxRecord.getNext(); rec != null; rec = rec.getNext()) { numberOfWritesToCheck += rec.getWriteSet().size(); } return ((float) numberOfWritesToCheck) / numberOfReadsToCheck > WR_THRESHOLD; }
protected void validateGlobalReads(Cons<ReadBlock> reads, int startIdx) { VBox[] array = reads.first().entries; // the first may not be full for (int i = startIdx + 1; i < array.length; i++) { InplaceWrite iter = array[i].inplace; do { int maxVersion = retrieveAncestorVersion(iter.orec.owner); if (maxVersion >= 0) { manualAbort(); TransactionSignaller.SIGNALLER.signalCommitFail(iter.orec.owner); } iter = iter.next; } while (iter != null); } // the rest are full for (ReadBlock block : reads.rest()) { array = block.entries; for (int i = 0; i < array.length; i++) { InplaceWrite iter = array[i].inplace; do { int maxVersion = retrieveAncestorVersion(iter.orec.owner); if (maxVersion >= 0) { manualAbort(); TransactionSignaller.SIGNALLER.signalCommitFail(iter.orec.owner); } iter = iter.next; } while (iter != null); } } }
private E removeExisting(Cons<E> frontElems) { E result = frontElems.first(); frontElems = frontElems.rest(); if (frontElems.isEmpty()) { frontElems = rear.get().reverse(); if (!frontElems.isEmpty()) { // only clear the rear if it had anything rear.put((Cons<E>) Cons.empty()); } } front.put(frontElems); size.dec(); return result; }