package itomych.com.jti.data.dao;
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Transaction;
import android.arch.persistence.room.Update;
import java.util.List;
import itomych.com.jti.data.model.tasks.TaskImage;
import itomych.com.jti.data.model.tasks.TaskItem;
/**
* Created by alexischenko on 08-04-2018.
*/
@Dao
public abstract class TaskDao {
/**
* Get Tasks
*/
@Query("SELECT * FROM TaskItem ORDER BY id DESC")
abstract List<TaskItem> getAllTasks();
@Query("SELECT * FROM TaskItem WHERE passed = 0 ORDER BY passedDate DESC")
abstract List<TaskItem> getActiveTasks();
@Query("SELECT * FROM TaskItem WHERE passed = 1 ORDER BY passedDate DESC")
abstract List<TaskItem> getPassedTasks();
/**
* Insert Task
*/
@Transaction
public void insert(TaskItem taskItem) {
long id = insertTaskEntity(taskItem);
// Task Images
List<TaskImage> images = taskItem.getImages();
for (TaskImage taskImage : images) {
taskImage.setTaskId(taskItem.getId());
}
// TestData
}
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract long insertTaskEntity(TaskItem taskItem);
@Update(onConflict = OnConflictStrategy.REPLACE)
abstract long updateTaskEntity(TaskItem... taskItems);
@Delete
abstract void delete(TaskItem... taskItems);
/**
* TaskImage Dao
*/
/**
* TestData Dao
*/
}
model.tasks.TaskItem;
/**
* Created by alexischenko on 08-04-2018.
*/
@Dao
public abstract class TaskDao {
/**
* Get Tasks
*/
@Query("SELECT * FROM TaskItem ORDER BY id DESC")
abstract List<TaskItem> getAllTasks();
@Query("SELECT * FROM TaskItem WHERE passed = 0 ORDER BY passedDate DESC")
abstract List<TaskItem> getActiveTasks();
@Query("SELECT * FROM TaskItem WHERE passed = 1 ORDER BY passedDate DESC")
abstract List<TaskItem> getPassedTasks();
/**
* Insert Task
*/
@Transaction
public void insert(TaskItem taskItem) {
long id = insertTaskEntity(taskItem);
// Task Images
List<TaskImage> images = taskItem.getImages();
for (TaskImage taskImage : images) {
taskImage.setTaskId(taskItem.getId());
}
// TestData
}
@Insert(onConflict = OnConflictStrategy.REPLACE)
abstract long insertTaskEntity(TaskItem taskItem);
@Update(onConflict = OnConflictStrategy.REPLACE)
abstract long updateTaskEntity(TaskItem... taskItems);
@Delete
abstract void delete(TaskItem... taskItems);
/**
* TaskImage Dao
*/
/**
* TestData Dao
*/
}