use of fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariable in project pyramus by otavanopisto.
the class CourseBaseVariableDAO method setCourseVariable.
public void setCourseVariable(Course course, String key, String value) {
CourseBaseVariableKeyDAO variableKeyDAO = DAOFactory.getInstance().getCourseBaseVariableKeyDAO();
CourseBaseVariableKey courseBaseVariableKey = variableKeyDAO.findByVariableKey(key);
if (courseBaseVariableKey != null) {
CourseBaseVariable courseBaseVariable = findByCourseAndVariableKey(course, courseBaseVariableKey);
if (StringUtils.isBlank(value)) {
delete(courseBaseVariable);
} else {
if (courseBaseVariable == null) {
courseBaseVariable = create(course, courseBaseVariableKey, value);
} else {
update(courseBaseVariable, value);
}
}
} else {
throw new PersistenceException("Unknown VariableKey");
}
}
use of fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariable in project pyramus by otavanopisto.
the class CourseBaseVariableDAO method findByCourseAndVariableKey.
public CourseBaseVariable findByCourseAndVariableKey(Course course, CourseBaseVariableKey key) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<CourseBaseVariable> criteria = criteriaBuilder.createQuery(CourseBaseVariable.class);
Root<CourseBaseVariable> root = criteria.from(CourseBaseVariable.class);
criteria.select(root);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(root.get(CourseBaseVariable_.courseBase), course), criteriaBuilder.equal(root.get(CourseBaseVariable_.key), key)));
return getSingleResult(entityManager.createQuery(criteria));
}
use of fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariable in project pyramus by otavanopisto.
the class CourseDAO method listByCourseVariable.
public List<Course> listByCourseVariable(String key, String value) {
CourseBaseVariableKeyDAO variableKeyDAO = DAOFactory.getInstance().getCourseBaseVariableKeyDAO();
CourseBaseVariableKey courseBaseVariableKey = variableKeyDAO.findByVariableKey(key);
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Course> criteria = criteriaBuilder.createQuery(Course.class);
Root<CourseBaseVariable> variable = criteria.from(CourseBaseVariable.class);
Root<Course> course = criteria.from(Course.class);
criteria.select(course);
criteria.where(criteriaBuilder.and(criteriaBuilder.equal(course, variable.get(CourseBaseVariable_.courseBase)), criteriaBuilder.equal(course.get(Course_.archived), Boolean.FALSE), criteriaBuilder.equal(variable.get(CourseBaseVariable_.key), courseBaseVariableKey), criteriaBuilder.equal(variable.get(CourseBaseVariable_.value), value)));
return entityManager.createQuery(criteria).getResultList();
}
Aggregations