Search in sources :

Example 1 with DomainDataRegionImpl

use of org.infinispan.hibernate.cache.v53.impl.DomainDataRegionImpl in project infinispan by infinispan.

the class TestSessionAccessImpl method collectionAccess.

@Override
public Object collectionAccess(InfinispanBaseRegion region, AccessType accessType) {
    DomainDataRegionImpl impl = (DomainDataRegionImpl) region;
    NavigableRole role = impl.config().getCollectionCaching().stream().filter(c -> c.getAccessType() == accessType).map(DomainDataCachingConfig::getNavigableRole).findFirst().orElseThrow(() -> new IllegalArgumentException());
    return impl.getCollectionDataAccess(role);
}
Also used : Connection(java.sql.Connection) TestSessionAccess(org.infinispan.test.hibernate.cache.commons.util.TestSessionAccess) Sync(org.infinispan.hibernate.cache.v53.impl.Sync) JdbcResourceTransactionMock(org.infinispan.test.hibernate.cache.commons.util.JdbcResourceTransactionMock) BatchModeJtaPlatform(org.infinispan.test.hibernate.cache.commons.util.BatchModeJtaPlatform) Transaction(org.hibernate.Transaction) Query(org.hibernate.query.Query) AccessType(org.hibernate.cache.spi.access.AccessType) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Synchronization(javax.transaction.Synchronization) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) JdbcResourceTransactionAccess(org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransactionAccess) NavigableRole(org.hibernate.metamodel.model.domain.NavigableRole) SoftLock(org.hibernate.cache.spi.access.SoftLock) JdbcSessionOwner(org.hibernate.resource.jdbc.spi.JdbcSessionOwner) ControlledTimeService(org.infinispan.util.ControlledTimeService) List(java.util.List) CacheException(org.hibernate.cache.CacheException) TransactionImpl(org.hibernate.engine.transaction.internal.TransactionImpl) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) Mockito.mock(org.mockito.Mockito.mock) JdbcConnectionAccess(org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess) DomainDataRegionImpl(org.infinispan.hibernate.cache.v53.impl.DomainDataRegionImpl) DomainDataCachingConfig(org.hibernate.cache.cfg.spi.DomainDataCachingConfig) TransactionCoordinator(org.hibernate.resource.transaction.spi.TransactionCoordinator) Session(org.hibernate.Session) MetaInfServices(org.kohsuke.MetaInfServices) SessionFactoryOptions(org.hibernate.boot.spi.SessionFactoryOptions) EntityDataAccess(org.hibernate.cache.spi.access.EntityDataAccess) DirectAccessRegion(org.hibernate.cache.spi.DirectAccessRegion) CachedDomainDataAccess(org.hibernate.cache.spi.access.CachedDomainDataAccess) SQLException(java.sql.SQLException) RegionFactory(org.hibernate.cache.spi.RegionFactory) TransactionCoordinatorOwner(org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner) NoJtaPlatform(org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform) AbstractSharedSessionContract(org.hibernate.internal.AbstractSharedSessionContract) FlushMode(org.hibernate.FlushMode) CacheImplementor(org.hibernate.cache.spi.CacheImplementor) JtaPlatform(org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) JdbcSessionContext(org.hibernate.resource.jdbc.spi.JdbcSessionContext) Mockito.when(org.mockito.Mockito.when) ServiceRegistry(org.hibernate.service.ServiceRegistry) InfinispanBaseRegion(org.infinispan.hibernate.cache.commons.InfinispanBaseRegion) Status(javax.transaction.Status) JdbcResourceLocalTransactionCoordinatorBuilderImpl(org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl) SqlExceptionHelper(org.hibernate.engine.jdbc.spi.SqlExceptionHelper) SessionCreationOptions(org.hibernate.internal.SessionCreationOptions) JpaCompliance(org.hibernate.jpa.spi.JpaCompliance) DomainDataRegionImpl(org.infinispan.hibernate.cache.v53.impl.DomainDataRegionImpl) DomainDataCachingConfig(org.hibernate.cache.cfg.spi.DomainDataCachingConfig) NavigableRole(org.hibernate.metamodel.model.domain.NavigableRole)

Example 2 with DomainDataRegionImpl

use of org.infinispan.hibernate.cache.v53.impl.DomainDataRegionImpl in project infinispan by infinispan.

the class TestSessionAccessImpl method entityAccess.

