Search in sources :

Example 1 with OpenJPAEntityManager

use of org.apache.openjpa.persistence.OpenJPAEntityManager in project openmeetings by apache.

the class RoomDao method get.

public List<Room> get() {
    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("getBackupRooms", Room.class);
        @SuppressWarnings("unchecked") OpenJPAQuery<Room> kq = OpenJPAPersistence.cast(q);
        kq.getFetchPlan().addFetchGroups("roomModerators", "roomGroups", "roomFiles");
        return kq.getResultList();
    } finally {
        oem.getFetchPlan().setQueryResultCacheEnabled(qrce);
    }
}
Also used : OpenJPAEntityManager(org.apache.openjpa.persistence.OpenJPAEntityManager) Room(org.apache.openmeetings.db.entity.room.Room)

Example 2 with OpenJPAEntityManager

use of org.apache.openjpa.persistence.OpenJPAEntityManager in project oozie by apache.

the class Store method getConnection.

public String getConnection() {
    OpenJPAEntityManager kem = OpenJPAPersistence.cast(entityManager);
    Connection conn = (Connection) kem.getConnection();
    return conn.toString();
}
Also used : OpenJPAEntityManager(org.apache.openjpa.persistence.OpenJPAEntityManager) Connection(java.sql.Connection)

Example 3 with OpenJPAEntityManager

use of org.apache.openjpa.persistence.OpenJPAEntityManager in project oozie by apache.

the class Store method isClosed.

public boolean isClosed() {
    OpenJPAEntityManager kem = OpenJPAPersistence.cast(entityManager);
    Connection conn = (Connection) kem.getConnection();
    try {
        return conn.isClosed();
    } catch (SQLException e) {
        XLog.getLog(getClass()).info(XLog.STD, e.getMessage(), e);
    }
    return true;
}
Also used : OpenJPAEntityManager(org.apache.openjpa.persistence.OpenJPAEntityManager) SQLException(java.sql.SQLException) Connection(java.sql.Connection)

Example 4 with OpenJPAEntityManager

use of org.apache.openjpa.persistence.OpenJPAEntityManager in project syncope by apache.

the class OpenJpaDialect method beginTransaction.

@Override
public Object beginTransaction(final EntityManager entityManager, final TransactionDefinition definition) throws PersistenceException, SQLException, TransactionException {
    OpenJPAEntityManager openJpaEntityManager = getOpenJPAEntityManager(entityManager);
    if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
        // Pass custom isolation level on to OpenJPA's JDBCFetchPlan configuration
        FetchPlan fetchPlan = openJpaEntityManager.getFetchPlan();
        if (fetchPlan instanceof JDBCFetchPlan) {
            IsolationLevel isolation = IsolationLevel.fromConnectionConstant(definition.getIsolationLevel());
            ((JDBCFetchPlan) fetchPlan).setIsolation(isolation);
        }
    }
    entityManager.getTransaction().begin();
    if (!definition.isReadOnly()) {
        // Like with EclipseLink, make sure to start the logic transaction early so that other
        // participants using the connection (such as JdbcTemplate) run in a transaction.
        openJpaEntityManager.beginStore();
    }
    // Custom implementation for OpenJPA savepoint handling
    return new OpenJpaTransactionData(openJpaEntityManager);
}
Also used : OpenJPAEntityManager(org.apache.openjpa.persistence.OpenJPAEntityManager) IsolationLevel(org.apache.openjpa.persistence.jdbc.IsolationLevel) JDBCFetchPlan(org.apache.openjpa.persistence.jdbc.JDBCFetchPlan) FetchPlan(org.apache.openjpa.persistence.FetchPlan) JDBCFetchPlan(org.apache.openjpa.persistence.jdbc.JDBCFetchPlan)

Example 5 with OpenJPAEntityManager

use of org.apache.openjpa.persistence.OpenJPAEntityManager in project openmeetings by apache.

the class UserDao method getAllBackupUsers.

public List<User> getAllBackupUsers() {
    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("getAllUsers", User.class);
        @SuppressWarnings("unchecked") OpenJPAQuery<User> kq = OpenJPAPersistence.cast(q);
        kq.getFetchPlan().addFetchGroups("backupexport", "groupUsers");
        return kq.getResultList();
    } finally {
        oem.getFetchPlan().setQueryResultCacheEnabled(qrce);
    }
}
Also used : OpenJPAEntityManager(org.apache.openjpa.persistence.OpenJPAEntityManager) User(org.apache.openmeetings.db.entity.user.User)

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