Back to project page campus.
The source code is released under:
GNU General Public License
If you think the Android project campus 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 lecho.app.campus.dao; /*ww w .j a va 2s .c om*/ 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 lecho.app.campus.dao.Unit; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. /** * DAO for table UNIT. */ public class UnitDao extends AbstractDao<Unit, Long> { public static final String TABLENAME = "UNIT"; /** * Properties of entity Unit.<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 ShortName = new Property(2, String.class, "shortName", false, "SHORT_NAME"); public final static Property FacultyId = new Property(3, Long.class, "facultyId", false, "FACULTY_ID"); }; private DaoSession daoSession; public UnitDao(DaoConfig config) { super(config); } public UnitDao(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 + "'UNIT' (" + // "'_id' INTEGER PRIMARY KEY ," + // 0: id "'NAME' TEXT NOT NULL ," + // 1: name "'SHORT_NAME' TEXT," + // 2: shortName "'FACULTY_ID' INTEGER);"); // 3: facultyId } /** Drops the underlying database table. */ public static void dropTable(SQLiteDatabase db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'UNIT'"; db.execSQL(sql); } /** @inheritdoc */ @Override protected void bindValues(SQLiteStatement stmt, Unit entity) { stmt.clearBindings(); Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } stmt.bindString(2, entity.getName()); String shortName = entity.getShortName(); if (shortName != null) { stmt.bindString(3, shortName); } Long facultyId = entity.getFacultyId(); if (facultyId != null) { stmt.bindLong(4, facultyId); } } @Override protected void attachEntity(Unit 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 Unit readEntity(Cursor cursor, int offset) { Unit entity = new Unit( // cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id cursor.getString(offset + 1), // name cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // shortName cursor.isNull(offset + 3) ? null : cursor.getLong(offset + 3) // facultyId ); return entity; } /** @inheritdoc */ @Override public void readEntity(Cursor cursor, Unit entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setName(cursor.getString(offset + 1)); entity.setShortName(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2)); entity.setFacultyId(cursor.isNull(offset + 3) ? null : cursor.getLong(offset + 3)); } /** @inheritdoc */ @Override protected Long updateKeyAfterInsert(Unit entity, long rowId) { entity.setId(rowId); return rowId; } /** @inheritdoc */ @Override public Long getKey(Unit 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.getFacultyDao().getAllColumns()); builder.append(" FROM UNIT T"); builder.append(" LEFT JOIN FACULTY T0 ON T.'FACULTY_ID'=T0.'_id'"); builder.append(' '); selectDeep = builder.toString(); } return selectDeep; } protected Unit loadCurrentDeep(Cursor cursor, boolean lock) { Unit entity = loadCurrent(cursor, 0, lock); int offset = getAllColumns().length; Faculty faculty = loadCurrentOther(daoSession.getFacultyDao(), cursor, offset); entity.setFaculty(faculty); return entity; } public Unit 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<Unit> loadAllDeepFromCursor(Cursor cursor) { int count = cursor.getCount(); List<Unit> list = new ArrayList<Unit>(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<Unit> 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<Unit> queryDeep(String where, String... selectionArg) { Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg); return loadDeepAllAndCloseCursor(cursor); } }