public static Test suite() {
return new FunctionalTestClassTestSuite( StatelessSessionTest.class );
}
public void testCreateUpdateReadDelete() {
StatelessSession ss = getSessions().openStatelessSession();
Transaction tx = ss.beginTransaction();
Document doc = new Document("blah blah blah", "Blahs");
ss.insert(doc);
assertNotNull( doc.getName() );
Date initVersion = doc.getLastModified();
assertNotNull( initVersion );
tx.commit();
tx = ss.beginTransaction();
doc.setText("blah blah blah .... blah");
ss.update(doc);
assertNotNull( doc.getLastModified() );
assertNotSame( doc.getLastModified(), initVersion );
tx.commit();
tx = ss.beginTransaction();
doc.setText("blah blah blah .... blah blay");
ss.update(doc);
tx.commit();
Document doc2 = (Document) ss.get(Document.class.getName(), "Blahs");
assertEquals("Blahs", doc2.getName());
assertEquals(doc.getText(), doc2.getText());
doc2 = (Document) ss.createQuery("from Document where text is not null").uniqueResult();
assertEquals("Blahs", doc2.getName());
assertEquals(doc.getText(), doc2.getText());
ScrollableResults sr = ss.createQuery("from Document where text is not null")
.scroll(ScrollMode.FORWARD_ONLY);
sr.next();
doc2 = (Document) sr.get(0);
sr.close();
assertEquals("Blahs", doc2.getName());
assertEquals(doc.getText(), doc2.getText());
doc2 = (Document) ss.createSQLQuery("select * from Document")
.addEntity(Document.class)
.uniqueResult();
assertEquals("Blahs", doc2.getName());
assertEquals(doc.getText(), doc2.getText());
doc2 = (Document) ss.createCriteria(Document.class).uniqueResult();
assertEquals("Blahs", doc2.getName());
assertEquals(doc.getText(), doc2.getText());
sr = ss.createCriteria(Document.class).scroll(ScrollMode.FORWARD_ONLY);
sr.next();
doc2 = (Document) sr.get(0);
sr.close();
assertEquals("Blahs", doc2.getName());
assertEquals(doc.getText(), doc2.getText());
tx = ss.beginTransaction();
ss.delete(doc);
tx.commit();
ss.close();
}