public void close() { if (closeAfterTx) { session.close(); } }
private void closeSession() { if (session != null) { session.close(); session = null; } } }
@After public void tearDown() throws IOException { for (Session s : openSessions) { s.close(); } System.out.println(); }
@After public void close() throws IOException { this.session.close(); }
@After public void tearDown() throws IOException { session.close(); }
public SeedEntityImpl( Configuration configuration, SessionFactory sessionFactory, List<Object> entities) throws IOException { this.persisted = new HashMap<Object, Object>(entities.size()); Session session = sessionFactory.openSession(); RDFBeanTransaction tx = session.beginTransaction(); try { for (Object entity : entities) { replaceReferences(configuration, entity); Object original = session.getByExample(entity); if (original == null) { session.save(entity); } else { persisted.put(entity, original); } } tx.commit(); } catch (Exception e) { logger.error(e.getMessage(), e); tx.rollback(); } finally { session.close(); } }
@Override public T toValue(String id) { Session session = sessionFactory.getCurrentSession(); boolean close = session == null; if (session == null) { session = sessionFactory.openSession(); } try { return session.getById(id, cl); } finally { if (close) { session.close(); } } } };
@Override public <T> T execute(SessionCallback<T> cb) { if (sessionContext.getCurrentSession() != null) { return cb.doInSession(sessionContext.getCurrentSession()); } else { Session session = openSession(); try { return cb.doInSession(session); } finally { session.close(); } } }
@Override public void evaluate() throws Throwable { Session session = SessionUtil.openSession(repository, new Locale("fi"), config.value()); RDFBeanTransaction tx = transactional ? session.beginTransaction() : null; try { Field field = target.getClass().getField("session"); field.setAccessible(true); field.set(target, session); base.evaluate(); } finally { if (tx != null) { tx.rollback(); } session.close(); } } };
@Test public void Save() throws IOException { Session session = SessionUtil.openSession(new MiniRepository(), Collections.<Locale> emptySet(), configuration); Category category = new Category(); category.label = "X"; category.children = Collections.singleton(new Category()); session.save(category); session.flush(); session.close(); }
sessionContext.releaseSession(); if (!inSession) { session.close();
assertTrue(project.dates.containsKey(_created)); assertEquals(0, project.participants.size()); session.close();
@Before public void setUp() { Configuration configuration = new DefaultConfiguration(TEST.NS, Entity.class); Repository repository = new MiniRepository(); sessionFactory = new SessionFactoryImpl(); sessionFactory.setConfiguration(configuration); sessionFactory.setRepository(repository); sessionFactory.initialize(); Session session = sessionFactory.openSession(); for (int i = 0; i < 10; i++) { session.save(new Entity()); } session.close(); }
@Before public void setUp() { Configuration configuration = new DefaultConfiguration(TEST.NS, Entity.class); Repository repository = new MiniRepository(); sessionFactory = new SessionFactoryImpl(); sessionFactory.setConfiguration(configuration); sessionFactory.setRepository(repository); sessionFactory.initialize(); Session session = sessionFactory.openSession(); for (int i = 0; i < 10; i++) { session.save(new Entity()); } session.close(); }
assertEquals("XXX", session.from(_product).list(_product).get(0).name); session.close();
sessionContext.releaseSession(); if (!inSession) { session.close();
@Before public void setUp() throws IOException { sessionFactory = new SessionFactoryImpl(); sessionFactory.setConfiguration(new DefaultConfiguration(User.class)); sessionFactory.setRepository(new MiniRepository()); sessionFactory.initialize(); Session session = sessionFactory.openSession(); session.save(new User("Anton", "Bruxner")); session.save(new User("John", "Smith")); session.save(new User("Zoe", "Ark")); session.save(new User("Chris", "Rock")); session.save(new User("Bernard", "Shaw")); session.close(); }
assertEquals(1, session.from(_user).list(_user).size()); session.close();
@Test public void Query() throws IOException { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addClass(TEST.NS, Person.class).addId("id").addProperties(); builder.addClass(new UID(TEST.NS, "Dept"), Department.class).addId("id").addProperties(); builder.addClass(TEST.NS, Company.class).addId("id").addProperties(); Configuration configuration = builder.build(); Session session = SessionUtil.openSession(new MiniRepository(), Collections.<Locale> emptySet(), configuration); Person person = new Person(); person.firstName = "Bob"; person.lastName = "Smith"; session.save(person); session.clear(); // getById Person other = session.getById(person.id, Person.class); assertNotNull(other.id); assertEquals(person.firstName, other.firstName); assertEquals(person.lastName, other.lastName); // query PathBuilder<Person> personPath = new PathBuilderFactory().create(Person.class); assertEquals(other, session.from(personPath).where(personPath.getString("firstName").eq("Bob")).uniqueResult(personPath)); assertEquals(other, session.from(personPath).where(personPath.getString("lastName").eq("Smith")).uniqueResult(personPath)); // list assertEquals(1, session.from(personPath).list(personPath).size()); // findInstances assertEquals(1, session.findInstances(Person.class).size()); session.close(); }