HibernateCollectionAdapter extends BasicAdapter { @Override public Entry updateEntry(Object entryId, Entry entry) throws Exception { Session session = getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); try { Object forUpdate = session.load( Class.forName((String) config.getProperty(ENTRY_MAPPING_CLASS_NAME)), (Serializable) entryId); if (forUpdate != null) { forUpdate = collectMappingObject(entry, forUpdate); session.update(forUpdate); tx.commit(); } } catch (HibernateException ex) { tx.rollback(); logger.error("error deleting the entry", ex); } finally { session.close(); } return entry; } HibernateCollectionAdapter(Abdera abdera, FeedConfiguration config); @Override Entry createEntry(Entry entry); @Override boolean deleteEntry(Object entryId); @Override Entry getEntry(Object entryId); @Override Feed getFeed(); @Override Entry updateEntry(Object entryId, Entry entry); static final String HIBERNATE_ANNOTATION_CONFIG; static final String HIBERNATE_CFG_PATH; static final String ENTRY_MAPPING_CLASS_NAME; }
@Test public void testUpdateEntry() { ClientResponse resp = client.get("http: Document<Entry> doc = resp.getDocument(); Entry entry = (Entry) doc.getRoot().clone(); entry.setTitle("This is the modified title"); resp.release(); resp = client.put("http: assertEquals(ResponseType.SUCCESS, resp.getType()); assertEquals(200, resp.getStatus()); resp.release(); resp = client.get("http: doc = resp.getDocument(); entry = doc.getRoot(); assertEquals("This is the modified title", entry.getTitle()); resp.release(); resp = client.get("http: Document<Feed> feed_doc = resp.getDocument(); Feed feed = feed_doc.getRoot(); assertEquals(1, feed.getEntries().size()); resp.release(); }