package jp.mydns.sys1yagi.android.greendaosample;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import de.greenrobot.dao.internal.DaoConfig;
import jp.mydns.sys1yagi.android.greendaosample.Todo;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table TODO.
*/
public class TodoDao extends AbstractDao<Todo, Long> {
public static final String TABLENAME = "TODO";
/**
* Properties of entity Todo.<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 Todo = new Property(1, String.class, "todo", false, "TODO");
public final static Property AddDate = new Property(2, java.util.Date.class, "addDate", false, "ADD_DATE");
public final static Property EndDate = new Property(3, java.util.Date.class, "endDate", false, "END_DATE");
public final static Property Status = new Property(4, int.class, "status", false, "STATUS");
};
public TodoDao(DaoConfig config) {
super(config);
}
public TodoDao(DaoConfig config, DaoSession daoSession) {
super(config, daoSession);
}
/** Creates the underlying database table. */
public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
String constraint = ifNotExists? "IF NOT EXISTS ": "";
db.execSQL("CREATE TABLE " + constraint + "'TODO' (" + //
"'_id' INTEGER PRIMARY KEY ," + // 0: id
"'TODO' TEXT," + // 1: todo
"'ADD_DATE' INTEGER NOT NULL ," + // 2: addDate
"'END_DATE' INTEGER," + // 3: endDate
"'STATUS' INTEGER NOT NULL UNIQUE );"); // 4: status
}
/** Drops the underlying database table. */
public static void dropTable(SQLiteDatabase db, boolean ifExists) {
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'TODO'";
db.execSQL(sql);
}
/** @inheritdoc */
@Override
protected void bindValues(SQLiteStatement stmt, Todo entity) {
stmt.clearBindings();
Long id = entity.getId();
if (id != null) {
stmt.bindLong(1, id);
}
String todo = entity.getTodo();
if (todo != null) {
stmt.bindString(2, todo);
}
stmt.bindLong(3, entity.getAddDate().getTime());
java.util.Date endDate = entity.getEndDate();
if (endDate != null) {
stmt.bindLong(4, endDate.getTime());
}
stmt.bindLong(5, entity.getStatus());
}
/** @inheritdoc */
@Override
public Long readKey(Cursor cursor, int offset) {
return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
}
/** @inheritdoc */
@Override
public Todo readEntity(Cursor cursor, int offset) {
Todo entity = new Todo( //
cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // todo
new java.util.Date(cursor.getLong(offset + 2)), // addDate
cursor.isNull(offset + 3) ? null : new java.util.Date(cursor.getLong(offset + 3)), // endDate
cursor.getInt(offset + 4) // status
);
return entity;
}
/** @inheritdoc */
@Override
public void readEntity(Cursor cursor, Todo entity, int offset) {
entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
entity.setTodo(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
entity.setAddDate(new java.util.Date(cursor.getLong(offset + 2)));
entity.setEndDate(cursor.isNull(offset + 3) ? null : new java.util.Date(cursor.getLong(offset + 3)));
entity.setStatus(cursor.getInt(offset + 4));
}
/** @inheritdoc */
@Override
protected Long updateKeyAfterInsert(Todo entity, long rowId) {
entity.setId(rowId);
return rowId;
}
/** @inheritdoc */
@Override
public Long getKey(Todo entity) {
if(entity != null) {
return entity.getId();
} else {
return null;
}
}
/** @inheritdoc */
@Override
protected boolean isEntityUpdateable() {
return true;
}
}