Package com.j256.ormlite.support

Examples of com.j256.ormlite.support.DatabaseConnection


  @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))).andReturn(foreignForeign);
    connectionSource.releaseConnection(connection);
    DatabaseResults results = createMock(DatabaseResults.class);
    ForeignAutoRefresh foreign = new ForeignAutoRefresh();
    replay(results, connectionSource, connection);
View Full Code Here


  private final DatabaseType databaseType = new StubDatabaseType();

  @Test(expected = SQLException.class)
  public void testNoIdBuildDelete() throws Exception {
    DatabaseConnection databaseConnection = createMock(DatabaseConnection.class);
    ConnectionSource connectionSource = createMock(ConnectionSource.class);
    expect(connectionSource.getDatabaseType()).andReturn(databaseType).anyTimes();
    replay(connectionSource);
    MappedDeleteCollection.deleteObjects(databaseType,
        new TableInfo<NoId, Void>(connectionSource, null, NoId.class), databaseConnection,
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);
      DatabaseResults results = stmt.runQuery();
      int fooC = 0;
View Full Code Here

    Class<LocalString> clazz = LocalString.class;
    Dao<LocalString, Object> dao = createDao(clazz, true);
    LocalString foo = new LocalString();
    foo.string = "not a date format";
    assertEquals(1, dao.create(foo));
    DatabaseConnection conn = connectionSource.getReadOnlyConnection();
    CompiledStatement stmt = null;
    try {
      stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes);
      DatabaseResults results = stmt.runQuery();
      assertTrue(results.next());
      int colNum = results.findColumn(STRING_COLUMN);
      DataType.DATE_STRING.getDataPersister().resultToJava(null, results, colNum);
    } finally {
View Full Code Here

    Class<LocalString> clazz = LocalString.class;
    Dao<LocalString, Object> dao = createDao(clazz, true);
    LocalString foo = new LocalString();
    foo.string = "not a date format";
    assertEquals(1, dao.create(foo));
    DatabaseConnection conn = connectionSource.getReadOnlyConnection();
    CompiledStatement stmt = null;
    try {
      stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes);
      DatabaseResults results = stmt.runQuery();
      assertTrue(results.next());
      int colNum = results.findColumn(STRING_COLUMN);
      DataType.JAVA_DATE_STRING.getDataPersister().resultToJava(null, results, colNum);
    } finally {
View Full Code Here

    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);
      DatabaseResults results = stmt.runQuery();
      assertTrue(results.next());
      FieldType fieldType =
          FieldType.createFieldType(connectionSource, TABLE_NAME,
              clazz.getDeclaredField(SERIALIZABLE_COLUMN), clazz);
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);
      DatabaseResults results = stmt.runQuery();
      assertTrue(results.next());
      FieldType fieldType =
          FieldType.createFieldType(connectionSource, TABLE_NAME,
              LocalSerializable.class.getDeclaredField(SERIALIZABLE_COLUMN), LocalSerializable.class);
View Full Code Here

    Dao<LocalEnumString, Object> dao = createDao(clazz, true);
    OurEnum val = OurEnum.SECOND;
    LocalEnumString foo = new LocalEnumString();
    foo.ourEnum = val;
    assertEquals(1, dao.create(foo));
    DatabaseConnection conn = connectionSource.getReadOnlyConnection();
    CompiledStatement stmt = null;
    try {
      stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes);
      DatabaseResults results = stmt.runQuery();
      assertTrue(results.next());
      assertEquals(val.toString(),
          DataType.ENUM_STRING.getDataPersister()
              .resultToJava(null, results, results.findColumn(ENUM_COLUMN)));
View Full Code Here

    Dao<LocalEnumInt, Object> dao = createDao(clazz, true);
    OurEnum val = OurEnum.SECOND;
    LocalEnumInt foo = new LocalEnumInt();
    foo.ourEnum = val;
    assertEquals(1, dao.create(foo));
    DatabaseConnection conn = connectionSource.getReadOnlyConnection();
    CompiledStatement stmt = null;
    try {
      stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes);
      DatabaseResults results = stmt.runQuery();
      assertTrue(results.next());
      assertEquals(
          val.ordinal(),
          DataType.ENUM_INTEGER.getDataPersister().resultToJava(null, results,
View Full Code Here

  private void testType(Class<?> clazz, Object javaVal, Object defaultSqlVal, Object sqlArg, String defaultValStr,
      DataType dataType, String columnName, boolean isValidGeneratedType, boolean isAppropriateId,
      boolean isEscapedValue, boolean isPrimitive, boolean isSelectArgRequired, boolean isStreamType,
      boolean isComparable, boolean isConvertableId) throws Exception {
    DataPersister dataPersister = dataType.getDataPersister();
    DatabaseConnection conn = connectionSource.getReadOnlyConnection();
    CompiledStatement stmt = null;
    try {
      stmt = conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes);
      DatabaseResults results = stmt.runQuery();
      assertTrue(results.next());
      int colNum = results.findColumn(columnName);
      FieldType fieldType =
          FieldType.createFieldType(connectionSource, TABLE_NAME, clazz.getDeclaredField(columnName), clazz);
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.