Examples of DatabaseFieldConfig


Examples of com.j256.ormlite.field.DatabaseFieldConfig

    if (columnAnnotation == null && idAnnotation == null && oneToOneAnnotation == null
        && manyToOneAnnotation == null) {
      return null;
    }

    DatabaseFieldConfig config = new DatabaseFieldConfig();
    String fieldName = field.getName();
    if (databaseType.isEntityNamesMustBeUpCase()) {
      fieldName = fieldName.toUpperCase();
    }
    config.setFieldName(fieldName);

    if (columnAnnotation != null) {
      try {
        Method method = columnAnnotation.getClass().getMethod("name");
        String name = (String) method.invoke(columnAnnotation);
        if (name != null && name.length() > 0) {
          config.setColumnName(name);
        }
        method = columnAnnotation.getClass().getMethod("length");
        config.setWidth((Integer) method.invoke(columnAnnotation));
        method = columnAnnotation.getClass().getMethod("nullable");
        config.setCanBeNull((Boolean) method.invoke(columnAnnotation));
        method = columnAnnotation.getClass().getMethod("unique");
        config.setUnique((Boolean) method.invoke(columnAnnotation));
      } catch (Exception e) {
        throw SqlExceptionUtil.create("Problem accessing fields from the Column annotation for field " + field,
            e);
      }
    }
    if (idAnnotation != null) {
      if (generatedValueAnnotation == null) {
        config.setId(true);
      } else {
        // generatedValue only works if it is also an id according to {@link GeneratedValue)
        config.setGeneratedId(true);
      }
    }
    // foreign values are always ones we can't map as primitives (or Strings)
    config.setForeign(oneToOneAnnotation != null || manyToOneAnnotation != null);
    config.setDataPersister(DataPersisterManager.lookupForField(field));
    config.setUseGetSet(DatabaseFieldConfig.findGetMethod(field, false) != null
        && DatabaseFieldConfig.findSetMethod(field, false) != null);
    return config;
  }
View Full Code Here

