本文整理汇总了Java中com.github.gfx.android.orma.annotation.Column类的典型用法代码示例。如果您正苦于以下问题:Java Column类的具体用法?Java Column怎么用?Java Column使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Column类属于com.github.gfx.android.orma.annotation包,在下文中一共展示了Column类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildOrderByHelpers
import com.github.gfx.android.orma.annotation.Column; //导入依赖的package包/类
void buildOrderByHelpers(List<MethodSpec> methodSpecs, ColumnDefinition column) {
if (column.hasHelper(Column.Helpers.ORDER_IN_ASC)) {
methodSpecs.add(MethodSpec.methodBuilder("orderBy" + Strings.toUpperFirst(column.name) + "Asc")
.addModifiers(Modifier.PUBLIC)
.returns(getTargetClassName())
.addStatement("return orderBy(schema.$L.orderInAscending())", column.name)
.build());
}
if (column.hasHelper(Column.Helpers.ORDER_IN_DESC)) {
methodSpecs.add(MethodSpec.methodBuilder("orderBy" + Strings.toUpperFirst(column.name) + "Desc")
.addModifiers(Modifier.PUBLIC)
.returns(getTargetClassName())
.addStatement("return orderBy(schema.$L.orderInDescending())", column.name)
.build()
);
}
}
示例2: foreignKeyAction
import com.github.gfx.android.orma.annotation.Column; //导入依赖的package包/类
void foreignKeyAction(StringBuilder sb, String clause, Column.ForeignKeyAction action) {
switch (action) {
case NO_ACTION:
// this is the SQLite default (see https://www.sqlite.org/foreignkeys.html)
break;
case RESTRICT:
sb.append(clause);
sb.append("RESTRICT");
break;
case SET_NULL:
sb.append(clause);
sb.append("SET NULL");
break;
case SET_DEFAULT:
sb.append(clause);
sb.append("SET DEFAULT");
break;
case CASCADE:
sb.append(clause);
sb.append("CASCADE");
break;
default:
throw new AssertionError("not reached");
}
}
示例3: ColumnDefinition
import com.github.gfx.android.orma.annotation.Column; //导入依赖的package包/类
private ColumnDefinition(SchemaDefinition schema) {
this.schema = schema;
context = schema.context;
element = null;
name = kDefaultPrimaryKeyName;
columnName = kDefaultPrimaryKeyName;
type = TypeName.LONG;
nullable = false;
explicitNonNull = false;
primaryKey = true;
primaryKeyOnConflict = OnConflict.NONE;
autoincrement = false;
autoId = true;
indexed = false;
unique = false;
uniqueOnConflict = OnConflict.NONE;
defaultExpr = "";
collate = Column.Collate.BINARY;
onDeleteAction = Column.ForeignKeyAction.NO_ACTION;
onUpdateAction = Column.ForeignKeyAction.NO_ACTION;
helperFlags = normalizeHelperFlags(primaryKey, indexed, autoincrement, autoId, Column.Helpers.AUTO);
typeAdapter = schema.context.getTypeAdapter(type);
storageType = null;
}
示例4: columnName
import com.github.gfx.android.orma.annotation.Column; //导入依赖的package包/类
static String columnName(Column column, Element element) {
if (column != null && !column.value().equals("")) {
return column.value();
} else {
for (AnnotationMirror annotation : element.getAnnotationMirrors()) {
Name annotationName = annotation.getAnnotationType().asElement().getSimpleName();
if (annotationName.contentEquals("SerializedName") // GSON
|| annotationName.contentEquals("JsonProperty") // Jackson
) {
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotation
.getElementValues().entrySet()) {
if (entry.getKey().getSimpleName().contentEquals("value")) {
return entry.getValue().getValue().toString();
}
}
}
}
}
return element.getSimpleName().toString();
}
示例5: normalizeHelperFlags
import com.github.gfx.android.orma.annotation.Column; //导入依赖的package包/类
@Column.Helpers
static long normalizeHelperFlags(boolean primaryKey, boolean indexed, boolean autoincrement, boolean autoId, long flags) {
if (flags == Column.Helpers.AUTO) {
if (primaryKey) {
return (autoincrement || !autoId)
? Column.Helpers.CONDITIONS | Column.Helpers.ORDERS
: Column.Helpers.CONDITIONS;
} else if (indexed) {
return Column.Helpers.CONDITIONS | Column.Helpers.ORDERS | Column.Helpers.AGGREGATORS;
} else {
return Column.Helpers.AGGREGATORS;
}
} else {
return flags;
}
}
示例6: buildConditionHelpersForCompositeIndex
import com.github.gfx.android.orma.annotation.Column; //导入依赖的package包/类
void buildConditionHelpersForCompositeIndex(List<MethodSpec> methodSpecs, IndexDefinition index) {
// create only "==" helper
if (!index.hasHelper(Column.Helpers.CONDITION_EQ)) {
return;
}
CharSequence baseName = buildBaseNameForCompositeIndex(index);
CodeBlock.Builder conditions = CodeBlock.builder();
List<ParameterSpec> paramSpecs = new ArrayList<>();
for (int i = 0; i < index.columns.size(); i++) {
ColumnDefinition column = index.columns.get(i);
ParameterSpec paramSpec = buildParameterSpec(column);
CodeBlock serializedFieldExpr = serializedFieldExpr(column, paramSpec);
if (i != 0) {
conditions.add(".");
}
conditions.add("where(schema.$L, $S, $L)",
column.columnName, "=", serializedFieldExpr);
paramSpecs.add(paramSpec);
}
MethodSpec.Builder methodSpec = MethodSpec.methodBuilder(baseName + "Eq")
.addModifiers(Modifier.PUBLIC)
.addParameters(paramSpecs)
.addStatement("return $L", conditions.build())
.returns(targetClassName);
methodSpecs.add(methodSpec.build());
}
示例7: extractIndexes
import com.github.gfx.android.orma.annotation.Column; //导入依赖的package包/类
Stream<IndexDefinition> extractIndexes() {
return columns.stream()
.filter(column -> column.indexed && !column.primaryKey)
.map(column -> new IndexDefinition(
context.sqlg.buildIndexName(tableName, column.columnName),
false,
Column.Helpers.AUTO,
column
));
}
示例8: buildAggregationHelpers
import com.github.gfx.android.orma.annotation.Column; //导入依赖的package包/类
void buildAggregationHelpers(List<MethodSpec> methodSpecs, ColumnDefinition column) {
if (column.hasHelper(Column.Helpers.MIN) && Types.isNumeric(column.type)) {
methodSpecs.add(MethodSpec.methodBuilder("minBy" + Strings.toUpperFirst(column.name))
.addAnnotation(Annotations.nullable())
.addModifiers(Modifier.PUBLIC)
.returns(column.getBoxType())
.addCode(buildAggregatorBody(column, "MIN",
() -> CodeBlock.of("schema.$L.getFromCursor(conn, cursor, 0)", column.name)))
.build()
);
}
if (column.hasHelper(Column.Helpers.MAX) && Types.isNumeric(column.type)) {
methodSpecs.add(MethodSpec.methodBuilder("maxBy" + Strings.toUpperFirst(column.name))
.addAnnotation(Annotations.nullable())
.addModifiers(Modifier.PUBLIC)
.returns(column.getBoxType())
.addCode(buildAggregatorBody(column, "MAX",
() -> CodeBlock.of("schema.$L.getFromCursor(conn, cursor, 0)", column.name)))
.build()
);
}
if (column.hasHelper(Column.Helpers.SUM) && Types.isNumeric(column.type)) {
boolean isInteger = Types.looksLikeIntegerType(column.type);
methodSpecs.add(MethodSpec.methodBuilder("sumBy" + Strings.toUpperFirst(column.name))
.addAnnotation(Annotations.nullable())
.addModifiers(Modifier.PUBLIC)
.returns(isInteger ? TypeName.LONG.box() : TypeName.DOUBLE.box())
.addCode(buildAggregatorBody(column, "SUM",
() -> isInteger ? CodeBlock.of("cursor.getLong(0)") : CodeBlock.of("cursor.getDouble(0)")))
.build()
);
}
if (column.hasHelper(Column.Helpers.AVG) && Types.isNumeric(column.type)) {
methodSpecs.add(MethodSpec.methodBuilder("avgBy" + Strings.toUpperFirst(column.name))
.addAnnotation(Annotations.nullable())
.addModifiers(Modifier.PUBLIC)
.returns(TypeName.DOUBLE.box())
.addCode(buildAggregatorBody(column, "AVG", () -> CodeBlock.of("cursor.getDouble(0)")))
.build()
);
}
}
示例9: buildUpsert
import com.github.gfx.android.orma.annotation.Column; //导入依赖的package包/类
private CodeBlock buildUpsert(String modelExpr) {
CodeBlock.Builder code = CodeBlock.builder();
Optional<ColumnDefinition> optionalPrimaryKey = schema.getPrimaryKey();
if (!optionalPrimaryKey.isPresent()) {
return code.addStatement("throw new $T($S)",
UnsupportedOperationException.class,
"upsert is not supported because of missing @PrimaryKey"
).build();
}
ColumnDefinition primaryKey = optionalPrimaryKey.get();
if (!primaryKey.hasHelper(Column.Helpers.CONDITION_EQ)) {
return code.addStatement("throw new $T($S)",
UnsupportedOperationException.class,
"upsert is not supported because of missing @PrimaryKey's CONDITION_EQ helper"
).build();
}
// build contentValues
code.addStatement("$T contentValues = new $T()", Types.ContentValues, Types.ContentValues);
for (ColumnDefinition column : schema.getColumnsWithoutAutoId()) {
CodeBlock expr = upsertColumnAndGet(modelExpr, column);
code.addStatement("contentValues.put($S, $L)", column.getEscapedColumnName(), expr);
}
// only "auto = true" supports conditional UPDATE
if (primaryKey.autoId) {
code.beginControlFlow("if ($L != 0)", primaryKey.buildGetColumnExpr(modelExpr));
}
code.addStatement("int updatedRows = updater().$LEq($L).putAll(contentValues).execute()",
primaryKey.name, primaryKey.buildGetColumnExpr(modelExpr));
code.beginControlFlow("if (updatedRows != 0)");
code.addStatement("return selector().$LEq($L).value()",
primaryKey.name, primaryKey.buildGetColumnExpr(modelExpr));
code.endControlFlow();
if (primaryKey.autoId) {
code.endControlFlow();
}
code.addStatement("long rowId = conn.insert(schema, contentValues, $T.NONE)", OnConflict.class);
code.addStatement("return conn.findByRowId(schema, rowId)");
return code.build();
}
示例10: appendColumnDef
import com.github.gfx.android.orma.annotation.Column; //导入依赖的package包/类
public void appendColumnDef(StringBuilder sb, ProcessingContext context, ColumnDefinition column) {
appendIdentifier(sb, column.columnName);
sb.append(' ');
sb.append(column.getStorageType());
sb.append(' ');
List<String> constraints = new ArrayList<>();
if (column.primaryKey) {
constraints.add("PRIMARY KEY");
if (column.primaryKeyOnConflict != OnConflict.NONE) {
constraints.add("ON CONFLICT");
constraints.add(onConflictClause(column.primaryKeyOnConflict));
}
if (column.autoincrement) {
constraints.add("AUTOINCREMENT");
}
} else {
if (column.unique) {
constraints.add("UNIQUE");
if (column.uniqueOnConflict != OnConflict.NONE) {
constraints.add("ON CONFLICT");
constraints.add(onConflictClause(column.uniqueOnConflict));
}
}
if (!column.nullable) {
constraints.add("NOT NULL");
}
}
if (!Strings.isEmpty(column.defaultExpr)) {
constraints.add("DEFAULT " + column.defaultExpr);
}
if (column.collate != Column.Collate.BINARY) {
constraints.add("COLLATE " + column.collate.name());
}
if (column.isAssociation()) {
constraints.add(foreignKeyConstraints(context, column));
}
sb.append(constraints.stream().collect(Collectors.joining(" ")));
}
示例11: hasConditionHelpers
import com.github.gfx.android.orma.annotation.Column; //导入依赖的package包/类
public boolean hasConditionHelpers() {
return (helperFlags & Column.Helpers.CONDITIONS) != 0;
}
示例12: hasOrderHelpers
import com.github.gfx.android.orma.annotation.Column; //导入依赖的package包/类
public boolean hasOrderHelpers() {
return (helperFlags & Column.Helpers.ORDERS) != 0;
}
示例13: hasAggregationHelpers
import com.github.gfx.android.orma.annotation.Column; //导入依赖的package包/类
public boolean hasAggregationHelpers() {
return (helperFlags & Column.Helpers.AGGREGATORS) != 0;
}
示例14: hasHelper
import com.github.gfx.android.orma.annotation.Column; //导入依赖的package包/类
public boolean hasHelper(@Column.Helpers long f) {
assert f != Column.Helpers.NONE && f != Column.Helpers.AUTO;
return (helperFlags & f) == f;
}
示例15: IndexDefinition
import com.github.gfx.android.orma.annotation.Column; //导入依赖的package包/类
public IndexDefinition(String name, boolean unique, @Column.Helpers long helperFlags, List<ColumnDefinition> columns) {
this.name = name;
this.unique = unique;
this.helperFlags = helperFlags == Column.Helpers.AUTO ? Column.Helpers.ALL : helperFlags;
this.columns = columns;
}