Package org.tmatesoft.sqljet.core.table

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


    public void setUp() throws Exception {
        super.setUp();
        db.createTable("CREATE TABLE IF NOT EXISTS table (name TEXT, count INTEGER)");
        db.createIndex("CREATE UNIQUE INDEX IF NOT EXISTS names_idx ON table(name)");
       
        db.runWriteTransaction(new ISqlJetTransaction() {
            public Object run(SqlJetDb db) throws SqlJetException {
               
                db.getTable("table").insert("XYZ", 1);
                db.getTable("table").insert("XYZZ", 1);
                db.getTable("table").insert("ABC", 1);
                db.getTable("table").insert("ABCD", 1);
                db.getTable("table").insert("ABCDEF", 1);
                db.getTable("table").insert("A", 1);
               
                return null;
            }
        });

        db.createTable("CREATE TABLE IF NOT EXISTS noindex (id INTEGER PRIMARY KEY)");
        db.runWriteTransaction(new ISqlJetTransaction() {
            public Object run(SqlJetDb db) throws SqlJetException {
               
                db.getTable("noindex").insert(1);
                db.getTable("noindex").insert(2);
                db.getTable("noindex").insert(3);
View Full Code Here


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

*/
public class InsertOrUpdateDoesntWorkTest extends AbstractNewDbTest {

    private void assertInsertedOrReplaced(final ISqlJetTable table,
            final long actual, final Object ... key) throws SqlJetException {
        db.runReadTransaction(new ISqlJetTransaction() {
            public Object run(SqlJetDb db) throws SqlJetException {
                ISqlJetCursor lookup = table.lookup(null, key);
                Assert.assertEquals(actual, lookup.getInteger("time"));
                return null;
            }
View Full Code Here

            }
        });
    }

    private void assertCount(final ISqlJetTable table, final int count) throws SqlJetException {
        db.runReadTransaction(new ISqlJetTransaction() {
            public Object run(SqlJetDb db) throws SqlJetException {
                ISqlJetCursor open = table.open();
                Assert.assertEquals(count, open.getRowCount());
                return null;
            }
View Full Code Here

public class LengthTest extends AbstractNewDbTest {

    @Test
    public void testLength() throws SqlJetException {
        try {
            db.runTransaction(new ISqlJetTransaction() {
                public Object run(SqlJetDb db) throws SqlJetException {
                    final String sql = "CREATE TABLE contacts ( " + "id INTEGER PRIMARY KEY,"
                            + "name TEXT NOT NULL COLLATE NOCASE," + "phone TEXT NOT NULL DEFAULT 'UNKNOWN',"
                            + "UNIQUE (name,phone)," + "CHECK(LENGTH(phone)>=7) );";
                    db.createTable(sql);
View Full Code Here

    }

    @Test
    public void testUniqueIndex() throws Exception {

        db.runTransaction(new ISqlJetTransaction() {
            public Object run(SqlJetDb arg0) throws SqlJetException {
                ISqlJetTable table = db.getTable("names");
                table.insertOr(SqlJetConflictAction.REPLACE, null, "same name");
                table.insertOr(SqlJetConflictAction.REPLACE, null, "same name");

                return null;
            }
        }, SqlJetTransactionMode.WRITE); // I would expect transaction fails or
                                         // one record in table. But in table
                                         // 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()) {
View Full Code Here

    try {
      File dbFile = new File("./src/test/data/db/test.db");
      SqlJetFileUtil.deleteFile(dbFile);
      SqlJetDb db = SqlJetDb.open(dbFile, true);
      db.getOptions().setAutovacuum(true);
      db.runTransaction(new ISqlJetTransaction() {
        public Object run(SqlJetDb db) throws SqlJetException {
          db.getOptions().setUserVersion(1);
          return true;
        }
      }, SqlJetTransactionMode.WRITE);
View Full Code Here

            table.insert(null, "jobname", 123456);
        } finally {
            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");
View Full Code Here

        db.createIndex("CREATE UNIQUE INDEX IF NOT EXISTS names_idx ON table(name)");

        db.createTable("CREATE TABLE IF NOT EXISTS pairs (x INTEGER, y INTEGER)");
        db.createIndex("CREATE INDEX IF NOT EXISTS pairs_idx ON pairs(x, y)");
       
        db.runWriteTransaction(new ISqlJetTransaction() {
            public Object run(SqlJetDb db) throws SqlJetException {
               
                db.getTable("table").insert("XYZ", 1);
                db.getTable("table").insert("XYZZ", 1);
                db.getTable("table").insert("ABC", 1);
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();
View Full Code Here

TOP

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

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.