Package com.j256.ormlite.support

Examples of com.j256.ormlite.support.DatabaseConnection


    Class<LocalSerializable> clazz = LocalSerializable.class;
    Dao<LocalSerializable, Object> dao = createDao(clazz, true);
    LocalSerializable foo = new LocalSerializable();
    foo.serializable = null;
    assertEquals(1, dao.create(foo));
    DatabaseConnection conn = connectionSource.getReadOnlyConnection();
    CompiledStatement stmt = null;
    try {
      stmt =
          conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
              DatabaseConnection.DEFAULT_RESULT_FLAGS);
      DatabaseResults results = stmt.runQuery(null);
      assertTrue(results.next());
      FieldType fieldType =
          FieldType.createFieldType(connectionSource, TABLE_NAME,
View Full Code Here


    Class<LocalByteArray> clazz = LocalByteArray.class;
    Dao<LocalByteArray, Object> dao = createDao(clazz, true);
    LocalByteArray foo = new LocalByteArray();
    foo.byteField = new byte[] { 1, 2, 3, 4, 5 };
    assertEquals(1, dao.create(foo));
    DatabaseConnection conn = connectionSource.getReadOnlyConnection();
    CompiledStatement stmt = null;
    try {
      stmt =
          conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
              DatabaseConnection.DEFAULT_RESULT_FLAGS);
      DatabaseResults results = stmt.runQuery(null);
      assertTrue(results.next());
      FieldType fieldType =
          FieldType.createFieldType(connectionSource, TABLE_NAME,
View Full Code Here

  @SuppressWarnings("unchecked")
  @Test
  public void testForeignAutoRefresh() throws Exception {
    Field field = ForeignAutoRefresh.class.getDeclaredField("foreign");
    ConnectionSource connectionSource = createMock(ConnectionSource.class);
    DatabaseConnection connection = createMock(DatabaseConnection.class);
    expect(connectionSource.getDatabaseType()).andReturn(databaseType).anyTimes();
    expect(connectionSource.getReadOnlyConnection()).andReturn(connection);
    ForeignForeign foreignForeign = new ForeignForeign();
    String stuff = "21312j3213";
    int id = 4123123;
    foreignForeign.id = id;
    foreignForeign.stuff = stuff;
    expect(
        connection.queryForOne(isA(String.class), isA(Object[].class), isA(FieldType[].class),
            isA(GenericRowMapper.class), (ObjectCache) isNull())).andReturn(foreignForeign);
    connectionSource.releaseConnection(connection);
    DatabaseResults results = createMock(DatabaseResults.class);
    ForeignAutoRefresh foreign = new ForeignAutoRefresh();
    replay(results, connectionSource, connection);
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],
              DatabaseConnection.DEFAULT_RESULT_FLAGS);

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

    checkResults(foos, preparedQuery, 2);
  }

  private void checkResults(List<LocalFoo> foos, MappedPreparedStmt<LocalFoo, Integer> preparedQuery, int expectedNum)
      throws SQLException {
    DatabaseConnection conn = connectionSource.getReadOnlyConnection();
    CompiledStatement stmt = null;
    try {
      stmt = preparedQuery.compile(conn, StatementType.SELECT);
      DatabaseResults results = stmt.runQuery(null);
      int fooC = 0;
View Full Code Here

  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),
            (GeneratedKeyHolder) isNull())).andReturn(1);

    replay(databaseConnection);
    GeneratedId genIdSeq = new GeneratedId();
    se.create(databaseConnection, genIdSeq, null);
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),
            (GeneratedKeyHolder) isNull())).andReturn(1);

    replay(databaseConnection);
    GeneratedIdLong genIdSeq = new GeneratedIdLong();
    se.create(databaseConnection, genIdSeq, null);
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

  @Test(expected = SQLException.class)
  public void testArgumentHolderDoubleSet() throws Exception {
    TableInfo<Foo, Integer> tableInfo = new TableInfo<Foo, Integer>(connectionSource, null, Foo.class);
    MappedCreate<Foo, Integer> mappedCreate = MappedCreate.build(databaseType, tableInfo);
    DatabaseConnection conn = createMock(DatabaseConnection.class);
    expect(
        conn.insert(isA(String.class), isA(Object[].class), isA(FieldType[].class),
            isA(GeneratedKeyHolder.class))).andAnswer(new IAnswer<Integer>() {
      public Integer answer() throws Throwable {
        GeneratedKeyHolder holder = (GeneratedKeyHolder) getCurrentArguments()[3];
        holder.addKey((Integer) 1);
        holder.addKey((Integer) 2);
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.