Java Code Examples for com.j256.ormlite.db.DatabaseType#isEntityNamesMustBeUpCase()
The following examples show how to use
com.j256.ormlite.db.DatabaseType#isEntityNamesMustBeUpCase() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TableUtils.java From ormlite-core with ISC License | 5 votes |
/** * Clear all data out of the table. For certain database types and with large sized tables, which may take a long * time. In some configurations, it may be faster to drop and re-create the table. * * <p> * <b>WARNING:</b> This is [obviously] very destructive and is unrecoverable. * </p> */ public static <T> int clearTable(ConnectionSource connectionSource, Class<T> dataClass) throws SQLException { DatabaseType databaseType = connectionSource.getDatabaseType(); String tableName = DatabaseTableConfig.extractTableName(databaseType, dataClass); String schemaName = DatabaseTableConfig.extractSchemaName(dataClass); if (databaseType.isEntityNamesMustBeUpCase()) { tableName = databaseType.upCaseEntityName(tableName); } return clearTable(connectionSource, schemaName, tableName); }
Example 2
Source File: DatabaseTableConfig.java From ormlite-core with ISC License | 5 votes |
/** * Extract the DatabaseTableConfig for a particular class by looking for class and field annotations. This is used * by internal classes to configure a class. */ public static <T> DatabaseTableConfig<T> fromClass(DatabaseType databaseType, Class<T> clazz) throws SQLException { String tableName = extractTableName(databaseType, clazz); String schemaName = extractSchemaName(clazz); if (databaseType.isEntityNamesMustBeUpCase()) { tableName = databaseType.upCaseEntityName(tableName); schemaName = databaseType.upCaseEntityName(schemaName); } return new DatabaseTableConfig<T>(databaseType, clazz, schemaName, tableName, extractFieldTypes(databaseType, clazz, tableName)); }
Example 3
Source File: DatabaseFieldConfig.java From ormlite-core with ISC License | 4 votes |
public static DatabaseFieldConfig fromDatabaseField(DatabaseType databaseType, String tableName, Field field, DatabaseField databaseField) { DatabaseFieldConfig config = new DatabaseFieldConfig(); config.fieldName = field.getName(); if (databaseType.isEntityNamesMustBeUpCase()) { config.fieldName = databaseType.upCaseEntityName(config.fieldName); } config.columnName = valueIfNotBlank(databaseField.columnName()); config.dataType = databaseField.dataType(); // NOTE: == did not work with the NO_DEFAULT string String defaultValue = databaseField.defaultValue(); if (!defaultValue.equals(DatabaseField.DEFAULT_STRING)) { config.defaultValue = defaultValue; } config.width = databaseField.width(); config.canBeNull = databaseField.canBeNull(); config.id = databaseField.id(); config.generatedId = databaseField.generatedId(); config.generatedIdSequence = valueIfNotBlank(databaseField.generatedIdSequence()); config.foreign = databaseField.foreign(); config.useGetSet = databaseField.useGetSet(); config.unknownEnumValue = findMatchingEnumVal(field, databaseField.unknownEnumName()); config.throwIfNull = databaseField.throwIfNull(); config.format = valueIfNotBlank(databaseField.format()); config.unique = databaseField.unique(); config.uniqueCombo = databaseField.uniqueCombo(); // add in the index information config.index = databaseField.index(); config.indexName = valueIfNotBlank(databaseField.indexName()); config.uniqueIndex = databaseField.uniqueIndex(); config.uniqueIndexName = valueIfNotBlank(databaseField.uniqueIndexName()); config.foreignAutoRefresh = databaseField.foreignAutoRefresh(); if (config.foreignAutoRefresh || databaseField.maxForeignAutoRefreshLevel() != DatabaseField.DEFAULT_MAX_FOREIGN_AUTO_REFRESH_LEVEL) { config.maxForeignAutoRefreshLevel = databaseField.maxForeignAutoRefreshLevel(); } else { config.maxForeignAutoRefreshLevel = NO_MAX_FOREIGN_AUTO_REFRESH_LEVEL_SPECIFIED; } config.persisterClass = databaseField.persisterClass(); config.allowGeneratedIdInsert = databaseField.allowGeneratedIdInsert(); config.columnDefinition = valueIfNotBlank(databaseField.columnDefinition()); config.foreignAutoCreate = databaseField.foreignAutoCreate(); config.version = databaseField.version(); config.foreignColumnName = valueIfNotBlank(databaseField.foreignColumnName()); config.readOnly = databaseField.readOnly(); config.fullColumnDefinition = valueIfNotBlank(databaseField.fullColumnDefinition()); return config; }
Example 4
Source File: JavaxPersistenceImpl.java From ormlite-core with ISC License | 4 votes |
@Override public DatabaseFieldConfig createFieldConfig(DatabaseType databaseType, Field field) { Column columnAnnotation = field.getAnnotation(Column.class); Basic basicAnnotation = field.getAnnotation(Basic.class); Id idAnnotation = field.getAnnotation(Id.class); GeneratedValue generatedValueAnnotation = field.getAnnotation(GeneratedValue.class); OneToOne oneToOneAnnotation = field.getAnnotation(OneToOne.class); ManyToOne manyToOneAnnotation = field.getAnnotation(ManyToOne.class); JoinColumn joinColumnAnnotation = field.getAnnotation(JoinColumn.class); Enumerated enumeratedAnnotation = field.getAnnotation(Enumerated.class); Version versionAnnotation = field.getAnnotation(Version.class); 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 = databaseType.upCaseEntityName(fieldName); } 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, databaseType, false) != null && DatabaseFieldConfig.findSetMethod(field, databaseType, false) != null); return config; }