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);
}
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();
}
};
}
Aggregations