Android Open Source - TodoList Meta Data






From Project

Back to project page TodoList.

License

The source code is released under:

Apache License

If you think the Android project TodoList listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package lyc.simplesqlite.util;
/*  ww  w . j  av  a2s  .  com*/
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import lyc.simplesqlite.annotation.Column;
import lyc.simplesqlite.annotation.Table;
import lyc.simplesqlite.exception.AnnotationNotFoundException;

import static lyc.simplesqlite.util.StringUtils.Callback;

/**
 * Created by ivan on 14-9-25.
 */
public class MetaData {

  private MetaData() {
  }

  public static String tableName(Class<?> clz) {
    Table table = clz.getAnnotation(Table.class);
    if (table != null) {
      return table.value();
    }
    throw new AnnotationNotFoundException(Table.class);
  }

  public static String schema(Class<?> clz) {
    StringBuilder sb = new StringBuilder();
    Table table = clz.getAnnotation(Table.class);
    if (table != null) {
      Field[] fields = clz.getDeclaredFields();
      final List<String> primaryKeyColumns = new ArrayList<String>();
      String columns = StringUtils.join(fields, new Callback<Field>() {
        public String process(Field field) {
          Column column = field.getAnnotation(Column.class);
          if (column.isPrimaryKey()) {
            primaryKeyColumns.add(column.name());
          }
          return String
              .format("%s %s %s", column.name(), column.type(), column.notNull() ? "NOT NULL" : "");
        }
      });

      if (columns.length() > 0) {
        sb.append(String.format("CREATE TABLE %s (", table.value()));
        sb.append(columns);
        String primaryKeys = StringUtils.join(primaryKeyColumns.toArray(), ", ");
        if (primaryKeys.length() > 0) {
          sb.append(", ");
          sb.append(String.format("PRIMARY KEY (%s)", primaryKeys));
        }
        sb.append(");");
        return sb.toString();
      } else {
        throw new AnnotationNotFoundException(Column.class);
      }
    }
    throw new AnnotationNotFoundException(Table.class);
  }

  public static String list() {
    return null;
  }
}




Java Source Code List

lyc.app.AddActivity.java
lyc.app.App.java
lyc.app.BootReceiver.java
lyc.app.DateUtils.java
lyc.app.MainActivity.java
lyc.app.TodoService.java
lyc.app.adapter.TodoCursorAdapter.java
lyc.app.fragment.FinishedTodoFragment.java
lyc.app.fragment.UnFinishedTodoFragment.java
lyc.app.provider.TodoProvider.java
lyc.simplesqlite.annotation.Column.java
lyc.simplesqlite.annotation.Table.java
lyc.simplesqlite.exception.AnnotationNotFoundException.java
lyc.simplesqlite.util.MetaData.java
lyc.simplesqlite.util.StringUtils.java