use of com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.StorIOContentResolverColumnMeta in project storio by pushtorefresh.
the class PutResolverGenerator method createMapToContentValuesMethodSpec.
@NotNull
private MethodSpec createMapToContentValuesMethodSpec(@NotNull final StorIOContentResolverTypeMeta storIOContentResolverTypeMeta, @NotNull final ClassName storIOContentResolverClassName) {
MethodSpec.Builder builder = MethodSpec.methodBuilder("mapToContentValues").addJavadoc("{@inheritDoc}\n").addAnnotation(Override.class).addAnnotation(ANDROID_NON_NULL_ANNOTATION_CLASS_NAME).addModifiers(PUBLIC).returns(ClassName.get("android.content", "ContentValues")).addParameter(ParameterSpec.builder(storIOContentResolverClassName, "object").addAnnotation(ANDROID_NON_NULL_ANNOTATION_CLASS_NAME).build()).addStatement("ContentValues contentValues = new ContentValues($L)", storIOContentResolverTypeMeta.columns.size()).addCode("\n");
for (final StorIOContentResolverColumnMeta columnMeta : storIOContentResolverTypeMeta.columns.values()) {
final boolean ignoreNull = columnMeta.storIOColumn.ignoreNull();
if (ignoreNull) {
builder.beginControlFlow("if (object.$L != null)", columnMeta.elementName + (columnMeta.isMethod() ? "()" : ""));
}
builder.addStatement("contentValues.put($S, object.$L)", columnMeta.storIOColumn.name(), columnMeta.elementName + (columnMeta.isMethod() ? "()" : ""));
if (ignoreNull) {
builder.endControlFlow();
}
}
return builder.addCode("\n").addStatement("return contentValues").build();
}
use of com.pushtorefresh.storio.contentresolver.annotations.processor.introspection.StorIOContentResolverColumnMeta in project storio by pushtorefresh.
the class QueryGenerator method createWhere.
@NotNull
public static Map<String, String> createWhere(@NotNull final StorIOContentResolverTypeMeta storIOContentResolverTypeMeta, @NotNull final String varName) {
final StringBuilder whereClause = new StringBuilder();
final StringBuilder whereArgs = new StringBuilder();
int i = 0;
for (final StorIOContentResolverColumnMeta columnMeta : storIOContentResolverTypeMeta.columns.values()) {
if (columnMeta.storIOColumn.key()) {
if (i == 0) {
whereClause.append(columnMeta.storIOColumn.name()).append(" = ?");
whereArgs.append(varName).append(".").append(columnMeta.elementName);
} else {
whereClause.append(" AND ").append(columnMeta.storIOColumn.name()).append(" = ?");
whereArgs.append(", ").append(varName).append(".").append(columnMeta.elementName);
}
if (columnMeta.isMethod()) {
whereArgs.append("()");
}
i++;
}
}
if (whereClause.length() == 0 || whereArgs.length() == 0) {
return Collections.emptyMap();
} else {
final Map<String, String> result = new HashMap<String, String>(2);
// example: "email = ? AND user_id = ?"
result.put(WHERE_CLAUSE, whereClause.toString());
// example: "object.email, object.userId"
result.put(WHERE_ARGS, whereArgs.toString());
return result;
}
}
Aggregations