/** * Loads an attributeValueBean from the TAttributeValue table by field, parameter and workItem * * @param field * @param workItem * @param parameterCode * @return */ @Override public TAttributeValueBean loadBeanByFieldAndWorkItemAndParameter( Integer field, Integer workItem, Integer parameterCode) { List<TAttributeValue> attributeValueList = null; Criteria criteria = new Criteria(); criteria.add(FIELDKEY, field); criteria.add(WORKITEM, workItem); criteria.addDescendingOrderByColumn(LASTEDIT); if (parameterCode == null) { criteria.add(PARAMETERCODE, (Object) null, Criteria.ISNULL); } else { criteria.add(PARAMETERCODE, parameterCode); } try { attributeValueList = doSelect(criteria); } catch (TorqueException e) { LOGGER.error( "Loading the attributevaluebean by field by field " + field + " parameterCode " + parameterCode + " and workItem " + workItem + " failed with " + e.getMessage(), e); } if (attributeValueList == null || attributeValueList.isEmpty()) { LOGGER.debug( "No attributevaluebean found for field " + field + " parameterCode " + parameterCode + " and workItem" + workItem); return null; } if (attributeValueList.size() > 1) { LOGGER.warn( "More than one attributevaluebean found for field " + field + " parameterCode " + parameterCode + " and workItem " + workItem + ". Delete them..."); boolean first = true; for (Iterator<TAttributeValue> iterator = attributeValueList.iterator(); iterator.hasNext(); ) { if (!first) { TAttributeValue attributeValue = iterator.next(); iterator.remove(); deleteByObjectID(attributeValue.getObjectID()); } first = false; } } return ((TAttributeValue) attributeValueList.get(0)).getBean(); }
/** * Saves an attributeValueBean in the TAttributeValue table * * @param attributeValueBean * @return */ @Override public Integer save(TAttributeValueBean attributeValueBean) { try { TAttributeValue tAttributeValue = BaseTAttributeValue.createTAttributeValue(attributeValueBean); tAttributeValue.save(); return tAttributeValue.getObjectID(); } catch (Exception e) { LOGGER.error("Saving of an attribute value failed with " + e.getMessage()); return null; } }