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 de.greenrobot.dao.query.Query; import de.greenrobot.dao.query.QueryBuilder; import com.pinecone.technology.mcommerce.learning.android.chapter06.example.dao.InvoiceLine; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. /** * DAO for table INVOICE_LINE. */ public class InvoiceLineDao extends AbstractDao<InvoiceLine, Long> { public static final String TABLENAME = "INVOICE_LINE"; /** * Properties of entity InvoiceLine.<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, "InvoiceLineId"); public final static Property InvoiceId = new Property(1, long.class, "InvoiceId", false, "INVOICE_ID"); public final static Property TrackId = new Property(2, long.class, "TrackId", false, "TRACK_ID"); public final static Property UnitPrice = new Property(3, double.class, "UnitPrice", false, "UNIT_PRICE"); public final static Property Quantity = new Property(4, Long.class, "Quantity", false, "QUANTITY"); }; private DaoSession daoSession; private Query<InvoiceLine> invoice_InvoiceLinesQuery; public InvoiceLineDao(DaoConfig config) { super(config); } public InvoiceLineDao(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 + "'INVOICE_LINE' (" + // "'InvoiceLineId' INTEGER PRIMARY KEY ," + // 0: id "'INVOICE_ID' INTEGER NOT NULL ," + // 1: InvoiceId "'TRACK_ID' INTEGER NOT NULL ," + // 2: TrackId "'UNIT_PRICE' REAL NOT NULL ," + // 3: UnitPrice "'QUANTITY' INTEGER);"); // 4: Quantity } /** Drops the underlying database table. */ public static void dropTable(SQLiteDatabase db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'INVOICE_LINE'"; db.execSQL(sql); } /** @inheritdoc */ @Override protected void bindValues(SQLiteStatement stmt, InvoiceLine entity) { stmt.clearBindings(); Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } stmt.bindLong(2, entity.getInvoiceId()); stmt.bindLong(3, entity.getTrackId()); stmt.bindDouble(4, entity.getUnitPrice()); Long Quantity = entity.getQuantity(); if (Quantity != null) { stmt.bindLong(5, Quantity); } } @Override protected void attachEntity(InvoiceLine 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 InvoiceLine readEntity(Cursor cursor, int offset) { InvoiceLine entity = new InvoiceLine( // cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id cursor.getLong(offset + 1), // InvoiceId cursor.getLong(offset + 2), // TrackId cursor.getDouble(offset + 3), // UnitPrice cursor.isNull(offset + 4) ? null : cursor.getLong(offset + 4) // Quantity ); return entity; } /** @inheritdoc */ @Override public void readEntity(Cursor cursor, InvoiceLine entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setInvoiceId(cursor.getLong(offset + 1)); entity.setTrackId(cursor.getLong(offset + 2)); entity.setUnitPrice(cursor.getDouble(offset + 3)); entity.setQuantity(cursor.isNull(offset + 4) ? null : cursor.getLong(offset + 4)); } /** @inheritdoc */ @Override protected Long updateKeyAfterInsert(InvoiceLine entity, long rowId) { entity.setId(rowId); return rowId; } /** @inheritdoc */ @Override public Long getKey(InvoiceLine entity) { if(entity != null) { return entity.getId(); } else { return null; } } /** @inheritdoc */ @Override protected boolean isEntityUpdateable() { return true; } /** Internal query to resolve the "InvoiceLines" to-many relationship of Invoice. */ public List<InvoiceLine> _queryInvoice_InvoiceLines(long InvoiceId) { synchronized (this) { if (invoice_InvoiceLinesQuery == null) { QueryBuilder<InvoiceLine> queryBuilder = queryBuilder(); queryBuilder.where(Properties.InvoiceId.eq(null)); invoice_InvoiceLinesQuery = queryBuilder.build(); } } Query<InvoiceLine> query = invoice_InvoiceLinesQuery.forCurrentThread(); query.setParameter(0, InvoiceId); 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.getInvoiceDao().getAllColumns()); builder.append(" FROM INVOICE_LINE T"); builder.append(" LEFT JOIN INVOICE T0 ON T.'INVOICE_ID'=T0.'InvoiceId'"); builder.append(' '); selectDeep = builder.toString(); } return selectDeep; } protected InvoiceLine loadCurrentDeep(Cursor cursor, boolean lock) { InvoiceLine entity = loadCurrent(cursor, 0, lock); int offset = getAllColumns().length; Invoice invoice = loadCurrentOther(daoSession.getInvoiceDao(), cursor, offset); if(invoice != null) { entity.setInvoice(invoice); } return entity; } public InvoiceLine 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<InvoiceLine> loadAllDeepFromCursor(Cursor cursor) { int count = cursor.getCount(); List<InvoiceLine> list = new ArrayList<InvoiceLine>(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<InvoiceLine> 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<InvoiceLine> queryDeep(String where, String... selectionArg) { Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg); return loadDeepAllAndCloseCursor(cursor); } }