Android Open Source - intelligent-lock-pattern Attempt 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;
//ww  w . j  av  a  2s.  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.Attempt;

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

    public static final String TABLENAME = "attempts";

    /**
     * Properties of entity Attempt.<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 Experience_id = new Property(1, Long.class, "experience_id", false, "EXPERIENCE_ID");
    };

    private DaoSession daoSession;

    private Query<Attempt> experience_AttemptsQuery;

    public AttemptDao(DaoConfig config) {
        super(config);
    }
    
    public AttemptDao(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 + "'attempts' (" + //
                "'_id' INTEGER PRIMARY KEY ," + // 0: id
                "'EXPERIENCE_ID' INTEGER);"); // 1: experience_id
    }

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

    /** @inheritdoc */
    @Override
    protected void bindValues(SQLiteStatement stmt, Attempt entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        Long experience_id = entity.getExperience_id();
        if (experience_id != null) {
            stmt.bindLong(2, experience_id);
        }
    }

    @Override
    protected void attachEntity(Attempt 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 Attempt readEntity(Cursor cursor, int offset) {
        Attempt entity = new Attempt( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1) // experience_id
        );
        return entity;
    }
     
    /** @inheritdoc */
    @Override
    public void readEntity(Cursor cursor, Attempt entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setExperience_id(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1));
     }
    
    /** @inheritdoc */
    @Override
    protected Long updateKeyAfterInsert(Attempt entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    /** @inheritdoc */
    @Override
    public Long getKey(Attempt entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

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

        Experience experience = loadCurrentOther(daoSession.getExperienceDao(), cursor, offset);
        entity.setExperience(experience);

        return entity;    
    }

    public Attempt 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<Attempt> loadAllDeepFromCursor(Cursor cursor) {
        int count = cursor.getCount();
        List<Attempt> list = new ArrayList<Attempt>(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<Attempt> 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<Attempt> 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