Back to project page ShareList-Android.
The source code is released under:
GNU General Public License
If you think the Android project ShareList-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.mybop.sharelist.app.database.entity; //from w w w .j ava2 s . com import android.database.Cursor; import com.j256.ormlite.android.AndroidDatabaseResults; import com.j256.ormlite.dao.DaoManager; import com.j256.ormlite.dao.ForeignCollection; import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.field.ForeignCollectionField; import com.j256.ormlite.misc.BaseDaoEnabled; import com.j256.ormlite.stmt.QueryBuilder; import com.j256.ormlite.table.DatabaseTable; import org.mybop.sharelist.app.database.NoIdCursorWrapper; import org.mybop.sharelist.app.database.repository.ElementRepository; import org.mybop.sharelist.app.database.repository.ListRepository; import java.sql.SQLException; /** * Created by gautier on 11/03/2014. */ @DatabaseTable(tableName = "list", daoClass = ListRepository.class) public class ListEntity extends BaseDaoEnabled { private static final String LOGGER_TAG = ListEntity.class.getSimpleName(); @DatabaseField(generatedId = true) private long id; @DatabaseField(canBeNull = false) private String name; @ForeignCollectionField(foreignFieldName = "list") ForeignCollection<ElementEntity> elements; private int count = -1; private int uncheckedCount = -1; /** * Only used by DAO */ ListEntity() { } public ListEntity(String name) { this.name = name; } public long getId() { return id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public ForeignCollection<ElementEntity> getElements() { return elements; } public int getNumberOfElements() { if (count == -1) { count = elements.size(); } return count; } public Cursor getElementsCursor() { return new NoIdCursorWrapper(((AndroidDatabaseResults) elements.getWrappedIterable().closeableIterator().getRawResults()).getRawCursor(), "id"); } public int getNumberOfUncheckedElements() throws SQLException { if (uncheckedCount == -1) { ElementRepository elementRepository = DaoManager.createDao(getDao().getConnectionSource(), ElementEntity.class); QueryBuilder<ElementEntity, Long> queryBuilder = elementRepository.queryBuilder(); String[] res = queryBuilder.selectRaw("COUNT(id)").where().eq("list_id", id).and().eq("checked", false).queryRawFirst(); uncheckedCount = Integer.parseInt(res[0]); } return uncheckedCount; } }