Package org.tmatesoft.sqljet.core.table

Examples of org.tmatesoft.sqljet.core.table.ISqlJetCursor


                                         // are two records!

        Integer count = (Integer) db.runTransaction(new ISqlJetTransaction() {
            public Object run(SqlJetDb arg0) throws SqlJetException {
                ISqlJetTable table = db.getTable("names");
                ISqlJetCursor cur = table.order(null);
                Integer counter = 0;
                if (!cur.eof()) {
                    do {
                        ++counter;
                    } while (cur.next());

                }
                ;
                return counter;
            }
View Full Code Here


            db.commit();
        }

        db.runReadTransaction(new ISqlJetTransaction() {
            public Object run(SqlJetDb db) throws SqlJetException {
                ISqlJetCursor open = table.open();
                try {
                    while (!open.eof()) {
                        long id = open.getInteger("id");
                        Assert.assertNotNull(id);
                        open.next();
                    }
                } finally {
                    open.close();
                }
                return null;
            }
        });
    }
View Full Code Here

            db.commit();
        }
        try {
            db.beginTransaction(SqlJetTransactionMode.READ_ONLY);
            ISqlJetTable table = db.getTable("test");
            ISqlJetCursor cursor = table.scope(null, new Object[] { Long.valueOf(10) },
                    new Object[] { Long.valueOf(20) });
            assertEquals(11, cursor.getRowCount());
            ISqlJetCursor reversed = cursor.reverse();
            assertEquals(11, reversed.getRowCount());
            List<Long> list = new LinkedList<Long>();
            if (!reversed.eof()) {
                do {
                    list.add(reversed.getInteger(0));
                } while (reversed.next());
            }
            assertEquals(11, list.size());
            assertEquals(Long.valueOf(20), list.get(0));
            assertEquals(Long.valueOf(10), list.get(list.size() - 1));
        } finally {
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());
                Assert.assertEquals(cursor.getRowCount(), 4);
                Assert.assertTrue(cursor.next());
                Assert.assertFalse(cursor.eof());
                Assert.assertFalse(cursor.next());
                Assert.assertTrue(cursor.eof());
               
                return null;
            }
        });
       
View Full Code Here

      /// and after that disappears row with pk 1
      table.insertOr(SqlJetConflictAction.REPLACE, 2, "test note", 1);

      db.beginTransaction(SqlJetTransactionMode.READ_ONLY);
      try {
        ISqlJetCursor cursor = table.lookup(table.getPrimaryKeyIndexName(), 1);
        assertFalse(cursor.eof());
      } finally {
        db.commit();
      }

    }
View Full Code Here

    public Object run(SqlJetDb db) throws SqlJetException {
        int n_read = 0;
        long start = System.currentTimeMillis();
        long end = start + _batch_millis;
        long now;
        ISqlJetCursor cursor = _table.open();
        try {
            boolean more = !cursor.eof();
            while ((now = System.currentTimeMillis()) < end && more) {
                n_read++;
                cursor.getInteger(0);
                more = cursor.next();
            }
        } finally {
            cursor.close();
        }
        System.out.println("scanned " + n_read + " in " + (now - start));
        return null;
    }
View Full Code Here

    private List<?> queryScope(final SqlJetScope scope, final String tableName, final String indexName, final boolean allFields) throws SqlJetException {
        return (List<?>) db.runReadTransaction(new ISqlJetTransaction() {
            public Object run(SqlJetDb db) throws SqlJetException {
                List<Object> valuesInScope = new ArrayList<Object>()
                ISqlJetCursor scopeCursor = db.getTable(tableName).scope(indexName, scope);
                Assert.assertNotNull(scopeCursor);
                try {
                    while(!scopeCursor.eof()) {
                        if (scopeCursor.getFieldsCount() == 1 || !allFields) {
                            valuesInScope.add(scopeCursor.getValue(0));
                        } else {
                            Object[] values = new Object[scopeCursor.getFieldsCount()];
                            for (int i = 0; i < values.length; i++) {
                                values[i] = scopeCursor.getValue(i);
                            }
                            valuesInScope.add(values);
                        }
                        scopeCursor.next();
                    }
                } finally {
                    scopeCursor.close();
                }
                return valuesInScope;
            }
        });
    }
View Full Code Here

          }, SqlJetTransactionMode.WRITE);

         db.runTransaction(new ISqlJetTransaction() {
            public Object run(SqlJetDb db) throws SqlJetException {
              ISqlJetTable table = db.getTable("beans");
              ISqlJetCursor cur = table.lookup(table.getPrimaryKeyIndexName(),1);
              if (!cur.eof()) {
                long v = cur.getInteger(0);
                Assert.assertEquals(1, v);
                boolean isNull = cur.isNull(0); // -> returns true
                Assert.assertFalse(isNull);
              }
              return true;
            }
          }, SqlJetTransactionMode.READ_ONLY);
View Full Code Here

    private static class Reader implements ISqlJetTransaction {
        public Object run(SqlJetDb db) throws SqlJetException {
            final ISqlJetTable table = db.getTable(TABLE);
            int n_read = 0;
            final ISqlJetCursor cursor = table.open();
            try {
                boolean more = !cursor.eof();
                while (n_read < TOTAL && more  && !exit.get()) {
                    n_read++;
                    cursor.getInteger(0);
                    more = cursor.next();
                }
            } finally {
                cursor.close();
            }
            logger.log(Level.INFO, "reader: scanned " + n_read);
            return null;
        }
View Full Code Here

                if (SqlJetErrorCode.CONSTRAINT.equals(e.getErrorCode())) {
                    // insert failed because record already exists -> update
                    // it

                    Object[] key = new Object[] { x, y, zoom, 0 };
                    ISqlJetCursor updateCursor = table.lookup("IND", key);
                    do {
                        updateCursor.update(x, y, zoom, 0, blob);
                    } while (updateCursor.next());
                    updateCursor.close();

                } else
                    throw e;
            }
            db.commit();
View Full Code Here

TOP

Related Classes of org.tmatesoft.sqljet.core.table.ISqlJetCursor

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.