public boolean updateAttrs(String[] attrNames, Object[] attrValues) { int len = attrNames.length; List<String> kvs = new ArrayList<String>(len); for (String attr : attrNames) { kvs.add(attr + " = ?"); } String sql = "update " + TableName() + " set " + StringUtils.join(kvs, ',') + " where id = ?"; List<Object> vals = new ArrayList<Object>(); for (Object val : attrValues) { vals.add(val); } vals.add(getId()); int ret = QueryHelper.update(sql, vals.toArray()); try { if (ret > 0) { for (int i = 0; i < len; i++) { BeanUtils.setProperty(this, attrNames[i], attrValues[i]); } } else { return false; } } catch (Exception e) { return false; } return true; }
public boolean Delete() { boolean dr = Evict(QueryHelper.update("DELETE FROM " + TableName() + " WHERE id = ?", getId()) == 1); if (dr) { CacheManager.evict(CacheRegion(), OBJ_COUNT_CACHE_KEY); } return dr; }
public boolean updateAttr(String attrName, Object attrValue) { String sql = "update " + TableName() + " set " + attrName + " = ? where id = ?"; int ret = QueryHelper.update(sql, attrValue, getId()); try { if (ret > 0) { BeanUtils.setProperty(this, attrName, attrValue); } else { return false; } } catch (Exception e) { return false; } return true; }