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; //from w ww .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.SceneDevice; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. /** * DAO for table SCENE_DEVICE. */ public class SceneDeviceDao extends AbstractDao<SceneDevice, Long> { public static final String TABLENAME = "SCENE_DEVICE"; /** * Properties of entity SceneDevice.<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 SceneId = new Property(1, Long.class, "sceneId", false, "SCENE_ID"); public final static Property DeviceId = new Property(2, Long.class, "deviceId", false, "DEVICE_ID"); public final static Property AttributableType = new Property(3, String.class, "attributableType", false, "ATTRIBUTABLE_TYPE"); }; private DaoSession daoSession; private Query<SceneDevice> scene_SceneDeviceListQuery; public SceneDeviceDao(DaoConfig config) { super(config); } public SceneDeviceDao(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 + "'SCENE_DEVICE' (" + // "'_id' INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "'SCENE_ID' INTEGER," + // 1: sceneId "'DEVICE_ID' INTEGER," + // 2: deviceId "'ATTRIBUTABLE_TYPE' TEXT);"); // 3: attributableType // Add Indexes db.execSQL("CREATE INDEX " + constraint + "IDX_SCENE_DEVICE__id_ATTRIBUTABLE_TYPE ON SCENE_DEVICE" + " (_id,ATTRIBUTABLE_TYPE);"); } /** Drops the underlying database table. */ public static void dropTable(SQLiteDatabase db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'SCENE_DEVICE'"; db.execSQL(sql); } /** @inheritdoc */ @Override protected void bindValues(SQLiteStatement stmt, SceneDevice entity) { stmt.clearBindings(); Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } Long sceneId = entity.getSceneId(); if (sceneId != null) { stmt.bindLong(2, sceneId); } Long deviceId = entity.getDeviceId(); if (deviceId != null) { stmt.bindLong(3, deviceId); } String attributableType = entity.getAttributableType(); if (attributableType != null) { stmt.bindString(4, attributableType); } } @Override protected void attachEntity(SceneDevice 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 SceneDevice readEntity(Cursor cursor, int offset) { SceneDevice entity = new SceneDevice( // cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1), // sceneId cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2), // deviceId cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // attributableType ); return entity; } /** @inheritdoc */ @Override public void readEntity(Cursor cursor, SceneDevice entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setSceneId(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1)); entity.setDeviceId(cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2)); entity.setAttributableType(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); } /** @inheritdoc */ @Override protected Long updateKeyAfterInsert(SceneDevice entity, long rowId) { entity.setId(rowId); return rowId; } /** @inheritdoc */ @Override public Long getKey(SceneDevice entity) { if(entity != null) { return entity.getId(); } else { return null; } } /** @inheritdoc */ @Override protected boolean isEntityUpdateable() { return true; } /** Internal query to resolve the "sceneDeviceList" to-many relationship of Scene. */ public List<SceneDevice> _queryScene_SceneDeviceList(Long sceneId) { synchronized (this) { if (scene_SceneDeviceListQuery == null) { QueryBuilder<SceneDevice> queryBuilder = queryBuilder(); queryBuilder.where(Properties.SceneId.eq(null)); scene_SceneDeviceListQuery = queryBuilder.build(); } } Query<SceneDevice> query = scene_SceneDeviceListQuery.forCurrentThread(); query.setParameter(0, sceneId); 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.getSceneDao().getAllColumns()); builder.append(','); SqlUtils.appendColumns(builder, "T1", daoSession.getDeviceDao().getAllColumns()); builder.append(" FROM SCENE_DEVICE T"); builder.append(" LEFT JOIN SCENE T0 ON T.'SCENE_ID'=T0.'_id'"); builder.append(" LEFT JOIN DEVICE T1 ON T.'DEVICE_ID'=T1.'_id'"); builder.append(' '); selectDeep = builder.toString(); } return selectDeep; } protected SceneDevice loadCurrentDeep(Cursor cursor, boolean lock) { SceneDevice entity = loadCurrent(cursor, 0, lock); int offset = getAllColumns().length; Scene scene = loadCurrentOther(daoSession.getSceneDao(), cursor, offset); entity.setScene(scene); offset += daoSession.getSceneDao().getAllColumns().length; Device device = loadCurrentOther(daoSession.getDeviceDao(), cursor, offset); entity.setDevice(device); return entity; } public SceneDevice 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<SceneDevice> loadAllDeepFromCursor(Cursor cursor) { int count = cursor.getCount(); List<SceneDevice> list = new ArrayList<SceneDevice>(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<SceneDevice> 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<SceneDevice> queryDeep(String where, String... selectionArg) { Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg); return loadDeepAllAndCloseCursor(cursor); } }