use of org.hibernate.annotations.common.reflection.XProperty in project hibernate-orm by hibernate.
the class AnnotationBinder method isIdClassPkOfTheAssociatedEntity.
private static boolean isIdClassPkOfTheAssociatedEntity(InheritanceState.ElementsToProcess elementsToProcess, XClass compositeClass, PropertyData inferredData, PropertyData baseInferredData, AccessType propertyAccessor, Map<XClass, InheritanceState> inheritanceStatePerClass, MetadataBuildingContext context) {
if (elementsToProcess.getIdPropertyCount() == 1) {
final PropertyData idPropertyOnBaseClass = getUniqueIdPropertyFromBaseClass(inferredData, baseInferredData, propertyAccessor, context);
final InheritanceState state = inheritanceStatePerClass.get(idPropertyOnBaseClass.getClassOrElement());
if (state == null) {
//while it is likely a user error, let's consider it is something that might happen
return false;
}
final XClass associatedClassWithIdClass = state.getClassWithIdClass(true);
if (associatedClassWithIdClass == null) {
//we cannot know for sure here unless we try and find the @EmbeddedId
//Let's not do this thorough checking but do some extra validation
final XProperty property = idPropertyOnBaseClass.getProperty();
return property.isAnnotationPresent(ManyToOne.class) || property.isAnnotationPresent(OneToOne.class);
} else {
final XClass idClass = context.getBuildingOptions().getReflectionManager().toXClass(associatedClassWithIdClass.getAnnotation(IdClass.class).value());
return idClass.equals(compositeClass);
}
} else {
return false;
}
}
use of org.hibernate.annotations.common.reflection.XProperty in project hibernate-orm by hibernate.
the class AnnotationBinder method addElementsOfClass.
/**
* @param elements List of {@code ProperyData} instances
* @param propertyContainer Metadata about a class and its properties
*
* @return the number of id properties found while iterating the elements of {@code annotatedClass} using
* the determined access strategy, {@code false} otherwise.
*/
static int addElementsOfClass(List<PropertyData> elements, PropertyContainer propertyContainer, MetadataBuildingContext context) {
int idPropertyCounter = 0;
Collection<XProperty> properties = propertyContainer.getProperties();
for (XProperty p : properties) {
final int currentIdPropertyCounter = addProperty(propertyContainer, p, elements, context);
idPropertyCounter += currentIdPropertyCounter;
}
return idPropertyCounter;
}
use of org.hibernate.annotations.common.reflection.XProperty in project hibernate-orm by hibernate.
the class AnnotationBinder method addProperty.
private static int addProperty(PropertyContainer propertyContainer, XProperty property, List<PropertyData> inFlightPropertyDataList, MetadataBuildingContext context) {
// and if so, skip it..
for (PropertyData propertyData : inFlightPropertyDataList) {
if (propertyData.getPropertyName().equals(property.getName())) {
// EARLY EXIT!!!
return 0;
}
}
final XClass declaringClass = propertyContainer.getDeclaringClass();
final XClass entity = propertyContainer.getEntityAtStake();
int idPropertyCounter = 0;
PropertyData propertyAnnotatedElement = new PropertyInferredData(declaringClass, property, propertyContainer.getClassLevelAccessType().getType(), context.getBuildingOptions().getReflectionManager());
/*
* put element annotated by @Id in front
* since it has to be parsed beforeQuery any association by Hibernate
*/
final XAnnotatedElement element = propertyAnnotatedElement.getProperty();
if (element.isAnnotationPresent(Id.class) || element.isAnnotationPresent(EmbeddedId.class)) {
inFlightPropertyDataList.add(0, propertyAnnotatedElement);
/**
* The property must be put in hibernate.properties as it's a system wide property. Fixable?
* TODO support true/false/default on the property instead of present / not present
* TODO is @Column mandatory?
* TODO add method support
*/
if (context.getBuildingOptions().isSpecjProprietarySyntaxEnabled()) {
if (element.isAnnotationPresent(Id.class) && element.isAnnotationPresent(Column.class)) {
String columnName = element.getAnnotation(Column.class).name();
for (XProperty prop : declaringClass.getDeclaredProperties(AccessType.FIELD.getType())) {
if (!prop.isAnnotationPresent(MapsId.class)) {
/**
* The detection of a configured individual JoinColumn differs between Annotation
* and XML configuration processing.
*/
boolean isRequiredAnnotationPresent = false;
JoinColumns groupAnnotation = prop.getAnnotation(JoinColumns.class);
if ((prop.isAnnotationPresent(JoinColumn.class) && prop.getAnnotation(JoinColumn.class).name().equals(columnName))) {
isRequiredAnnotationPresent = true;
} else if (prop.isAnnotationPresent(JoinColumns.class)) {
for (JoinColumn columnAnnotation : groupAnnotation.value()) {
if (columnName.equals(columnAnnotation.name())) {
isRequiredAnnotationPresent = true;
break;
}
}
}
if (isRequiredAnnotationPresent) {
//create a PropertyData fpr the specJ property holding the mapping
PropertyData specJPropertyData = new PropertyInferredData(declaringClass, //same dec
prop, // the actual @XToOne property
propertyContainer.getClassLevelAccessType().getType(), //TODO we should get the right accessor but the same as id would do
context.getBuildingOptions().getReflectionManager());
context.getMetadataCollector().addPropertyAnnotatedWithMapsIdSpecj(entity, specJPropertyData, element.toString());
}
}
}
}
}
if (element.isAnnotationPresent(ManyToOne.class) || element.isAnnotationPresent(OneToOne.class)) {
context.getMetadataCollector().addToOneAndIdProperty(entity, propertyAnnotatedElement);
}
idPropertyCounter++;
} else {
inFlightPropertyDataList.add(propertyAnnotatedElement);
}
if (element.isAnnotationPresent(MapsId.class)) {
context.getMetadataCollector().addPropertyAnnotatedWithMapsId(entity, propertyAnnotatedElement);
}
return idPropertyCounter;
}
use of org.hibernate.annotations.common.reflection.XProperty in project hibernate-orm by hibernate.
the class AnnotationBinder method hasAnnotationsOnIdClass.
private static boolean hasAnnotationsOnIdClass(XClass idClass) {
// if(idClass.getAnnotation(Embeddable.class) != null)
// return true;
List<XProperty> properties = idClass.getDeclaredProperties(XClass.ACCESS_FIELD);
for (XProperty property : properties) {
if (property.isAnnotationPresent(Column.class) || property.isAnnotationPresent(OneToMany.class) || property.isAnnotationPresent(ManyToOne.class) || property.isAnnotationPresent(Id.class) || property.isAnnotationPresent(GeneratedValue.class) || property.isAnnotationPresent(OneToOne.class) || property.isAnnotationPresent(ManyToMany.class)) {
return true;
}
}
List<XMethod> methods = idClass.getDeclaredMethods();
for (XMethod method : methods) {
if (method.isAnnotationPresent(Column.class) || method.isAnnotationPresent(OneToMany.class) || method.isAnnotationPresent(ManyToOne.class) || method.isAnnotationPresent(Id.class) || method.isAnnotationPresent(GeneratedValue.class) || method.isAnnotationPresent(OneToOne.class) || method.isAnnotationPresent(ManyToMany.class)) {
return true;
}
}
return false;
}
use of org.hibernate.annotations.common.reflection.XProperty in project hibernate-orm by hibernate.
the class SimpleValue method createParameterImpl.
private void createParameterImpl() {
try {
String[] columnsNames = new String[columns.size()];
for (int i = 0; i < columns.size(); i++) {
Selectable column = columns.get(i);
if (column instanceof Column) {
columnsNames[i] = ((Column) column).getName();
}
}
final XProperty xProperty = (XProperty) typeParameters.get(DynamicParameterizedType.XPROPERTY);
// todo : not sure this works for handling @MapKeyEnumerated
final Annotation[] annotations = xProperty == null ? null : xProperty.getAnnotations();
final ClassLoaderService classLoaderService = getMetadata().getMetadataBuildingOptions().getServiceRegistry().getService(ClassLoaderService.class);
typeParameters.put(DynamicParameterizedType.PARAMETER_TYPE, new ParameterTypeImpl(classLoaderService.classForName(typeParameters.getProperty(DynamicParameterizedType.RETURNED_CLASS)), annotations, table.getCatalog(), table.getSchema(), table.getName(), Boolean.valueOf(typeParameters.getProperty(DynamicParameterizedType.IS_PRIMARY_KEY)), columnsNames));
} catch (ClassLoadingException e) {
throw new MappingException("Could not create DynamicParameterizedType for type: " + typeName, e);
}
}
Aggregations