package model.daoModels;
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 model.daoModels.Language;
// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
* DAO for table "LANGUAGE".
*/
public class LanguageDao extends AbstractDao<Language, Long> {
public static final String TABLENAME = "LANGUAGE";
/**
* Properties of entity Language.<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 UniqueSlug = new Property(1, String.class, "uniqueSlug", false, "UNIQUE_SLUG");
public final static Property Slug = new Property(2, String.class, "slug", false, "SLUG");
public final static Property LanguageAbbreviation = new Property(3, String.class, "languageAbbreviation", false, "LANGUAGE_ABBREVIATION");
public final static Property Modified = new Property(4, java.util.Date.class, "modified", false, "MODIFIED");
public final static Property ProjectId = new Property(5, long.class, "projectId", false, "PROJECT_ID");
};
private DaoSession daoSession;
private Query<Language> project_LanguagesQuery;
public LanguageDao(DaoConfig config) {
super(config);
}
public LanguageDao(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 + "\"LANGUAGE\" (" + //
"\"_id\" INTEGER PRIMARY KEY ," + // 0: id
"\"UNIQUE_SLUG\" TEXT," + // 1: uniqueSlug
"\"SLUG\" TEXT," + // 2: slug
"\"LANGUAGE_ABBREVIATION\" TEXT," + // 3: languageAbbreviation
"\"MODIFIED\" INTEGER," + // 4: modified
"\"PROJECT_ID\" INTEGER NOT NULL );"); // 5: projectId
}
/** Drops the underlying database table. */
public static void dropTable(SQLiteDatabase db, boolean ifExists) {
String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"LANGUAGE\"";
db.execSQL(sql);
}
/** @inheritdoc */
@Override
protected void bindValues(SQLiteStatement stmt, Language entity) {
stmt.clearBindings();
Long id = entity.getId();
if (id != null) {
stmt.bindLong(1, id);
}
String uniqueSlug = entity.getUniqueSlug();
if (uniqueSlug != null) {
stmt.bindString(2, uniqueSlug);
}
String slug = entity.getSlug();
if (slug != null) {
stmt.bindString(3, slug);
}
String languageAbbreviation = entity.getLanguageAbbreviation();
if (languageAbbreviation != null) {
stmt.bindString(4, languageAbbreviation);
}
java.util.Date modified = entity.getModified();
if (modified != null) {
stmt.bindLong(5, modified.getTime());
}
stmt.bindLong(6, entity.getProjectId());
}
@Override
protected void attachEntity(Language 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 Language readEntity(Cursor cursor, int offset) {
Language entity = new Language( //
cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // uniqueSlug
cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // slug
cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // languageAbbreviation
cursor.isNull(offset + 4) ? null : new java.util.Date(cursor.getLong(offset + 4)), // modified
cursor.getLong(offset + 5) // projectId
);
return entity;
}
/** @inheritdoc */
@Override
public void readEntity(Cursor cursor, Language entity, int offset) {
entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
entity.setUniqueSlug(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
entity.setSlug(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
entity.setLanguageAbbreviation(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
entity.setModified(cursor.isNull(offset + 4) ? null : new java.util.Date(cursor.getLong(offset + 4)));
entity.setProjectId(cursor.getLong(offset + 5));
}
/** @inheritdoc */
@Override
protected Long updateKeyAfterInsert(Language entity, long rowId) {
entity.setId(rowId);
return rowId;
}
/** @inheritdoc */
@Override
public Long getKey(Language entity) {
if(entity != null) {
return entity.getId();
} else {
return null;
}
}
/** @inheritdoc */
@Override
protected boolean isEntityUpdateable() {
return true;
}
/** Internal query to resolve the "languages" to-many relationship of Project. */
public List<Language> _queryProject_Languages(long projectId) {
synchronized (this) {
if (project_LanguagesQuery == null) {
QueryBuilder<Language> queryBuilder = queryBuilder();
queryBuilder.where(Properties.ProjectId.eq(null));
project_LanguagesQuery = queryBuilder.build();
}
}
Query<Language> query = project_LanguagesQuery.forCurrentThread();
query.setParameter(0, projectId);
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.getProjectDao().getAllColumns());
builder.append(" FROM LANGUAGE T");
builder.append(" LEFT JOIN PROJECT T0 ON T.\"PROJECT_ID\"=T0.\"_id\"");
builder.append(' ');
selectDeep = builder.toString();
}
return selectDeep;
}
protected Language loadCurrentDeep(Cursor cursor, boolean lock) {
Language entity = loadCurrent(cursor, 0, lock);
int offset = getAllColumns().length;
Project project = loadCurrentOther(daoSession.getProjectDao(), cursor, offset);
if(project != null) {
entity.setProject(project);
}
return entity;
}
public Language 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<Language> loadAllDeepFromCursor(Cursor cursor) {
int count = cursor.getCount();
List<Language> list = new ArrayList<Language>(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<Language> 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<Language> queryDeep(String where, String... selectionArg) {
Cursor cursor = db.rawQuery(getSelectDeep() + where, selectionArg);
return loadDeepAllAndCloseCursor(cursor);
}
}