public SqlJetScope reverse() { SqlJetScopeBound rightBound = getRightBound() != null ? new SqlJetScopeBound(getRightBound().getValue(), getRightBound().isInclusive()) : null; SqlJetScopeBound leftBound = getLeftBound() != null ? new SqlJetScopeBound(getLeftBound().getValue(), getLeftBound().isInclusive()) : null; return new SqlJetScope(rightBound, leftBound); }
public String toString() { return getLeftBound() + ":" + getRightBound(); } }
/** * @param table * @param db * @param indexName * @param firstKey * @param lastKey * @throws SqlJetException */ public SqlJetIndexScopeCursor(ISqlJetBtreeDataTable table, SqlJetDb db, String indexName, Object[] firstKey, Object[] lastKey) throws SqlJetException { this(table, db, indexName, new SqlJetScope(firstKey, lastKey)); }
public Object runWithLock(SqlJetDb db) throws SqlJetException { final SqlJetBtreeDataTable table = new SqlJetBtreeDataTable(btree, tableName, write); checkIndexName(indexName, table); if (isNeedReverse(getIndexTable(indexName, table), adjustedScope)) { return new SqlJetReverseOrderCursor(new SqlJetIndexScopeCursor(table, db, indexName, adjustedScope.reverse())); } else { return new SqlJetIndexScopeCursor(table, db, indexName, adjustedScope); } } });
/** * @param indexName * @param scope * @param reverse * @param table * @return * @throws SqlJetException */ private boolean isNeedReverse(final ISqlJetBtreeIndexTable indexTable, SqlJetScope scope) throws SqlJetException { Object[] firstKey = scope.getLeftBound() != null ? scope.getLeftBound().getValue() : null; Object[] lastKey = scope.getRightBound() != null ? scope.getRightBound().getValue() : null; if (firstKey != null && lastKey != null && firstKey.length > 0 && lastKey.length > 0) { if (indexTable != null) { return indexTable.compareKeys(firstKey, lastKey) < 0; } else if (firstKey.length == 1 && lastKey.length == 1 && firstKey[0] instanceof Long && lastKey[0] instanceof Long) { return ((Long) firstKey[0]).compareTo((Long) lastKey[0]) > 0; } } return false; }
public ISqlJetCursor scope(final String indexName, final Object[] firstKey, final Object[] lastKey) throws SqlJetException { return scope(indexName, new SqlJetScope(firstKey, lastKey)); }
public static final SqlJetScope adjustScopeNumberTypes(SqlJetScope scope) { if (null == scope) return null; SqlJetScopeBound leftBound = scope.getLeftBound(); SqlJetScopeBound rightBound = scope.getRightBound(); if (leftBound != null) { leftBound = new SqlJetScopeBound(adjustNumberTypes(leftBound.getValue()), leftBound.isInclusive()); } if (rightBound != null) { rightBound = new SqlJetScopeBound(adjustNumberTypes(rightBound.getValue()), rightBound.isInclusive()); } return new SqlJetScope(leftBound, rightBound); }
/** * @param table * @param db * @param indexName * @param scope * @throws SqlJetException */ public SqlJetIndexScopeCursor(ISqlJetBtreeDataTable table, SqlJetDb db, String indexName, SqlJetScope scope) throws SqlJetException { super(table, db, indexName); this.firstKey = SqlJetUtility.copyArray(scope.getLeftBound() != null ? scope.getLeftBound().getValue() : null); this.firstKeyIncluded = scope.getLeftBound() != null ? scope.getLeftBound().isInclusive() : true; this.lastKey = SqlJetUtility.copyArray(scope.getRightBound() != null ? scope.getRightBound().getValue() : null); this.lastKeyIncluded = scope.getRightBound() != null ? scope.getRightBound().isInclusive() : true; if (null == indexTable) { firstRowId = getRowIdFromKey(this.firstKey); lastRowId = getRowIdFromKey(this.lastKey); if (!firstKeyIncluded && firstRowId > 0) { firstRowId++; } if (!lastKeyIncluded && lastRowId > 0) { lastRowId--; } } first(); }