Android Open Source - blink Device Dao






From Project

Back to project page blink.

License

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.

Java Source Code

package com.nashlincoln.blink.model;
/*from ww  w.  ja v  a  2  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 com.nashlincoln.blink.model.Device;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table DEVICE.
*/
public class DeviceDao extends AbstractDao<Device, Long> {

    public static final String TABLENAME = "DEVICE";

    /**
     * Properties of entity Device.<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 Name = new Property(1, String.class, "name", false, "NAME");
        public final static Property State = new Property(2, Integer.class, "state", false, "STATE");
        public final static Property Interconnect = new Property(3, String.class, "interconnect", false, "INTERCONNECT");
        public final static Property AttributableType = new Property(4, String.class, "attributableType", false, "ATTRIBUTABLE_TYPE");
        public final static Property DeviceTypeId = new Property(5, Long.class, "deviceTypeId", false, "DEVICE_TYPE_ID");
    };

    private DaoSession daoSession;


    public DeviceDao(DaoConfig config) {
        super(config);
    }
    
    public DeviceDao(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 + "'DEVICE' (" + //
                "'_id' INTEGER PRIMARY KEY ," + // 0: id
                "'NAME' TEXT," + // 1: name
                "'STATE' INTEGER," + // 2: state
                "'INTERCONNECT' TEXT," + // 3: interconnect
                "'ATTRIBUTABLE_TYPE' TEXT," + // 4: attributableType
                "'DEVICE_TYPE_ID' INTEGER);"); // 5: deviceTypeId
    }

    /** Drops the underlying database table. */
    public static void dropTable(SQLiteDatabase db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'DEVICE'";
        db.execSQL(sql);
    }

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, Device entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(2, name);
        }
 
        Integer state = entity.getState();
        if (state != null) {
            stmt.bindLong(3, state);
        }
 
        String interconnect = entity.getInterconnect();
        if (interconnect != null) {
            stmt.bindString(4, interconnect);
        }
 
        String attributableType = entity.getAttributableType();
        if (attributableType != null) {
            stmt.bindString(5, attributableType);
        }
 
        Long deviceTypeId = entity.getDeviceTypeId();
        if (deviceTypeId != null) {
            stmt.bindLong(6, deviceTypeId);
        }
    }

    @Override
    protected void attachEntity(Device 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 Device readEntity(Cursor cursor, int offset) {
        Device entity = new Device( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // name
            cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // state
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // interconnect
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // attributableType
            cursor.isNull(offset + 5) ? null : cursor.getLong(offset + 5) // deviceTypeId
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, Device entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setState(cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2));
        entity.setInterconnect(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setAttributableType(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setDeviceTypeId(cursor.isNull(offset + 5) ? null : cursor.getLong(offset + 5));
     }
    
    /** @inheritdoc */
    @Override
    protected Long updateKeyAfterInsert(Device entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    /** @inheritdoc */
    @Override
    public Long getKey(Device entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    /** @inheritdoc */
    @Override    
    protected boolean isEntityUpdateable() {
        return true;
    }
    
    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.getDeviceTypeDao().getAllColumns());
            builder.append(" FROM DEVICE T");
            builder.append(" LEFT JOIN DEVICE_TYPE T0 ON T.'DEVICE_TYPE_ID'=T0.'_id'");
            builder.append(' ');
            selectDeep = builder.toString();
        }
        return selectDeep;
    }
    
    protected Device loadCurrentDeep(Cursor cursor, boolean lock) {
        Device entity = loadCurrent(cursor, 0, lock);
        int offset = getAllColumns().length;

        DeviceType deviceType = loadCurrentOther(daoSession.getDeviceTypeDao(), cursor, offset);
        entity.setDeviceType(deviceType);

        return entity;    
    }

    public Device 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<Device> loadAllDeepFromCursor(Cursor cursor) {
        int count = cursor.getCount();
        List<Device> list = new ArrayList<Device>(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<Device> 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<Device> queryDeep(String where, String... selectionArg) {
        Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg);
        return loadDeepAllAndCloseCursor(cursor);
    }
 
}




Java Source Code List

com.nashlincoln.blink.ApplicationTest.java
com.nashlincoln.blink.app.BlinkApp.java
com.nashlincoln.blink.app.FragmentPagerAdapter.java
com.nashlincoln.blink.app.NetworkReceiver.java
com.nashlincoln.blink.app.PreferenceUtils.java
com.nashlincoln.blink.content.Command.java
com.nashlincoln.blink.content.DeviceLoader.java
com.nashlincoln.blink.content.DeviceTypeLoader.java
com.nashlincoln.blink.content.GroupLoader.java
com.nashlincoln.blink.content.ModelLoader.java
com.nashlincoln.blink.content.SceneLoader.java
com.nashlincoln.blink.content.Syncro.java
com.nashlincoln.blink.event.Event.java
com.nashlincoln.blink.event.Status.java
com.nashlincoln.blink.event.Type.java
com.nashlincoln.blink.model.AttributeDao.java
com.nashlincoln.blink.model.AttributeTypeDao.java
com.nashlincoln.blink.model.AttributeType.java
com.nashlincoln.blink.model.Attribute.java
com.nashlincoln.blink.model.DaoMaster.java
com.nashlincoln.blink.model.DaoSession.java
com.nashlincoln.blink.model.DeviceDao.java
com.nashlincoln.blink.model.DeviceTypeDao.java
com.nashlincoln.blink.model.DeviceType.java
com.nashlincoln.blink.model.Device.java
com.nashlincoln.blink.model.GroupDao.java
com.nashlincoln.blink.model.GroupDeviceDao.java
com.nashlincoln.blink.model.GroupDevice.java
com.nashlincoln.blink.model.Group.java
com.nashlincoln.blink.model.SceneDao.java
com.nashlincoln.blink.model.SceneDeviceDao.java
com.nashlincoln.blink.model.SceneDevice.java
com.nashlincoln.blink.model.Scene.java
com.nashlincoln.blink.model.TimerDao.java
com.nashlincoln.blink.model.Timer.java
com.nashlincoln.blink.network.BlinkApiInterface.java
com.nashlincoln.blink.network.BlinkApi.java
com.nashlincoln.blink.nfc.NfcCommand.java
com.nashlincoln.blink.nfc.NfcUtils.java
com.nashlincoln.blink.ui.AddDeviceFragment.java
com.nashlincoln.blink.ui.BlinkActivity.java
com.nashlincoln.blink.ui.BlinkListFragment.java
com.nashlincoln.blink.ui.DeviceListFragment.java
com.nashlincoln.blink.ui.EditListActivity.java
com.nashlincoln.blink.ui.EditListFragment.java
com.nashlincoln.blink.ui.EditNameDialogFragment.java
com.nashlincoln.blink.ui.GroupListFragment.java
com.nashlincoln.blink.ui.SceneListFragment.java
com.nashlincoln.blink.ui.SettingsActivity.java
com.nashlincoln.blink.widget.DeviceSummary.java
com.nashlincoln.blink.widget.SlidingTabLayout.java
com.nashlincoln.blink.widget.SlidingTabStrip.java
com.nashlincoln.dao.Generator.java