Search in sources :

Example 1 with SessionWork

use of org.ow2.proactive.db.SessionWork in project scheduling by ow2-proactive.

the class TransactionHelperTest method setUp.

@Before
public void setUp() {
    sessionFactory = mock(SessionFactory.class);
    session = mock(Session.class);
    transaction = mock(Transaction.class);
    when(sessionFactory.openSession()).thenReturn(session);
    when(session.beginTransaction()).thenReturn(transaction);
    when(session.getTransaction()).thenReturn(transaction);
    transactionHelper = new TransactionHelper(sessionFactory);
    sessionWork = mock(SessionWork.class);
}
Also used : SessionFactory(org.hibernate.SessionFactory) SessionWork(org.ow2.proactive.db.SessionWork) Transaction(org.hibernate.Transaction) TransactionHelper(org.ow2.proactive.db.TransactionHelper) Session(org.hibernate.Session) Before(org.junit.Before)

Example 2 with SessionWork

use of org.ow2.proactive.db.SessionWork in project scheduling by ow2-proactive.

the class TaskDBUtils method getTotalNumberOfTasks.

public static SessionWork<Integer> getTotalNumberOfTasks(final DBTaskDataParameters params) {
    return new SessionWork<Integer>() {

        @Override
        public Integer doInTransaction(Session session) {
            Set<TaskStatus> taskStatuses = params.getStatuses();
            if (taskStatuses.isEmpty()) {
                return 0;
            }
            boolean hasUser = params.hasUser();
            boolean hasTag = params.hasTag();
            boolean hasDateFrom = params.hasDateFrom();
            boolean hasDateTo = params.hasDateTo();
            String queryPrefix = "select count(*) from TaskData T where ";
            Query query = getQuery(session, params, taskStatuses, hasUser, hasTag, hasDateFrom, hasDateTo, SortSpecifierContainer.EMPTY_CONTAINER, queryPrefix);
            Long count = (Long) query.uniqueResult();
            return count.intValue();
        }
    };
}
Also used : SessionWork(org.ow2.proactive.db.SessionWork) Query(org.hibernate.Query) TaskStatus(org.ow2.proactive.scheduler.common.task.TaskStatus) Session(org.hibernate.Session)

Aggregations

Session (org.hibernate.Session)2 SessionWork (org.ow2.proactive.db.SessionWork)2 Query (org.hibernate.Query)1 SessionFactory (org.hibernate.SessionFactory)1 Transaction (org.hibernate.Transaction)1 Before (org.junit.Before)1 TransactionHelper (org.ow2.proactive.db.TransactionHelper)1 TaskStatus (org.ow2.proactive.scheduler.common.task.TaskStatus)1