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"); } }
private UserVariable create(User user, UserVariableKey key, String value) { EntityManager entityManager = getEntityManager(); UserVariable userVariable = new UserVariable(); userVariable.setUser(user); userVariable.setKey(key); userVariable.setValue(value); entityManager.persist(userVariable); user.getVariables().add(userVariable); entityManager.persist(user); return userVariable; }
private void updateValue(UserVariable userVariable, String value) { EntityManager entityManager = getEntityManager(); userVariable.setValue(value); entityManager.persist(userVariable); }