package com.pinecone.technology.mcommerce.learning.android.chapter06.example.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 com.pinecone.technology.mcommerce.learning.android.chapter06.example.dao.Customer; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. /** * DAO for table CUSTOMER. */ public class CustomerDao extends AbstractDao<Customer, Long> { public static final String TABLENAME = "CUSTOMER"; /** * Properties of entity Customer.<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, "CustomerId"); public final static Property FirstName = new Property(1, String.class, "FirstName", false, "FirstName"); public final static Property LastName = new Property(2, String.class, "LastName", false, "LastName"); public final static Property Company = new Property(3, String.class, "Company", false, "Company"); public final static Property Address = new Property(4, String.class, "Address", false, "Address"); public final static Property City = new Property(5, String.class, "City", false, "City"); public final static Property State = new Property(6, String.class, "State", false, "State"); public final static Property Country = new Property(7, String.class, "Country", false, "Country"); public final static Property PostalCode = new Property(8, String.class, "PostalCode", false, "PostalCode"); public final static Property Phone = new Property(9, String.class, "Phone", false, "Phone"); public final static Property Fax = new Property(10, String.class, "Fax", false, "Fax"); public final static Property Email = new Property(11, String.class, "Email", false, "Email"); public final static Property SupportRepId = new Property(12, Long.class, "SupportRepId", false, "SupportRepId"); }; private DaoSession daoSession; public CustomerDao(DaoConfig config) { super(config); } public CustomerDao(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 + "'CUSTOMER' (" + // "'CustomerId' INTEGER PRIMARY KEY ," + // 0: id "'FirstName' NVARCHAR NOT NULL ," + // 1: FirstName "'LastName' NVARCHAR NOT NULL ," + // 2: LastName "'Company' NVARCHAR," + // 3: Company "'Address' NVARCHAR," + // 4: Address "'City' NVARCHAR," + // 5: City "'State' NVARCHAR," + // 6: State "'Country' NVARCHAR," + // 7: Country "'PostalCode' NVARCHAR," + // 8: PostalCode "'Phone' NVARCHAR," + // 9: Phone "'Fax' NVARCHAR," + // 10: Fax "'Email' NVARCHAR NOT NULL ," + // 11: Email "'SupportRepId' INTEGER);"); // 12: SupportRepId } /** Drops the underlying database table. */ public static void dropTable(SQLiteDatabase db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'CUSTOMER'"; db.execSQL(sql); } /** @inheritdoc */ @Override protected void bindValues(SQLiteStatement stmt, Customer entity) { stmt.clearBindings(); Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } stmt.bindString(2, entity.getFirstName()); stmt.bindString(3, entity.getLastName()); String Company = entity.getCompany(); if (Company != null) { stmt.bindString(4, Company); } String Address = entity.getAddress(); if (Address != null) { stmt.bindString(5, Address); } String City = entity.getCity(); if (City != null) { stmt.bindString(6, City); } String State = entity.getState(); if (State != null) { stmt.bindString(7, State); } String Country = entity.getCountry(); if (Country != null) { stmt.bindString(8, Country); } String PostalCode = entity.getPostalCode(); if (PostalCode != null) { stmt.bindString(9, PostalCode); } String Phone = entity.getPhone(); if (Phone != null) { stmt.bindString(10, Phone); } String Fax = entity.getFax(); if (Fax != null) { stmt.bindString(11, Fax); } stmt.bindString(12, entity.getEmail()); Long SupportRepId = entity.getSupportRepId(); if (SupportRepId != null) { stmt.bindLong(13, SupportRepId); } } @Override protected void attachEntity(Customer 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 Customer readEntity(Cursor cursor, int offset) { Customer entity = new Customer( // cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id cursor.getString(offset + 1), // FirstName cursor.getString(offset + 2), // LastName cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // Company cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // Address cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // City cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // State cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // Country cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // PostalCode cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // Phone cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // Fax cursor.getString(offset + 11), // Email cursor.isNull(offset + 12) ? null : cursor.getLong(offset + 12) // SupportRepId ); return entity; } /** @inheritdoc */ @Override public void readEntity(Cursor cursor, Customer entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setFirstName(cursor.getString(offset + 1)); entity.setLastName(cursor.getString(offset + 2)); entity.setCompany(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); entity.setAddress(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4)); entity.setCity(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5)); entity.setState(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6)); entity.setCountry(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7)); entity.setPostalCode(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8)); entity.setPhone(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9)); entity.setFax(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10)); entity.setEmail(cursor.getString(offset + 11)); entity.setSupportRepId(cursor.isNull(offset + 12) ? null : cursor.getLong(offset + 12)); } /** @inheritdoc */ @Override protected Long updateKeyAfterInsert(Customer entity, long rowId) { entity.setId(rowId); return rowId; } /** @inheritdoc */ @Override public Long getKey(Customer 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.getEmployeeDao().getAllColumns()); builder.append(" FROM CUSTOMER T"); builder.append(" LEFT JOIN EMPLOYEE T0 ON T.'SupportRepId'=T0.'EmployeeId'"); builder.append(' '); selectDeep = builder.toString(); } return selectDeep; } protected Customer loadCurrentDeep(Cursor cursor, boolean lock) { Customer entity = loadCurrent(cursor, 0, lock); int offset = getAllColumns().length; Employee employee = loadCurrentOther(daoSession.getEmployeeDao(), cursor, offset); entity.setEmployee(employee); return entity; } public Customer 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<Customer> loadAllDeepFromCursor(Cursor cursor) { int count = cursor.getCount(); List<Customer> list = new ArrayList<Customer>(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<Customer> 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<Customer> queryDeep(String where, String... selectionArg) { Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg); return loadDeepAllAndCloseCursor(cursor); } }