*/
@SuppressWarnings("unchecked")
public void updateFeed(ServerBaseFeed feed, String accountname)
throws StorageException {
if (feed == null)
throw new StorageException("Can not update feed -- is null");
if (feed.getId() == null)
throw new StorageException("Can not update feed -- id is null");
if(feed.getServiceType() == null)
throw new StorageException("Can not update feed -- service type is null");
if(accountname == null)
throw new StorageException("Account name is null");
GDataAccount account = getAccount(accountname);
Query query = this.container.query();
query.constrain(ServerBaseFeed.class);
query.descend("feed").descend("id").constrain(feed.getId());
ObjectSet<ServerBaseFeed> set= query.execute();
if (set.size() > 1)
throw new StorageException("Query for feed id " + feed.getId()
+ " returns more than one result");
if (set.size() < 1)
throw new StorageException("can not find feed for given feed id -- "
+ feed.getId());
ServerBaseFeed result = set.next();
refreshPersistentObject(result);
BaseFeed oldFeed = result.getFeed();
result.setAccount(account);
result.setFeed(feed.getFeed());
try {
this.container.delete(oldFeed);
this.container.set(result);
this.container.commit();
} catch (Exception e) {
LOG
.error("Error occurred on persisting changes -- rollback changes");
this.container.rollback();
throw new StorageException("Can not persist changes -- "
+ e.getMessage(), e);
}
}