use of org.hibernate.transform.ResultTransformer in project RecordManager2 by moravianlibrary.
the class SkatKeyDAOHibernate method getSkatKeysForRecord.
@SuppressWarnings({ "unchecked", "serial" })
@Override
public List<SkatKey> getSkatKeysForRecord(Long skatRecordId) {
Session session = sessionFactory.getCurrentSession();
return (List<SkatKey>) session.createSQLQuery("SELECT skat_record_id,sigla,local_record_id,manually_merged" + " FROM skat_keys" + " WHERE skat_record_id = ?").setResultTransformer(new ResultTransformer() {
@Override
public Object transformTuple(Object[] tuple, String[] aliases) {
SkatKeyCompositeId compositeId = new SkatKeyCompositeId();
boolean manuallyMerged = false;
for (int i = 0; i < tuple.length; i++) {
switch(aliases[i]) {
case "skat_record_id":
compositeId.setSkatHarvestedRecordId(((BigDecimal) tuple[i]).longValue());
break;
case "sigla":
compositeId.setSigla(((String) tuple[i]));
break;
case "local_record_id":
compositeId.setRecordId((String) tuple[i]);
break;
case "manually_merged":
manuallyMerged = (boolean) tuple[i];
break;
}
}
SkatKey key = new SkatKey(compositeId);
key.setManuallyMerged(manuallyMerged);
return key;
}
@SuppressWarnings("rawtypes")
@Override
public List transformList(List collection) {
return collection;
}
}).setParameter(0, skatRecordId).list();
}
Aggregations