Skip to content

Commit

Permalink
#51 - Build out EntityHierarchy and EntityTypeMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
sebersole committed Oct 24, 2023
1 parent 2b52229 commit b63b9ca
Show file tree
Hide file tree
Showing 17 changed files with 666 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @author Steve Ebersole
*/
public class StringHelper {
public static final String[] EMPTY_STRINGS = new String[0];

public static boolean isEmpty(String string) {
return string == null || string.isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import org.hibernate.boot.model.source.spi.AttributeRole;
import org.hibernate.boot.model.source.spi.NaturalIdMutability;
import org.hibernate.models.internal.IndexedConsumer;
import org.hibernate.models.orm.MultipleAttributeNaturesException;
import org.hibernate.models.orm.spi.AttributeMetadata;
import org.hibernate.models.orm.HibernateAnnotations;
import org.hibernate.models.orm.JpaAnnotations;
import org.hibernate.models.orm.MultipleAttributeNaturesException;
import org.hibernate.models.orm.spi.AttributeMetadata;
import org.hibernate.models.orm.spi.ManagedTypeMetadata;
import org.hibernate.models.orm.spi.OrmModelBuildingContext;
import org.hibernate.models.source.spi.AnnotationUsage;
Expand Down Expand Up @@ -148,11 +148,9 @@ public void forEachAttribute(IndexedConsumer<AttributeMetadata> consumer) {
}

protected List<AttributeMetadata> resolveAttributes() {
final List<MemberDetails> backingMembers = StandardPersistentAttributeMemberResolver.INSTANCE.resolveAttributesMembers(
classDetails,
getAccessType(),
modelContext
);
final List<MemberDetails> backingMembers = getModelContext()
.getPersistentAttributeMemberResolver()
.resolveAttributesMembers( classDetails, getAccessType(), modelContext );

final List<AttributeMetadata> attributeList = arrayList( backingMembers.size() );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private Set<EntityHierarchy> process(
hierarchies.add( new EntityHierarchyImpl(
rootEntity,
defaultAccessType,
org.hibernate.cache.spi.access.AccessType.TRANSACTIONAL,
typeConsumer,
modelContext
) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
import java.util.Locale;
import java.util.function.Consumer;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.NaturalIdCache;
import org.hibernate.cache.spi.access.AccessType;
import org.hibernate.models.orm.JpaAnnotations;
import org.hibernate.models.orm.spi.CacheRegion;
import org.hibernate.models.orm.spi.EntityHierarchy;
import org.hibernate.models.orm.spi.EntityTypeMetadata;
import org.hibernate.models.orm.spi.IdentifiableTypeMetadata;
import org.hibernate.models.orm.JpaAnnotations;
import org.hibernate.models.orm.spi.NaturalIdCacheRegion;
import org.hibernate.models.orm.spi.OrmModelBuildingContext;
import org.hibernate.models.source.spi.AnnotationUsage;
import org.hibernate.models.source.spi.ClassDetails;
Expand All @@ -29,12 +34,15 @@ public class EntityHierarchyImpl implements EntityHierarchy {
private final EntityTypeMetadata rootEntityTypeMetadata;

private final InheritanceType inheritanceType;
private final CacheRegion cacheRegion;
private final NaturalIdCacheRegion naturalIdCacheRegion;

// todo (models) : version? row-id? tenant-id? others?
// todo : version? optimistic-locking? row-id? tenant-id? others?

public EntityHierarchyImpl(
ClassDetails rootEntityClassDetails,
jakarta.persistence.AccessType defaultAccessType,
AccessType defaultCacheAccessType,
Consumer<IdentifiableTypeMetadata> typeConsumer,
OrmModelBuildingContext processingContext) {
this.rootEntityTypeMetadata = new EntityTypeMetadataImpl(
Expand All @@ -46,6 +54,12 @@ public EntityHierarchyImpl(
);

this.inheritanceType = determineInheritanceType( rootEntityTypeMetadata );

final AnnotationUsage<Cache> cacheAnnotation = rootEntityClassDetails.getAnnotationUsage( Cache.class );
final AnnotationUsage<NaturalIdCache> naturalIdCacheAnnotation = rootEntityClassDetails.getAnnotationUsage( NaturalIdCache.class );

cacheRegion = new CacheRegion( cacheAnnotation, defaultCacheAccessType, rootEntityClassDetails.getName() );
naturalIdCacheRegion = new NaturalIdCacheRegion( naturalIdCacheAnnotation, cacheRegion );
}

private InheritanceType determineInheritanceType(EntityTypeMetadata root) {
Expand Down Expand Up @@ -104,6 +118,16 @@ public InheritanceType getInheritanceType() {
return inheritanceType;
}

@Override
public CacheRegion getCacheRegion() {
return cacheRegion;
}

@Override
public NaturalIdCacheRegion getNaturalIdCacheRegion() {
return naturalIdCacheRegion;
}

@Override
public String toString() {
return String.format(
Expand Down
Loading

0 comments on commit b63b9ca

Please sign in to comment.