use of org.eclipse.persistence.sessions.UnitOfWork in project cuba by cuba-platform.
the class PersistenceImplSupport method fireEntityListeners.
public void fireEntityListeners(EntityManager entityManager, boolean warnAboutImplicitFlush) {
UnitOfWork unitOfWork = entityManager.getDelegate().unwrap(UnitOfWork.class);
String storeName = getStorageName(unitOfWork);
traverseEntities(getInstanceContainerResourceHolder(storeName), new OnFlushEntityVisitor(storeName), warnAboutImplicitFlush);
}
use of org.eclipse.persistence.sessions.UnitOfWork in project cuba by cuba-platform.
the class PersistenceImplSupport method detach.
public void detach(EntityManager entityManager, Entity entity) {
UnitOfWork unitOfWork = entityManager.getDelegate().unwrap(UnitOfWork.class);
String storeName = getStorageName(unitOfWork);
if (entity instanceof BaseGenericIdEntity) {
fireBeforeDetachEntityListener((BaseGenericIdEntity) entity, storeName);
ContainerResourceHolder container = getInstanceContainerResourceHolder(storeName);
container.unregisterInstance(entity, unitOfWork);
if (BaseEntityInternalAccess.isNew((BaseGenericIdEntity) entity)) {
container.getNewDetachedInstances().add(entity);
}
}
makeDetached(entity);
}
use of org.eclipse.persistence.sessions.UnitOfWork 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.sessions.UnitOfWork in project cuba by cuba-platform.
the class PersistenceImplSupport method registerInstance.
public void registerInstance(Entity entity, EntityManager entityManager) {
if (!TransactionSynchronizationManager.isActualTransactionActive())
throw new RuntimeException("No transaction");
UnitOfWork unitOfWork = entityManager.getDelegate().unwrap(UnitOfWork.class);
getInstanceContainerResourceHolder(getStorageName(unitOfWork)).registerInstanceForUnitOfWork(entity, unitOfWork);
if (entity instanceof BaseGenericIdEntity) {
BaseEntityInternalAccess.setDetached((BaseGenericIdEntity) entity, false);
}
}
use of org.eclipse.persistence.sessions.UnitOfWork in project cuba by cuba-platform.
the class PersistenceImplSupport method processFlush.
public void processFlush(EntityManager entityManager, boolean warnAboutImplicitFlush) {
UnitOfWork unitOfWork = entityManager.getDelegate().unwrap(UnitOfWork.class);
String storeName = getStorageName(unitOfWork);
traverseEntities(getInstanceContainerResourceHolder(storeName), new OnSaveEntityVisitor(storeName), warnAboutImplicitFlush);
}
Aggregations