Package com.j256.ormlite.support

Examples of com.j256.ormlite.support.DatabaseConnection


  public void testGeneratedId() throws Exception {
    TableInfo<GeneratedId, Integer> tableInfo =
        new TableInfo<GeneratedId, Integer>(connectionSource, null, GeneratedId.class);
    StatementExecutor<GeneratedId, Integer> se =
        new StatementExecutor<GeneratedId, Integer>(databaseType, tableInfo, null);
    DatabaseConnection databaseConnection = createMock(DatabaseConnection.class);
    databaseConnection.insert(isA(String.class), isA(Object[].class), isA(FieldType[].class),
        isA(GeneratedKeyHolder.class));
    expectLastCall().andAnswer(new IAnswer<Object>() {
      public Integer answer() throws Throwable {
        GeneratedKeyHolder keyHolder = (GeneratedKeyHolder) (LastControl.getCurrentArguments())[3];
        keyHolder.addKey(2);
View Full Code Here


    connectionSource.setDatabaseType(databaseType);
    TableInfo<GeneratedId, Integer> tableInfo =
        new TableInfo<GeneratedId, Integer>(connectionSource, null, GeneratedId.class);
    StatementExecutor<GeneratedId, Integer> se =
        new StatementExecutor<GeneratedId, Integer>(databaseType, tableInfo, null);
    DatabaseConnection databaseConnection = createMock(DatabaseConnection.class);
    expect(databaseConnection.queryForLong(isA(String.class))).andReturn(1L);
    expect(databaseConnection.insert(isA(String.class), isA(Object[].class), isA(FieldType[].class))).andReturn(1);

    replay(databaseConnection);
    GeneratedId genIdSeq = new GeneratedId();
    se.create(databaseConnection, genIdSeq);
    verify(databaseConnection);
View Full Code Here

    DatabaseType databaseType = new NeedsSequenceDatabaseType();
    connectionSource.setDatabaseType(databaseType);
    StatementExecutor<GeneratedIdLong, Long> se =
        new StatementExecutor<GeneratedIdLong, Long>(databaseType, new TableInfo<GeneratedIdLong, Long>(
            connectionSource, null, GeneratedIdLong.class), null);
    DatabaseConnection databaseConnection = createMock(DatabaseConnection.class);
    expect(databaseConnection.queryForLong(isA(String.class))).andReturn(1L);
    expect(databaseConnection.insert(isA(String.class), isA(Object[].class), isA(FieldType[].class))).andReturn(1);

    replay(databaseConnection);
    GeneratedIdLong genIdSeq = new GeneratedIdLong();
    se.create(databaseConnection, genIdSeq);
    verify(databaseConnection);
View Full Code Here

    MappedCreate.build(databaseType, new TableInfo<GeneratedId, Integer>(connectionSource, null, GeneratedId.class));
  }

  @Test(expected = SQLException.class)
  public void testSequenceZero() throws Exception {
    DatabaseConnection databaseConnection = createMock(DatabaseConnection.class);
    expect(databaseConnection.queryForLong(isA(String.class))).andReturn(0L);
    replay(databaseConnection);
    NeedsSequenceDatabaseType needsSequence = new NeedsSequenceDatabaseType();;
    MappedCreate<GeneratedIdSequence, Integer> mappedCreate =
        MappedCreate.build(needsSequence, new TableInfo<GeneratedIdSequence, Integer>(connectionSource, null,
            GeneratedIdSequence.class));
View Full Code Here

        new TableInfo<LocalFoo, Integer>(connectionSource, null, LocalFoo.class);
    MappedPreparedStmt<LocalFoo, Integer> rowMapper =
        new MappedPreparedStmt<LocalFoo, Integer>(tableInfo, null, new FieldType[0], tableInfo.getFieldTypes(),
            new ArgumentHolder[0], null, StatementType.SELECT);

    DatabaseConnection conn = connectionSource.getReadOnlyConnection();
    CompiledStatement stmt = null;
    try {
      stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, new FieldType[0]);

      DatabaseResults results = stmt.runQuery();
      while (results.next()) {
        LocalFoo foo2 = rowMapper.mapRow(results);
        assertEquals(foo1.id, foo2.id);
View Full Code Here

public class StatementExecutorTest extends BaseCoreStmtTest {

  @Test
  public void testUpdateThrow() throws Exception {
    TableInfo<Foo, String> tableInfo = new TableInfo<Foo, String>(connectionSource, null, Foo.class);
    DatabaseConnection connection = createMock(DatabaseConnection.class);
    @SuppressWarnings("unchecked")
    PreparedUpdate<Foo> update = createMock(PreparedUpdate.class);
    CompiledStatement compiledStmt = createMock(CompiledStatement.class);
    expect(update.compile(connection)).andReturn(compiledStmt);
    expect(compiledStmt.runUpdate()).andThrow(new SQLException("expected"));
View Full Code Here

  }

  @Test
  public void testDeleteThrow() throws Exception {
    TableInfo<Foo, String> tableInfo = new TableInfo<Foo, String>(connectionSource, null, Foo.class);
    DatabaseConnection connection = createMock(DatabaseConnection.class);
    @SuppressWarnings("unchecked")
    PreparedDelete<Foo> delete = createMock(PreparedDelete.class);
    CompiledStatement compiledStmt = createMock(CompiledStatement.class);
    expect(delete.compile(connection)).andReturn(compiledStmt);
    expect(compiledStmt.runUpdate()).andThrow(new SQLException("expected"));
View Full Code Here

  }

  @Test
  public void testCallBatchTasksNoAutoCommit() throws Exception {
    TableInfo<Foo, String> tableInfo = new TableInfo<Foo, String>(connectionSource, null, Foo.class);
    DatabaseConnection connection = createMock(DatabaseConnection.class);
    expect(connection.isAutoCommitSupported()).andReturn(false);
    StatementExecutor<Foo, String> statementExec =
        new StatementExecutor<Foo, String>(databaseType, tableInfo, null);
    replay(connection);
    final AtomicBoolean called = new AtomicBoolean(false);
    statementExec.callBatchTasks(connection, false, new Callable<Void>() {
View Full Code Here

  }

  @Test
  public void testCallBatchTasksAutoCommitFalse() throws Exception {
    TableInfo<Foo, String> tableInfo = new TableInfo<Foo, String>(connectionSource, null, Foo.class);
    DatabaseConnection connection = createMock(DatabaseConnection.class);
    expect(connection.isAutoCommitSupported()).andReturn(true);
    expect(connection.getAutoCommit()).andReturn(false);
    StatementExecutor<Foo, String> statementExec =
        new StatementExecutor<Foo, String>(databaseType, tableInfo, null);
    replay(connection);
    final AtomicBoolean called = new AtomicBoolean(false);
    statementExec.callBatchTasks(connection, false, new Callable<Void>() {
View Full Code Here

  }

  @Test
  public void testCallBatchTasksAutoCommitTrue() throws Exception {
    TableInfo<Foo, String> tableInfo = new TableInfo<Foo, String>(connectionSource, null, Foo.class);
    DatabaseConnection connection = createMock(DatabaseConnection.class);
    expect(connection.isAutoCommitSupported()).andReturn(true);
    expect(connection.getAutoCommit()).andReturn(true);
    connection.setAutoCommit(false);
    connection.setAutoCommit(true);
    StatementExecutor<Foo, String> statementExec =
        new StatementExecutor<Foo, String>(databaseType, tableInfo, null);
    replay(connection);
    final AtomicBoolean called = new AtomicBoolean(false);
    statementExec.callBatchTasks(connection, false, new Callable<Void>() {
View Full Code Here

TOP

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

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.