Commit 1ee7387b3a84de76a74c3aa4d478afda1b521e0b

Authored by YangShuai
1 parent b3f3717e

1 添加数据库

moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/sql/dao/CalorieEntityDao.java 0 → 100644
  1 +package com.cnlive.moudle.pedometer.sql.dao;
  2 +
  3 +import android.database.Cursor;
  4 +import android.database.sqlite.SQLiteStatement;
  5 +
  6 +import org.greenrobot.greendao.AbstractDao;
  7 +import org.greenrobot.greendao.Property;
  8 +import org.greenrobot.greendao.internal.DaoConfig;
  9 +import org.greenrobot.greendao.database.Database;
  10 +import org.greenrobot.greendao.database.DatabaseStatement;
  11 +
  12 +import com.cnlive.moudle.pedometer.sql.entity.CalorieEntity;
  13 +
  14 +// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
  15 +/**
  16 + * DAO for table "CALORIE_ENTITY".
  17 +*/
  18 +public class CalorieEntityDao extends AbstractDao<CalorieEntity, String> {
  19 +
  20 + public static final String TABLENAME = "CALORIE_ENTITY";
  21 +
  22 + /**
  23 + * Properties of entity CalorieEntity.<br/>
  24 + * Can be used for QueryBuilder and for referencing column names.
  25 + */
  26 + public static class Properties {
  27 + public final static Property Uuid = new Property(0, String.class, "uuid", true, "UUID");
  28 + public final static Property UserId = new Property(1, String.class, "userId", false, "USER_ID");
  29 + public final static Property CurrentDate = new Property(2, String.class, "currentDate", false, "CURRENT_DATE");
  30 + public final static Property Step = new Property(3, String.class, "step", false, "STEP");
  31 + public final static Property Calorie = new Property(4, String.class, "calorie", false, "CALORIE");
  32 + }
  33 +
  34 +
  35 + public CalorieEntityDao(DaoConfig config) {
  36 + super(config);
  37 + }
  38 +
  39 + public CalorieEntityDao(DaoConfig config, DaoSession daoSession) {
  40 + super(config, daoSession);
  41 + }
  42 +
  43 + /** Creates the underlying database table. */
  44 + public static void createTable(Database db, boolean ifNotExists) {
  45 + String constraint = ifNotExists? "IF NOT EXISTS ": "";
  46 + db.execSQL("CREATE TABLE " + constraint + "\"CALORIE_ENTITY\" (" + //
  47 + "\"UUID\" TEXT PRIMARY KEY NOT NULL ," + // 0: uuid
  48 + "\"USER_ID\" TEXT," + // 1: userId
  49 + "\"CURRENT_DATE\" TEXT," + // 2: currentDate
  50 + "\"STEP\" TEXT," + // 3: step
  51 + "\"CALORIE\" TEXT);"); // 4: calorie
  52 + }
  53 +
  54 + /** Drops the underlying database table. */
  55 + public static void dropTable(Database db, boolean ifExists) {
  56 + String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"CALORIE_ENTITY\"";
  57 + db.execSQL(sql);
  58 + }
  59 +
  60 + @Override
  61 + protected final void bindValues(DatabaseStatement stmt, CalorieEntity entity) {
  62 + stmt.clearBindings();
  63 +
  64 + String uuid = entity.getUuid();
  65 + if (uuid != null) {
  66 + stmt.bindString(1, uuid);
  67 + }
  68 +
  69 + String userId = entity.getUserId();
  70 + if (userId != null) {
  71 + stmt.bindString(2, userId);
  72 + }
  73 +
  74 + String currentDate = entity.getCurrentDate();
  75 + if (currentDate != null) {
  76 + stmt.bindString(3, currentDate);
  77 + }
  78 +
  79 + String step = entity.getStep();
  80 + if (step != null) {
  81 + stmt.bindString(4, step);
  82 + }
  83 +
  84 + String calorie = entity.getCalorie();
  85 + if (calorie != null) {
  86 + stmt.bindString(5, calorie);
  87 + }
  88 + }
  89 +
  90 + @Override
  91 + protected final void bindValues(SQLiteStatement stmt, CalorieEntity entity) {
  92 + stmt.clearBindings();
  93 +
  94 + String uuid = entity.getUuid();
  95 + if (uuid != null) {
  96 + stmt.bindString(1, uuid);
  97 + }
  98 +
  99 + String userId = entity.getUserId();
  100 + if (userId != null) {
  101 + stmt.bindString(2, userId);
  102 + }
  103 +
  104 + String currentDate = entity.getCurrentDate();
  105 + if (currentDate != null) {
  106 + stmt.bindString(3, currentDate);
  107 + }
  108 +
  109 + String step = entity.getStep();
  110 + if (step != null) {
  111 + stmt.bindString(4, step);
  112 + }
  113 +
  114 + String calorie = entity.getCalorie();
  115 + if (calorie != null) {
  116 + stmt.bindString(5, calorie);
  117 + }
  118 + }
  119 +
  120 + @Override
  121 + public String readKey(Cursor cursor, int offset) {
  122 + return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
  123 + }
  124 +
  125 + @Override
  126 + public CalorieEntity readEntity(Cursor cursor, int offset) {
  127 + CalorieEntity entity = new CalorieEntity( //
  128 + cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // uuid
  129 + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // userId
  130 + cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // currentDate
  131 + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // step
  132 + cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4) // calorie
  133 + );
  134 + return entity;
  135 + }
  136 +
  137 + @Override
  138 + public void readEntity(Cursor cursor, CalorieEntity entity, int offset) {
  139 + entity.setUuid(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
  140 + entity.setUserId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
  141 + entity.setCurrentDate(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
  142 + entity.setStep(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
  143 + entity.setCalorie(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
  144 + }
  145 +
  146 + @Override
  147 + protected final String updateKeyAfterInsert(CalorieEntity entity, long rowId) {
  148 + return entity.getUuid();
  149 + }
  150 +
  151 + @Override
  152 + public String getKey(CalorieEntity entity) {
  153 + if(entity != null) {
  154 + return entity.getUuid();
  155 + } else {
  156 + return null;
  157 + }
  158 + }
  159 +
  160 + @Override
  161 + public boolean hasKey(CalorieEntity entity) {
  162 + return entity.getUuid() != null;
  163 + }
  164 +
  165 + @Override
  166 + protected final boolean isEntityUpdateable() {
  167 + return true;
  168 + }
  169 +
  170 +}
... ...
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/sql/db/MyOpenHelper.java
... ... @@ -45,6 +45,7 @@ package com.cnlive.moudle.pedometer.sql.db;
45 45  
46 46 import android.content.Context;
47 47  
  48 +import com.cnlive.moudle.pedometer.sql.dao.CalorieEntityDao;
48 49 import com.cnlive.moudle.pedometer.sql.dao.CollFailedEntityDao;
49 50 import com.cnlive.moudle.pedometer.sql.dao.CollUserStepEntityDao;
50 51 import com.cnlive.moudle.pedometer.sql.dao.DaoMaster;
... ... @@ -78,7 +79,11 @@ public class MyOpenHelper extends DaoMaster.OpenHelper {
78 79 try {
79 80 //进行数据库升级
80 81 new UpgradeHelper().migrate(db,
81   - UserStepEntityDao.class, FailedEntityDao.class, CollUserStepEntityDao.class, CollFailedEntityDao.class
  82 + UserStepEntityDao.class,
  83 + FailedEntityDao.class,
  84 + CollUserStepEntityDao.class,
  85 + CollFailedEntityDao.class,
  86 + CalorieEntityDao.class
82 87 );
83 88 } catch (ClassCastException e) {
84 89 }
... ...