Package org.tmatesoft.sqljet.core.table

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


      newOptions.setSchemaVersion(SQLJET_SCHEMA_VERSION);
      newOptions.setCacheSize(SQLJET_PAGE_CACHE_SIZE);
      persistenceDb.createTable(GROUP_TABLE_DDL);
      persistenceDb.createTable(CUSTOMER_TABLE_DDL);
      classLogger.log(Level.CONFIG, "2 tables created in a new data file {0}.", new Object[] {SqlJetDb.IN_MEMORY, persistenceDb.getSchema().getTableNames()});
      ISqlJetTable groupTable = persistenceDb.getTable(GROUP_TABLE_NAME);
      ISqlJetTable customerTable = persistenceDb.getTable(CUSTOMER_TABLE_NAME);
      Date update = new Date();
      groupTable.insert(1, update.getTime(), "ACTIVE", 0, true);
      groupTable.insert(2, update.getTime(), "INACTIVE", 1, false);
      customerTable.insert(1, 1, update.getTime(), "SERVING", "nobody@example.com", "ENCOM1", 0, true);
      customerTable.insert(2, 1, update.getTime(), "SERVING", "nobody@example.com", "ENCOM2", 1, true);
      customerTable.insert(3, 1, update.getTime(), "SERVING", "nobody@example.com", "ENCOM3", 3, true);
      customerTable.insert(4, 1, update.getTime(), "SERVING", "nobody@example.com", "ENCOM4", 2, true);
    }
    finally
    {
      persistenceDb.commit();
    }
View Full Code Here


        "`id` INTEGER PRIMARY KEY AUTOINCREMENT," +
        "`jobname` VARCHAR(75) NOT NULL," +
        "`startdate` LONG not null" +
        ");" );

        final ISqlJetTable table = db.getTable(createTable.getName());
        db.beginTransaction(SqlJetTransactionMode.EXCLUSIVE);
        try{
            table.insert(null, "jobname", 123456);
            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");
                        Assert.assertNotNull(id);
                        open.next();
View Full Code Here

  @Test
  public void testRowCount() throws SqlJetException
  {
    persistenceDb.getTable(GROUP_TABLE_NAME);
    ISqlJetTable customerTable = persistenceDb.getTable(CUSTOMER_TABLE_NAME);
    // begin a read transaction before reading data (this is required by SqlJet).
    persistenceDb.beginTransaction(SqlJetTransactionMode.READ_ONLY);
    try
    {
      classLogger.log(Level.CONFIG, "Getting Group ID {0} to merge Customer ID {1}.", new Object[] {1, 1});
      ISqlJetCursor foundRow = customerTable.lookup(customerTable.getPrimaryKeyIndexName(), 1);
      if(foundRow != null && foundRow.first())
      {
        int rowCount = intFromLong(foundRow.getRowCount());
        classLogger.log(Level.CONFIG, "Reading {0} Customers.", rowCount);
      }
View Full Code Here

  @Test
  public void testDelete() throws SqlJetException
  {
    persistenceDb.getTable(GROUP_TABLE_NAME);
    ISqlJetTable customerTable = persistenceDb.getTable(CUSTOMER_TABLE_NAME);
    // begin a read transaction before reading data (this is required by SqlJet).
    persistenceDb.beginTransaction(SqlJetTransactionMode.WRITE);
    try
    {
      classLogger.log(Level.CONFIG, "Getting Group ID {0} to merge Customer ID {1}.", new Object[] {1, 1});
      ISqlJetCursor foundRow = customerTable.lookup(customerTable.getPrimaryKeyIndexName(), 1);
      if(foundRow != null && foundRow.first())
      {
        foundRow.delete();
      }
    }
View Full Code Here

        // Prepare data
        try {
            db.beginTransaction(SqlJetTransactionMode.WRITE);
            db.createTable("CREATE TABLE IF NOT EXISTS test (test_bean_id INTEGER PRIMARY KEY AUTOINCREMENT,number FLOAT)");

            ISqlJetTable table = db.getTable("test");
            for (int i = 0; i < 30; i++) {
                table.insert(null, Double.valueOf(30.0));
            }
        } finally {
            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>();
View Full Code Here

    @Test
    public void testCorruptIndex() throws Exception {
      db.createTable(CREATE_TABLE);
      db.createIndex(CREATE_INDEX);

      ISqlJetTable table = db.getTable("child_beans_many");
      db.beginTransaction(SqlJetTransactionMode.WRITE);

      try {
        for (int i = 0; i < 5; i++) {
          table.insertOr(SqlJetConflictAction.REPLACE, null, "test note", 1);
        }
      } finally {
        db.commit();
      }

      /// 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

    }

    @Test
    public void addField() throws SqlJetException {
        final ISqlJetTableDef alterTable = db.alterTable("alter table t add b int;");
        final ISqlJetTable t = db.getTable("t");
        Assert.assertNotNull(alterTable);
        Assert.assertNotNull(alterTable.getColumn("b"));
        Assert.assertNotNull(table.getDefinition().getColumn("b"));
        Assert.assertNotNull(t);
        Assert.assertNotNull(t.getDefinition().getColumn("b"));
        assertDbOpen();
    }
View Full Code Here

    }

    @Test
    public void addField1() throws SqlJetException {
        final ISqlJetTableDef alterTable = db.alterTable("alter table t add b int");
        final ISqlJetTable t = db.getTable("t");
        Assert.assertNotNull(alterTable);
        Assert.assertNotNull(alterTable.getColumn("b"));
        Assert.assertNotNull(table.getDefinition().getColumn("b"));
        Assert.assertNotNull(t);
        Assert.assertNotNull(t.getDefinition().getColumn("b"));
        assertDbOpen();
    }
View Full Code Here

    }

    @Test
    public void addField2() throws SqlJetException {
        final ISqlJetTableDef alterTable = db.alterTable("alter table t add column b int;");
        final ISqlJetTable t = db.getTable("t");
        Assert.assertNotNull(alterTable);
        Assert.assertNotNull(alterTable.getColumn("b"));
        Assert.assertNotNull(table.getDefinition().getColumn("b"));
        Assert.assertNotNull(t);
        Assert.assertNotNull(t.getDefinition().getColumn("b"));
        assertDbOpen();
    }
View Full Code Here

    }

    @Test
    public void addField3() throws SqlJetException {
        final ISqlJetTableDef alterTable = db.alterTable("alter table t add column b int default 0;");
        final ISqlJetTable t = db.getTable("t");
        Assert.assertNotNull(alterTable);
        Assert.assertNotNull(alterTable.getColumn("b"));
        Assert.assertNotNull(table.getDefinition().getColumn("b"));
        Assert.assertNotNull(t);
        Assert.assertNotNull(t.getDefinition().getColumn("b"));
        assertDbOpen();
    }
View Full Code Here

TOP

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

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.