Search in sources :

Example 6 with DaoException

use of gov.ca.cwds.data.DaoException 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);
    }
}
Also used : Transaction(org.hibernate.Transaction) Query(org.hibernate.Query) HibernateException(org.hibernate.HibernateException) SystemCode(gov.ca.cwds.data.persistence.cms.SystemCode) DaoException(gov.ca.cwds.data.DaoException) Session(org.hibernate.Session)

Aggregations

DaoException (gov.ca.cwds.data.DaoException)6 Session (org.hibernate.Session)6 HibernateException (org.hibernate.HibernateException)5 Query (org.hibernate.Query)5 Transaction (org.hibernate.Transaction)5 ImmutableList (com.google.common.collect.ImmutableList)2 SystemCode (gov.ca.cwds.data.persistence.cms.SystemCode)2 SystemMeta (gov.ca.cwds.data.persistence.cms.SystemMeta)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ProcedureCall (org.hibernate.procedure.ProcedureCall)1