package com.braunster.chatsdk.dao; 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 de.greenrobot.dao.query.Query; import de.greenrobot.dao.query.QueryBuilder; import com.braunster.chatsdk.dao.ContactLink; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. /** * DAO for table CONTACT_LINK. */ public class ContactLinkDao extends AbstractDao<ContactLink, Long> { public static final String TABLENAME = "CONTACT_LINK"; /** * Properties of entity ContactLink.<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 BUserDaoId = new Property(1, Long.class, "BUserDaoId", false, "BUSER_DAO_ID"); public final static Property LinkOwnerBUserDaoId = new Property(2, Long.class, "linkOwnerBUserDaoId", false, "LINK_OWNER_BUSER_DAO_ID"); }; private DaoSession daoSession; private Query<ContactLink> bUser_ContactLinksQuery; public ContactLinkDao(DaoConfig config) { super(config); } public ContactLinkDao(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 + "'CONTACT_LINK' (" + // "'_id' INTEGER PRIMARY KEY ," + // 0: id "'BUSER_DAO_ID' INTEGER," + // 1: BUserDaoId "'LINK_OWNER_BUSER_DAO_ID' INTEGER);"); // 2: linkOwnerBUserDaoId } /** Drops the underlying database table. */ public static void dropTable(SQLiteDatabase db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'CONTACT_LINK'"; db.execSQL(sql); } /** @inheritdoc */ @Override protected void bindValues(SQLiteStatement stmt, ContactLink entity) { stmt.clearBindings(); Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } Long BUserDaoId = entity.getBUserDaoId(); if (BUserDaoId != null) { stmt.bindLong(2, BUserDaoId); } Long linkOwnerBUserDaoId = entity.getLinkOwnerBUserDaoId(); if (linkOwnerBUserDaoId != null) { stmt.bindLong(3, linkOwnerBUserDaoId); } } @Override protected void attachEntity(ContactLink 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 ContactLink readEntity(Cursor cursor, int offset) { ContactLink entity = new ContactLink( // cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1), // BUserDaoId cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2) // linkOwnerBUserDaoId ); return entity; } /** @inheritdoc */ @Override public void readEntity(Cursor cursor, ContactLink entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setBUserDaoId(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1)); entity.setLinkOwnerBUserDaoId(cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2)); } /** @inheritdoc */ @Override protected Long updateKeyAfterInsert(ContactLink entity, long rowId) { entity.setId(rowId); return rowId; } /** @inheritdoc */ @Override public Long getKey(ContactLink entity) { if(entity != null) { return entity.getId(); } else { return null; } } /** @inheritdoc */ @Override protected boolean isEntityUpdateable() { return true; } /** Internal query to resolve the "contactLinks" to-many relationship of BUser. */ public List<ContactLink> _queryBUser_ContactLinks(Long BUserDaoId) { synchronized (this) { if (bUser_ContactLinksQuery == null) { QueryBuilder<ContactLink> queryBuilder = queryBuilder(); queryBuilder.where(Properties.BUserDaoId.eq(null)); bUser_ContactLinksQuery = queryBuilder.build(); } } Query<ContactLink> query = bUser_ContactLinksQuery.forCurrentThread(); query.setParameter(0, BUserDaoId); 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.getBUserDao().getAllColumns()); builder.append(','); SqlUtils.appendColumns(builder, "T1", daoSession.getBUserDao().getAllColumns()); builder.append(" FROM CONTACT_LINK T"); builder.append(" LEFT JOIN BUSER T0 ON T.'BUSER_DAO_ID'=T0.'_id'"); builder.append(" LEFT JOIN BUSER T1 ON T.'LINK_OWNER_BUSER_DAO_ID'=T1.'_id'"); builder.append(' '); selectDeep = builder.toString(); } return selectDeep; } protected ContactLink loadCurrentDeep(Cursor cursor, boolean lock) { ContactLink entity = loadCurrent(cursor, 0, lock); int offset = getAllColumns().length; BUser BUser = loadCurrentOther(daoSession.getBUserDao(), cursor, offset); entity.setBUser(BUser); offset += daoSession.getBUserDao().getAllColumns().length; BUser linkOwnerBUser = loadCurrentOther(daoSession.getBUserDao(), cursor, offset); entity.setLinkOwnerBUser(linkOwnerBUser); return entity; } public ContactLink 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<ContactLink> loadAllDeepFromCursor(Cursor cursor) { int count = cursor.getCount(); List<ContactLink> list = new ArrayList<ContactLink>(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<ContactLink> 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<ContactLink> queryDeep(String where, String... selectionArg) { Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg); return loadDeepAllAndCloseCursor(cursor); } }