private boolean step(Cursor cursor) { return reverse ? cursor.previous() : cursor.next(); }
/** {@inheritDoc} */ @Override public long getRowCount(Session ses) { Cursor cursor = find(ses, null, null); long res = 0; while (cursor.next()) res++; return res; }
/** {@inheritDoc} */ @Override public long getRowCount(Session ses) { Cursor c = find(ses, null, null); long cnt = 0; while (c.next()) cnt++; return cnt; }
@Override public boolean next() { while (true) { if (cursor == null) { nextCursor(); if (cursor == null) { return false; } } if (cursor.next()) { return true; } cursor = null; } }
@Override public Cursor findFirstOrLast(Session session, boolean first) { Cursor cursor; if (first) { cursor = mainIndex.find(session, Long.MIN_VALUE, Long.MAX_VALUE, false); } else { long x = mainIndex.getLastKey(); cursor = mainIndex.find(session, x, x, false); } cursor.next(); return cursor; }
/** * Check if there is an uncommitted row with the given key * within a different session. * * @param session the original session * @param row the row (only the key is checked) * @return true if there is an uncommitted row */ public boolean isUncommittedFromOtherSession(Session session, Row row) { Cursor c = delta.find(session, row, row); while (c.next()) { Row r = c.get(); return r.getSessionId() != session.getId(); } return false; }
private void checkMetaFree(Session session, int id) { SearchRow r = meta.getTemplateSimpleRow(false); r.setValue(0, ValueInt.get(id)); Cursor cursor = metaIdIndex.find(session, r, r); if (cursor.next()) { DbException.throwInternalError(); } }
/** * Advance iterator. */ private void advance() { next = null; try { boolean hasNext = false; while (cursor == null || !(hasNext = cursor.next())) { if (idxIter.hasNext()) cursor = idxIter.next().findInStream(null, null); else { releaseIfNeeded(); break; } } if (hasNext) { Row row = cursor.get(); int cols = row.getColumnCount(); List<Object> res = new ArrayList<>(cols); for (int c = 0; c < cols; c++) res.add(row.getValue(c).getObject()); next = res; } } catch (Exception e) { releaseIfNeeded(); throw e; } }
public BitField getObjectIds() { BitField f = new BitField(); Cursor cursor = metaIndex.find(pageStoreSession, null, null); while (cursor.next()) { Row row = cursor.get(); int id = row.getValue(0).getInt(); if (id > 0) { f.set(id); } } return f; }
private void readMetaData() { Cursor cursor = metaIndex.find(pageStoreSession, null, null); // first, create all tables while (cursor.next()) { Row row = cursor.get(); int type = row.getValue(1).getInt(); if (type == META_TYPE_DATA_INDEX) { addMeta(row, pageStoreSession, false); } } // now create all secondary indexes // otherwise the table might not be created yet cursor = metaIndex.find(pageStoreSession, null, null); while (cursor.next()) { Row row = cursor.get(); int type = row.getValue(1).getInt(); if (type != META_TYPE_DATA_INDEX) { addMeta(row, pageStoreSession, false); } } }
private void rebuildIndexBuffered(Session session, Index index) { Index scan = getScanIndex(session); long remaining = scan.getRowCount(session); long total = remaining; Cursor cursor = scan.find(session, null, null); long i = 0; int bufferSize = (int) Math.min(total, database.getMaxMemoryRows()); ArrayList<Row> buffer = new ArrayList<>(bufferSize); String n = getName() + ":" + index.getName(); int t = MathUtils.convertLongToInt(total); while (cursor.next()) { Row row = cursor.get(); buffer.add(row); database.setProgress(DatabaseEventListener.STATE_CREATE_INDEX, n, MathUtils.convertLongToInt(i++), t); if (buffer.size() >= bufferSize) { addRowsToIndex(session, buffer, index); } remaining--; } addRowsToIndex(session, buffer, index); if (SysProperties.CHECK && remaining != 0) { DbException.throwInternalError("rowcount remaining=" + remaining + " " + getName()); } }
private Cursor find(Row row) { if (index == null) { // for the case "in(select ...)", the query might // use an optimization and not create the index // up front createIndex(); } Cursor cursor = index.find(session, row, row); while (cursor.next()) { SearchRow found = cursor.getSearchRow(); boolean ok = true; Database db = session.getDatabase(); for (int i = 0; i < row.getColumnCount(); i++) { if (!db.areEqual(row.getValue(i), found.getValue(i))) { ok = false; break; } } if (ok) { return cursor; } } return null; }
private boolean existsRow(Session session, Index searchIndex, SearchRow check, Row excluding) { Table searchTable = searchIndex.getTable(); searchTable.lock(session, false, false); Cursor cursor = searchIndex.find(session, check, check); while (cursor.next()) { SearchRow found; found = cursor.getSearchRow(); if (excluding != null && found.getKey() == excluding.getKey()) { continue; } Column[] cols = searchIndex.getColumns(); boolean allEqual = true; int len = Math.min(columns.length, cols.length); for (int i = 0; i < len; i++) { int idx = cols[i].getColumnId(); Value c = check.getValue(idx); Value f = found.getValue(idx); if (searchTable.compareTypeSafe(c, f) != 0) { allEqual = false; break; } } if (allEqual) { return true; } } return false; }
private boolean removeIfExists(Session session, Row row) { // maybe it was inserted by the same session just before Cursor c = delta.find(session, row, row); while (c.next()) { Row r = c.get(); if (r.getKey() == row.getKey() && r.getVersion() == row.getVersion()) { if (r != row && table.getScanIndex(session).compareRows(r, row) != 0) { row.setVersion(r.getVersion() + 1); } else { delta.remove(session, r); return true; } } } return false; }
@Override public Value[] next() { if (resultCursor == null) { Index idx; if (distinct || sort != null) { idx = index; } else { idx = table.getScanIndex(session); } if (session.getDatabase().getMvStore() != null) { // sometimes the transaction is already committed, // in which case we can't use the session if (idx.getRowCount(session) == 0 && rowCount > 0) { // this means querying is not transactional resultCursor = idx.find((Session) null, null, null); } else { // the transaction is still open resultCursor = idx.find(session, null, null); } } else { resultCursor = idx.find(session, null, null); } } if (!resultCursor.next()) { return null; } Row row = resultCursor.get(); return row.getValueList(); }
while (cursor.next()) { SearchRow row = cursor.getSearchRow(); Value v = row.getValue(columnIds[0]);
while (cursor.next()) { SearchRow row = cursor.getSearchRow(); Value v = row.getValue(columnIds[0]);
while (cursor.next()) { SearchRow row = cursor.getSearchRow(); Value v = row.getValue(firstColumn.getColumnId());
boolean wasLocked = lockMeta(session); Cursor cursor = metaIdIndex.find(session, r, r); if (cursor.next()) { if (SysProperties.CHECK) { if (lockMode != Constants.LOCK_MODE_OFF && !wasLocked) {
setCurrentRowNumber(rowNumber + 1); Cursor cursor = index.findNext(session, first, null); if (!cursor.next()) { break;