package com.csq.thesceneryalong.db;
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.csq.thesceneryalong.db.Scenery;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table SCENERY.
*/
public class SceneryDao extends AbstractDao<Scenery, Long> {
public static final String TABLENAME = "SCENERY";
/**
* Properties of entity Scenery.<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 Name = new Property(1, String.class, "name", false, "NAME");
public final static Property Description = new Property(2, String.class, "description", false, "DESCRIPTION");
public final static Property Type = new Property(3, String.class, "type", false, "TYPE");
public final static Property UniqueMack = new Property(4, String.class, "uniqueMack", false, "UNIQUE_MACK");
public final static Property TrackId = new Property(5, long.class, "trackId", false, "TRACK_ID");
public final static Property Time = new Property(6, long.class, "time", false, "TIME");
public final static Property Longitude = new Property(7, double.class, "longitude", false, "LONGITUDE");
public final static Property Latitude = new Property(8, double.class, "latitude", false, "LATITUDE");
public final static Property Altitude = new Property(9, Double.class, "altitude", false, "ALTITUDE");
public final static Property Accuracy = new Property(10, Float.class, "accuracy", false, "ACCURACY");
public final static Property Speed = new Property(11, Float.class, "speed", false, "SPEED");
public final static Property Bearing = new Property(12, Float.class, "bearing", false, "BEARING");
public final static Property Provider = new Property(13, String.class, "provider", false, "PROVIDER");
public final static Property Address = new Property(14, String.class, "address", false, "ADDRESS");
};
private DaoSession daoSession;
private Query<Scenery> track_ScenerysQuery;
public SceneryDao(DaoConfig config) {
super(config);
}
public SceneryDao(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 + "'SCENERY' (" + //
"'_id' INTEGER PRIMARY KEY ," + // 0: id
"'NAME' TEXT NOT NULL ," + // 1: name
"'DESCRIPTION' TEXT," + // 2: description
"'TYPE' TEXT NOT NULL ," + // 3: type
"'UNIQUE_MACK' TEXT NOT NULL ," + // 4: uniqueMack
"'TRACK_ID' INTEGER NOT NULL ," + // 5: trackId
"'TIME' INTEGER NOT NULL ," + // 6: time
"'LONGITUDE' REAL NOT NULL ," + // 7: longitude
"'LATITUDE' REAL NOT NULL ," + // 8: latitude
"'ALTITUDE' REAL," + // 9: altitude
"'ACCURACY' REAL," + // 10: accuracy
"'SPEED' REAL," + // 11: speed
"'BEARING' REAL," + // 12: bearing
"'PROVIDER' TEXT," + // 13: provider
"'ADDRESS' TEXT);"); // 14: address
}
/** Drops the underlying database table. */
public static void dropTable(SQLiteDatabase db, boolean ifExists) {
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'SCENERY'";
db.execSQL(sql);
}
/** @inheritdoc */
@Override
protected void bindValues(SQLiteStatement stmt, Scenery entity) {
stmt.clearBindings();
Long id = entity.getId();
if (id != null) {
stmt.bindLong(1, id);
}
stmt.bindString(2, entity.getName());
String description = entity.getDescription();
if (description != null) {
stmt.bindString(3, description);
}
stmt.bindString(4, entity.getType());
stmt.bindString(5, entity.getUniqueMack());
stmt.bindLong(6, entity.getTrackId());
stmt.bindLong(7, entity.getTime());
stmt.bindDouble(8, entity.getLongitude());
stmt.bindDouble(9, entity.getLatitude());
Double altitude = entity.getAltitude();
if (altitude != null) {
stmt.bindDouble(10, altitude);
}
Float accuracy = entity.getAccuracy();
if (accuracy != null) {
stmt.bindDouble(11, accuracy);
}
Float speed = entity.getSpeed();
if (speed != null) {
stmt.bindDouble(12, speed);
}
Float bearing = entity.getBearing();
if (bearing != null) {
stmt.bindDouble(13, bearing);
}
String provider = entity.getProvider();
if (provider != null) {
stmt.bindString(14, provider);
}
String address = entity.getAddress();
if (address != null) {
stmt.bindString(15, address);
}
}
@Override
protected void attachEntity(Scenery 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 Scenery readEntity(Cursor cursor, int offset) {
Scenery entity = new Scenery( //
cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
cursor.getString(offset + 1), // name
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // description
cursor.getString(offset + 3), // type
cursor.getString(offset + 4), // uniqueMack
cursor.getLong(offset + 5), // trackId
cursor.getLong(offset + 6), // time
cursor.getDouble(offset + 7), // longitude
cursor.getDouble(offset + 8), // latitude
cursor.isNull(offset + 9) ? null : cursor.getDouble(offset + 9), // altitude
cursor.isNull(offset + 10) ? null : cursor.getFloat(offset + 10), // accuracy
cursor.isNull(offset + 11) ? null : cursor.getFloat(offset + 11), // speed
cursor.isNull(offset + 12) ? null : cursor.getFloat(offset + 12), // bearing
cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13), // provider
cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14) // address
);
return entity;
}
/** @inheritdoc */
@Override
public void readEntity(Cursor cursor, Scenery entity, int offset) {
entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
entity.setName(cursor.getString(offset + 1));
entity.setDescription(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
entity.setType(cursor.getString(offset + 3));
entity.setUniqueMack(cursor.getString(offset + 4));
entity.setTrackId(cursor.getLong(offset + 5));
entity.setTime(cursor.getLong(offset + 6));
entity.setLongitude(cursor.getDouble(offset + 7));
entity.setLatitude(cursor.getDouble(offset + 8));
entity.setAltitude(cursor.isNull(offset + 9) ? null : cursor.getDouble(offset + 9));
entity.setAccuracy(cursor.isNull(offset + 10) ? null : cursor.getFloat(offset + 10));
entity.setSpeed(cursor.isNull(offset + 11) ? null : cursor.getFloat(offset + 11));
entity.setBearing(cursor.isNull(offset + 12) ? null : cursor.getFloat(offset + 12));
entity.setProvider(cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13));
entity.setAddress(cursor.isNull(offset + 14) ? null : cursor.getString(offset + 14));
}
/** @inheritdoc */
@Override
protected Long updateKeyAfterInsert(Scenery entity, long rowId) {
entity.setId(rowId);
return rowId;
}
/** @inheritdoc */
@Override
public Long getKey(Scenery entity) {
if(entity != null) {
return entity.getId();
} else {
return null;
}
}
/** @inheritdoc */
@Override
protected boolean isEntityUpdateable() {
return true;
}
/** Internal query to resolve the "scenerys" to-many relationship of Track. */
public List<Scenery> _queryTrack_Scenerys(long trackId) {
synchronized (this) {
if (track_ScenerysQuery == null) {
QueryBuilder<Scenery> queryBuilder = queryBuilder();
queryBuilder.where(Properties.TrackId.eq(null));
queryBuilder.orderRaw("TIME ASC");
track_ScenerysQuery = queryBuilder.build();
}
}
Query<Scenery> query = track_ScenerysQuery.forCurrentThread();
query.setParameter(0, trackId);
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.getTrackDao().getAllColumns());
builder.append(" FROM SCENERY T");
builder.append(" LEFT JOIN TRACK T0 ON T.'TRACK_ID'=T0.'_id'");
builder.append(' ');
selectDeep = builder.toString();
}
return selectDeep;
}
protected Scenery loadCurrentDeep(Cursor cursor, boolean lock) {
Scenery entity = loadCurrent(cursor, 0, lock);
int offset = getAllColumns().length;
Track track = loadCurrentOther(daoSession.getTrackDao(), cursor, offset);
if(track != null) {
entity.setTrack(track);
}
return entity;
}
public Scenery 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<Scenery> loadAllDeepFromCursor(Cursor cursor) {
int count = cursor.getCount();
List<Scenery> list = new ArrayList<Scenery>(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<Scenery> 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<Scenery> queryDeep(String where, String... selectionArg) {
Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg);
return loadDeepAllAndCloseCursor(cursor);
}
}