Examples of DatabaseFieldConfig


Examples of com.j256.ormlite.field.DatabaseFieldConfig

  }

  @Test
  public void testSetTableNameCase() {
    List<DatabaseFieldConfig> fieldConfigs = new ArrayList<DatabaseFieldConfig>();
    DatabaseFieldConfig fieldId = new DatabaseFieldConfig("id");
    fieldId.setId(true);
    fieldConfigs.add(fieldId);
    fieldConfigs.add(new DatabaseFieldConfig("stuff"));

    DatabaseTableConfig<SubWithoutAnno> tableConfig = new DatabaseTableConfig<SubWithoutAnno>();
    tableConfig.setDataClass(SubWithoutAnno.class);
    String tableName = "mixEDcaSE";
    tableConfig.setTableName(tableName);
View Full Code Here

Examples of com.j256.ormlite.field.DatabaseFieldConfig

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

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

    if (columnAnnotation != null) {
      if (stringNotEmpty(columnAnnotation.name())) {
        config.setColumnName(columnAnnotation.name());
      }
      if (stringNotEmpty(columnAnnotation.columnDefinition())) {
        config.setColumnDefinition(columnAnnotation.columnDefinition());
      }
      config.setWidth(columnAnnotation.length());
      config.setCanBeNull(columnAnnotation.nullable());
      config.setUnique(columnAnnotation.unique());
    }
    if (basicAnnotation != null) {
      config.setCanBeNull(basicAnnotation.optional());
    }
    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);
      }
    }
    if (oneToOneAnnotation != null || manyToOneAnnotation != null) {
      // if we have a collection then make it a foreign collection
      if (Collection.class.isAssignableFrom(field.getType())
          || ForeignCollection.class.isAssignableFrom(field.getType())) {
        config.setForeignCollection(true);
        if (joinColumnAnnotation != null && stringNotEmpty(joinColumnAnnotation.name())) {
          config.setForeignCollectionColumnName(joinColumnAnnotation.name());
        }
        if (manyToOneAnnotation != null) {
          FetchType fetchType = manyToOneAnnotation.fetch();
          if (fetchType != null && fetchType == FetchType.EAGER) {
            config.setForeignCollectionEager(true);
          }
        }
      } else {
        // otherwise it is a foreign field
        config.setForeign(true);
        if (joinColumnAnnotation != null) {
          if (stringNotEmpty(joinColumnAnnotation.name())) {
            config.setColumnName(joinColumnAnnotation.name());
          }
          config.setCanBeNull(joinColumnAnnotation.nullable());
          config.setUnique(joinColumnAnnotation.unique());
        }
      }
    }
    if (enumeratedAnnotation != null) {
      EnumType enumType = enumeratedAnnotation.value();
      if (enumType != null && enumType == EnumType.STRING) {
        config.setDataType(DataType.ENUM_STRING);
      } else {
        config.setDataType(DataType.ENUM_INTEGER);
      }
    }
    if (versionAnnotation != null) {
      // just the presence of the version...
      config.setVersion(true);
    }
    if (config.getDataPersister() == 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

  }

  private Dao<Account, Integer> createLazyOrderDao() throws SQLException, 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 testUpperCaseFieldNames() throws Exception {
    Field[] fields = Javax.class.getDeclaredFields();
    UpperCaseFieldDatabaseType ucDatabaseType = new UpperCaseFieldDatabaseType();
    for (Field field : fields) {
      DatabaseFieldConfig config = new JavaxPersistenceImpl().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

    String tableName = "pojgefwpjoefwpjo";
    config.setTableName(tableName);
    body.append("tableName=").append(tableName).append(LINE_SEP);
    checkConfigOutput(config, body, writer, buffer, false);

    DatabaseFieldConfig field1 = new DatabaseFieldConfig();
    String columnName = "efjpowefpjoefw";
    field1.setColumnName(columnName);
    config.setFieldConfigs(Arrays.asList(field1));
    StringWriter fieldWriter = new StringWriter();
    BufferedWriter fieldBuffer = new BufferedWriter(fieldWriter);
    DatabaseFieldConfigLoader.write(fieldBuffer, field1, tableName);
    fieldBuffer.flush();
View Full Code Here

Examples of com.j256.ormlite.field.DatabaseFieldConfig

  }

  @Test
  public void testFieldConfig() throws Exception {
    List<DatabaseFieldConfig> fieldConfigs = new ArrayList<DatabaseFieldConfig>();
    fieldConfigs.add(new DatabaseFieldConfig("id", "id2", DataType.UNKNOWN, null, 0, false, false, true, null,
        false, null, false, null, false, null, false, null, null, false, -1, 0));
    fieldConfigs.add(new DatabaseFieldConfig("stuff", "stuffy", DataType.UNKNOWN, null, 0, false, false, false,
        null, false, null, false, null, false, null, false, null, null, false, -1, 0));
    DatabaseTableConfig<NoAnno> tableConfig = new DatabaseTableConfig<NoAnno>(NoAnno.class, "noanno", fieldConfigs);
    Dao<NoAnno, Integer> noAnnotaionDao = createDao(tableConfig, true);
    NoAnno noa = new NoAnno();
    String stuff = "qpoqwpjoqwp12";
View Full Code Here

Examples of com.j256.ormlite.field.DatabaseFieldConfig

  }

  @Test
  public void testFieldConfigForeign() throws Exception {
    List<DatabaseFieldConfig> noAnnotationsFieldConfigs = new ArrayList<DatabaseFieldConfig>();
    DatabaseFieldConfig field1 = new DatabaseFieldConfig("id");
    field1.setColumnName("idthingie");
    field1.setGeneratedId(true);
    noAnnotationsFieldConfigs.add(field1);
    DatabaseFieldConfig field2 = new DatabaseFieldConfig("stuff");
    field2.setColumnName("stuffy");
    noAnnotationsFieldConfigs.add(field2);
    DatabaseTableConfig<NoAnno> noAnnotationsTableConfig =
        new DatabaseTableConfig<NoAnno>(NoAnno.class, noAnnotationsFieldConfigs);
    Dao<NoAnno, Integer> noAnnotationDao = createDao(noAnnotationsTableConfig, true);
    NoAnno noa = new NoAnno();
    String stuff = "qpoqwpjoqwp12";
    noa.stuff = stuff;
    assertEquals(1, noAnnotationDao.create(noa));
    assertNotNull(noAnnotationDao.queryForId(noa.id));

    List<DatabaseFieldConfig> noAnnotationsForiegnFieldConfigs = new ArrayList<DatabaseFieldConfig>();
    DatabaseFieldConfig field3 = new DatabaseFieldConfig("id");
    field3.setColumnName("anotherid");
    field3.setGeneratedId(true);
    noAnnotationsForiegnFieldConfigs.add(field3);
    DatabaseFieldConfig field4 = new DatabaseFieldConfig("foreign");
    field4.setColumnName("foreignThingie");
    field4.setForeign(true);
    field4.setForeignTableConfig(noAnnotationsTableConfig);
    noAnnotationsForiegnFieldConfigs.add(field4);
    DatabaseTableConfig<NoAnnoFor> noAnnotationsForiegnTableConfig =
        new DatabaseTableConfig<NoAnnoFor>(NoAnnoFor.class, noAnnotationsForiegnFieldConfigs);

    Dao<NoAnnoFor, Integer> noAnnotaionForeignDao = createDao(noAnnotationsForiegnTableConfig, true);
View Full Code Here

Examples of com.j256.ormlite.field.DatabaseFieldConfig

    TableUtils.createTable(connectionSource, deliveryTableConfig);
  }

  private DatabaseTableConfig<Account> buildAccountTableConfig() {
    ArrayList<DatabaseFieldConfig> fieldConfigs = new ArrayList<DatabaseFieldConfig>();
    DatabaseFieldConfig fieldConfig = new DatabaseFieldConfig("id");
    fieldConfig.setGeneratedId(true);
    fieldConfigs.add(fieldConfig);
    fieldConfigs.add(new DatabaseFieldConfig("name"));
    fieldConfig = new DatabaseFieldConfig("password");
    fieldConfig.setCanBeNull(true);
    fieldConfigs.add(fieldConfig);
    DatabaseTableConfig<Account> tableConfig = new DatabaseTableConfig<Account>(Account.class, fieldConfigs);
    return tableConfig;
  }
View Full Code Here

Examples of com.j256.ormlite.field.DatabaseFieldConfig

    return tableConfig;
  }

  private DatabaseTableConfig<Delivery> buildDeliveryTableConfig(DatabaseTableConfig<Account> accountTableConfig) {
    ArrayList<DatabaseFieldConfig> fieldConfigs = new ArrayList<DatabaseFieldConfig>();
    DatabaseFieldConfig fieldConfig = new DatabaseFieldConfig("id");
    fieldConfig.setGeneratedId(true);
    fieldConfigs.add(fieldConfig);
    fieldConfigs.add(new DatabaseFieldConfig("when"));
    fieldConfigs.add(new DatabaseFieldConfig("signedBy"));
    fieldConfig = new DatabaseFieldConfig("account");
    fieldConfig.setForeign(true);
    fieldConfig.setForeignTableConfig(accountTableConfig);
    fieldConfigs.add(fieldConfig);
    DatabaseTableConfig<Delivery> tableConfig = new DatabaseTableConfig<Delivery>(Delivery.class, fieldConfigs);
    return tableConfig;
  }
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.