@Test public void testTupleBrowserRemove() throws Exception { BufferManagerImpl bm = BufferManagerFactory.getTestBufferManager(1, 1); ElementSymbol e1 = new ElementSymbol("x"); e1.setType(Integer.class); ElementSymbol e2 = new ElementSymbol("x"); e2.setType(Integer.class); List<ElementSymbol> elements = Arrays.asList(e1, e2); STree map = bm.createSTree(elements, "1", 2); map.insert(Arrays.asList(1, 1), InsertMode.NEW, -1); TupleBrowser tb = new TupleBrowser(map, new CollectionTupleSource(Collections.singletonList(Arrays.asList(1)).iterator()), true, false); assertNotNull(tb.nextTuple()); tb.removed(); assertEquals(Integer.valueOf(0), tb.getValueCount()); }
public List insert(List tuple, InsertMode mode, int sizeHint) throws TeiidComponentException { if (tuple.size() != this.leafManager.getTypes().length) { throw new AssertionError("Invalid tuple."); } LinkedList<SearchResult> places = new LinkedList<SearchResult>(); List match = null; if (this.lobManager != null) { this.lobManager.updateReferences(tuple, ReferenceMode.CREATE); } if (mode == InsertMode.ORDERED) { SPage last = null; while (last == null || last.children != null) { last = findChildTail(last); List<List<?>> batch = last.getValues(); places.add(new SearchResult(-batch.size() -1, last, batch)); } } else { match = find(tuple, places); if (match != null) { if (mode != InsertMode.UPDATE) { return match; } SearchResult last = places.getLast(); SPage page = last.page; last.values.set(last.index, tuple); page.setValues(last.values); if (this.lobManager != null) { this.lobManager.updateReferences(tuple, ReferenceMode.REMOVE); } return match; } } List key = extractKey(tuple); int level = 0; if (mode != InsertMode.ORDERED) { if (sizeHint > -1) { level = Math.min(sizeHint, randomLevel()); } else { level = randomLevel(); } } else if (!places.isEmpty() && places.getLast().values.size() == getPageSize(true)) { long row = rowCount.get(); while (row != 0 && row%getPageSize(true) == 0) { row = (row - getPageSize(true) + 1)/getPageSize(true); level++; } } assert header.length == places.size(); if (level >= header.length) { header = Arrays.copyOf(header, level + 1); } rowCount.addAndGet(1); SPage page = null; for (int i = 0; i <= level; i++) { if (places.isEmpty()) { SPage newHead = new SPage(this, false); List<List<?>> batch = newHead.getValues(); batch.add(key); newHead.setValues(batch); newHead.children.add(page); header[i] = newHead; page = newHead; } else { SearchResult result = places.removeLast(); Object value = (i == 0 ? tuple : page); page = insert(key, result, places.peekLast(), value, mode == InsertMode.ORDERED); } } return null; }
STree implements Cloneable { public List insert(List tuple, InsertMode mode, int sizeHint) throws TeiidComponentException { if (tuple.size() != this.leafManager.getTypes().length) { throw new AssertionError("Invalid tuple."); } LinkedList<SearchResult> places = new LinkedList<SearchResult>(); List match = null; if (this.lobManager != null) { this.lobManager.updateReferences(tuple, ReferenceMode.CREATE); } if (mode == InsertMode.ORDERED) { SPage last = null; while (last == null || last.children != null) { last = findChildTail(last); List<List<?>> batch = last.getValues(); places.add(new SearchResult(-batch.size() -1, last, batch)); } } else { match = find(tuple, places); if (match != null) { if (mode != InsertMode.UPDATE) { return match; } SearchResult last = places.getLast(); SPage page = last.page; last.values.set(last.index, tuple); page.setValues(last.values); if (this.lobManager != null) { this.lobManager.updateReferences(tuple, ReferenceMode.REMOVE); } return match; } } List key = extractKey(tuple); int level = 0; if (mode != InsertMode.ORDERED) { if (sizeHint > -1) { level = Math.min(sizeHint, randomLevel()); } else { level = randomLevel(); } } else if (!places.isEmpty() && places.getLast().values.size() == getPageSize(true)) { long row = rowCount.get(); while (row != 0 && row%getPageSize(true) == 0) { row = (row - getPageSize(true) + 1)/getPageSize(true); level++; } } assert header.length == places.size(); if (level >= header.length) { header = Arrays.copyOf(header, level + 1); } rowCount.addAndGet(1); SPage page = null; for (int i = 0; i <= level; i++) { if (places.isEmpty()) { SPage newHead = new SPage(this, false); List<List<?>> batch = newHead.getValues(); batch.add(key); newHead.setValues(batch); newHead.children.add(page); header[i] = newHead; page = newHead; } else { SearchResult result = places.removeLast(); Object value = (i == 0 ? tuple : page); page = insert(key, result, places.peekLast(), value, mode == InsertMode.ORDERED); } } return null; } }
STree implements Cloneable { public List insert(List tuple, InsertMode mode, int sizeHint) throws TeiidComponentException { if (tuple.size() != this.leafManager.getTypes().length) { throw new AssertionError("Invalid tuple."); } LinkedList<SearchResult> places = new LinkedList<SearchResult>(); List match = null; if (this.lobManager != null) { this.lobManager.updateReferences(tuple, ReferenceMode.CREATE); } if (mode == InsertMode.ORDERED) { SPage last = null; while (last == null || last.children != null) { last = findChildTail(last); List<List<?>> batch = last.getValues(); places.add(new SearchResult(-batch.size() -1, last, batch)); } } else { match = find(tuple, places); if (match != null) { if (mode != InsertMode.UPDATE) { return match; } SearchResult last = places.getLast(); SPage page = last.page; last.values.set(last.index, tuple); page.setValues(last.values); if (this.lobManager != null) { this.lobManager.updateReferences(tuple, ReferenceMode.REMOVE); } return match; } } List key = extractKey(tuple); int level = 0; if (mode != InsertMode.ORDERED) { if (sizeHint > -1) { level = Math.min(sizeHint, randomLevel()); } else { level = randomLevel(); } } else if (!places.isEmpty() && places.getLast().values.size() == getPageSize(true)) { long row = rowCount.get(); while (row != 0 && row%getPageSize(true) == 0) { row = (row - getPageSize(true) + 1)/getPageSize(true); level++; } } assert header.length == places.size(); if (level >= header.length) { header = Arrays.copyOf(header, level + 1); } rowCount.addAndGet(1); SPage page = null; for (int i = 0; i <= level; i++) { if (places.isEmpty()) { SPage newHead = new SPage(this, false); List<List<?>> batch = newHead.getValues(); batch.add(key); newHead.setValues(batch); newHead.children.add(page); header[i] = newHead; page = newHead; } else { SearchResult result = places.removeLast(); Object value = (i == 0 ? tuple : page); page = insert(key, result, places.peekLast(), value, mode == InsertMode.ORDERED); } } return null; } STree(BatchManager manager,
            BatchManager leafManager,
            final ListNestedSortComparator comparator,
            int pageSize,
            int leafSize,
            int keyLength,
            LobManager lobManager); }
