Android Open Source - intelligent-lock-pattern Sample Dao






From Project

Back to project page intelligent-lock-pattern.

License

The source code is released under:

GNU General Public License

If you think the Android project intelligent-lock-pattern 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 org.unioeste.ilp.models;
/*  w ww.  ja va  2 s. co 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.DaoConfig;
import de.greenrobot.dao.Property;
import de.greenrobot.dao.SqlUtils;
import de.greenrobot.dao.Query;
import de.greenrobot.dao.QueryBuilder;

import org.unioeste.ilp.models.Sample;

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

    public static final String TABLENAME = "samples";

    /**
     * Properties of entity Sample.<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 Event_time = new Property(1, double.class, "event_time", false, "EVENT_TIME");
        public final static Property Pressure = new Property(2, double.class, "pressure", false, "PRESSURE");
        public final static Property Pressure_area = new Property(3, double.class, "pressure_area", false, "PRESSURE_AREA");
        public final static Property Attempt_id = new Property(4, Long.class, "attempt_id", false, "ATTEMPT_ID");
    };

    private DaoSession daoSession;

    private Query<Sample> attempt_SamplesQuery;

    public SampleDao(DaoConfig config) {
        super(config);
    }
    
    public SampleDao(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 + "'samples' (" + //
                "'_id' INTEGER PRIMARY KEY ," + // 0: id
                "'EVENT_TIME' REAL NOT NULL ," + // 1: event_time
                "'PRESSURE' REAL NOT NULL ," + // 2: pressure
                "'PRESSURE_AREA' REAL NOT NULL ," + // 3: pressure_area
                "'ATTEMPT_ID' INTEGER);"); // 4: attempt_id
    }

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

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, Sample entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindDouble(2, entity.getEvent_time());
        stmt.bindDouble(3, entity.getPressure());
        stmt.bindDouble(4, entity.getPressure_area());
 
        Long attempt_id = entity.getAttempt_id();
        if (attempt_id != null) {
            stmt.bindLong(5, attempt_id);
        }
    }

    @Override
    protected void attachEntity(Sample 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 Sample readEntity(Cursor cursor, int offset) {
        Sample entity = new Sample( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.getDouble(offset + 1), // event_time
            cursor.getDouble(offset + 2), // pressure
            cursor.getDouble(offset + 3), // pressure_area
            cursor.isNull(offset + 4) ? null : cursor.getLong(offset + 4) // attempt_id
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, Sample entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setEvent_time(cursor.getDouble(offset + 1));
        entity.setPressure(cursor.getDouble(offset + 2));
        entity.setPressure_area(cursor.getDouble(offset + 3));
        entity.setAttempt_id(cursor.isNull(offset + 4) ? null : cursor.getLong(offset + 4));
     }
    
    /** @inheritdoc */
    @Override
    protected Long updateKeyAfterInsert(Sample entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    /** @inheritdoc */
    @Override
    public Long getKey(Sample entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    /** @inheritdoc */
    @Override    
    protected boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "samples" to-many relationship of Attempt. */
    public synchronized List<Sample> _queryAttempt_Samples(Long attempt_id) {
        if (attempt_SamplesQuery == null) {
            QueryBuilder<Sample> queryBuilder = queryBuilder();
            queryBuilder.where(Properties.Attempt_id.eq(attempt_id));
            attempt_SamplesQuery = queryBuilder.build();
        } else {
            attempt_SamplesQuery.setParameter(0, attempt_id);
        }
        return attempt_SamplesQuery.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.getAttemptDao().getAllColumns());
            builder.append(" FROM samples T");
            builder.append(" LEFT JOIN attempts T0 ON T.'ATTEMPT_ID'=T0.'_id'");
            builder.append(' ');
            selectDeep = builder.toString();
        }
        return selectDeep;
    }
    
    protected Sample loadCurrentDeep(Cursor cursor, boolean lock) {
        Sample entity = loadCurrent(cursor, 0, lock);
        int offset = getAllColumns().length;

        Attempt attempt = loadCurrentOther(daoSession.getAttemptDao(), cursor, offset);
        entity.setAttempt(attempt);

        return entity;    
    }

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




Java Source Code List

group.pals.android.lib.ui.lockpattern.LockPatternActivity.java
group.pals.android.lib.ui.lockpattern.collect.Lists.java
group.pals.android.lib.ui.lockpattern.widget.LockPatternUtils.java
group.pals.android.lib.ui.lockpattern.widget.LockPatternView.java
org.unioeste.ilp.BaseActivity.java
org.unioeste.ilp.CollectSamplesActivity.java
org.unioeste.ilp.DatabaseExporterActivity.java
org.unioeste.ilp.ILPApp.java
org.unioeste.ilp.InsertPatternActivity.java
org.unioeste.ilp.LockPatternActivity.java
org.unioeste.ilp.MainMenuActivity.java
org.unioeste.ilp.PrefsActivity.java
org.unioeste.ilp.ShowPatternsActivity.java
org.unioeste.ilp.StartExperimentActivity.java
org.unioeste.ilp.TestAuthActivity.java
org.unioeste.ilp.adapters.ExperiencesUserAdapter.java
org.unioeste.ilp.adapters.LockPatternGalleryAdapter.java
org.unioeste.ilp.db.DBHelper.java
org.unioeste.ilp.models.AttemptDao.java
org.unioeste.ilp.models.Attempt.java
org.unioeste.ilp.models.DaoMaster.java
org.unioeste.ilp.models.DaoSession.java
org.unioeste.ilp.models.ExperienceDao.java
org.unioeste.ilp.models.Experience.java
org.unioeste.ilp.models.PatternDao.java
org.unioeste.ilp.models.Pattern.java
org.unioeste.ilp.models.SampleDao.java
org.unioeste.ilp.models.Sample.java
org.unioeste.ilp.models.UserDao.java
org.unioeste.ilp.models.User.java
org.unioeste.ilp.services.SamplesCollectorService.java