use of org.hibernate.metamodel.model.domain.NavigableRole in project hibernate-orm by hibernate.
the class DomainDataRegionTemplate method generateNaturalIdAccess.
@Override
public NaturalIdDataAccess generateNaturalIdAccess(NaturalIdDataCachingConfig accessConfig) {
final NavigableRole namedEntityRole = accessConfig.getNavigableRole();
final AccessType accessType = accessConfig.getAccessType();
log.debugf("Generating entity natural-id access [%s] : %s", accessType.getExternalName(), namedEntityRole);
switch(accessType) {
case READ_ONLY:
{
return generateReadOnlyNaturalIdAccess(accessConfig);
}
case READ_WRITE:
{
return generateReadWriteNaturalIdAccess(accessConfig);
}
case NONSTRICT_READ_WRITE:
{
return generateNonStrictReadWriteNaturalIdAccess(accessConfig);
}
case TRANSACTIONAL:
{
return generateTransactionalNaturalIdDataAccess(accessConfig);
}
default:
{
throw new IllegalArgumentException("Unrecognized cache AccessType - " + accessType);
}
}
}
use of org.hibernate.metamodel.model.domain.NavigableRole in project hibernate-orm by hibernate.
the class DomainDataRegionTemplate method generateEntityAccess.
@Override
public EntityDataAccess generateEntityAccess(EntityDataCachingConfig entityAccessConfig) {
final NavigableRole namedEntityRole = entityAccessConfig.getNavigableRole();
final AccessType accessType = entityAccessConfig.getAccessType();
log.debugf("Generating entity cache access [%s] : %s", accessType.getExternalName(), namedEntityRole);
switch(accessType) {
case READ_ONLY:
{
return generateReadOnlyEntityAccess(entityAccessConfig);
}
case READ_WRITE:
{
return generateReadWriteEntityAccess(entityAccessConfig);
}
case NONSTRICT_READ_WRITE:
{
return generateNonStrictReadWriteEntityAccess(entityAccessConfig);
}
case TRANSACTIONAL:
{
return generateTransactionalEntityDataAccess(entityAccessConfig);
}
default:
{
throw new IllegalArgumentException("Unrecognized cache AccessType - " + accessType);
}
}
}
use of org.hibernate.metamodel.model.domain.NavigableRole in project hibernate-orm by hibernate.
the class RegionNameTest method testLegacyCacheSpi.
@Test
public void testLegacyCacheSpi() {
// these need to be the prefixed name
final String regionName = cachePrefix + '.' + localName;
final CacheImplementor cache = sessionFactory().getCache();
// just like stats, the cache for queries cannot be accessed second level cache regions map
assertEquals(2, cache.getSecondLevelCacheRegionNames().length);
boolean foundRegion = false;
for (String name : cache.getSecondLevelCacheRegionNames()) {
if (EqualsHelper.areEqual(name, regionName)) {
foundRegion = true;
break;
}
}
if (!foundRegion) {
fail("Could not find region [" + regionName + "] in reported list of region names");
}
final NavigableRole personEntityName = new NavigableRole(Person.class.getName());
final NavigableRole nickNamesRole = personEntityName.append("nickNames");
assert cache.getEntityRegionAccess(personEntityName) != null;
assert cache.getNaturalIdCacheRegionAccessStrategy(personEntityName) != null;
assert cache.getCollectionRegionAccess(nickNamesRole) != null;
}
use of org.hibernate.metamodel.model.domain.NavigableRole in project hibernate-orm by hibernate.
the class DomainDataRegionTemplate method generateCollectionAccess.
@Override
public CollectionDataAccess generateCollectionAccess(CollectionDataCachingConfig accessConfig) {
final NavigableRole namedCollectionRole = accessConfig.getNavigableRole();
log.debugf("Generating collection cache access : %s", namedCollectionRole);
switch(accessConfig.getAccessType()) {
case READ_ONLY:
{
return generateReadOnlyCollectionAccess(accessConfig);
}
case READ_WRITE:
{
return generateReadWriteCollectionAccess(accessConfig);
}
case NONSTRICT_READ_WRITE:
{
return generateNonStrictReadWriteCollectionAccess(accessConfig);
}
case TRANSACTIONAL:
{
return generateTransactionalCollectionDataAccess(accessConfig);
}
default:
{
throw new IllegalArgumentException("Unrecognized cache AccessType - " + accessConfig.getAccessType());
}
}
}
use of org.hibernate.metamodel.model.domain.NavigableRole in project hibernate-orm by hibernate.
the class MetamodelImpl method initialize.
/**
* Prepare the metamodel using the information from the collection of Hibernate
* {@link PersistentClass} models
*
* @param mappingMetadata The mapping information
* @param jpaMetaModelPopulationSetting Should the JPA Metamodel be built as well?
*/
public void initialize(MetadataImplementor mappingMetadata, JpaMetaModelPopulationSetting jpaMetaModelPopulationSetting) {
this.imports.putAll(mappingMetadata.getImports());
primeSecondLevelCacheRegions(mappingMetadata);
final PersisterCreationContext persisterCreationContext = new PersisterCreationContext() {
@Override
public SessionFactoryImplementor getSessionFactory() {
return sessionFactory;
}
@Override
public MetadataImplementor getMetadata() {
return mappingMetadata;
}
};
final PersisterFactory persisterFactory = sessionFactory.getServiceRegistry().getService(PersisterFactory.class);
for (final PersistentClass model : mappingMetadata.getEntityBindings()) {
final NavigableRole rootEntityRole = new NavigableRole(model.getRootClass().getEntityName());
final EntityDataAccess accessStrategy = sessionFactory.getCache().getEntityRegionAccess(rootEntityRole);
final NaturalIdDataAccess naturalIdAccessStrategy = sessionFactory.getCache().getNaturalIdCacheRegionAccessStrategy(rootEntityRole);
final EntityPersister cp = persisterFactory.createEntityPersister(model, accessStrategy, naturalIdAccessStrategy, persisterCreationContext);
entityPersisterMap.put(model.getEntityName(), cp);
if (cp.getConcreteProxyClass() != null && cp.getConcreteProxyClass().isInterface() && !Map.class.isAssignableFrom(cp.getConcreteProxyClass()) && cp.getMappedClass() != cp.getConcreteProxyClass()) {
if (cp.getMappedClass().equals(cp.getConcreteProxyClass())) {
// this part handles an odd case in the Hibernate test suite where we map an interface
// as the class and the proxy. I cannot think of a real life use case for that
// specific test, but..
log.debugf("Entity [%s] mapped same interface [%s] as class and proxy", cp.getEntityName(), cp.getMappedClass());
} else {
final String old = entityProxyInterfaceMap.put(cp.getConcreteProxyClass(), cp.getEntityName());
if (old != null) {
throw new HibernateException(String.format(Locale.ENGLISH, "Multiple entities [%s, %s] named the same interface [%s] as their proxy which is not supported", old, cp.getEntityName(), cp.getConcreteProxyClass().getName()));
}
}
}
}
for (final Collection model : mappingMetadata.getCollectionBindings()) {
final NavigableRole navigableRole = new NavigableRole(model.getRole());
final CollectionDataAccess accessStrategy = sessionFactory.getCache().getCollectionRegionAccess(navigableRole);
final CollectionPersister persister = persisterFactory.createCollectionPersister(model, accessStrategy, persisterCreationContext);
collectionPersisterMap.put(model.getRole(), persister);
Type indexType = persister.getIndexType();
if (indexType != null && indexType.isAssociationType() && !indexType.isAnyType()) {
String entityName = ((AssociationType) indexType).getAssociatedEntityName(sessionFactory);
Set<String> roles = collectionRolesByEntityParticipant.get(entityName);
if (roles == null) {
roles = new HashSet<>();
collectionRolesByEntityParticipant.put(entityName, roles);
}
roles.add(persister.getRole());
}
Type elementType = persister.getElementType();
if (elementType.isAssociationType() && !elementType.isAnyType()) {
String entityName = ((AssociationType) elementType).getAssociatedEntityName(sessionFactory);
Set<String> roles = collectionRolesByEntityParticipant.get(entityName);
if (roles == null) {
roles = new HashSet<>();
collectionRolesByEntityParticipant.put(entityName, roles);
}
roles.add(persister.getRole());
}
}
// after *all* persisters and named queries are registered
entityPersisterMap.values().forEach(EntityPersister::generateEntityDefinition);
for (EntityPersister persister : entityPersisterMap.values()) {
persister.postInstantiate();
registerEntityNameResolvers(persister, entityNameResolvers);
}
collectionPersisterMap.values().forEach(CollectionPersister::postInstantiate);
if (jpaMetaModelPopulationSetting != JpaMetaModelPopulationSetting.DISABLED) {
MetadataContext context = new MetadataContext(sessionFactory, mappingMetadata.getMappedSuperclassMappingsCopy(), jpaMetaModelPopulationSetting);
for (PersistentClass entityBinding : mappingMetadata.getEntityBindings()) {
locateOrBuildEntityType(entityBinding, context);
}
handleUnusedMappedSuperclasses(context);
context.wrapUp();
this.jpaEntityTypeMap.putAll(context.getEntityTypeMap());
this.jpaEmbeddableTypeMap.putAll(context.getEmbeddableTypeMap());
this.jpaMappedSuperclassTypeMap.putAll(context.getMappedSuperclassTypeMap());
this.jpaEntityTypesByEntityName.putAll(context.getEntityTypesByEntityName());
applyNamedEntityGraphs(mappingMetadata.getNamedEntityGraphs().values());
}
}
Aggregations