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 Long doInSession(Session session) { BeanQuery countQry = session.from(sources); if (condition != null) { countQry.where(condition); } return countQry.count(); } });
public RDFBeanTransaction doBegin(Session session) { RDFBeanTransaction txn = session.beginTransaction( false, // not readonly -1, // default timeout -1); // default isolation session.setFlushMode(FlushMode.COMMIT); return txn; }
category.name = "XXX"; category.products.add(product); session.save(product); session.save(category); session.save(new User()); session.clear(); session.findInstances(Category.class); session.findInstances(Identifiable.class); session.findInstances(Product.class); session.findInstances(User.class); session.clear(); PathBuilder<Product> _product = new PathBuilder<Product>(Product.class, "product"); PathBuilder<User> _user = new PathBuilder<User>(User.class, "user"); assertEquals(1, session.from(_category).list(_category).size()); assertEquals(3, session.from(_identifiable).list(_identifiable).size()); assertEquals(1, session.from(_product).list(_product).size()); assertEquals(1, session.from(_user).list(_user).size()); session.close();
inSession = true; Session session = sessionContext.getCurrentSession(); inTx = session.getTransaction() != null && session.getTransaction().isActive(); FlushMode savedFlushMode = session.getFlushMode(); session.setFlushMode(savedFlushMode); sessionContext.releaseSession(); if (!inSession) { session.close();
@Test public void test() { Session session = SessionUtil.openSession(Company.class, Department.class, Employee.class); Company company = new Company(); Department department = new Department(); Employee employee = new Employee(); employee.department = department; department.company = company; session.save(company); session.save(department); session.save(employee); session.flush(); session.clear(); department = session.get(Department.class, department.id); assertFalse(department.employees.isEmpty()); assertTrue(department.employees.iterator().next() instanceof Employee); company = session.get(Company.class, company.id); assertFalse(company.departments.isEmpty()); assertTrue(company.departments.iterator().next() instanceof Department); }
@Test public void test() { EntityRevision revision = new EntityRevision(); revision.text = "a bcd e"; session.save(revision); session.flush(); session.clear(); EntityRevision var = Alias.alias(EntityRevision.class); assertNotNull(session.from($(var)).where($(var.getText()).containsIgnoreCase("a bcd e")).uniqueResult($(var))); }
@Test public void ConstructorInjection() { Session session = SessionUtil.openSession(Child.class, Parent.class); Parent parent = new Parent(); Child child = new Child(parent); session.saveAll(parent, child); session.flush(); session.clear(); Child child2 = session.get(Child.class, child.id); assertNotNull(child2); assertEquals(child.id, child2.id); assertEquals(child.parent.id, child2.parent.id); }
@Test public void ConstructorInjection() { Session session = SessionUtil.openSession(Entity.class); Entity entity = new Entity(new BID(), "Jon", "Doe"); session.save(entity); session.clear(); entity = session.get(Entity.class, entity.id); assertEquals("Jon", entity.firstName); assertEquals("Doe", entity.lastName); } }
@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(); }
@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(); }
public void close() { if (closeAfterTx) { session.close(); } }
@Test public void Write() { Project project = new Project(); project.dates = new HashMap<UID, LocalDate>(); project.dates.put(_created, CREATED); project.dates.put(_deadline, DEADLINE); session.save(project); session.clear(); Project project2 = session.getById(project.id, Project.class); assertEquals(project.dates, project2.dates); }
@Test public void Load_String_List() { Session session = SessionUtil.openSession(Example.class); Example example = new Example(); example.list = Arrays.asList("1", "2", "3", "4"); session.save(example); session.clear(); example = session.findInstances(Example.class).get(0); assertEquals(Arrays.asList("1", "2", "3", "4"), example.list); }
@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(); } } };