STree implements Cloneable { public List insert(List tuple, InsertMode mode, int sizeHint) throws TeiidComponentException { if (tuple.size() != this.leafManager.getTypes().length) { throw new AssertionError("Invalid tuple."); } LinkedList<SearchResult> places = new LinkedList<SearchResult>(); List match = null; if (this.lobManager != null) { this.lobManager.updateReferences(tuple, ReferenceMode.CREATE); } if (mode == InsertMode.ORDERED) { SPage last = null; while (last == null || last.children != null) { last = findChildTail(last); List<List<?>> batch = last.getValues(); places.add(new SearchResult(-batch.size() -1, last, batch)); } } else { match = find(tuple, places); if (match != null) { if (mode != InsertMode.UPDATE) { return match; } SearchResult last = places.getLast(); SPage page = last.page; last.values.set(last.index, tuple); page.setValues(last.values); if (this.lobManager != null) { this.lobManager.updateReferences(tuple, ReferenceMode.REMOVE); } return match; } } List key = extractKey(tuple); int level = 0; if (mode != InsertMode.ORDERED) { if (sizeHint > -1) { level = Math.min(sizeHint, randomLevel()); } else { level = randomLevel(); } } else if (!places.isEmpty() && places.getLast().values.size() == getPageSize(true)) { long row = rowCount.get(); while (row != 0 && row%getPageSize(true) == 0) { row = (row - getPageSize(true) + 1)/getPageSize(true); level++; } } assert header.length == places.size(); if (level >= header.length) { header = Arrays.copyOf(header, level + 1); } rowCount.addAndGet(1); SPage page = null; for (int i = 0; i <= level; i++) { if (places.isEmpty()) { SPage newHead = new SPage(this, false); List<List<?>> batch = newHead.getValues(); batch.add(key); newHead.setValues(batch); newHead.children.add(page); header[i] = newHead; page = newHead; } else { SearchResult result = places.removeLast(); Object value = (i == 0 ? tuple : page); page = insert(key, result, places.peekLast(), value, mode == InsertMode.ORDERED); } } return null; } STree(BatchManager manager,
            BatchManager leafManager,
            final ListNestedSortComparator comparator,
            int pageSize,
            int leafSize,
            int keyLength,
            LobManager lobManager); STree clone(); void writeValuesTo(ObjectOutputStream oos); void setBatchInsert(boolean batchInsert); void readValuesFrom(ObjectInputStream ois); List find(List n); List insert(List tuple, InsertMode mode, int sizeHint); int getExpectedHeight(long sizeHint); List remove(List key); void remove(); long getRowCount(); long truncate(boolean force); int getHeight(); @Override String toString(); int getKeyLength(); void setPreferMemory(boolean preferMemory); boolean isPreferMemory(); ListNestedSortComparator getComparator(); void compact(); void removeRowIdFromKey(); void clearClonedFlags(); int getPageSize(boolean leaf); TupleSource getTupleSource(final boolean destructive); void setMinStorageSize(int minStorageSize); void setSaveTemporaryLobs(boolean b); }
