Search in sources :

Example 6 with OpenJPAEntityManager

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;
}
Also used : OpenJPAEntityManager(org.apache.openjpa.persistence.OpenJPAEntityManager) User(org.apache.openmeetings.db.entity.user.User)

Example 7 with OpenJPAEntityManager

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;
}
Also used : OpenJPAEntityManager(org.apache.openjpa.persistence.OpenJPAEntityManager) Room(org.apache.openmeetings.db.entity.room.Room)

Aggregations

OpenJPAEntityManager (org.apache.openjpa.persistence.OpenJPAEntityManager)7 Connection (java.sql.Connection)2 Room (org.apache.openmeetings.db.entity.room.Room)2 User (org.apache.openmeetings.db.entity.user.User)2 SQLException (java.sql.SQLException)1 FetchPlan (org.apache.openjpa.persistence.FetchPlan)1 IsolationLevel (org.apache.openjpa.persistence.jdbc.IsolationLevel)1 JDBCFetchPlan (org.apache.openjpa.persistence.jdbc.JDBCFetchPlan)1