本文整理汇总了Java中com.j256.ormlite.field.DatabaseField.generatedId方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseField.generatedId方法的具体用法?Java DatabaseField.generatedId怎么用?Java DatabaseField.generatedId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.j256.ormlite.field.DatabaseField
的用法示例。
在下文中一共展示了DatabaseField.generatedId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findIdField
import com.j256.ormlite.field.DatabaseField; //导入方法依赖的package包/类
/**
* Find a Field with a DatabaseField annotation that defines it as being an id column.
*
* @param annotationRetriever the annotation retriever that caches the annotations
* @param modelClass the class to find the ID field in
* @return the Field or null
*/
@Nullable
public static Field findIdField(AnnotationRetriever annotationRetriever, Class<?> modelClass) {
for (Field field : modelClass.getDeclaredFields()) {
DatabaseField database_field = annotationRetriever.getAnnotation(field, DatabaseField.class);
if (database_field == null) {
continue;
}
if (database_field.generatedId() || database_field.id()) {
return field;
}
}
if (modelClass.getSuperclass() == null) {
return null;
}
// Recursively check superclass
return findIdField(annotationRetriever, modelClass.getSuperclass());
}
示例2: fromDatabaseField
import com.j256.ormlite.field.DatabaseField; //导入方法依赖的package包/类
public static FieldBindings fromDatabaseField(DatabaseType databaseType, Element field, DatabaseField databaseField, Types typeUtils, Messager messager) {
FieldBindings bindings = new FieldBindings();
bindings.fieldName = field.getSimpleName().toString();
if (databaseType.isEntityNamesMustBeUpCase()) {
bindings.fieldName = bindings.fieldName.toUpperCase();
}
bindings.columnName = valueIfNotBlank(databaseField.columnName());
bindings.dataType = databaseField.dataType();
// NOTE: == did not work with the NO_DEFAULT string
String defaultValue = databaseField.defaultValue();
if (!defaultValue.equals(DatabaseField.DEFAULT_STRING)) {
bindings.defaultValue = defaultValue;
}
bindings.width = databaseField.width();
bindings.canBeNull = databaseField.canBeNull();
bindings.id = databaseField.id();
bindings.generatedId = databaseField.generatedId();
bindings.generatedIdSequence = valueIfNotBlank(databaseField.generatedIdSequence());
bindings.foreign = databaseField.foreign();
bindings.useGetSet = databaseField.useGetSet();
bindings.unknownEnumValue = findMatchingEnumVal(field, databaseField.unknownEnumName(), messager);
bindings.throwIfNull = databaseField.throwIfNull();
bindings.format = valueIfNotBlank(databaseField.format());
bindings.unique = databaseField.unique();
bindings.uniqueCombo = databaseField.uniqueCombo();
// add in the index information
bindings.index = databaseField.index();
bindings.indexName = valueIfNotBlank(databaseField.indexName());
bindings.uniqueIndex = databaseField.uniqueIndex();
bindings.uniqueIndexName = valueIfNotBlank(databaseField.uniqueIndexName());
bindings.foreignAutoRefresh = databaseField.foreignAutoRefresh();
bindings.maxForeignAutoRefreshLevel = databaseField.maxForeignAutoRefreshLevel();
try {
databaseField.persisterClass();
} catch (MirroredTypeException e) {
Element element = typeUtils.asElement(e.getTypeMirror());
if (!element.getKind().equals(ElementKind.CLASS)) {
messager.printMessage(Diagnostic.Kind.ERROR, "persisterClass must be a class", element);
return null;
}
bindings.persisterClass = (TypeElement) element;
}
bindings.allowGeneratedIdInsert = databaseField.allowGeneratedIdInsert();
bindings.columnDefinition = valueIfNotBlank(databaseField.columnDefinition());
bindings.foreignAutoCreate = databaseField.foreignAutoCreate();
bindings.version = databaseField.version();
bindings.foreignColumnName = valueIfNotBlank(databaseField.foreignColumnName());
bindings.readOnly = databaseField.readOnly();
return bindings;
}
示例3: isId
import com.j256.ormlite.field.DatabaseField; //导入方法依赖的package包/类
/**
* Check if the DatabaseField is an ID field.
*
* @param databaseField the annotation to check
* @return true if id() or generatedId() are true
*/
public static boolean isId(DatabaseField databaseField) {
return databaseField.id() || databaseField.generatedId();
}