.createQuery("update PlanProperties pp set pp.openHandle = 1, pp.openedByUser = :user where (pp.openHandle is null or pp.openHandle = 0) and pp.id = :propid");
q.setParameter("user", user.getUsername());
q.setParameter("propid", propertyId);
int num = q.executeUpdate();
if (num < 1) {
throw new PlanningException("The plan has been loaded by another user. Please choose another plan.");
}
// and add it to the list of loaded plans, so we can unlock it in
// any case
sessionPlans.add(propertyId);
}
// then load the plan
Object result = em.createQuery("select p.id from Plan p where p.planProperties.id = " + propertyId)
.getSingleResult();
if (result != null) {
Plan plan = loadPlan((Integer) result);
plan.setReadOnly(readOnly);
log.info("Plan {} : {} loaded.", propertyId, plan.getPlanProperties().getName());
return plan;
} else {
throw new PlanningException("An unexpected error has occured while loading the plan.");
}
}