public static List<Pair<Task,Recurrence>> getAllTasksForUser(int userId,int categoryId,
	    CompletionType completionType,long startDateMilliseconds) {
	
	String queryString = "SELECT * from public.\"Task\" INNER JOIN public.\"Recurrence\" ON public.\"Task\".\"ID\" = public.\"Recurrence\".\"TaskID\" WHERE \"UserID\" = ?";
	if (completionType == CompletionType.COMPLETED) {
	    queryString += " AND (  \"CompletionGrade\"="+Task.COMPLETED_VALUE + " OR \"ID\" in (SELECT \"ParentID\" from public.\"Task\" WHERE \"CompletionGrade\"=" + Task.COMPLETED_VALUE + ") )";
	} else if (completionType == CompletionType.UNFINISHED) {
	    queryString += " AND  \"CompletionGrade\"<"+Task.COMPLETED_VALUE;
	}
	
	if(categoryId>0){
	    queryString += " AND \"CategoryID\"= ? ";
	
	}
	
	if(startDateMilliseconds > 0){
	    queryString += " AND \"StartDate\" <= ?";
	}
	
	try {
	    Connection connection = getConnection();
	    PreparedStatement prepStatement = connection
		    .prepareStatement(queryString);
	    int index = 1;
	    prepStatement.setInt(index++, userId);
	    if(categoryId>0){
		prepStatement.setInt(index++, categoryId);
	    }
	    if(startDateMilliseconds > 0){
		prepStatement.setDate(index++, new Date(startDateMilliseconds));
	    }
	    return executeTaskSelectQuery(prepStatement);
	} catch (SQLException e) {
	    e.printStackTrace();
	}
	return new ArrayList<Pair<Task,Recurrence>>();
    }