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.Invoice;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table INVOICE.
*/
public class InvoiceDao extends AbstractDao<Invoice, Long> {
public static final String TABLENAME = "INVOICE";
/**
* Properties of entity Invoice.<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, "InvoiceId");
public final static Property InvoiceDate = new Property(1, java.util.Date.class, "InvoiceDate", false, "InvoiceDate");
public final static Property CustomerId = new Property(2, long.class, "CustomerId", false, "CUSTOMER_ID");
public final static Property BillingAddress = new Property(3, String.class, "BillingAddress", false, "BillingAddress");
public final static Property BillingCity = new Property(4, String.class, "BillingCity", false, "BillingCity");
public final static Property BillingState = new Property(5, String.class, "BillingState", false, "BillingState");
public final static Property BillingCountry = new Property(6, String.class, "BillingCountry", false, "BillingCountry");
public final static Property BillingPostalCode = new Property(7, String.class, "BillingPostalCode", false, "BillingPostalCode");
public final static Property Total = new Property(8, Double.class, "Total", false, "Total");
};
private DaoSession daoSession;
public InvoiceDao(DaoConfig config) {
super(config);
}
public InvoiceDao(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' (" + //
"'InvoiceId' INTEGER PRIMARY KEY ," + // 0: id
"'InvoiceDate' DATATIME," + // 1: InvoiceDate
"'CUSTOMER_ID' INTEGER NOT NULL ," + // 2: CustomerId
"'BillingAddress' NVARCHAR," + // 3: BillingAddress
"'BillingCity' NVARCHAR," + // 4: BillingCity
"'BillingState' NVARCHAR," + // 5: BillingState
"'BillingCountry' NVARCHAR," + // 6: BillingCountry
"'BillingPostalCode' NVARCHAR," + // 7: BillingPostalCode
"'Total' NUMERIC);"); // 8: Total
}
/** Drops the underlying database table. */
public static void dropTable(SQLiteDatabase db, boolean ifExists) {
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'INVOICE'";
db.execSQL(sql);
}
/** @inheritdoc */
@Override
protected void bindValues(SQLiteStatement stmt, Invoice entity) {
stmt.clearBindings();
Long id = entity.getId();
if (id != null) {
stmt.bindLong(1, id);
}
java.util.Date InvoiceDate = entity.getInvoiceDate();
if (InvoiceDate != null) {
stmt.bindLong(2, InvoiceDate.getTime());
}
stmt.bindLong(3, entity.getCustomerId());
String BillingAddress = entity.getBillingAddress();
if (BillingAddress != null) {
stmt.bindString(4, BillingAddress);
}
String BillingCity = entity.getBillingCity();
if (BillingCity != null) {
stmt.bindString(5, BillingCity);
}
String BillingState = entity.getBillingState();
if (BillingState != null) {
stmt.bindString(6, BillingState);
}
String BillingCountry = entity.getBillingCountry();
if (BillingCountry != null) {
stmt.bindString(7, BillingCountry);
}
String BillingPostalCode = entity.getBillingPostalCode();
if (BillingPostalCode != null) {
stmt.bindString(8, BillingPostalCode);
}
Double Total = entity.getTotal();
if (Total != null) {
stmt.bindDouble(9, Total);
}
}
@Override
protected void attachEntity(Invoice 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 Invoice readEntity(Cursor cursor, int offset) {
Invoice entity = new Invoice( //
cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
cursor.isNull(offset + 1) ? null : new java.util.Date(cursor.getLong(offset + 1)), // InvoiceDate
cursor.getLong(offset + 2), // CustomerId
cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // BillingAddress
cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // BillingCity
cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // BillingState
cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // BillingCountry
cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // BillingPostalCode
cursor.isNull(offset + 8) ? null : cursor.getDouble(offset + 8) // Total
);
return entity;
}
/** @inheritdoc */
@Override
public void readEntity(Cursor cursor, Invoice entity, int offset) {
entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
entity.setInvoiceDate(cursor.isNull(offset + 1) ? null : new java.util.Date(cursor.getLong(offset + 1)));
entity.setCustomerId(cursor.getLong(offset + 2));
entity.setBillingAddress(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
entity.setBillingCity(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
entity.setBillingState(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
entity.setBillingCountry(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
entity.setBillingPostalCode(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
entity.setTotal(cursor.isNull(offset + 8) ? null : cursor.getDouble(offset + 8));
}
/** @inheritdoc */
@Override
protected Long updateKeyAfterInsert(Invoice entity, long rowId) {
entity.setId(rowId);
return rowId;
}
/** @inheritdoc */
@Override
public Long getKey(Invoice 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.getCustomerDao().getAllColumns());
builder.append(" FROM INVOICE T");
builder.append(" LEFT JOIN CUSTOMER T0 ON T.'CUSTOMER_ID'=T0.'CustomerId'");
builder.append(' ');
selectDeep = builder.toString();
}
return selectDeep;
}
protected Invoice loadCurrentDeep(Cursor cursor, boolean lock) {
Invoice entity = loadCurrent(cursor, 0, lock);
int offset = getAllColumns().length;
Customer customer = loadCurrentOther(daoSession.getCustomerDao(), cursor, offset);
if(customer != null) {
entity.setCustomer(customer);
}
return entity;
}
public Invoice 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<Invoice> loadAllDeepFromCursor(Cursor cursor) {
int count = cursor.getCount();
List<Invoice> list = new ArrayList<Invoice>(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<Invoice> 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<Invoice> queryDeep(String where, String... selectionArg) {
Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg);
return loadDeepAllAndCloseCursor(cursor);
}
}