package id.ac.itats.skripsi.orm; 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 id.ac.itats.skripsi.orm.Way; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. /** * DAO for table WAY. */ public class WayDao extends AbstractDao<Way, Long> { public static final String TABLENAME = "WAY"; /** * Properties of entity Way.<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 WayID = new Property(1, String.class, "wayID", false, "WAY_ID"); public final static Property Fk_sourceNode = new Property(2, Long.class, "fk_sourceNode", false, "FK_SOURCE_NODE"); public final static Property Fk_targetNode = new Property(3, Long.class, "fk_targetNode", false, "FK_TARGET_NODE"); public final static Property Weight = new Property(4, Double.class, "weight", false, "WEIGHT"); }; private DaoSession daoSession; private Query<Way> node_SourceAdjacenciesQuery; private Query<Way> node_TargetAdjacenciesQuery; public WayDao(DaoConfig config) { super(config); } public WayDao(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 + "'WAY' (" + // "'_id' INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "'WAY_ID' TEXT," + // 1: wayID "'FK_SOURCE_NODE' INTEGER," + // 2: fk_sourceNode "'FK_TARGET_NODE' INTEGER," + // 3: fk_targetNode "'WEIGHT' REAL);"); // 4: weight // Add Indexes db.execSQL("CREATE INDEX " + constraint + "IDX_WAY_WAY_ID ON WAY" + " (WAY_ID);"); } /** Drops the underlying database table. */ public static void dropTable(SQLiteDatabase db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'WAY'"; db.execSQL(sql); } /** @inheritdoc */ @Override protected void bindValues(SQLiteStatement stmt, Way entity) { stmt.clearBindings(); Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } String wayID = entity.getWayID(); if (wayID != null) { stmt.bindString(2, wayID); } Long fk_sourceNode = entity.getFk_sourceNode(); if (fk_sourceNode != null) { stmt.bindLong(3, fk_sourceNode); } Long fk_targetNode = entity.getFk_targetNode(); if (fk_targetNode != null) { stmt.bindLong(4, fk_targetNode); } Double weight = entity.getWeight(); if (weight != null) { stmt.bindDouble(5, weight); } } @Override protected void attachEntity(Way 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 Way readEntity(Cursor cursor, int offset) { Way entity = new Way( // cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // wayID cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2), // fk_sourceNode cursor.isNull(offset + 3) ? null : cursor.getLong(offset + 3), // fk_targetNode cursor.isNull(offset + 4) ? null : cursor.getDouble(offset + 4) // weight ); return entity; } /** @inheritdoc */ @Override public void readEntity(Cursor cursor, Way entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setWayID(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); entity.setFk_sourceNode(cursor.isNull(offset + 2) ? null : cursor.getLong(offset + 2)); entity.setFk_targetNode(cursor.isNull(offset + 3) ? null : cursor.getLong(offset + 3)); entity.setWeight(cursor.isNull(offset + 4) ? null : cursor.getDouble(offset + 4)); } /** @inheritdoc */ @Override protected Long updateKeyAfterInsert(Way entity, long rowId) { entity.setId(rowId); return rowId; } /** @inheritdoc */ @Override public Long getKey(Way entity) { if(entity != null) { return entity.getId(); } else { return null; } } /** @inheritdoc */ @Override protected boolean isEntityUpdateable() { return true; } /** Internal query to resolve the "sourceAdjacencies" to-many relationship of Node. */ public List<Way> _queryNode_SourceAdjacencies(Long fk_sourceNode) { synchronized (this) { if (node_SourceAdjacenciesQuery == null) { QueryBuilder<Way> queryBuilder = queryBuilder(); queryBuilder.where(Properties.Fk_sourceNode.eq(null)); node_SourceAdjacenciesQuery = queryBuilder.build(); } } Query<Way> query = node_SourceAdjacenciesQuery.forCurrentThread(); query.setParameter(0, fk_sourceNode); return query.list(); } /** Internal query to resolve the "targetAdjacencies" to-many relationship of Node. */ public List<Way> _queryNode_TargetAdjacencies(Long fk_targetNode) { synchronized (this) { if (node_TargetAdjacenciesQuery == null) { QueryBuilder<Way> queryBuilder = queryBuilder(); queryBuilder.where(Properties.Fk_targetNode.eq(null)); node_TargetAdjacenciesQuery = queryBuilder.build(); } } Query<Way> query = node_TargetAdjacenciesQuery.forCurrentThread(); query.setParameter(0, fk_targetNode); 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.getNodeDao().getAllColumns()); builder.append(','); SqlUtils.appendColumns(builder, "T1", daoSession.getNodeDao().getAllColumns()); builder.append(" FROM WAY T"); builder.append(" LEFT JOIN NODE T0 ON T.'FK_SOURCE_NODE'=T0.'NODE_ID'"); builder.append(" LEFT JOIN NODE T1 ON T.'FK_TARGET_NODE'=T1.'NODE_ID'"); builder.append(' '); selectDeep = builder.toString(); } return selectDeep; } protected Way loadCurrentDeep(Cursor cursor, boolean lock) { Way entity = loadCurrent(cursor, 0, lock); int offset = getAllColumns().length; Node sourceNode = loadCurrentOther(daoSession.getNodeDao(), cursor, offset); entity.setSourceNode(sourceNode); offset += daoSession.getNodeDao().getAllColumns().length; Node targetNode = loadCurrentOther(daoSession.getNodeDao(), cursor, offset); entity.setTargetNode(targetNode); return entity; } public Way 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<Way> loadAllDeepFromCursor(Cursor cursor) { int count = cursor.getCount(); List<Way> list = new ArrayList<Way>(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<Way> 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<Way> queryDeep(String where, String... selectionArg) { Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg); return loadDeepAllAndCloseCursor(cursor); } }