Back to project page blink.
The source code is released under:
Apache License
If you think the Android project blink listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.nashlincoln.blink.model; /* w w w. j a v a2 s . c o m*/ import java.util.List; import java.util.ArrayList; 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.SqlUtils; import de.greenrobot.dao.internal.DaoConfig; import de.greenrobot.dao.query.Query; import de.greenrobot.dao.query.QueryBuilder; import com.nashlincoln.blink.model.GroupDevice; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. /** * DAO for table GROUP_DEVICE. */ public class GroupDeviceDao extends AbstractDao<GroupDevice, Long> { public static final String TABLENAME = "GROUP_DEVICE"; /** * Properties of entity GroupDevice.<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 State = new Property(1, Integer.class, "state", false, "STATE"); public final static Property GroupId = new Property(2, Long.class, "groupId", false, "GROUP_ID"); public final static Property DeviceId = new Property(3, Long.class, "deviceId", false, "DEVICE_ID"); }; private DaoSession daoSession; private Query<GroupDevice> group_GroupDeviceListQuery; public GroupDeviceDao(DaoConfig config) { super(config); } public GroupDeviceDao(DaoConfig config, DaoSession daoSession) { super(config, daoSession); this.daoSession = 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 + "'GROUP_DEVICE' (" + // "'_id' INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "'STATE' INTEGER," + // 1: state "'GROUP_ID' INTEGER," + // 2: groupId "'DEVICE_ID' INTEGER);"); // 3: deviceId // Add Indexes db.execSQL("CREATE INDEX " + constraint + "IDX_GROUP_DEVICE_GROUP_ID ON GROUP_DEVICE" + " (GROUP_ID);"); } /** Drops the underlying database table. */ public static void dropTable(SQLiteDatabase db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'GROUP_DEVICE'"; db.execSQL(sql); } /** @inheritdoc */ @Override protected void bindValues(SQLiteStatement stmt, GroupDevice entity) { stmt.clearBindings(); Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } Integer state = entity.getState(); if (state != null) { stmt.bindLong(2, state); } Long groupId = entity.getGroupId(); if (groupId != null) { stmt.bindLong(3, groupId); } Long deviceId = entity.getDeviceId(); if (deviceId != null) { stmt.bindLong(4, deviceId); } } @Override protected void attachEntity(GroupDevice entity) { super.attachEntity(entity); entity.__setDaoSession(daoSession); } /** @inheritdoc */ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); } /** @inheritdoc */ @Override public GroupDevice readEntity(Cursor cursor, int offset) { GroupDevice entity = new GroupDevice( // cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id cursor.isNull(offset + 1) ? null : cursor.getInt(offset + 1), // state cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2), // groupId cursor.isNull(offset + 3) ? null : cursor.getLong(offset + 3) // deviceId ); return entity; } /** @inheritdoc */ @Override public void readEntity(Cursor cursor, GroupDevice entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setState(cursor.isNull(offset + 1) ? null : cursor.getInt(offset + 1)); entity.setGroupId(cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2)); entity.setDeviceId(cursor.isNull(offset + 3) ? null : cursor.getLong(offset + 3)); } /** @inheritdoc */ @Override protected Long updateKeyAfterInsert(GroupDevice entity, long rowId) { entity.setId(rowId); return rowId; } /** @inheritdoc */ @Override public Long getKey(GroupDevice entity) { if(entity != null) { return entity.getId(); } else { return null; } } /** @inheritdoc */ @Override protected boolean isEntityUpdateable() { return true; } /** Internal query to resolve the "groupDeviceList" to-many relationship of Group. */ public List<GroupDevice> _queryGroup_GroupDeviceList(Long groupId) { synchronized (this) { if (group_GroupDeviceListQuery == null) { QueryBuilder<GroupDevice> queryBuilder = queryBuilder(); queryBuilder.where(Properties.GroupId.eq(null)); group_GroupDeviceListQuery = queryBuilder.build(); } } Query<GroupDevice> query = group_GroupDeviceListQuery.forCurrentThread(); query.setParameter(0, groupId); return query.list(); } private String selectDeep; protected String getSelectDeep() { if (selectDeep == null) { StringBuilder builder = new StringBuilder("SELECT "); SqlUtils.appendColumns(builder, "T", getAllColumns()); builder.append(','); SqlUtils.appendColumns(builder, "T0", daoSession.getDeviceDao().getAllColumns()); builder.append(','); SqlUtils.appendColumns(builder, "T1", daoSession.getGroupDao().getAllColumns()); builder.append(" FROM GROUP_DEVICE T"); builder.append(" LEFT JOIN DEVICE T0 ON T.'DEVICE_ID'=T0.'_id'"); builder.append(" LEFT JOIN BLINK_GROUP T1 ON T.'GROUP_ID'=T1.'_id'"); builder.append(' '); selectDeep = builder.toString(); } return selectDeep; } protected GroupDevice loadCurrentDeep(Cursor cursor, boolean lock) { GroupDevice entity = loadCurrent(cursor, 0, lock); int offset = getAllColumns().length; Device device = loadCurrentOther(daoSession.getDeviceDao(), cursor, offset); entity.setDevice(device); offset += daoSession.getDeviceDao().getAllColumns().length; Group group = loadCurrentOther(daoSession.getGroupDao(), cursor, offset); entity.setGroup(group); return entity; } public GroupDevice loadDeep(Long key) { assertSinglePk(); if (key == null) { return null; } StringBuilder builder = new StringBuilder(getSelectDeep()); builder.append("WHERE "); SqlUtils.appendColumnsEqValue(builder, "T", getPkColumns()); String sql = builder.toString(); String[] keyArray = new String[] { key.toString() }; Cursor cursor = db.rawQuery(sql, keyArray); try { boolean available = cursor.moveToFirst(); if (!available) { return null; } else if (!cursor.isLast()) { throw new IllegalStateException("Expected unique result, but count was " + cursor.getCount()); } return loadCurrentDeep(cursor, true); } finally { cursor.close(); } } /** Reads all available rows from the given cursor and returns a list of new ImageTO objects. */ public List<GroupDevice> loadAllDeepFromCursor(Cursor cursor) { int count = cursor.getCount(); List<GroupDevice> list = new ArrayList<GroupDevice>(count); if (cursor.moveToFirst()) { if (identityScope != null) { identityScope.lock(); identityScope.reserveRoom(count); } try { do { list.add(loadCurrentDeep(cursor, false)); } while (cursor.moveToNext()); } finally { if (identityScope != null) { identityScope.unlock(); } } } return list; } protected List<GroupDevice> loadDeepAllAndCloseCursor(Cursor cursor) { try { return loadAllDeepFromCursor(cursor); } finally { cursor.close(); } } /** A raw-style query where you can pass any WHERE clause and arguments. */ public List<GroupDevice> queryDeep(String where, String... selectionArg) { Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg); return loadDeepAllAndCloseCursor(cursor); } }