Package org.tmatesoft.sqljet.core.table

Examples of org.tmatesoft.sqljet.core.table.SqlJetScope$SqlJetScopeBound


            }
        });
    }

    public ISqlJetCursor scope(final String indexName, final Object[] firstKey, final Object[] lastKey) throws SqlJetException {
        return scope(indexName, new SqlJetScope(firstKey, lastKey));
    }
View Full Code Here


     *
     * @see org.tmatesoft.sqljet.core.table.ISqlJetTable#scope(java.lang.String,
     * java.lang.Object[], java.lang.Object[])
     */
    public ISqlJetCursor scope(final String indexName, SqlJetScope scopethrows SqlJetException {
        final SqlJetScope adjustedScope = SqlJetUtility.adjustScopeNumberTypes(scope);
        return (ISqlJetCursor) db.runWithLock(new ISqlJetRunnableWithLock() {
            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);
                }
            }
        });
View Full Code Here

     * @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));
    }
View Full Code Here

            leftBound = new SqlJetScopeBound(adjustNumberTypes(leftBound.getValue()), leftBound.isInclusive());
        }
        if (rightBound != null) {
            rightBound = new SqlJetScopeBound(adjustNumberTypes(rightBound.getValue()), rightBound.isInclusive());
        }
        return new SqlJetScope(leftBound, rightBound);
    }
View Full Code Here

    }

    @Test
    public void testOpenScope() throws SqlJetException {
       
        SqlJetScope closedScope = new SqlJetScope(new Object[] {"ABC"}, new Object[] {"XYZ"});
        SqlJetScope openScope = new SqlJetScope(new Object[] {"ABC"}, false, new Object[] {"XYZ"}, false);
        SqlJetScope emptyOpenScope = new SqlJetScope(new Object[] {"ABCD"}, false, new Object[] {"ABCDEF"}, false);
        SqlJetScope notMatchingOpenScope = new SqlJetScope(new Object[] {"AB"}, false, new Object[] {"XY"}, false);
        SqlJetScope notMatchingClosedScope = new SqlJetScope(new Object[] {"AB"}, true, new Object[] {"XY"}, true);
        SqlJetScope outOfBoundsClosedScope = new SqlJetScope(new Object[] {"XYZZZ"}, true, new Object[] {"XYZZZZZ"}, true);
        SqlJetScope outOfBoundsOpenScope = new SqlJetScope(new Object[] {"XYZZ"}, false, new Object[] {"XYZZZZZ"}, true);
        SqlJetScope unbounded = new SqlJetScope((SqlJetScopeBound) null, (SqlJetScopeBound) null);
        SqlJetScope unbounded2 = new SqlJetScope((Object[]) null, (Object[]) null);
       
        assertIndexScope(closedScope, "ABC", "ABCD", "ABCDEF", "XYZ");
        assertIndexScope(closedScope.reverse(), "XYZ", "ABCDEF", "ABCD", "ABC");
        assertIndexScope(openScope, "ABCD", "ABCDEF");
        assertIndexScope(openScope.reverse(), "ABCDEF", "ABCD");
        assertIndexScope(emptyOpenScope);
        assertIndexScope(emptyOpenScope.reverse());
        assertIndexScope(notMatchingClosedScope, "ABC", "ABCD", "ABCDEF");
        assertIndexScope(notMatchingOpenScope, "ABC", "ABCD", "ABCDEF");
        assertIndexScope(outOfBoundsClosedScope);
        assertIndexScope(outOfBoundsOpenScope);

        assertIndexScope(unbounded, "A", "ABC", "ABCD", "ABCDEF", "XYZ", "XYZZ" );
        assertIndexScope(unbounded.reverse(), "A", "ABC", "ABCD", "ABCDEF", "XYZ", "XYZZ" );
        assertIndexScope(unbounded2, "A", "ABC", "ABCD", "ABCDEF", "XYZ", "XYZZ" );
        assertIndexScope(unbounded2.reverse(), "A", "ABC", "ABCD", "ABCDEF", "XYZ", "XYZZ" );
    }
