public List<T> getResults(final int from, final int to) { return sessionFactory.execute(new SessionCallback<List<T>>() { public List<T> doInSession(Session session) { BeanQuery qry = session.from(sources).offset(from).limit(to - from).orderBy(order); if (condition != null) { qry.where(condition); } return qry.list(projection); } }); }
public Session getOrCreateSession() { if (sessionHolder.get() == null) { Session session = sessionFactory.openSession(); sessionHolder.set(session); return session; } else { return sessionHolder.get(); } }
@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(); } } } };
@Inject public void setSessionFactory(SessionFactory sessionFactory) { this.sessionContext = new SimpleSessionContext(sessionFactory); sessionFactory.setSessionContext(sessionContext); }
public TransactionalAdvisorImpl(SessionFactory sessionFactory) { this.sessionContext = new SimpleSessionContext(sessionFactory); this.advice = new TransactionalMethodAdvice(this, sessionContext); sessionFactory.setSessionContext(sessionContext); }
@Override public int getAvailableRows() { return sessionFactory.execute(new SessionCallback<Integer>() { @Override public Integer doInSession(Session session) { BeanQuery beanQuery = session.from(entityPath); if (conditions != null) { beanQuery.where(conditions); } return (int) beanQuery.count(); } }); }
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 void prepare(final int start, final int end, final List<SortConstraint> sortConstraints) { Assert.notNull(sortConstraints, "sortContraints"); sessionFactory.execute(new SessionCallback<Void>() { @Override public Void doInSession(Session session) { prepare(session, start, end, sortConstraints); return null; } }); }
public BeanListSource(SessionFactory sessionFactory, EntityPath<?>[] sourceArray, QueryMetadata metadata, Path<T> projection) { this.sessionFactory = sessionFactory; this.sources = sourceArray.clone(); this.condition = metadata.getWhere(); this.projection = projection; this.order = metadata.getOrderBy().toArray(new OrderSpecifier[metadata.getOrderBy().size()]); this.size = sessionFactory.execute(new SessionCallback<Long>() { @Override public Long doInSession(Session session) { BeanQuery countQry = session.from(sources); if (condition != null) { countQry.where(condition); } return countQry.count(); } }); }