Adjusted tag query template

pull/14/head
Sam Bosley 12 years ago
parent aff1b279c1
commit d5c0f1c090

@ -145,10 +145,12 @@ public final class TagService {
* @return * @return
*/ */
public QueryTemplate queryTemplate(Criterion criterion) { public QueryTemplate queryTemplate(Criterion criterion) {
return new QueryTemplate().join(Join.inner(Metadata.TABLE.as("mtags"), Criterion fullCriterion = Criterion.and(
Criterion.and(Task.ID.eq(Field.field("mtags." + Metadata.TASK.name)), Field.field("mtags." + Metadata.KEY.name).eq(TagMetadata.KEY),
Field.field("mtags." + Metadata.KEY.name).eq(TagMetadata.KEY), Field.field("mtags." + TagMetadata.TAG_UUID.name).eq(remoteId),
Field.field("mtags." + TagMetadata.TAG_NAME.name).eqCaseInsensitive(tag)))).where(criterion); criterion);
return new QueryTemplate().join(Join.inner(Metadata.TABLE.as("mtags"), Task.REMOTE_ID.eq(Field.field("mtags." + TagMetadata.TASK_UUID))))
.where(fullCriterion);
} }
} }
@ -171,10 +173,11 @@ public final class TagService {
} }
public QueryTemplate untaggedTemplate() { public QueryTemplate untaggedTemplate() {
String[] emergentTags = getEmergentTags(); Long[] emergentTags = getEmergentTagIds();
return new QueryTemplate().where(Criterion.and( return new QueryTemplate().where(Criterion.and(
Criterion.not(Task.ID.in(Query.select(Metadata.TASK).from(Metadata.TABLE).where(Criterion.and(MetadataCriteria.withKey(TagMetadata.KEY), Criterion.not(TagMetadata.TAG_NAME.in(emergentTags)))))), Criterion.not(Task.REMOTE_ID.in(Query.select(TagMetadata.TASK_UUID).from(Metadata.TABLE)
.where(Criterion.and(MetadataCriteria.withKey(TagMetadata.KEY), Criterion.not(TagMetadata.TAG_UUID.in(emergentTags)))))),
TaskCriteria.isActive(), TaskCriteria.isActive(),
TaskApiDao.TaskCriteria.ownedByMe(), TaskApiDao.TaskCriteria.ownedByMe(),
TaskCriteria.isVisible())); TaskCriteria.isVisible()));
@ -193,7 +196,7 @@ public final class TagService {
if (includeEmergent) if (includeEmergent)
criterion = Criterion.and(activeStatus, MetadataCriteria.withKey(TagMetadata.KEY)); criterion = Criterion.and(activeStatus, MetadataCriteria.withKey(TagMetadata.KEY));
else else
criterion = Criterion.and(activeStatus, MetadataCriteria.withKey(TagMetadata.KEY), Criterion.not(TagMetadata.TAG_NAME.in(getEmergentTags()))); criterion = Criterion.and(activeStatus, MetadataCriteria.withKey(TagMetadata.KEY), Criterion.not(TagMetadata.TAG_NAME.in(getEmergentTagNames())));
Query query = Query.select(TagMetadata.TAG_NAME, TagMetadata.TAG_UUID, COUNT). Query query = Query.select(TagMetadata.TAG_NAME, TagMetadata.TAG_UUID, COUNT).
join(Join.inner(Task.TABLE, Metadata.TASK.eq(Task.ID))). join(Join.inner(Task.TABLE, Metadata.TASK.eq(Task.ID))).
where(criterion). where(criterion).
@ -213,7 +216,7 @@ public final class TagService {
} }
} }
public String[] getEmergentTags() { public String[] getEmergentTagNames() {
TodorooCursor<TagData> emergent = tagDataService.query(Query.select(TagData.NAME) TodorooCursor<TagData> emergent = tagDataService.query(Query.select(TagData.NAME)
.where(Functions.bitwiseAnd(TagData.FLAGS, TagData.FLAG_EMERGENT).gt(0))); .where(Functions.bitwiseAnd(TagData.FLAGS, TagData.FLAG_EMERGENT).gt(0)));
try { try {
@ -276,7 +279,7 @@ public final class TagService {
MetadataCriteria.byTask(taskId)); MetadataCriteria.byTask(taskId));
else else
criterion = Criterion.and(MetadataCriteria.withKey(TagMetadata.KEY), criterion = Criterion.and(MetadataCriteria.withKey(TagMetadata.KEY),
MetadataCriteria.byTask(taskId), Criterion.not(TagMetadata.TAG_NAME.in(getEmergentTags()))); MetadataCriteria.byTask(taskId), Criterion.not(TagMetadata.TAG_NAME.in(getEmergentTagNames())));
Query query = Query.select(TagMetadata.TAG_NAME, TagMetadata.TAG_UUID).where(criterion).orderBy(Order.asc(Functions.upper(TagMetadata.TAG_NAME))); Query query = Query.select(TagMetadata.TAG_NAME, TagMetadata.TAG_UUID).where(criterion).orderBy(Order.asc(Functions.upper(TagMetadata.TAG_NAME)));
return metadataDao.query(query); return metadataDao.query(query);
} }

@ -902,13 +902,13 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
if (getActiveTagData() != null) if (getActiveTagData() != null)
tagName = getActiveTagData().getValue(TagData.NAME); tagName = getActiveTagData().getValue(TagData.NAME);
String[] emergentTags = TagService.getInstance().getEmergentTags(); Long[] emergentTagIds = TagService.getInstance().getEmergentTagIds();
StringProperty tagProperty = new StringProperty(null, TAGS_METADATA_JOIN + "." + TagMetadata.TAG_NAME.name); StringProperty tagProperty = new StringProperty(null, TAGS_METADATA_JOIN + "." + TagMetadata.TAG_UUID.name);
Criterion tagsJoinCriterion = Criterion.and( Criterion tagsJoinCriterion = Criterion.and(
Field.field(TAGS_METADATA_JOIN + "." + Metadata.KEY.name).eq(TagMetadata.KEY), //$NON-NLS-1$ Field.field(TAGS_METADATA_JOIN + "." + Metadata.KEY.name).eq(TagMetadata.KEY), //$NON-NLS-1$
Task.ID.eq(Field.field(TAGS_METADATA_JOIN + "." + Metadata.TASK.name)), Task.ID.eq(Field.field(TAGS_METADATA_JOIN + "." + Metadata.TASK.name)),
Criterion.not(tagProperty.in(emergentTags))); Criterion.not(tagProperty.in(emergentTagIds)));
if (tagName != null) if (tagName != null)
tagsJoinCriterion = Criterion.and(tagsJoinCriterion, Field.field(TAGS_METADATA_JOIN + "." + TagMetadata.TAG_NAME.name).neq(tagName)); tagsJoinCriterion = Criterion.and(tagsJoinCriterion, Field.field(TAGS_METADATA_JOIN + "." + TagMetadata.TAG_NAME.name).neq(tagName));

Loading…
Cancel
Save