Back to project page EnklawaPlayer.
The source code is released under:
GNU General Public License
If you think the Android project EnklawaPlayer 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 macbury.pod.db.scopes; //w w w .j a v a2 s . c o m import com.j256.ormlite.dao.Dao; import com.j256.ormlite.stmt.QueryBuilder; import java.sql.SQLException; import java.util.List; import macbury.pod.api.APIProgram; import macbury.pod.db.models.Program; /** * Created by macbury on 09.09.14. */ public class ProgramsScope extends AbstractScope<Program> { public ProgramsScope(Dao<Program, Integer> dao) { super(dao); } public Program buildFromApi(APIProgram apiObject) { Program program = new Program(); program.id = apiObject.id; program.name = apiObject.name; program.description = apiObject.description; program.author = apiObject.author; program.image = apiObject.image; program.live = apiObject.live; return program; } public Program find(APIProgram apiObject) { return find(apiObject.id); } public List<Program> allOrderedByName() { QueryBuilder<Program, Integer> builder = dao.queryBuilder(); try { return builder.orderBy("name", true).query(); } catch (SQLException e) { e.printStackTrace(); } return null; } public List<Program> allFavorited() { QueryBuilder<Program, Integer> builder = dao.queryBuilder(); try { return builder.orderBy("name", true).where().eq("favorite", true).query(); } catch (SQLException e) { e.printStackTrace(); } return null; } public boolean updateFromApi(APIProgram apiProgram) { Program oldProgram = find(apiProgram); Program newProgram = buildFromApi(apiProgram); if (oldProgram != null) { newProgram.favorite = oldProgram.favorite; } return update(newProgram); } @Override public void afterCreate(Program model) { } @Override public void afterDestroy(Program object) { } @Override public void afterSave(Program object) { } }