Package com.j256.ormlite.field

Examples of com.j256.ormlite.field.FieldType


      for (FieldType fieldType : fieldTypes) {
        map.put(fieldType.getColumnName().toLowerCase(), fieldType);
      }
      fieldNameMap = map;
    }
    FieldType fieldType = fieldNameMap.get(columnName.toLowerCase());
    // if column name is found, return it
    if (fieldType != null) {
      return fieldType;
    }
    // look to see if someone is using the field-name instead of column-name
View Full Code Here


  private static <T> FieldType[] extractFieldTypes(ConnectionSource connectionSource, Class<T> clazz, String tableName)
      throws SQLException {
    List<FieldType> fieldTypes = new ArrayList<FieldType>();
    for (Class<?> classWalk = clazz; classWalk != null; classWalk = classWalk.getSuperclass()) {
      for (Field field : classWalk.getDeclaredFields()) {
        FieldType fieldType = FieldType.createFieldType(connectionSource, tableName, field, clazz);
        if (fieldType != null) {
          fieldTypes.add(fieldType);
        }
      }
    }
View Full Code Here

    assertFalse(databaseType.isLimitAfterSelect());
  }

  @Test
  public void testBooleanConverterJavaToArg() throws Exception {
    FieldType fieldType =
        FieldType.createFieldType(connectionSource, "foo", ManyFields.class.getDeclaredField("bool"),
            ManyFields.class);
    assertEquals(Byte.valueOf((byte) 1), booleanFieldConverter.javaToSqlArg(fieldType, Boolean.TRUE));
    assertEquals(Byte.valueOf((byte) 0), booleanFieldConverter.javaToSqlArg(fieldType, Boolean.FALSE));
  }
View Full Code Here

  private FieldType[] convertFieldConfigs(ConnectionSource connectionSource, String tableName,
      List<DatabaseFieldConfig> fieldConfigs) throws SQLException {
    List<FieldType> fieldTypes = new ArrayList<FieldType>();
    for (DatabaseFieldConfig fieldConfig : fieldConfigs) {
      FieldType fieldType = null;
      // walk up the classes until we find the field
      for (Class<?> classWalk = dataClass; classWalk != null; classWalk = classWalk.getSuperclass()) {
        Field field;
        try {
          field = classWalk.getDeclaredField(fieldConfig.getFieldName());
        } catch (NoSuchFieldException e) {
          // we ignore this and just loop hopefully finding it in a upper class
          continue;
        }
        if (field != null) {
          fieldType = new FieldType(connectionSource, tableName, field, fieldConfig, dataClass);
          break;
        }
      }

      if (fieldType == null) {
View Full Code Here

    boolean first = Boolean.TRUE;
    boolean second = Boolean.FALSE;
    expect(results.getByte(1)).andReturn((byte) 1);
    expect(results.getByte(2)).andReturn((byte) 0);
    replay(results);
    FieldType fieldType =
        FieldType.createFieldType(connectionSource, "foo", ManyFields.class.getDeclaredField("bool"),
            ManyFields.class);
    assertEquals(first, booleanFieldConverter.resultToJava(fieldType, results, 1));
    assertEquals(second, booleanFieldConverter.resultToJava(fieldType, results, 2));
    verify(results);
View Full Code Here

    verify(results);
  }

  @Test
  public void testBooleanConverterParseDefaultString() throws Exception {
    FieldType fieldType =
        FieldType.createFieldType(connectionSource, "foo", ManyFields.class.getDeclaredField("bool"),
            ManyFields.class);
    assertEquals(Byte.valueOf((byte) 1),
        booleanFieldConverter.parseDefaultString(fieldType, Boolean.TRUE.toString()));
    assertEquals(Byte.valueOf((byte) 0),
View Full Code Here

    StringBuilder sb = new StringBuilder();
    List<String> additionalArgs = new ArrayList<String>();
    List<String> stmtsBefore = new ArrayList<String>();
    List<String> stmtsAfter = new ArrayList<String>();
    List<String> queriesAfter = new ArrayList<String>();
    FieldType fieldType =
        FieldType.createFieldType(connectionSource, "foo", ManyFields.class.getDeclaredField(fieldName),
            ManyFields.class);
    databaseType.appendColumnArg(null, sb, fieldType, additionalArgs, stmtsBefore, stmtsAfter, queriesAfter);
    StringBuilder expectedSb = new StringBuilder();
    databaseType.appendEscapedEntityName(expectedSb, fieldName);
View Full Code Here

public class BaseSqliteDatabaseTypeTest extends BaseCoreTest {

  @Test(expected = IllegalArgumentException.class)
  public void testConfigureGeneratedIdNotInteger() throws Exception {
    Field field = Foo.class.getField("stringField");
    FieldType fieldType = FieldType.createFieldType(connectionSource, "foo", field, Foo.class);
    OurSqliteDatabaseType dbType = new OurSqliteDatabaseType();
    StringBuilder sb = new StringBuilder();
    dbType.configureGeneratedId(null, sb, fieldType, new ArrayList<String>(), null, new ArrayList<String>(),
        new ArrayList<String>());
  }
View Full Code Here

  }

  @Test
  public void testConfigureGeneratedIdInteger() throws Exception {
    Field field = Foo.class.getField("val");
    FieldType fieldType = FieldType.createFieldType(connectionSource, "foo", field, Foo.class);
    OurSqliteDatabaseType dbType = new OurSqliteDatabaseType();
    StringBuilder sb = new StringBuilder();
    dbType.configureGeneratedId(null, sb, fieldType, new ArrayList<String>(), null, new ArrayList<String>(),
        new ArrayList<String>());
    assertTrue(sb.toString().contains("PRIMARY KEY AUTOINCREMENT"));
View Full Code Here

   * NOTE: Use of this means that the resulting objects may not have a valid ID column value so cannot be deleted or
   * updated.
   * </p>
   */
  public QueryBuilder<T, ID> groupBy(String columnName) {
    FieldType fieldType = verifyColumnName(columnName);
    if (fieldType.isForeignCollection()) {
      throw new IllegalArgumentException("Can't groupBy foreign colletion field: " + columnName);
    }
    addGroupBy(ColumnNameOrRawSql.withColumnName(columnName));
    return this;
  }
View Full Code Here

TOP

Related Classes of com.j256.ormlite.field.FieldType

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.