STree implements Cloneable { public List insert(List tuple, InsertMode mode, int sizeHint) throws TeiidComponentException { if (tuple.size() != this.leafManager.getTypes().length) { throw new AssertionError("Invalid tuple."); } LinkedList<SearchResult> places = new LinkedList<SearchResult>(); List match = null; if (this.lobManager != null) { this.lobManager.updateReferences(tuple, ReferenceMode.CREATE); } if (mode == InsertMode.ORDERED) { SPage last = null; while (last == null || last.children != null) { last = findChildTail(last); List<List<?>> batch = last.getValues(); places.add(new SearchResult(-batch.size() -1, last, batch)); } } else { match = find(tuple, places); if (match != null) { if (mode != InsertMode.UPDATE) { return match; } SearchResult last = places.getLast(); SPage page = last.page; last.values.set(last.index, tuple); page.setValues(last.values); if (this.lobManager != null) { this.lobManager.updateReferences(tuple, ReferenceMode.REMOVE); } return match; } } List key = extractKey(tuple); int level = 0; if (mode != InsertMode.ORDERED) { if (sizeHint > -1) { level = Math.min(sizeHint, randomLevel()); } else { level = randomLevel(); } } else if (!places.isEmpty() && places.getLast().values.size() == getPageSize(true)) { long row = rowCount.get(); while (row != 0 && row%getPageSize(true) == 0) { row = (row - getPageSize(true) + 1)/getPageSize(true); level++; } } assert header.length == places.size(); if (level >= header.length) { header = Arrays.copyOf(header, level + 1); } rowCount.addAndGet(1); SPage page = null; for (int i = 0; i <= level; i++) { if (places.isEmpty()) { SPage newHead = new SPage(this, false); List<List<?>> batch = newHead.getValues(); batch.add(key); newHead.setValues(batch); newHead.children.add(page); header[i] = newHead; page = newHead; } else { SearchResult result = places.removeLast(); Object value = (i == 0 ? tuple : page); page = insert(key, result, places.peekLast(), value, mode == InsertMode.ORDERED); } } return null; } STree(BatchManager manager,
            BatchManager leafManager,
            final ListNestedSortComparator comparator,
            int pageSize,
            int leafSize,
            int keyLength,
            LobManager lobManager); STree clone(); void writeValuesTo(ObjectOutputStream oos); void setBatchInsert(boolean batchInsert); void readValuesFrom(ObjectInputStream ois); List find(List n); List insert(List tuple, InsertMode mode, int sizeHint); int getExpectedHeight(long sizeHint); List remove(List key); void remove(); long getRowCount(); long truncate(boolean force); int getHeight(); @Override String toString(); int getKeyLength(); void setPreferMemory(boolean preferMemory); boolean isPreferMemory(); ListNestedSortComparator getComparator(); void compact(); void removeRowIdFromKey(); void clearClonedFlags(); int getPageSize(boolean leaf); TupleSource getTupleSource(final boolean destructive); void setMinStorageSize(int minStorageSize); void setSaveTemporaryLobs(boolean b);  }