use of org.hibernate.jpa.spi.JpaCompliance in project hibernate-orm by hibernate.
the class JpaComplianceTests method testSettingTrue.
@Test
public void testSettingTrue() {
ServiceRegistryScope.using(() -> new StandardServiceRegistryBuilder().applySetting(AvailableSettings.JPA_COMPLIANCE, true).build(), (serviceRegistryScope) -> {
final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) new MetadataSources(serviceRegistryScope.getRegistry()).buildMetadata().buildSessionFactory();
final JpaCompliance jpaCompliance = sessionFactory.getSessionFactoryOptions().getJpaCompliance();
assertAll(jpaCompliance, true);
});
// MutableJpaComplianceImpl defaults its values based on the passed
// `jpaByDefault` (`true` here). ultimately we want to source this
// from `AvailableSettings#JPA_COMPLIANCE`
final MutableJpaComplianceImpl compliance = new MutableJpaComplianceImpl(Collections.emptyMap(), true);
assertAll(compliance, true);
}
use of org.hibernate.jpa.spi.JpaCompliance in project hibernate-orm by hibernate.
the class IdentifierLoadAccessImpl method doLoad.
@SuppressWarnings("unchecked")
protected final T doLoad(Object id) {
final SessionImplementor session = context.getSession();
final EventSource eventSource = (EventSource) session;
final LoadQueryInfluencers loadQueryInfluencers = session.getLoadQueryInfluencers();
final JpaCompliance jpaCompliance = session.getFactory().getSessionFactoryOptions().getJpaCompliance();
if (!jpaCompliance.isLoadByIdComplianceEnabled()) {
id = entityPersister.getIdentifierMapping().getJavaType().coerce(id, this);
}
String entityName = entityPersister.getEntityName();
Boolean readOnly = this.readOnly != null ? this.readOnly : loadQueryInfluencers.getReadOnly();
if (this.lockOptions != null) {
LoadEvent event = new LoadEvent(id, entityName, lockOptions, eventSource, readOnly);
context.fireLoad(event, LoadEventListener.GET);
final Object result = event.getResult();
initializeIfNecessary(result);
return (T) result;
}
LoadEvent event = new LoadEvent(id, entityName, false, eventSource, readOnly);
boolean success = false;
try {
context.fireLoad(event, LoadEventListener.GET);
success = true;
} catch (ObjectNotFoundException e) {
// if session cache contains proxy for non-existing object
} finally {
context.afterOperation(success);
}
final Object result = event.getResult();
initializeIfNecessary(result);
return (T) result;
}
use of org.hibernate.jpa.spi.JpaCompliance in project hibernate-orm by hibernate.
the class IdentifierLoadAccessImpl method doGetReference.
@SuppressWarnings("unchecked")
protected T doGetReference(Object id) {
final SessionImplementor session = context.getSession();
final EventSource eventSource = (EventSource) session;
final LoadQueryInfluencers loadQueryInfluencers = session.getLoadQueryInfluencers();
final JpaCompliance jpaCompliance = session.getFactory().getSessionFactoryOptions().getJpaCompliance();
if (!jpaCompliance.isLoadByIdComplianceEnabled()) {
id = entityPersister.getIdentifierMapping().getJavaType().coerce(id, this);
}
String entityName = entityPersister.getEntityName();
Boolean readOnly = this.readOnly != null ? this.readOnly : loadQueryInfluencers.getReadOnly();
if (this.lockOptions != null) {
LoadEvent event = new LoadEvent(id, entityName, lockOptions, eventSource, readOnly);
context.fireLoad(event, LoadEventListener.LOAD);
return (T) event.getResult();
}
LoadEvent event = new LoadEvent(id, entityName, false, eventSource, readOnly);
boolean success = false;
try {
context.fireLoad(event, LoadEventListener.LOAD);
if (event.getResult() == null) {
session.getFactory().getEntityNotFoundDelegate().handleEntityNotFound(entityName, id);
}
success = true;
return (T) event.getResult();
} finally {
context.afterOperation(success);
}
}
use of org.hibernate.jpa.spi.JpaCompliance in project infinispan by infinispan.
the class TestSessionAccessImpl method mockSession.
@Override
public Object mockSession(Class<? extends JtaPlatform> jtaPlatform, ControlledTimeService timeService, RegionFactory regionFactory) {
SessionMock session = mock(SessionMock.class);
when(session.isClosed()).thenReturn(false);
when(session.isOpen()).thenReturn(true);
when(session.getTransactionStartTimestamp()).thenReturn(timeService.wallClockTime());
TransactionCoordinator txCoord;
if (jtaPlatform == BatchModeJtaPlatform.class) {
BatchModeTransactionCoordinator batchModeTxCoord = new BatchModeTransactionCoordinator();
txCoord = batchModeTxCoord;
when(session.getTransactionCoordinator()).thenReturn(txCoord);
when(session.beginTransaction()).then(invocation -> {
Transaction tx = batchModeTxCoord.newTransaction();
tx.begin();
return tx;
});
} else if (jtaPlatform == null || jtaPlatform == NoJtaPlatform.class) {
Connection connection = mock(Connection.class);
JdbcConnectionAccess jdbcConnectionAccess = mock(JdbcConnectionAccess.class);
try {
when(jdbcConnectionAccess.obtainConnection()).thenReturn(connection);
} catch (SQLException e) {
// never thrown from mock
}
JdbcSessionOwner jdbcSessionOwner = mock(JdbcSessionOwner.class);
when(jdbcSessionOwner.getJdbcConnectionAccess()).thenReturn(jdbcConnectionAccess);
SqlExceptionHelper sqlExceptionHelper = mock(SqlExceptionHelper.class);
JdbcServices jdbcServices = mock(JdbcServices.class);
when(jdbcServices.getSqlExceptionHelper()).thenReturn(sqlExceptionHelper);
ServiceRegistry serviceRegistry = mock(ServiceRegistry.class);
when(serviceRegistry.getService(JdbcServices.class)).thenReturn(jdbcServices);
JdbcSessionContext jdbcSessionContext = mock(JdbcSessionContext.class);
when(jdbcSessionContext.getServiceRegistry()).thenReturn(serviceRegistry);
JpaCompliance jpaCompliance = mock(JpaCompliance.class);
when(jpaCompliance.isJpaTransactionComplianceEnabled()).thenReturn(true);
SessionFactoryImplementor sessionFactory = mock(SessionFactoryImplementor.class);
SessionFactoryOptions sessionFactoryOptions = mock(SessionFactoryOptions.class);
when(sessionFactoryOptions.getJpaCompliance()).thenReturn(jpaCompliance);
when(sessionFactory.getSessionFactoryOptions()).thenReturn(sessionFactoryOptions);
when(jdbcSessionContext.getSessionFactory()).thenReturn(sessionFactory);
when(jdbcSessionOwner.getJdbcSessionContext()).thenReturn(jdbcSessionContext);
when(session.getSessionFactory()).thenReturn(sessionFactory);
when(session.getFactory()).thenReturn(sessionFactory);
NonJtaTransactionCoordinator txOwner = mock(NonJtaTransactionCoordinator.class);
when(txOwner.getResourceLocalTransaction()).thenReturn(new JdbcResourceTransactionMock());
when(txOwner.getJdbcSessionOwner()).thenReturn(jdbcSessionOwner);
when(txOwner.isActive()).thenReturn(true);
txCoord = JdbcResourceLocalTransactionCoordinatorBuilderImpl.INSTANCE.buildTransactionCoordinator(txOwner, null);
when(session.getTransactionCoordinator()).thenReturn(txCoord);
when(session.beginTransaction()).then(invocation -> {
Transaction tx = new TransactionImpl(txCoord, session.getExceptionConverter(), session);
tx.begin();
return tx;
});
} else {
throw new IllegalStateException("Unknown JtaPlatform: " + jtaPlatform);
}
Sync sync = new Sync(regionFactory);
TestSynchronization synchronization = new TestSynchronization(sync);
when(session.getCacheTransactionSynchronization()).thenAnswer(invocation -> {
if (!synchronization.registered) {
txCoord.getLocalSynchronizations().registerSynchronization(synchronization);
synchronization.registered = true;
}
return sync;
});
return session;
}
use of org.hibernate.jpa.spi.JpaCompliance in project hibernate-orm by hibernate.
the class JpaComplianceTests method testSettingFalse.
@Test
public void testSettingFalse() {
ServiceRegistryScope.using(() -> new StandardServiceRegistryBuilder().applySetting(AvailableSettings.JPA_COMPLIANCE, false).build(), (serviceRegistryScope) -> {
final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) new MetadataSources(serviceRegistryScope.getRegistry()).buildMetadata().buildSessionFactory();
final JpaCompliance jpaCompliance = sessionFactory.getSessionFactoryOptions().getJpaCompliance();
assertAll(jpaCompliance, false);
});
// MutableJpaComplianceImpl defaults its values based on the passed
// `jpaByDefault` (`true` here). ultimately we want to source this
// from `AvailableSettings#JPA_COMPLIANCE`
final MutableJpaComplianceImpl compliance = new MutableJpaComplianceImpl(Collections.emptyMap(), true);
assertAll(compliance, true);
}
Aggregations