mirror of https://github.com/tasks/tasks
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.
74 lines
1.9 KiB
Java
74 lines
1.9 KiB
Java
/*
|
|
* Copyright (c) 2009, Todoroo Inc
|
|
* All Rights Reserved
|
|
* http://www.todoroo.com
|
|
*/
|
|
package com.todoroo.astrid.dao;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import com.todoroo.andlib.data.GenericDao;
|
|
import com.todoroo.andlib.data.Property;
|
|
import com.todoroo.andlib.data.TodorooCursor;
|
|
import com.todoroo.andlib.data.sql.Criterion;
|
|
import com.todoroo.andlib.data.sql.Join;
|
|
import com.todoroo.andlib.data.sql.Query;
|
|
import com.todoroo.andlib.service.Autowired;
|
|
import com.todoroo.andlib.service.DependencyInjectionService;
|
|
import com.todoroo.astrid.model.Metadata;
|
|
import com.todoroo.astrid.model.Task;
|
|
|
|
/**
|
|
* Data Access layer for {@link Metadata}-related operations.
|
|
*
|
|
* @author Tim Su <tim@todoroo.com>
|
|
*
|
|
*/
|
|
public class MetadataDao extends GenericDao<Metadata> {
|
|
|
|
@Autowired
|
|
Database database;
|
|
|
|
public MetadataDao() {
|
|
super(Metadata.class);
|
|
DependencyInjectionService.getInstance().inject(this);
|
|
setDatabase(database);
|
|
}
|
|
|
|
// --- SQL clause generators
|
|
|
|
/**
|
|
* Generates SQL clauses
|
|
*/
|
|
public static class MetadataCriteria {
|
|
|
|
/** Returns all metadata associated with a given task */
|
|
public static Criterion byTask(long taskId) {
|
|
return Metadata.TASK.eq(taskId);
|
|
}
|
|
|
|
/** Returns all metadata associated with a given key */
|
|
public static Criterion withKey(String key) {
|
|
return Metadata.KEY.eq(key);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Fetch all metadata that are unattached to the task
|
|
* @param database
|
|
* @param properties
|
|
* @return
|
|
*/
|
|
public TodorooCursor<Metadata> fetchDangling(Property<?>[] properties) {
|
|
Query sql = Query.select(properties).from(Metadata.TABLE).join(Join.left(Task.TABLE,
|
|
Metadata.TASK.eq(Task.ID))).where(Task.TITLE.isNull());
|
|
Cursor cursor = database.getDatabase().rawQuery(sql.toString(), null);
|
|
return new TodorooCursor<Metadata>(cursor, properties);
|
|
}
|
|
|
|
}
|
|
|