use of org.apache.openjpa.persistence.OpenJPAEntityManager in project openmeetings by apache.
the class UserDao method get.
private User get(Long id, boolean force) {
User u = null;
if (id != null && id.longValue() > 0) {
OpenJPAEntityManager oem = OpenJPAPersistence.cast(em);
boolean qrce = oem.getFetchPlan().getQueryResultCacheEnabled();
try {
// update in cache during update
oem.getFetchPlan().setQueryResultCacheEnabled(false);
TypedQuery<User> q = oem.createNamedQuery("getUserById", User.class).setParameter("id", id);
@SuppressWarnings("unchecked") OpenJPAQuery<User> kq = OpenJPAPersistence.cast(q);
kq.getFetchPlan().addFetchGroup("groupUsers");
if (force) {
kq.getFetchPlan().addFetchGroup("backupexport");
}
List<User> list = kq.getResultList();
u = list.size() == 1 ? list.get(0) : null;
} finally {
oem.getFetchPlan().setQueryResultCacheEnabled(qrce);
}
} else {
log.info("[get]: No user id given");
}
return u;
}
use of org.apache.openjpa.persistence.OpenJPAEntityManager in project openmeetings by apache.
the class RoomDao method get.
@Override
public Room get(Long id) {
Room r = null;
if (id != null && id.longValue() > 0) {
OpenJPAEntityManager oem = OpenJPAPersistence.cast(em);
boolean qrce = oem.getFetchPlan().getQueryResultCacheEnabled();
try {
// update in cache during update
oem.getFetchPlan().setQueryResultCacheEnabled(false);
TypedQuery<Room> q = oem.createNamedQuery("getRoomById", Room.class);
q.setParameter("id", id);
@SuppressWarnings("unchecked") OpenJPAQuery<Room> kq = OpenJPAPersistence.cast(q);
kq.getFetchPlan().addFetchGroups("roomModerators", "roomGroups", "roomFiles");
List<Room> l = kq.getResultList();
r = l.isEmpty() ? r : l.get(0);
} finally {
oem.getFetchPlan().setQueryResultCacheEnabled(qrce);
}
} else {
log.info("[get] " + "Info: No room id given");
}
return r;
}
Aggregations