use of jakarta.persistence.Access in project hibernate-orm by hibernate.
the class PropertyContainer method determineLocalClassDefinedAccessStrategy.
//
// private void considerExplicitFieldAndPropertyAccess() {
// for ( XProperty property : fieldAccessMap.values() ) {
// Access access = property.getAnnotation( Access.class );
// if ( access == null ) {
// continue;
// }
//
// // see "2.3.2 Explicit Access Type" of JPA 2 spec
// // the access type for this property is explicitly set to AccessType.FIELD, hence we have to
// // use field access for this property even if the default access type for the class is AccessType.PROPERTY
// AccessType accessType = AccessType.getAccessStrategy( access.value() );
// if (accessType == AccessType.FIELD) {
// propertyAccessMap.put(property.getName(), property);
// }
// else {
// LOG.debug( "Placing @Access(AccessType.FIELD) on a field does not have any effect." );
// }
// }
//
// for ( XProperty property : propertyAccessMap.values() ) {
// Access access = property.getAnnotation( Access.class );
// if ( access == null ) {
// continue;
// }
//
// AccessType accessType = AccessType.getAccessStrategy( access.value() );
//
// // see "2.3.2 Explicit Access Type" of JPA 2 spec
// // the access type for this property is explicitly set to AccessType.PROPERTY, hence we have to
// // return use method access even if the default class access type is AccessType.FIELD
// if (accessType == AccessType.PROPERTY) {
// fieldAccessMap.put(property.getName(), property);
// }
// else {
// LOG.debug( "Placing @Access(AccessType.PROPERTY) on a field does not have any effect." );
// }
// }
// }
// /**
// * Retrieves all properties from the {@code xClass} with the specified access type. This method does not take
// * any jpa access rules/annotations into account yet.
// *
// * @param access The access type - {@code AccessType.FIELD} or {@code AccessType.Property}
// *
// * @return A maps of the properties with the given access type keyed against their property name
// */
// private TreeMap<String, XProperty> initProperties(AccessType access) {
// if ( !( AccessType.PROPERTY.equals( access ) || AccessType.FIELD.equals( access ) ) ) {
// throw new IllegalArgumentException( "Access type has to be AccessType.FIELD or AccessType.Property" );
// }
//
// //order so that property are used in the same order when binding native query
// TreeMap<String, XProperty> propertiesMap = new TreeMap<String, XProperty>();
// List<XProperty> properties = xClass.getDeclaredProperties( access.getType() );
// for ( XProperty property : properties ) {
// if ( mustBeSkipped( property ) ) {
// continue;
// }
// // HHH-10242 detect registration of the same property twice eg boolean isId() + UUID getId()
// XProperty oldProperty = propertiesMap.get( property.getName() );
// if ( oldProperty != null ) {
// throw new org.hibernate.boot.MappingException(
// LOG.ambiguousPropertyMethods(
// xClass.getName(),
// HCANNHelper.annotatedElementSignature( oldProperty ),
// HCANNHelper.annotatedElementSignature( property )
// ),
// new Origin( SourceType.ANNOTATION, xClass.getName() )
// );
// }
//
// propertiesMap.put( property.getName(), property );
// }
// return propertiesMap;
// }
private AccessType determineLocalClassDefinedAccessStrategy() {
AccessType classDefinedAccessType = AccessType.DEFAULT;
Access access = xClass.getAnnotation(Access.class);
if (access != null) {
classDefinedAccessType = AccessType.getAccessStrategy(access.value());
}
return classDefinedAccessType;
}
use of jakarta.persistence.Access in project hibernate-orm by hibernate.
the class PropertyInferredData method getDefaultAccess.
public AccessType getDefaultAccess() throws MappingException {
AccessType accessType = defaultAccess;
AccessType jpaAccessType = AccessType.DEFAULT;
Access access = property.getAnnotation(Access.class);
if (access != null) {
jpaAccessType = AccessType.getAccessStrategy(access.value());
}
if (jpaAccessType != AccessType.DEFAULT) {
accessType = jpaAccessType;
}
return accessType;
}
use of jakarta.persistence.Access in project hibernate-orm by hibernate.
the class CollectionBinder method handleElementCollection.
private void handleElementCollection(Collection collValue, AnnotatedColumn[] elementColumns, boolean isEmbedded, XClass collType, XProperty property, PropertyHolder parentPropertyHolder, MetadataBuildingContext buildingContext, String hqlOrderBy) {
XClass elementClass;
AnnotatedClassType classType;
CollectionPropertyHolder holder;
if (BinderHelper.PRIMITIVE_NAMES.contains(collType.getName())) {
classType = AnnotatedClassType.NONE;
elementClass = null;
holder = PropertyHolderBuilder.buildPropertyHolder(collValue, collValue.getRole(), null, property, parentPropertyHolder, buildingContext);
} else {
elementClass = collType;
classType = buildingContext.getMetadataCollector().getClassType(elementClass);
holder = PropertyHolderBuilder.buildPropertyHolder(collValue, collValue.getRole(), elementClass, property, parentPropertyHolder, buildingContext);
// 'parentPropertyHolder' is the PropertyHolder for the owner of the collection
// 'holder' is the CollectionPropertyHolder.
// 'property' is the collection XProperty
parentPropertyHolder.startingProperty(property);
// force in case of attribute override
boolean attributeOverride = property.isAnnotationPresent(AttributeOverride.class) || property.isAnnotationPresent(AttributeOverrides.class);
// todo : force in the case of Convert annotation(s) with embedded paths (beyond key/value prefixes)?
if (isEmbedded || attributeOverride) {
classType = AnnotatedClassType.EMBEDDABLE;
}
}
final Class<? extends CompositeUserType<?>> compositeUserType = resolveCompositeUserType(property, elementClass, buildingContext);
if (AnnotatedClassType.EMBEDDABLE == classType || compositeUserType != null) {
holder.prepare(property);
EntityBinder entityBinder = new EntityBinder();
PersistentClass owner = collValue.getOwner();
final AccessType baseAccessType;
final Access accessAnn = property.getAnnotation(Access.class);
if (accessAnn != null) {
// the attribute is locally annotated with `@Access`, use that
baseAccessType = accessAnn.value() == PROPERTY ? AccessType.PROPERTY : AccessType.FIELD;
} else if (owner.getIdentifierProperty() != null) {
// use the access for the owning entity's id attribute, if one
baseAccessType = owner.getIdentifierProperty().getPropertyAccessorName().equals("property") ? AccessType.PROPERTY : AccessType.FIELD;
} else if (owner.getIdentifierMapper() != null && owner.getIdentifierMapper().getPropertySpan() > 0) {
// use the access for the owning entity's "id mapper", if one
Property prop = owner.getIdentifierMapper().getProperties().get(0);
baseAccessType = prop.getPropertyAccessorName().equals("property") ? AccessType.PROPERTY : AccessType.FIELD;
} else {
// otherwise...
throw new AssertionFailure("Unable to guess collection property accessor name");
}
// TODO be smart with isNullable
Component component = fillComponent(holder, getSpecialMembers(elementClass), baseAccessType, true, entityBinder, false, false, true, resolveCustomInstantiator(property, elementClass, buildingContext), compositeUserType, buildingContext, inheritanceStatePerClass);
collValue.setElement(component);
if (StringHelper.isNotEmpty(hqlOrderBy)) {
String orderBy = adjustUserSuppliedValueCollectionOrderingFragment(hqlOrderBy);
if (orderBy != null) {
collValue.setOrderBy(orderBy);
}
}
} else {
holder.prepare(property);
final BasicValueBinder elementBinder = new BasicValueBinder(BasicValueBinder.Kind.COLLECTION_ELEMENT, buildingContext);
elementBinder.setReturnedClassName(collType.getName());
if (elementColumns == null || elementColumns.length == 0) {
elementColumns = new AnnotatedColumn[1];
AnnotatedColumn column = new AnnotatedColumn();
column.setImplicit(false);
// not following the spec but more clean
column.setNullable(true);
column.setLogicalColumnName(Collection.DEFAULT_ELEMENT_COLUMN_NAME);
// TODO create an EMPTY_JOINS collection
column.setJoins(new HashMap<>());
column.setBuildingContext(buildingContext);
column.bind();
elementColumns[0] = column;
}
// override the table
for (AnnotatedColumn column : elementColumns) {
column.setTable(collValue.getCollectionTable());
}
elementBinder.setColumns(elementColumns);
elementBinder.setType(property, elementClass, collValue.getOwnerEntityName(), holder.resolveElementAttributeConverterDescriptor(property, elementClass));
elementBinder.setPersistentClassName(propertyHolder.getEntityName());
elementBinder.setAccessType(accessType);
collValue.setElement(elementBinder.make());
String orderBy = adjustUserSuppliedValueCollectionOrderingFragment(hqlOrderBy);
if (orderBy != null) {
collValue.setOrderBy(orderBy);
}
}
}
use of jakarta.persistence.Access in project hibernate-orm by hibernate.
the class EntityBinder method getExplicitAccessType.
public AccessType getExplicitAccessType(XAnnotatedElement element) {
AccessType accessType = null;
Access access = element.getAnnotation(Access.class);
if (access != null) {
accessType = AccessType.getAccessStrategy(access.value());
}
return accessType;
}
use of jakarta.persistence.Access in project hibernate-orm by hibernate.
the class JPAXMLOverriddenAnnotationReader method getAccessType.
private Access getAccessType(ManagedType root, XMLContext.Default defaults) {
AccessType access = root == null ? null : root.getAccess();
if (access != null) {
AnnotationDescriptor ad = new AnnotationDescriptor(Access.class);
ad.setValue("value", access);
return AnnotationFactory.create(ad);
} else if (defaults.canUseJavaAnnotations() && isPhysicalAnnotationPresent(Access.class)) {
return getPhysicalAnnotation(Access.class);
} else if (defaults.getAccess() != null) {
AnnotationDescriptor ad = new AnnotationDescriptor(Access.class);
ad.setValue("value", defaults.getAccess());
return AnnotationFactory.create(ad);
} else {
return null;
}
}
Aggregations