-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
292 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
app/src/main/java/com/carlos/grabredenvelope/db/DaoMaster.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.carlos.grabredenvelope.db; | ||
|
||
import android.content.Context; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteDatabase.CursorFactory; | ||
import android.util.Log; | ||
|
||
import org.greenrobot.greendao.AbstractDaoMaster; | ||
import org.greenrobot.greendao.database.StandardDatabase; | ||
import org.greenrobot.greendao.database.Database; | ||
import org.greenrobot.greendao.database.DatabaseOpenHelper; | ||
import org.greenrobot.greendao.identityscope.IdentityScopeType; | ||
|
||
|
||
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. | ||
/** | ||
* Master of DAO (schema version 1): knows all DAOs. | ||
*/ | ||
public class DaoMaster extends AbstractDaoMaster { | ||
public static final int SCHEMA_VERSION = 1; | ||
|
||
/** Creates underlying database table using DAOs. */ | ||
public static void createAllTables(Database db, boolean ifNotExists) { | ||
WechatRedEnvelopeDao.createTable(db, ifNotExists); | ||
} | ||
|
||
/** Drops underlying database table using DAOs. */ | ||
public static void dropAllTables(Database db, boolean ifExists) { | ||
WechatRedEnvelopeDao.dropTable(db, ifExists); | ||
} | ||
|
||
/** | ||
* WARNING: Drops all table on Upgrade! Use only during development. | ||
* Convenience method using a {@link DevOpenHelper}. | ||
*/ | ||
public static DaoSession newDevSession(Context context, String name) { | ||
Database db = new DevOpenHelper(context, name).getWritableDb(); | ||
DaoMaster daoMaster = new DaoMaster(db); | ||
return daoMaster.newSession(); | ||
} | ||
|
||
public DaoMaster(SQLiteDatabase db) { | ||
this(new StandardDatabase(db)); | ||
} | ||
|
||
public DaoMaster(Database db) { | ||
super(db, SCHEMA_VERSION); | ||
registerDaoClass(WechatRedEnvelopeDao.class); | ||
} | ||
|
||
public DaoSession newSession() { | ||
return new DaoSession(db, IdentityScopeType.Session, daoConfigMap); | ||
} | ||
|
||
public DaoSession newSession(IdentityScopeType type) { | ||
return new DaoSession(db, type, daoConfigMap); | ||
} | ||
|
||
/** | ||
* Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} - | ||
*/ | ||
public static abstract class OpenHelper extends DatabaseOpenHelper { | ||
public OpenHelper(Context context, String name) { | ||
super(context, name, SCHEMA_VERSION); | ||
} | ||
|
||
public OpenHelper(Context context, String name, CursorFactory factory) { | ||
super(context, name, factory, SCHEMA_VERSION); | ||
} | ||
|
||
@Override | ||
public void onCreate(Database db) { | ||
Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION); | ||
createAllTables(db, false); | ||
} | ||
} | ||
|
||
/** WARNING: Drops all table on Upgrade! Use only during development. */ | ||
public static class DevOpenHelper extends OpenHelper { | ||
public DevOpenHelper(Context context, String name) { | ||
super(context, name); | ||
} | ||
|
||
public DevOpenHelper(Context context, String name, CursorFactory factory) { | ||
super(context, name, factory); | ||
} | ||
|
||
@Override | ||
public void onUpgrade(Database db, int oldVersion, int newVersion) { | ||
Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables"); | ||
dropAllTables(db, true); | ||
onCreate(db); | ||
} | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
app/src/main/java/com/carlos/grabredenvelope/db/DaoSession.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.carlos.grabredenvelope.db; | ||
|
||
import java.util.Map; | ||
|
||
import org.greenrobot.greendao.AbstractDao; | ||
import org.greenrobot.greendao.AbstractDaoSession; | ||
import org.greenrobot.greendao.database.Database; | ||
import org.greenrobot.greendao.identityscope.IdentityScopeType; | ||
import org.greenrobot.greendao.internal.DaoConfig; | ||
|
||
import com.carlos.grabredenvelope.db.WechatRedEnvelope; | ||
|
||
import com.carlos.grabredenvelope.db.WechatRedEnvelopeDao; | ||
|
||
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @see org.greenrobot.greendao.AbstractDaoSession | ||
*/ | ||
public class DaoSession extends AbstractDaoSession { | ||
|
||
private final DaoConfig wechatRedEnvelopeDaoConfig; | ||
|
||
private final WechatRedEnvelopeDao wechatRedEnvelopeDao; | ||
|
||
public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig> | ||
daoConfigMap) { | ||
super(db); | ||
|
||
wechatRedEnvelopeDaoConfig = daoConfigMap.get(WechatRedEnvelopeDao.class).clone(); | ||
wechatRedEnvelopeDaoConfig.initIdentityScope(type); | ||
|
||
wechatRedEnvelopeDao = new WechatRedEnvelopeDao(wechatRedEnvelopeDaoConfig, this); | ||
|
||
registerDao(WechatRedEnvelope.class, wechatRedEnvelopeDao); | ||
} | ||
|
||
public void clear() { | ||
wechatRedEnvelopeDaoConfig.clearIdentityScope(); | ||
} | ||
|
||
public WechatRedEnvelopeDao getWechatRedEnvelopeDao() { | ||
return wechatRedEnvelopeDao; | ||
} | ||
|
||
} |
133 changes: 133 additions & 0 deletions
133
app/src/main/java/com/carlos/grabredenvelope/db/WechatRedEnvelopeDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package com.carlos.grabredenvelope.db; | ||
|
||
import android.database.Cursor; | ||
import android.database.sqlite.SQLiteStatement; | ||
|
||
import org.greenrobot.greendao.AbstractDao; | ||
import org.greenrobot.greendao.Property; | ||
import org.greenrobot.greendao.internal.DaoConfig; | ||
import org.greenrobot.greendao.database.Database; | ||
import org.greenrobot.greendao.database.DatabaseStatement; | ||
|
||
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. | ||
/** | ||
* DAO for table "WECHAT_RED_ENVELOPE". | ||
*/ | ||
public class WechatRedEnvelopeDao extends AbstractDao<WechatRedEnvelope, Long> { | ||
|
||
public static final String TABLENAME = "WECHAT_RED_ENVELOPE"; | ||
|
||
/** | ||
* Properties of entity WechatRedEnvelope.<br/> | ||
* Can be used for QueryBuilder and for referencing column names. | ||
*/ | ||
public static class Properties { | ||
public final static Property Id = new Property(0, Long.class, "id", true, "_id"); | ||
public final static Property Time = new Property(1, long.class, "time", false, "TIME"); | ||
public final static Property Count = new Property(2, String.class, "count", false, "COUNT"); | ||
} | ||
|
||
|
||
public WechatRedEnvelopeDao(DaoConfig config) { | ||
super(config); | ||
} | ||
|
||
public WechatRedEnvelopeDao(DaoConfig config, DaoSession daoSession) { | ||
super(config, daoSession); | ||
} | ||
|
||
/** Creates the underlying database table. */ | ||
public static void createTable(Database db, boolean ifNotExists) { | ||
String constraint = ifNotExists? "IF NOT EXISTS ": ""; | ||
db.execSQL("CREATE TABLE " + constraint + "\"WECHAT_RED_ENVELOPE\" (" + // | ||
"\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id | ||
"\"TIME\" INTEGER NOT NULL ," + // 1: time | ||
"\"COUNT\" TEXT);"); // 2: count | ||
} | ||
|
||
/** Drops the underlying database table. */ | ||
public static void dropTable(Database db, boolean ifExists) { | ||
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"WECHAT_RED_ENVELOPE\""; | ||
db.execSQL(sql); | ||
} | ||
|
||
@Override | ||
protected final void bindValues(DatabaseStatement stmt, WechatRedEnvelope entity) { | ||
stmt.clearBindings(); | ||
|
||
Long id = entity.getId(); | ||
if (id != null) { | ||
stmt.bindLong(1, id); | ||
} | ||
stmt.bindLong(2, entity.getTime()); | ||
|
||
String count = entity.getCount(); | ||
if (count != null) { | ||
stmt.bindString(3, count); | ||
} | ||
} | ||
|
||
@Override | ||
protected final void bindValues(SQLiteStatement stmt, WechatRedEnvelope entity) { | ||
stmt.clearBindings(); | ||
|
||
Long id = entity.getId(); | ||
if (id != null) { | ||
stmt.bindLong(1, id); | ||
} | ||
stmt.bindLong(2, entity.getTime()); | ||
|
||
String count = entity.getCount(); | ||
if (count != null) { | ||
stmt.bindString(3, count); | ||
} | ||
} | ||
|
||
@Override | ||
public Long readKey(Cursor cursor, int offset) { | ||
return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); | ||
} | ||
|
||
@Override | ||
public WechatRedEnvelope readEntity(Cursor cursor, int offset) { | ||
WechatRedEnvelope entity = new WechatRedEnvelope( // | ||
cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id | ||
cursor.getLong(offset + 1), // time | ||
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2) // count | ||
); | ||
return entity; | ||
} | ||
|
||
@Override | ||
public void readEntity(Cursor cursor, WechatRedEnvelope entity, int offset) { | ||
entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); | ||
entity.setTime(cursor.getLong(offset + 1)); | ||
entity.setCount(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); | ||
} | ||
|
||
@Override | ||
protected final Long updateKeyAfterInsert(WechatRedEnvelope entity, long rowId) { | ||
entity.setId(rowId); | ||
return rowId; | ||
} | ||
|
||
@Override | ||
public Long getKey(WechatRedEnvelope entity) { | ||
if(entity != null) { | ||
return entity.getId(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean hasKey(WechatRedEnvelope entity) { | ||
return entity.getId() != null; | ||
} | ||
|
||
@Override | ||
protected final boolean isEntityUpdateable() { | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.