Back to project page guerrillaprose.
The source code is released under:
GNU General Public License
If you think the Android project guerrillaprose 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 de.handler.mobile.android.bachelorapp.app.database; //from w w w .ja v a2 s . c o m import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteStatement; import java.util.ArrayList; import java.util.List; import de.greenrobot.dao.AbstractDao; import de.greenrobot.dao.Property; import de.greenrobot.dao.internal.DaoConfig; import de.greenrobot.dao.internal.SqlUtils; import de.greenrobot.dao.query.Query; import de.greenrobot.dao.query.QueryBuilder; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. /** * DAO for table MEDIA. */ public class MediaDao extends AbstractDao<Media, Long> { public static final String TABLENAME = "MEDIA"; /** * Properties of entity Media.<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 Media_author = new Property(1, String.class, "media_author", false, "MEDIA_AUTHOR"); public final static Property Url = new Property(2, String.class, "url", false, "URL"); public final static Property Remote_url = new Property(3, String.class, "remote_url", false, "REMOTE_URL"); public final static Property Media_type_id = new Property(4, Long.class, "media_type_id", false, "MEDIA_TYPE_ID"); }; private DaoSession daoSession; private Query<Media> mediaType_MediaListQuery; public MediaDao(DaoConfig config) { super(config); } public MediaDao(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 + "'MEDIA' (" + // "'_id' INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "'MEDIA_AUTHOR' TEXT," + // 1: media_author "'URL' TEXT NOT NULL ," + // 2: url "'REMOTE_URL' TEXT," + // 3: remote_url "'MEDIA_TYPE_ID' INTEGER);"); // 4: media_type_id } /** Drops the underlying database table. */ public static void dropTable(SQLiteDatabase db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'MEDIA'"; db.execSQL(sql); } /** @inheritdoc */ @Override protected void bindValues(SQLiteStatement stmt, Media entity) { stmt.clearBindings(); Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } String media_author = entity.getMedia_author(); if (media_author != null) { stmt.bindString(2, media_author); } stmt.bindString(3, entity.getUrl()); String remote_url = entity.getRemote_url(); if (remote_url != null) { stmt.bindString(4, remote_url); } Long media_type_id = entity.getMedia_type_id(); if (media_type_id != null) { stmt.bindLong(5, media_type_id); } } @Override protected void attachEntity(Media 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 Media readEntity(Cursor cursor, int offset) { Media entity = new Media( // cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // media_author cursor.getString(offset + 2), // url cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // remote_url cursor.isNull(offset + 4) ? null : cursor.getLong(offset + 4) // media_type_id ); return entity; } /** @inheritdoc */ @Override public void readEntity(Cursor cursor, Media entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setMedia_author(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); entity.setUrl(cursor.getString(offset + 2)); entity.setRemote_url(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); entity.setMedia_type_id(cursor.isNull(offset + 4) ? null : cursor.getLong(offset + 4)); } /** @inheritdoc */ @Override protected Long updateKeyAfterInsert(Media entity, long rowId) { entity.setId(rowId); return rowId; } /** @inheritdoc */ @Override public Long getKey(Media entity) { if(entity != null) { return entity.getId(); } else { return null; } } /** @inheritdoc */ @Override protected boolean isEntityUpdateable() { return true; } /** Internal query to resolve the "mediaList" to-many relationship of MediaType. */ public List<Media> _queryMediaType_MediaList(Long media_type_id) { synchronized (this) { if (mediaType_MediaListQuery == null) { QueryBuilder<Media> queryBuilder = queryBuilder(); queryBuilder.where(Properties.Media_type_id.eq(null)); mediaType_MediaListQuery = queryBuilder.build(); } } Query<Media> query = mediaType_MediaListQuery.forCurrentThread(); query.setParameter(0, media_type_id); 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.getMediaTypeDao().getAllColumns()); builder.append(" FROM MEDIA T"); builder.append(" LEFT JOIN MEDIA_TYPE T0 ON T.'MEDIA_TYPE_ID'=T0.'_id'"); builder.append(' '); selectDeep = builder.toString(); } return selectDeep; } protected Media loadCurrentDeep(Cursor cursor, boolean lock) { Media entity = loadCurrent(cursor, 0, lock); int offset = getAllColumns().length; MediaType mediaType = loadCurrentOther(daoSession.getMediaTypeDao(), cursor, offset); entity.setMediaType(mediaType); return entity; } public Media 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<Media> loadAllDeepFromCursor(Cursor cursor) { int count = cursor.getCount(); List<Media> list = new ArrayList<Media>(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<Media> 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<Media> queryDeep(String where, String... selectionArg) { Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg); return loadDeepAllAndCloseCursor(cursor); } }