public String findByUserAndKey(User user, String key) { UserVariableKeyDAO variableKeyDAO = DAOFactory.getInstance().getUserVariableKeyDAO(); UserVariableKey userVariableKey = variableKeyDAO.findByVariableKey(key); if (userVariableKey != null) { UserVariable userVariable = findByUserAndVariableKey(user, userVariableKey); return userVariable == null ? null : userVariable.getValue(); } else { throw new PersistenceException("Unknown VariableKey"); } }
public void setUserVariable(User user, String key, String value) { UserVariableKeyDAO variableKeyDAO = DAOFactory.getInstance().getUserVariableKeyDAO(); UserVariableKey userVariableKey = variableKeyDAO.findByVariableKey(key); if (userVariableKey != null) { UserVariable userVariable = findByUserAndVariableKey(user, userVariableKey); if (StringUtils.isBlank(value)) { if (userVariable != null) { delete(userVariable); } } else { if (userVariable == null) { userVariable = create(user, userVariableKey, value); } else { updateValue(userVariable, value); } } } else { throw new PersistenceException("Unknown VariableKey"); } }