@Override
public Object entityAccess(InfinispanBaseRegion region, AccessType accessType) {
    DomainDataRegionImpl impl = (DomainDataRegionImpl) region;
    NavigableRole role = impl.config().getEntityCaching().stream().filter(c -> c.getAccessType() == accessType).map(DomainDataCachingConfig::getNavigableRole).findFirst().orElseThrow(() -> new IllegalArgumentException());
    return impl.getEntityDataAccess(role);
}
Also used : Connection(java.sql.Connection) TestSessionAccess(org.infinispan.test.hibernate.cache.commons.util.TestSessionAccess) Sync(org.infinispan.hibernate.cache.v53.impl.Sync) JdbcResourceTransactionMock(org.infinispan.test.hibernate.cache.commons.util.JdbcResourceTransactionMock) BatchModeJtaPlatform(org.infinispan.test.hibernate.cache.commons.util.BatchModeJtaPlatform) Transaction(org.hibernate.Transaction) Query(org.hibernate.query.Query) AccessType(org.hibernate.cache.spi.access.AccessType) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Synchronization(javax.transaction.Synchronization) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) JdbcResourceTransactionAccess(org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransactionAccess) NavigableRole(org.hibernate.metamodel.model.domain.NavigableRole) SoftLock(org.hibernate.cache.spi.access.SoftLock) JdbcSessionOwner(org.hibernate.resource.jdbc.spi.JdbcSessionOwner) ControlledTimeService(org.infinispan.util.ControlledTimeService) List(java.util.List) CacheException(org.hibernate.cache.CacheException) TransactionImpl(org.hibernate.engine.transaction.internal.TransactionImpl) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) Mockito.mock(org.mockito.Mockito.mock) JdbcConnectionAccess(org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess) DomainDataRegionImpl(org.infinispan.hibernate.cache.v53.impl.DomainDataRegionImpl) DomainDataCachingConfig(org.hibernate.cache.cfg.spi.DomainDataCachingConfig) TransactionCoordinator(org.hibernate.resource.transaction.spi.TransactionCoordinator) Session(org.hibernate.Session) MetaInfServices(org.kohsuke.MetaInfServices) SessionFactoryOptions(org.hibernate.boot.spi.SessionFactoryOptions) EntityDataAccess(org.hibernate.cache.spi.access.EntityDataAccess) DirectAccessRegion(org.hibernate.cache.spi.DirectAccessRegion) CachedDomainDataAccess(org.hibernate.cache.spi.access.CachedDomainDataAccess) SQLException(java.sql.SQLException) RegionFactory(org.hibernate.cache.spi.RegionFactory) TransactionCoordinatorOwner(org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner) NoJtaPlatform(org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform) AbstractSharedSessionContract(org.hibernate.internal.AbstractSharedSessionContract) FlushMode(org.hibernate.FlushMode) CacheImplementor(org.hibernate.cache.spi.CacheImplementor) JtaPlatform(org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) JdbcSessionContext(org.hibernate.resource.jdbc.spi.JdbcSessionContext) Mockito.when(org.mockito.Mockito.when) ServiceRegistry(org.hibernate.service.ServiceRegistry) InfinispanBaseRegion(org.infinispan.hibernate.cache.commons.InfinispanBaseRegion) Status(javax.transaction.Status) JdbcResourceLocalTransactionCoordinatorBuilderImpl(org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl) SqlExceptionHelper(org.hibernate.engine.jdbc.spi.SqlExceptionHelper) SessionCreationOptions(org.hibernate.internal.SessionCreationOptions) JpaCompliance(org.hibernate.jpa.spi.JpaCompliance) DomainDataRegionImpl(org.infinispan.hibernate.cache.v53.impl.DomainDataRegionImpl) DomainDataCachingConfig(org.hibernate.cache.cfg.spi.DomainDataCachingConfig) NavigableRole(org.hibernate.metamodel.model.domain.NavigableRole)

Example 3 with DomainDataRegionImpl

use of org.infinispan.hibernate.cache.v53.impl.DomainDataRegionImpl in project infinispan by infinispan.

the class InfinispanRegionFactory method buildDomainDataRegion.

@Override
public DomainDataRegion buildDomainDataRegion(DomainDataRegionConfig regionConfig, DomainDataRegionBuildingContext buildingContext) {
    log.debugf("Building domain data region [%s] entities=%s collections=%s naturalIds=%s", regionConfig.getRegionName(), regionConfig.getEntityCaching(), regionConfig.getCollectionCaching(), regionConfig.getNaturalIdCaching());
    // TODO: data type is probably deprecated, but we need it for backwards-compatible configuration
    DataType dataType;
    int entities = regionConfig.getEntityCaching().size();
    int collections = regionConfig.getCollectionCaching().size();
    int naturalIds = regionConfig.getNaturalIdCaching().size();
    if (entities > 0 && collections == 0 && naturalIds == 0) {
        dataType = regionConfig.getEntityCaching().stream().allMatch(c -> !c.isMutable()) ? DataType.IMMUTABLE_ENTITY : DataType.ENTITY;
    } else if (entities == 0 && collections > 0 && naturalIds == 0) {
        dataType = DataType.COLLECTION;
    } else if (entities == 0 && collections == 0 && naturalIds > 0) {
        dataType = DataType.NATURAL_ID;
    } else {
        // some mix, let's use entity
        dataType = DataType.ENTITY;
    }
    AdvancedCache cache = getCache(qualify(regionConfig.getRegionName()), regionConfig.getRegionName(), dataType, Collections.emptyList());
    DomainDataRegionImpl region = new DomainDataRegionImpl(cache, regionConfig, this, getCacheKeysFactory());
    startRegion(region);
    return region;
}
Also used : DomainDataRegionImpl(org.infinispan.hibernate.cache.v53.impl.DomainDataRegionImpl) DataType(org.infinispan.hibernate.cache.commons.DataType) AdvancedCache(org.infinispan.AdvancedCache)

Aggregations

Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 Collection (java.util.Collection)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Status (javax.transaction.Status)2 Synchronization (javax.transaction.Synchronization)2 FlushMode (org.hibernate.FlushMode)2 Session (org.hibernate.Session)2 Transaction (org.hibernate.Transaction)2 SessionFactoryOptions (org.hibernate.boot.spi.SessionFactoryOptions)2 CacheException (org.hibernate.cache.CacheException)2 DomainDataCachingConfig (org.hibernate.cache.cfg.spi.DomainDataCachingConfig)2 CacheImplementor (org.hibernate.cache.spi.CacheImplementor)2 DirectAccessRegion (org.hibernate.cache.spi.DirectAccessRegion)2 RegionFactory (org.hibernate.cache.spi.RegionFactory)2 AccessType (org.hibernate.cache.spi.access.AccessType)2 CachedDomainDataAccess (org.hibernate.cache.spi.access.CachedDomainDataAccess)2 EntityDataAccess (org.hibernate.cache.spi.access.EntityDataAccess)2 SoftLock (org.hibernate.cache.spi.access.SoftLock)2