Examples of com.j256.ormlite.field.DatabaseFieldConfig

  @Test
  public void testLazyCollection() throws Exception {
    List<DatabaseFieldConfig> fieldConfigs = new ArrayList<DatabaseFieldConfig>();
    for (Field field : Account.class.getDeclaredFields()) {
      DatabaseFieldConfig fieldConfig = DatabaseFieldConfig.fromField(databaseType, "account", field);
      if (fieldConfig != null) {
        if (fieldConfig.isForeignCollection()) {
          fieldConfig.setForeignCollectionEager(false);
        }
        fieldConfigs.add(fieldConfig);
      }
    }
    DatabaseTableConfig<Account> tableConfig = new DatabaseTableConfig<Account>(Account.class, fieldConfigs);
View Full Code Here

Examples of com.j256.ormlite.field.DatabaseFieldConfig

  @Test
  public void testConversions() throws Exception {
    Field[] fields = Javax.class.getDeclaredFields();
    for (Field field : fields) {
      DatabaseFieldConfig config = JavaxPersistence.createFieldConfig(databaseType, field);
      if (field.getName().equals("generatedId")) {
        assertFalse(config.isId());
        assertTrue(config.isGeneratedId());
        assertEquals(field.getName(), config.getFieldName());
        assertNull(config.getColumnName());
      } else if (field.getName().equals("id")) {
        assertTrue(config.isId());
        assertFalse(config.isGeneratedId());
        assertEquals(field.getName(), config.getFieldName());
        assertNull(config.getColumnName());
      } else if (field.getName().equals("stuff")) {
        assertFalse(config.isId());
        assertFalse(config.isGeneratedId());
        assertEquals(field.getName(), config.getFieldName());
        assertEquals(STUFF_FIELD_NAME, config.getColumnName());
      } else if (field.getName().equals("unknown")) {
        assertFalse(config.isId());
        assertFalse(config.isGeneratedId());
        assertNull(config.getDataPersister());
        assertEquals(field.getName(), config.getFieldName());
        assertNull(config.getColumnName());
      } else if (field.getName().equals("foreignManyToOne")) {
        assertFalse(config.isId());
        assertFalse(config.isGeneratedId());
        assertTrue(config.isForeign());
        assertNull(config.getDataPersister());
        assertEquals(field.getName(), config.getFieldName());
        assertNull(config.getColumnName());
      } else if (field.getName().equals("foreignOneToOne")) {
        assertFalse(config.isId());
        assertFalse(config.isGeneratedId());
        assertTrue(config.isForeign());
        assertNull(config.getDataPersister());
        assertEquals(field.getName(), config.getFieldName());
        assertNull(config.getColumnName());
      } else {
        System.err.println("\n\n\nUnknown field: " + field.getName());
      }
    }
  }
View Full Code Here

Examples of com.j256.ormlite.field.DatabaseFieldConfig

  @Test
  public void testUpperCaseFieldNames() throws Exception {
    Field[] fields = Javax.class.getDeclaredFields();
    UpperCaseFieldDatabaseType ucDatabaseType = new UpperCaseFieldDatabaseType();
    for (Field field : fields) {
      DatabaseFieldConfig config = JavaxPersistence.createFieldConfig(ucDatabaseType, field);
      if (field.getName().equals("id")) {
        assertTrue(config.isId());
        assertFalse(config.isGeneratedId());
        assertEquals("ID", config.getFieldName());
      }
    }
  }
View Full Code Here

Examples of com.j256.ormlite.field.DatabaseFieldConfig

  @Test
  public void testCreateClass() throws Exception {
    testClass(Foo.class);
    DatabaseTableConfig<Foo> tableConfig =
        new DatabaseTableConfig<Foo>(Foo.class, Arrays.asList(new DatabaseFieldConfig("id", null,
            DataType.UNKNOWN, null, 0, false, false, false, null, false, null, false, null, false, null,
            false, null, null, false, 0, 0)));
    testTable(tableConfig);
  }
View Full Code Here

Examples of com.j256.ormlite.field.DatabaseFieldConfig

  @SuppressWarnings("deprecation")
  @Test
  public void testRegisterDaoTable() throws Exception {
    DatabaseTableConfig<Bar> tableConfig =
        new DatabaseTableConfig<Bar>(Bar.class, Arrays.asList(new DatabaseFieldConfig("foo", null,
            DataType.UNKNOWN, null, 0, false, false, false, null, false, null, false, null, false, null,
            false, null, null, false, 0, 0)));
    Dao<Bar, Void> dao = DaoManager.lookupDao(connectionSource, tableConfig);
    assertNull(dao);
    Dao<? extends Bar, Object> daoImpl = BaseDaoImpl.createDao(connectionSource, tableConfig);
View Full Code Here

Examples of com.j256.ormlite.field.DatabaseFieldConfig

  @Test
  public void testDaoClassBaseDaoImpl() throws Exception {
    testClass(Bar.class);
    DatabaseTableConfig<Bar> tableConfig =
        new DatabaseTableConfig<Bar>(Bar.class, Arrays.asList(new DatabaseFieldConfig("foo", null,
            DataType.UNKNOWN, null, 0, false, false, false, null, false, null, false, null, false, null,
            false, null, null, false, 0, 0)));
    testTable(tableConfig);
  }
View Full Code Here

Examples of com.j256.ormlite.field.DatabaseFieldConfig

  @Test
  public void testDaoClassDifferentDao() throws Exception {
    testClass(Baz.class);
    DatabaseTableConfig<Baz> tableConfig =
        new DatabaseTableConfig<Baz>(Baz.class, Arrays.asList(new DatabaseFieldConfig("foo", null,
            DataType.UNKNOWN, null, 0, false, false, false, null, false, null, false, null, false, null,
            false, null, null, false, 0, 0)));
    testTable(tableConfig);
  }
View Full Code Here

Examples of com.j256.ormlite.field.DatabaseFieldConfig

    } catch (SQLException e) {
      // expected
    }
    DatabaseTableConfig<PrivateConstructor> tableConfig =
        new DatabaseTableConfig<PrivateConstructor>(PrivateConstructor.class,
            Arrays.asList(new DatabaseFieldConfig("foo", null, DataType.UNKNOWN, null, 0, false, false,
                false, null, false, null, false, null, false, null, false, null, null, false, 0, 0)));
    try {
      testTable(tableConfig);
      fail("exception expected");
    } catch (SQLException e) {
View Full Code Here

Examples of com.j256.ormlite.field.DatabaseFieldConfig

      fail("exception expected");
    } catch (SQLException e) {
      // expected
    }
    DatabaseTableConfig<ConstructorFail> tableConfig =
        new DatabaseTableConfig<ConstructorFail>(ConstructorFail.class, Arrays.asList(new DatabaseFieldConfig(
            "foo", null, DataType.UNKNOWN, null, 0, false, false, false, null, false, null, false, null,
            false, null, false, null, null, false, 0, 0)));
    try {
      testTable(tableConfig);
      fail("exception expected");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.