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;
}
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);
}
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();
}
Aggregations