Search in sources :

Example 1 with JpaEntityManager

use of org.eclipse.persistence.jpa.JpaEntityManager in project cuba by cuba-platform.

the class SoftDeleteTest method setPrintInnerJoinInWhereClause.

protected boolean setPrintInnerJoinInWhereClause(EntityManager entityManager, boolean value) {
    JpaEntityManager jpaEntityManager = (JpaEntityManager) entityManager.getDelegate();
    DatabasePlatform platform = jpaEntityManager.getActiveSession().getPlatform();
    boolean prevValue = platform.shouldPrintInnerJoinInWhereClause();
    platform.setPrintInnerJoinInWhereClause(value);
    return prevValue;
}
Also used : JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) DatabasePlatform(org.eclipse.persistence.platform.database.DatabasePlatform)

Example 2 with JpaEntityManager

use of org.eclipse.persistence.jpa.JpaEntityManager in project cuba by cuba-platform.

the class CubaEclipseLinkJpaDialect method beginTransaction.

@Override
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) throws PersistenceException, SQLException, TransactionException {
    Object result = super.beginTransaction(entityManager, definition);
    Preconditions.checkState(result == null, "Transactional data should be null for EclipseLink dialect");
    // Read default timeout every time - may be somebody wants to change it on the fly
    int defaultTimeout = 0;
    String defaultTimeoutProp = AppContext.getProperty("cuba.defaultQueryTimeoutSec");
    if (!"0".equals(defaultTimeoutProp) && !StringUtils.isBlank(defaultTimeoutProp)) {
        try {
            defaultTimeout = Integer.parseInt(defaultTimeoutProp);
        } catch (NumberFormatException e) {
            log.error("Invalid cuba.defaultQueryTimeoutSec value", e);
        }
    }
    int timeoutSec = 0;
    if (definition.getTimeout() != TransactionDefinition.TIMEOUT_DEFAULT)
        timeoutSec = definition.getTimeout();
    else if (defaultTimeout != 0)
        timeoutSec = defaultTimeout;
    if (timeoutSec != 0) {
        log.trace("Applying query timeout {} sec", timeoutSec);
        if (entityManager instanceof JpaEntityManager) {
            UnitOfWork unitOfWork = ((JpaEntityManager) entityManager).getUnitOfWork();
            if (unitOfWork != null) {
                // setup delay in seconds on unit of work
                unitOfWork.setQueryTimeoutDefault(timeoutSec);
            }
        }
        String s = DbmsSpecificFactory.getDbmsFeatures().getTransactionTimeoutStatement();
        if (s != null) {
            Connection connection = entityManager.unwrap(Connection.class);
            try (Statement statement = connection.createStatement()) {
                statement.execute(String.format(s, timeoutSec * 1000));
            }
        }
    }
    return new CubaEclipseLinkTransactionData(entityManager);
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) Statement(java.sql.Statement) Connection(java.sql.Connection)

Example 3 with JpaEntityManager

use of org.eclipse.persistence.jpa.JpaEntityManager in project spring-framework by spring-projects.

the class EclipseLinkEntityManagerFactoryIntegrationTests method testCanCastSharedEntityManagerProxyToEclipseLinkEntityManager.

@Test
public void testCanCastSharedEntityManagerProxyToEclipseLinkEntityManager() {
    boolean condition = sharedEntityManager instanceof JpaEntityManager;
    assertThat(condition).isTrue();
    JpaEntityManager eclipselinkEntityManager = (JpaEntityManager) sharedEntityManager;
    assertThat(eclipselinkEntityManager.getActiveSession()).isNotNull();
}
Also used : JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) Test(org.junit.jupiter.api.Test)

Aggregations

JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)3 Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 DatabasePlatform (org.eclipse.persistence.platform.database.DatabasePlatform)1 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)1 Test (org.junit.jupiter.api.Test)1