Android Open Source - SORM Model






From Project

Back to project page SORM.

License

The source code is released under:

MIT License

If you think the Android project SORM 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 com.annotation.core;
/* ww w  .  ja va  2  s  .  c  o m*/
import android.content.Context;

import com.annotation.Ignore;
import com.annotation.entity.ORMcallback;
import com.annotation.utils.DBUtils;

public class Model {
  private static Object lock = new Object();

  @Ignore
  private Context context;


  private Long __id = null;

  private boolean saveDone = false, deleteDone = false;

  public void save(Context context) {
    synchronized (lock) {

      String sql =DBUtils.createSaveSql(this);
      saveDone = DBUtils.save(context, this.getClass(), sql);

    }
  }

  public void saveAsync(final Context context, final ORMcallback callback) {
    new Thread(new Runnable() {

      @Override
      public void run() {
        Model.this.save(context);
        if (callback != null) {
          if (saveDone)
            callback.onFinish();
          else
            callback.onFaild();
        }
      }
    }).start();
  }

  public void delete(Context context) {
    synchronized (lock) {
      String sql = null;
      sql = new Deletor().from(this.getClass())
          .where("__id", "=", String.valueOf(__id)).build();
      deleteDone = DBUtils.delete(context, this.getClass(), sql,
          this.__id);

    }
  }

  public void deleteAsync(final Context context, final ORMcallback callback) {
    new Thread(new Runnable() {

      @Override
      public void run() {
        Model.this.delete(context);
        if (callback != null) {
          if (deleteDone)
            callback.onFinish();
          else
            callback.onFaild();
        }
      }
    }).start();
  }

  public Long get__id() {
    return __id;
  }

  public void set__id(Long __id) {
    this.__id = __id;
  }

  @Override
  public String toString() {
    return " Model [__id=" + __id + "] ";
  }
}




Java Source Code List

.Creator.java
com.annotation.Column.java
com.annotation.Ignore.java
com.annotation.Index.java
com.annotation.NoNull.java
com.annotation.Table.java
com.annotation.Unique.java
com.annotation.core.Deletor.java
com.annotation.core.Droper.java
com.annotation.core.Indexer.java
com.annotation.core.Inserter.java
com.annotation.core.Model.java
com.annotation.core.Query.java
com.annotation.core.Selector.java
com.annotation.core.Updater.java
com.annotation.entity.ColumnInfo.java
com.annotation.entity.ORMcallback.java
com.annotation.entity.QueryCallback.java
com.annotation.entity.Sqlable.java
com.annotation.entity.Wherable.java
com.annotation.entity.WhereImpl.java
com.annotation.utils.DBHelper.java
com.annotation.utils.DBUtils.java
com.annotation.utils.NameBuilder.java
com.annotation.utils.ReflectionUtils.java
com.annotation.utils.SqlUtils.java
com.annotation.utils._.java