use of gov.ca.cwds.data.persistence.cms.SystemCode in project api-core by ca-cwds.
the class ApiHibernateInterceptorTest method testForSynchronizedPreFlush.
@SuppressWarnings("unused")
@Test
public void testForSynchronizedPreFlush() throws Exception {
ExecutorService service = Executors.newFixedThreadPool(4);
ApiHibernateInterceptor interceptor = new ApiHibernateInterceptor();
final HashMap<Integer, Object> map = new HashMap<>();
SystemCode code1 = new SystemCode();
SystemCode code2 = new SystemCode();
SystemCode code3 = new SystemCode();
SystemCode code4 = new SystemCode();
map.put(1, code1);
map.put(2, code2);
map.put(3, code3);
map.put(4, code4);
Iterator<?> iter = map.entrySet().iterator();
Future<Date> future1 = execCallable(service, iter, interceptor);
Future<Date> future2 = execCallable(service, iter, interceptor);
Future<Date> future3 = execCallable(service, iter, interceptor);
Future<Date> future4 = execCallable(service, iter, interceptor);
}
use of gov.ca.cwds.data.persistence.cms.SystemCode in project api-core by ca-cwds.
the class SystemCodeDao method findBySystemCodeId.
@SuppressWarnings("unchecked")
public SystemCode findBySystemCodeId(Number systemCodeId) {
final String namedQueryName = SystemCode.class.getName() + ".findBySystemCodeId";
Session session = getSessionFactory().getCurrentSession();
Transaction txn = session.getTransaction();
boolean transactionExists = txn != null && txn.isActive();
txn = transactionExists ? txn : session.beginTransaction();
try {
final Query query = session.getNamedQuery(namedQueryName).setShort("systemId", systemCodeId.shortValue());
final SystemCode systemCode = (SystemCode) query.getSingleResult();
if (!transactionExists)
txn.commit();
return systemCode;
} catch (HibernateException h) {
txn.rollback();
throw new DaoException(h);
}
}
use of gov.ca.cwds.data.persistence.cms.SystemCode in project api-core by ca-cwds.
the class SystemCodeDaoTest method findAll_Args__.
@Test
public void findAll_Args__() throws Exception {
SessionFactory sessionFactory = mock(SessionFactory.class);
Session session = mock(Session.class);
Transaction tx = mock(Transaction.class);
Query query = mock(Query.class);
when(sessionFactory.getCurrentSession()).thenReturn(session);
when(session.getNamedQuery(any(String.class))).thenReturn(query);
when(session.beginTransaction()).thenReturn(tx);
when(query.list()).thenReturn(new ArrayList<SystemCode>());
when(query.setString(any(String.class), any(String.class))).thenReturn(query);
SystemCodeDao target = new SystemCodeDao(sessionFactory);
SystemCode[] actual = target.findByForeignKeyMetaTable("asdf");
SystemCode[] expected = new SystemCode[0];
assertThat(actual, is(equalTo(expected)));
}
use of gov.ca.cwds.data.persistence.cms.SystemCode in project api-core by ca-cwds.
the class SystemCodeDao method findByForeignKeyMetaTable.
/**
* @param foreignKeyMetaTable meta group
* @return all keys by meta table
*/
@SuppressWarnings("unchecked")
public SystemCode[] findByForeignKeyMetaTable(String foreignKeyMetaTable) {
final String namedQueryName = SystemCode.class.getName() + ".findByForeignKeyMetaTable";
final Session session = getCurrentSession();
Transaction txn = session.getTransaction();
boolean transactionExists = txn != null && txn.isActive();
txn = transactionExists ? txn : session.beginTransaction();
try {
final Query query = session.getNamedQuery(namedQueryName).setString("foreignKeyMetaTable", foreignKeyMetaTable);
final SystemCode[] systemCodes = (SystemCode[]) query.list().toArray(new SystemCode[0]);
if (!transactionExists)
txn.commit();
return systemCodes;
} catch (HibernateException h) {
txn.rollback();
throw new DaoException(h);
}
}
Aggregations