*/
public void mailUser(long id){
//data
DataManager dm = DataManagerFactory.getInstance();
PersistenceManager pm = dm.newPersistenceManager();
//fetch user
User user = pm.getObjectById(User.class,id);
if (user.getLastEmail() == null){
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR, -(4 * 24));
user.setLastEmail(cal.getTime());
}
Date now = Calendar.getInstance().getTime();
boolean ismail = false;
StringBuilder email = new StringBuilder();
email.append("Hello ");
email.append(user.getId());
email.append("\r\n\r\nHere are your updates since ");
email.append(user.getLastEmail());
email.append("\r\n\r\n");
//retrieve subscriptions
//fetch sub
Query sq = pm.newQuery(Subscription.class);
sq.setFilter("userKey == uk && lastDate > date");
sq.declareParameters("com.google.appengine.api.datastore.Key uk, java.util.Date date");
@SuppressWarnings("unchecked")
List<Subscription> ls = (List<Subscription>) sq.execute(user.getKey(),user.getLastEmail());
//fetch new subscriptions
for(Subscription sub : ls){
//fetch entries
Query qEntry = pm.newQuery(BlogEntry.class);
qEntry.setFilter("blogKey == bk && pubDate > date");
qEntry.declareParameters("com.google.appengine.api.datastore.Key bk, java.util.Date date");
//fetch entries
List<BlogEntry> entries = (List<BlogEntry>) qEntry.execute(sub.getBlogKey(),user.getLastEmail());