You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tasks/app/src/main/java/com/todoroo/astrid/dao/TagDataDao.java

74 lines
1.9 KiB
Java

/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.dao;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.data.TagData;
import org.tasks.injection.ApplicationScope;
import java.util.List;
import javax.inject.Inject;
/**
* Data Access layer for {@link TagData}-related operations.
*
* @author Tim Su <tim@todoroo.com>
*/
@ApplicationScope
public class TagDataDao {
private final RemoteModelDao<TagData> dao;
@Inject
public TagDataDao(Database database) {
dao = new RemoteModelDao<>(database, TagData.class);
}
public TagData getTagByName(String name) {
return dao.getFirst(Query.select(TagData.PROPERTIES).where(TagData.NAME.eqCaseInsensitive(name)));
}
public List<TagData> allTags() {
// TODO: does this need to be ordered?
return dao.toList(Query.select(TagData.PROPERTIES)
.where(TagData.DELETION_DATE.eq(0))
.orderBy(Order.asc(TagData.ID)));
}
public TagData getByUuid(String uuid) {
return dao.getFirst(Query.select(TagData.PROPERTIES).where(TagData.UUID.eq(uuid)));
}
public List<TagData> tagDataOrderedByName() {
return dao.toList(Query.select(TagData.PROPERTIES).where(Criterion.and(
TagData.DELETION_DATE.eq(0),
TagData.NAME.isNotNull()))
.orderBy(Order.asc(Functions.upper(TagData.NAME))));
}
public void persist(TagData tagData) {
dao.persist(tagData);
}
public void update(Criterion where, TagData template) {
dao.update(where, template);
}
public void delete(long id) {
dao.delete(id);
}
public void createNew(TagData tag) {
dao.createNew(tag);
}
}