// won't matter
Query weblogQuery = strategy.getNamedQuery(
"WeblogEntryTagAggregate.getByName&WebsiteOrderByLastUsedDesc");
weblogQuery.setParameter(1, name);
weblogQuery.setParameter(2, website);
WeblogEntryTagAggregate weblogTagData;
try {
weblogTagData = (WeblogEntryTagAggregate)weblogQuery.getSingleResult();
} catch (NoResultException e) {
weblogTagData = null;
}
Query siteQuery = strategy.getNamedQuery(
"WeblogEntryTagAggregate.getByName&WebsiteNullOrderByLastUsedDesc");
siteQuery.setParameter(1, name);
WeblogEntryTagAggregate siteTagData;
try {
siteTagData = (WeblogEntryTagAggregate)siteQuery.getSingleResult();
} catch (NoResultException e) {
siteTagData = null;
}
Timestamp lastUsed = new Timestamp((new Date()).getTime());
// create it only if we are going to need it.
if (weblogTagData == null && amount > 0) {
weblogTagData = new WeblogEntryTagAggregate(null, website, name, amount);
weblogTagData.setLastUsed(lastUsed);
strategy.store(weblogTagData);
} else if (weblogTagData != null) {
weblogTagData.setTotal(weblogTagData.getTotal() + amount);
weblogTagData.setLastUsed(lastUsed);
strategy.store(weblogTagData);
// Why use update query when only one object needs update?
// Query update = strategy.getNamedUpdate(
// "WeblogEntryTagAggregate.updateAddToTotalByName&Weblog");
// update.setParameter(1, new Long(amount));
// update.setParameter(2, lastUsed);
// update.setParameter(3, weblogTagData.getName());
// update.setParameter(4, website);
// update.executeUpdate();
}
// create it only if we are going to need it.
if (siteTagData == null && amount > 0) {
siteTagData = new WeblogEntryTagAggregate(null, null, name, amount);
siteTagData.setLastUsed(lastUsed);
strategy.store(siteTagData);
} else if(siteTagData != null) {
siteTagData.setTotal(siteTagData.getTotal() + amount);
siteTagData.setLastUsed(lastUsed);
strategy.store(siteTagData);
// Why use update query when only one object needs update?
// Query update = strategy.getNamedUpdate(
// "WeblogEntryTagAggregate.updateAddToTotalByName&WeblogNull");
// update.setParameter(1, new Long(amount));