View Full Code Here

        assertIndexScope(unbounded2.reverse(), "A", "ABC", "ABCD", "ABCDEF", "XYZ", "XYZZ" );
    }

    @Test
    public void testNoIndexScope() throws SqlJetException {
        SqlJetScope closedScope = new SqlJetScope(new Object[] {2}, new Object[] {5});
        SqlJetScope openScope = new SqlJetScope(new Object[] {2}, false, new Object[] {5}, false);
        SqlJetScope emptyScope = new SqlJetScope(new Object[] {3}, false, new Object[] {4}, false);
       
        assertNoIndexScope(closedScope, new Long(2), new Long(3), new Long(4), new Long(5));
        assertNoIndexScope(openScope, new Long(3), new Long(4));
        assertNoIndexScope(emptyScope);

        assertNoIndexScope(closedScope.reverse(), Long.valueOf(5),Long.valueOf(4),Long.valueOf(3), Long.valueOf(2));
        assertNoIndexScope(openScope.reverse(), new Long(4), new Long(3));
        assertNoIndexScope(emptyScope.reverse());
       
        db.runWriteTransaction(new ISqlJetTransaction() {
            public Object run(SqlJetDb db) throws SqlJetException {
                db.getTable("noindex").lookup(null, Long.valueOf(3)).delete();
                return null;
            }
        });

        assertNoIndexScope(openScope, new Long(4));
        assertNoIndexScope(openScope.reverse(), new Long(4));

        db.runWriteTransaction(new ISqlJetTransaction() {
            public Object run(SqlJetDb db) throws SqlJetException {
                db.getTable("noindex").insert(3);
                db.getTable("noindex").insert(6);
                return null;
            }
        });
        assertNoIndexScope(openScope, new Long(3), new Long(4));
        assertNoIndexScope(openScope.reverse(), new Long(4), new Long(3));
        assertNoIndexScope(new SqlJetScope((SqlJetScopeBound) null, (SqlJetScopeBound)null),
                 new Long(1), new Long(2), new Long(3), new Long(4), new Long(5), new Long(6));
    }
View Full Code Here

    }

    @Test
    public void testScope() throws SqlJetException {
        Object[] expectedValue = {Long.valueOf(1), Long.valueOf(2)};
        SqlJetScope closedScope = new SqlJetScope(new Object[] {1, 2}, true, new Object[] {1, 2}, true);
        SqlJetScope openScope = new SqlJetScope(new Object[] {1, 1}, false, new Object[] {1, 2}, true);

        assertScope(closedScope, "pairs", "pairs_idx", true, new Object[] {expectedValue, expectedValue});
        assertScope(closedScope, "pairs", "pairs_idx", true, new Object[] {expectedValue, expectedValue});

        assertScope(openScope, "pairs", "pairs_idx", true, new Object[] {expectedValue, expectedValue});
View Full Code Here

   
    @Test
    public void testRowCountIsStateless() throws SqlJetException {
        db.runReadTransaction(new ISqlJetTransaction() {
            public Object run(SqlJetDb db) throws SqlJetException {
                SqlJetScope scope = new SqlJetScope(new Object[] {"AB"}, new Object[] {"BC"});
                ISqlJetCursor cursor = db.getTable("table").scope("names_idx", scope);
                Assert.assertTrue(!cursor.eof());
                long count = cursor.getRowCount();
                Assert.assertTrue(count > 0);
                Assert.assertTrue(!cursor.eof());
View Full Code Here

   
    @Test
    public void testRowCountIsStatelessWhenIndexIsNotUnique() throws SqlJetException {
        db.runReadTransaction(new ISqlJetTransaction() {
            public Object run(SqlJetDb db) throws SqlJetException {
                SqlJetScope scope = new SqlJetScope(new Object[] {1, 2}, true, new Object[] {1, 2}, true);
                ISqlJetCursor cursor = db.getTable("pairs").scope("pairs_idx", scope);
       
                Assert.assertTrue(!cursor.eof());
                Assert.assertTrue(cursor.next());
                Assert.assertTrue(cursor.next());
View Full Code Here

        }
    }

    @Test
    public void testScopeWithCoercion() throws SqlJetException {
        SqlJetScope halvesScope = new SqlJetScope(new Object[] {2}, new Object[] {5});
        assertScope(halvesScope, "halves", "halves_idx", 2.5, 3.5, 4.5);

        SqlJetScope wholesScope = new SqlJetScope(new Object[] {2}, new Object[] {5});
        assertScope(wholesScope, "wholes", "wholes_idx", 2.0, 3.0, 4.0, 5.0);
    }
View Full Code Here

TOP

Related Classes of org.tmatesoft.sqljet.core.table.SqlJetScope$SqlJetScopeBound

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.