/** * 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(); }
/** * Converts a list of TOption torque objects to a list of TOptionBean objects * * @param torqueList * @return */ private static List<TAttributeValueBean> convertTorqueListToBeanList( List<TAttributeValue> torqueList) { List<TAttributeValueBean> beanList = new ArrayList<TAttributeValueBean>(); if (torqueList != null) { Iterator<TAttributeValue> itrTorqueList = torqueList.iterator(); while (itrTorqueList.hasNext()) { TAttributeValue tAttributeValue = itrTorqueList.next(); beanList.add(tAttributeValue.getBean()); } } return beanList; }
/** * 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; } }
/** * Loads the attribute value by primary key * * @param objectID * @return */ @Override public TAttributeValueBean loadByPrimaryKey(Integer objectID) { TAttributeValue tAttributeValue = null; try { tAttributeValue = retrieveByPK(objectID); } catch (Exception e) { LOGGER.info( "Loading of an attribute value by primary key " + objectID + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } if (tAttributeValue != null) { return tAttributeValue.getBean(); } return null; }