Package com.j256.ormlite.support

Examples of com.j256.ormlite.support.ConnectionSource


    });
  }

  @Test
  public void testDropTable() throws Exception {
    final ConnectionSource connectionSource = createMock(ConnectionSource.class);
    testDrop(connectionSource, 0, false, new Callable<Integer>() {
      public Integer call() throws Exception {
        return (int) TableUtils.dropTable(connectionSource, LocalFoo.class, false);
      }
    });
View Full Code Here


    });
  }

  @Test(expected = SQLException.class)
  public void testDropTableThrow() throws Exception {
    final ConnectionSource connectionSource = createMock(ConnectionSource.class);
    testDrop(connectionSource, 0, true, new Callable<Integer>() {
      public Integer call() throws Exception {
        return (int) TableUtils.dropTable(connectionSource, LocalFoo.class, false);
      }
    });
View Full Code Here

    });
  }

  @Test
  public void testDropTableThrowIgnore() throws Exception {
    final ConnectionSource connectionSource = createMock(ConnectionSource.class);
    testDrop(connectionSource, 0, true, new Callable<Integer>() {
      public Integer call() throws Exception {
        return (int) TableUtils.dropTable(connectionSource, LocalFoo.class, true);
      }
    });
View Full Code Here

    });
  }

  @Test(expected = SQLException.class)
  public void testDropTableNegRows() throws Exception {
    final ConnectionSource connectionSource = createMock(ConnectionSource.class);
    testDrop(connectionSource, -1, false, new Callable<Integer>() {
      public Integer call() throws Exception {
        return (int) TableUtils.dropTable(connectionSource, LocalFoo.class, false);
      }
    });
View Full Code Here

    });
  }

  @Test
  public void testDropTableTableConfig() throws Exception {
    final ConnectionSource connectionSource = createMock(ConnectionSource.class);
    testDrop(connectionSource, 0, false, new Callable<Integer>() {
      public Integer call() throws Exception {
        return (int) TableUtils.dropTable(connectionSource,
            DatabaseTableConfig.fromClass(connectionSource, LocalFoo.class), false);
      }
View Full Code Here

    });
  }

  @Test
  public void testIndex() throws Exception {
    final ConnectionSource connectionSource = createMock(ConnectionSource.class);
    expect(connectionSource.getDatabaseType()).andReturn(databaseType).anyTimes();
    DatabaseConnection conn = createMock(DatabaseConnection.class);
    expect(connectionSource.getReadWriteConnection()).andReturn(conn);
    final CompiledStatement stmt = createMock(CompiledStatement.class);
    expect(conn.compileStatement(isA(String.class), isA(StatementType.class), isA(FieldType[].class), anyInt())).andAnswer(
        new IAnswer<CompiledStatement>() {
          private int stmtC = 0;
          public CompiledStatement answer() {
            Object[] args = EasyMock.getCurrentArguments();
            assertNotNull(args);
            assertEquals(4, args.length);
            if (stmtC == 0) {
              assertEquals("CREATE TABLE `index` (`stuff` VARCHAR(255) ) ", args[0]);
            } else if (stmtC == 1) {
              assertEquals("CREATE INDEX `index_stuff_idx` ON `index` ( `stuff` )", args[0]);
            } else if (stmtC == 2) {
              assertEquals("DROP INDEX `index_stuff_idx`", args[0]);
            } else if (stmtC == 3) {
              assertEquals("DROP TABLE `index` ", args[0]);
            } else {
              fail("Should only be called 4 times");
            }
            stmtC++;
            assertEquals(StatementType.EXECUTE, args[1]);
            assertEquals(0, ((FieldType[]) args[2]).length);
            return stmt;
          }
        })
        .anyTimes();
    expect(stmt.runExecute()).andReturn(0).anyTimes();
    connectionSource.releaseConnection(conn);
    expect(connectionSource.getReadWriteConnection()).andReturn(conn);
    connectionSource.releaseConnection(conn);
    expectLastCall().anyTimes();
    stmt.close();
    expectLastCall().anyTimes();
    replay(connectionSource, conn, stmt);
    TableUtils.createTable(connectionSource, Index.class);
View Full Code Here

    verify(connectionSource, conn, stmt);
  }

  @Test
  public void testComboIndex() throws Exception {
    final ConnectionSource connectionSource = createMock(ConnectionSource.class);
    expect(connectionSource.getDatabaseType()).andReturn(databaseType).anyTimes();
    DatabaseConnection conn = createMock(DatabaseConnection.class);
    expect(connectionSource.getReadWriteConnection()).andReturn(conn);
    final CompiledStatement stmt = createMock(CompiledStatement.class);
    expect(conn.compileStatement(isA(String.class), isA(StatementType.class), isA(FieldType[].class), anyInt())).andAnswer(
        new IAnswer<CompiledStatement>() {
          private int stmtC = 0;
          public CompiledStatement answer() {
            Object[] args = EasyMock.getCurrentArguments();
            assertNotNull(args);
            assertEquals(4, args.length);
            if (stmtC == 0) {
              assertEquals("CREATE TABLE `comboindex` (`stuff` VARCHAR(255) , `junk` BIGINT ) ", args[0]);
            } else if (stmtC == 1) {
              assertEquals("CREATE INDEX `" + ComboIndex.INDEX_NAME
                  + "` ON `comboindex` ( `stuff`, `junk` )", args[0]);
            } else if (stmtC == 2) {
              assertEquals("DROP INDEX `" + ComboIndex.INDEX_NAME + "`", args[0]);
            } else if (stmtC == 3) {
              assertEquals("DROP TABLE `comboindex` ", args[0]);
            } else {
              fail("Should only be called 4 times");
            }
            stmtC++;
            assertEquals(StatementType.EXECUTE, args[1]);
            assertEquals(0, ((FieldType[]) args[2]).length);
            return stmt;
          }
        })
        .anyTimes();
    expect(stmt.runExecute()).andReturn(0).anyTimes();
    connectionSource.releaseConnection(conn);
    expect(connectionSource.getReadWriteConnection()).andReturn(conn);
    connectionSource.releaseConnection(conn);
    expectLastCall().anyTimes();
    stmt.close();
    expectLastCall().anyTimes();
    replay(connectionSource, conn, stmt);
    TableUtils.createTable(connectionSource, ComboIndex.class);
View Full Code Here

    verify(connectionSource, conn, stmt);
  }

  @Test
  public void testUniqueIndex() throws Exception {
    final ConnectionSource connectionSource = createMock(ConnectionSource.class);
    expect(connectionSource.getDatabaseType()).andReturn(databaseType).anyTimes();
    DatabaseConnection conn = createMock(DatabaseConnection.class);
    expect(connectionSource.getReadWriteConnection()).andReturn(conn);
    final CompiledStatement stmt = createMock(CompiledStatement.class);
    expect(conn.compileStatement(isA(String.class), isA(StatementType.class), isA(FieldType[].class), anyInt())).andAnswer(
        new IAnswer<CompiledStatement>() {
          private int stmtC = 0;
          public CompiledStatement answer() {
            Object[] args = EasyMock.getCurrentArguments();
            assertNotNull(args);
            assertEquals(4, args.length);
            if (stmtC == 0) {
              assertEquals("CREATE TABLE `uniqueindex` (`stuff` VARCHAR(255) ) ", args[0]);
            } else if (stmtC == 1) {
              assertEquals("CREATE UNIQUE INDEX `uniqueindex_stuff_idx` ON `uniqueindex` ( `stuff` )",
                  args[0]);
            } else if (stmtC == 2) {
              assertEquals("DROP INDEX `uniqueindex_stuff_idx`", args[0]);
            } else if (stmtC == 3) {
              assertEquals("DROP TABLE `uniqueindex` ", args[0]);
            } else {
              fail("Should only be called 4 times");
            }
            stmtC++;
            assertEquals(StatementType.EXECUTE, args[1]);
            assertEquals(0, ((FieldType[]) args[2]).length);
            return stmt;
          }
        }).anyTimes();
    expect(stmt.runExecute()).andReturn(0).anyTimes();
    connectionSource.releaseConnection(conn);
    expect(connectionSource.getReadWriteConnection()).andReturn(conn);
    connectionSource.releaseConnection(conn);
    expectLastCall().anyTimes();
    stmt.close();
    expectLastCall().anyTimes();
    replay(connectionSource, conn, stmt);
    TableUtils.createTable(connectionSource, UniqueIndex.class);
View Full Code Here

    assertFalse(iterator.hasNext());
  }

  @Test(expected = IllegalStateException.class)
  public void testHasNextThrow() throws Exception {
    ConnectionSource cs = createMock(ConnectionSource.class);
    cs.releaseConnection(null);
    CompiledStatement stmt = createMock(CompiledStatement.class);
    DatabaseResults results = createMock(DatabaseResults.class);
    expect(stmt.runQuery(null)).andReturn(results);
    expect(results.first()).andThrow(new SQLException("some database problem"));
    stmt.close();
View Full Code Here

    iterator.hasNext();
  }

  @Test(expected = IllegalStateException.class)
  public void testNextThrow() throws Exception {
    ConnectionSource cs = createMock(ConnectionSource.class);
    cs.releaseConnection(null);
    CompiledStatement stmt = createMock(CompiledStatement.class);
    DatabaseResults results = createMock(DatabaseResults.class);
    expect(stmt.runQuery(null)).andReturn(results);
    expect(results.first()).andReturn(true);
    @SuppressWarnings("unchecked")
View Full Code Here

TOP

Related Classes of com.j256.ormlite.support.ConnectionSource

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.