mirror of https://github.com/tasks/tasks
Added properties to cursor, and gettin' stuff to work
parent
9819308af1
commit
6d9eb09111
@ -1 +1 @@
|
|||||||
Subproject commit efc282fa500e8f4e73c7c53e31aab2941e4200f1
|
Subproject commit 9eae7b3b4ab1272513cbdd202f6ec4e70ac20b2d
|
||||||
@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2009, Todoroo Inc
|
|
||||||
* All Rights Reserved
|
|
||||||
* http://www.todoroo.com
|
|
||||||
*/
|
|
||||||
package com.todoroo.astrid.tagsold;
|
|
||||||
|
|
||||||
|
|
||||||
import android.content.ContentValues;
|
|
||||||
|
|
||||||
import com.todoroo.andlib.data.AbstractModel;
|
|
||||||
import com.todoroo.andlib.data.Property;
|
|
||||||
import com.todoroo.andlib.data.Table;
|
|
||||||
import com.todoroo.andlib.data.TodorooCursor;
|
|
||||||
import com.todoroo.andlib.data.Property.LongProperty;
|
|
||||||
import com.todoroo.andlib.data.Property.StringProperty;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data Model which represents a task users need to accomplish.
|
|
||||||
*
|
|
||||||
* @author Tim Su <tim@todoroo.com>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("nls")
|
|
||||||
public class Tag extends AbstractModel {
|
|
||||||
|
|
||||||
// --- table
|
|
||||||
|
|
||||||
public static final Table TABLE = new Table("tags", Tag.class);
|
|
||||||
|
|
||||||
// --- properties
|
|
||||||
|
|
||||||
/** ID */
|
|
||||||
public static final LongProperty ID = new LongProperty(
|
|
||||||
TABLE, ID_PROPERTY_NAME);
|
|
||||||
|
|
||||||
/** Name of Task */
|
|
||||||
public static final StringProperty NAME = new StringProperty(
|
|
||||||
TABLE, "name");
|
|
||||||
|
|
||||||
/** List of all properties for this model */
|
|
||||||
public static final Property<?>[] PROPERTIES = generateProperties(Tag.class);
|
|
||||||
|
|
||||||
// --- defaults
|
|
||||||
|
|
||||||
/** Default values container */
|
|
||||||
private static final ContentValues defaultValues = new ContentValues();
|
|
||||||
|
|
||||||
static {
|
|
||||||
defaultValues.put(NAME.name, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ContentValues getDefaultValues() {
|
|
||||||
return defaultValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- data access boilerplate
|
|
||||||
|
|
||||||
public Tag() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Tag(TodorooCursor<Tag> cursor, Property<?>[] properties) {
|
|
||||||
this();
|
|
||||||
readPropertiesFromCursor(cursor, properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFromCursor(TodorooCursor<Tag> cursor, Property<?>[] properties) {
|
|
||||||
super.readPropertiesFromCursor(cursor, properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getId() {
|
|
||||||
return getIdHelper(ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* ASTRID: Android's Simple Task Recording Dashboard
|
|
||||||
*
|
|
||||||
* Copyright (c) 2009 Tim Su
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*/
|
|
||||||
package com.todoroo.astrid.tagsold;
|
|
||||||
|
|
||||||
import android.database.SQLException;
|
|
||||||
|
|
||||||
import com.todoroo.andlib.data.GenericDao;
|
|
||||||
import com.todoroo.andlib.data.Property;
|
|
||||||
import com.todoroo.andlib.data.TodorooCursor;
|
|
||||||
import com.todoroo.andlib.data.sql.Join;
|
|
||||||
import com.todoroo.andlib.data.sql.Query;
|
|
||||||
import com.todoroo.astrid.model.Task;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Service layer for tags plugin
|
|
||||||
*
|
|
||||||
* @author Tim Su <tim@todoroo.com>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class TagService {
|
|
||||||
|
|
||||||
private GenericDao<Tag> tagDao;
|
|
||||||
private GenericDao<TagToTaskMapping> tagToTaskDao;
|
|
||||||
|
|
||||||
public TagService() {
|
|
||||||
TagsDatabase tagDatabase = new TagsDatabase();
|
|
||||||
tagDao = new GenericDao<Tag>(Tag.class, tagDatabase);
|
|
||||||
tagToTaskDao = new GenericDao<TagToTaskMapping>(TagToTaskMapping.class,
|
|
||||||
tagDatabase);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- tag batch operations
|
|
||||||
|
|
||||||
/** Get a list of all tags */
|
|
||||||
public TodorooCursor<Tag> getAllTags(Property<?>... properties) {
|
|
||||||
return tagDao.query(Query.select(properties));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Get a list of tag identifiers for the given task */
|
|
||||||
public TodorooCursor<Tag> getTaskTags(Task task, Property<?>... properties) throws SQLException {
|
|
||||||
Query query = Query.select(properties).join(Join.inner(TagToTaskMapping.TABLE,
|
|
||||||
Tag.ID.eq(TagToTaskMapping.TAG))).where(TagToTaskMapping.TASK.eq(task.getId()));
|
|
||||||
return tagDao.query(query);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2009, Todoroo Inc
|
|
||||||
* All Rights Reserved
|
|
||||||
* http://www.todoroo.com
|
|
||||||
*/
|
|
||||||
package com.todoroo.astrid.tagsold;
|
|
||||||
|
|
||||||
|
|
||||||
import android.content.ContentValues;
|
|
||||||
|
|
||||||
import com.todoroo.andlib.data.AbstractModel;
|
|
||||||
import com.todoroo.andlib.data.Property;
|
|
||||||
import com.todoroo.andlib.data.Table;
|
|
||||||
import com.todoroo.andlib.data.TodorooCursor;
|
|
||||||
import com.todoroo.andlib.data.Property.LongProperty;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data Model which represents a task users need to accomplish.
|
|
||||||
*
|
|
||||||
* @author Tim Su <tim@todoroo.com>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("nls")
|
|
||||||
public class TagToTaskMapping extends AbstractModel {
|
|
||||||
|
|
||||||
// --- table
|
|
||||||
|
|
||||||
public static final Table TABLE = new Table("tagTaskMap", TagToTaskMapping.class);
|
|
||||||
|
|
||||||
// --- properties
|
|
||||||
|
|
||||||
/** Tag */
|
|
||||||
public static final LongProperty TAG = new LongProperty(
|
|
||||||
TABLE, "tag");
|
|
||||||
|
|
||||||
/** Task */
|
|
||||||
public static final LongProperty TASK = new LongProperty(
|
|
||||||
TABLE, "task");
|
|
||||||
|
|
||||||
/** List of all properties for this model */
|
|
||||||
public static final Property<?>[] PROPERTIES = generateProperties(TagToTaskMapping.class);
|
|
||||||
|
|
||||||
// --- defaults
|
|
||||||
|
|
||||||
/** Default values container */
|
|
||||||
private static final ContentValues defaultValues = new ContentValues();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ContentValues getDefaultValues() {
|
|
||||||
return defaultValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- data access boilerplate
|
|
||||||
|
|
||||||
public TagToTaskMapping() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TagToTaskMapping(TodorooCursor<TagToTaskMapping> cursor, Property<?>[] properties) {
|
|
||||||
this();
|
|
||||||
readPropertiesFromCursor(cursor, properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFromCursor(TodorooCursor<TagToTaskMapping> cursor, Property<?>[] properties) {
|
|
||||||
super.readPropertiesFromCursor(cursor, properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getId() {
|
|
||||||
return NO_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2009, Todoroo Inc
|
|
||||||
* All Rights Reserved
|
|
||||||
* http://www.todoroo.com
|
|
||||||
*/
|
|
||||||
package com.todoroo.astrid.tagsold;
|
|
||||||
|
|
||||||
import com.todoroo.andlib.data.AbstractDatabase;
|
|
||||||
import com.todoroo.andlib.data.Table;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Database wrapper
|
|
||||||
*
|
|
||||||
* @author Tim Su <tim@todoroo.com>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("nls")
|
|
||||||
public class TagsDatabase extends AbstractDatabase {
|
|
||||||
|
|
||||||
// --- constants
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Database version number. This variable must be updated when database
|
|
||||||
* tables are updated, as it determines whether a database needs updating.
|
|
||||||
*/
|
|
||||||
public static final int VERSION = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Database name (must be unique)
|
|
||||||
*/
|
|
||||||
private static final String NAME = "tags";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of table/ If you're adding a new table, add it to this list and
|
|
||||||
* also make sure that our SQLite helper does the right thing.
|
|
||||||
*/
|
|
||||||
public static final Table[] TABLES = new Table[] {
|
|
||||||
Tag.TABLE,
|
|
||||||
TagToTaskMapping.TABLE,
|
|
||||||
};
|
|
||||||
|
|
||||||
// --- implementation
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getName() {
|
|
||||||
return NAME;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getVersion() {
|
|
||||||
return VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Table[] getTables() {
|
|
||||||
return TABLES;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreateTables() {
|
|
||||||
StringBuilder sql = new StringBuilder();
|
|
||||||
sql.append("CREATE INDEX IF NOT EXISTS tm_tag ON ").
|
|
||||||
append(TagToTaskMapping.TABLE).append('(').
|
|
||||||
append(TagToTaskMapping.TAG.name).
|
|
||||||
append(')');
|
|
||||||
database.execSQL(sql.toString());
|
|
||||||
|
|
||||||
sql.setLength(0);
|
|
||||||
sql.append("CREATE INDEX IF NOT EXISTS tm_task ON ").
|
|
||||||
append(TagToTaskMapping.TABLE).append('(').
|
|
||||||
append(TagToTaskMapping.TASK.name).
|
|
||||||
append(')');
|
|
||||||
database.execSQL(sql.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean onUpgrade(int oldVersion, int newVersion) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue