/**
  * Add the {@link AuditOverride} annotations.
  *
  * @param property the property being processed
  * @param propertyData the Envers auditing data for this property
  */
 private void addPropertyAuditingOverrides(XProperty property, PropertyAuditingData propertyData) {
   final AuditOverride annotationOverride = property.getAnnotation(AuditOverride.class);
   if (annotationOverride != null) {
     propertyData.addAuditingOverride(annotationOverride);
   }
   final AuditOverrides annotationOverrides = property.getAnnotation(AuditOverrides.class);
   if (annotationOverrides != null) {
     propertyData.addAuditingOverrides(annotationOverrides);
   }
 }
  /**
   * Checks if a property is audited and if yes, fills all of its data.
   *
   * @param property Property to check.
   * @param propertyData Property data, on which to set this property's modification store.
   * @param accessType Access type for the property.
   * @return False if this property is not audited.
   */
  private boolean fillPropertyData(
      XProperty property,
      PropertyAuditingData propertyData,
      String accessType,
      Audited allClassAudited) {

    // check if a property is declared as not audited to exclude it
    // useful if a class is audited but some properties should be excluded
    final NotAudited unVer = property.getAnnotation(NotAudited.class);
    if ((unVer != null && !overriddenAuditedProperties.contains(property))
        || overriddenNotAuditedProperties.contains(property)) {
      return false;
    } else {
      // if the optimistic locking field has to be unversioned and the current property
      // is the optimistic locking field, don't audit it
      if (globalCfg.isDoNotAuditOptimisticLockingField()) {
        final Version jpaVer = property.getAnnotation(Version.class);
        if (jpaVer != null) {
          return false;
        }
      }
    }

    if (!this.checkAudited(property, propertyData, allClassAudited)) {
      return false;
    }

    final String propertyName = propertyNamePrefix + property.getName();
    propertyData.setName(propertyName);
    propertyData.setModifiedFlagName(
        MetadataTools.getModifiedFlagPropertyName(propertyName, globalCfg.getModifiedFlagSuffix()));
    propertyData.setBeanName(property.getName());
    propertyData.setAccessType(accessType);

    addPropertyJoinTables(property, propertyData);
    addPropertyAuditingOverrides(property, propertyData);
    if (!processPropertyAuditingOverrides(property, propertyData)) {
      // not audited due to AuditOverride annotation
      return false;
    }
    addPropertyMapKey(property, propertyData);
    setPropertyAuditMappedBy(property, propertyData);
    setPropertyRelationMappedBy(property, propertyData);

    return true;
  }
 private void addPropertyJoinTables(XProperty property, PropertyAuditingData propertyData) {
   // first set the join table based on the AuditJoinTable annotation
   final AuditJoinTable joinTable = property.getAnnotation(AuditJoinTable.class);
   if (joinTable != null) {
     propertyData.setJoinTable(joinTable);
   } else {
     propertyData.setJoinTable(DEFAULT_AUDIT_JOIN_TABLE);
   }
 }
 private void setPropertyAuditMappedBy(XProperty property, PropertyAuditingData propertyData) {
   final AuditMappedBy auditMappedBy = property.getAnnotation(AuditMappedBy.class);
   if (auditMappedBy != null) {
     propertyData.setAuditMappedBy(auditMappedBy.mappedBy());
     if (!"".equals(auditMappedBy.positionMappedBy())) {
       propertyData.setPositionMappedBy(auditMappedBy.positionMappedBy());
     }
   }
 }
 public static Float getBoost(XProperty member, Annotation fieldAnn) {
   float computedBoost = 1.0f;
   Boost boostAnn = member.getAnnotation(Boost.class);
   if (boostAnn != null) {
     computedBoost = boostAnn.value();
   }
   if (fieldAnn != null) {
     float boost;
     if (fieldAnn instanceof org.hibernate.search.annotations.Field) {
       boost = ((org.hibernate.search.annotations.Field) fieldAnn).boost().value();
     } else if (fieldAnn instanceof Spatial) {
       boost = ((Spatial) fieldAnn).boost().value();
     } else {
       raiseAssertionOnIncorrectAnnotation(fieldAnn);
       boost = 0; // never reached
     }
     computedBoost *= boost;
   }
   return computedBoost;
 }
 protected boolean checkAudited(
     XProperty property, PropertyAuditingData propertyData, Audited allClassAudited) {
   // Checking if this property is explicitly audited or if all properties are.
   Audited aud =
       (property.isAnnotationPresent(Audited.class))
           ? property.getAnnotation(Audited.class)
           : allClassAudited;
   if (aud == null
       && overriddenAuditedProperties.contains(property)
       && !overriddenNotAuditedProperties.contains(property)) {
     // Assigning @Audited defaults. If anyone needs to customize those values in the future,
     // appropriate fields shall be added to @AuditOverride annotation.
     aud = DEFAULT_AUDITED;
   }
   if (aud != null) {
     propertyData.setStore(aud.modStore());
     propertyData.setRelationTargetAuditMode(aud.targetAuditMode());
     propertyData.setUsingModifiedFlag(checkUsingModifiedFlag(aud));
     return true;
   } else {
     return false;
   }
 }
  private void searchForRevisionInfoCfgInProperties(
      XClass clazz,
      ReflectionManager reflectionManager,
      MutableBoolean revisionNumberFound,
      MutableBoolean revisionTimestampFound,
      MutableBoolean modifiedEntityNamesFound,
      String accessType) {
    for (XProperty property : clazz.getDeclaredProperties(accessType)) {
      RevisionNumber revisionNumber = property.getAnnotation(RevisionNumber.class);
      RevisionTimestamp revisionTimestamp = property.getAnnotation(RevisionTimestamp.class);
      ModifiedEntityNames modifiedEntityNames = property.getAnnotation(ModifiedEntityNames.class);

      if (revisionNumber != null) {
        if (revisionNumberFound.isSet()) {
          throw new MappingException("Only one property may be annotated with @RevisionNumber!");
        }

        XClass revisionNumberClass = property.getType();
        if (reflectionManager.equals(revisionNumberClass, Integer.class)
            || reflectionManager.equals(revisionNumberClass, Integer.TYPE)) {
          revisionInfoIdData =
              new PropertyData(property.getName(), property.getName(), accessType, null);
          revisionNumberFound.set();
        } else if (reflectionManager.equals(revisionNumberClass, Long.class)
            || reflectionManager.equals(revisionNumberClass, Long.TYPE)) {
          revisionInfoIdData =
              new PropertyData(property.getName(), property.getName(), accessType, null);
          revisionNumberFound.set();

          // The default is integer
          revisionPropType = "long";
        } else {
          throw new MappingException(
              "The field annotated with @RevisionNumber must be of type "
                  + "int, Integer, long or Long");
        }

        // Getting the @Column definition of the revision number property, to later use that info to
        // generate the same mapping for the relation from an audit table's revision number to the
        // revision entity revision number.
        Column revisionPropColumn = property.getAnnotation(Column.class);
        if (revisionPropColumn != null) {
          revisionPropSqlType = revisionPropColumn.columnDefinition();
        }
      }

      if (revisionTimestamp != null) {
        if (revisionTimestampFound.isSet()) {
          throw new MappingException("Only one property may be annotated with @RevisionTimestamp!");
        }

        XClass revisionTimestampClass = property.getType();
        if (reflectionManager.equals(revisionTimestampClass, Long.class)
            || reflectionManager.equals(revisionTimestampClass, Long.TYPE)
            || reflectionManager.equals(revisionTimestampClass, Date.class)
            || reflectionManager.equals(revisionTimestampClass, java.sql.Date.class)) {
          revisionInfoTimestampData =
              new PropertyData(property.getName(), property.getName(), accessType, null);
          revisionTimestampFound.set();
        } else {
          throw new MappingException(
              "The field annotated with @RevisionTimestamp must be of type "
                  + "long, Long, java.util.Date or java.sql.Date");
        }
      }

      if (modifiedEntityNames != null) {
        if (modifiedEntityNamesFound.isSet()) {
          throw new MappingException(
              "Only one property may be annotated with @ModifiedEntityNames!");
        }
        XClass modifiedEntityNamesClass = property.getType();
        if (reflectionManager.equals(modifiedEntityNamesClass, Set.class)
            && reflectionManager.equals(property.getElementClass(), String.class)) {
          modifiedEntityNamesData =
              new PropertyData(property.getName(), property.getName(), accessType, null);
          modifiedEntityNamesFound.set();
        } else {
          throw new MappingException(
              "The field annotated with @ModifiedEntityNames must be of Set<String> type.");
        }
      }
    }
  }
 private void addPropertyMapKey(XProperty property, PropertyAuditingData propertyData) {
   final MapKey mapKey = property.getAnnotation(MapKey.class);
   if (mapKey != null) {
     propertyData.setMapKey(mapKey.name());
   }
 }
 private void setPropertyRelationMappedBy(XProperty property, PropertyAuditingData propertyData) {
   final OneToMany oneToMany = property.getAnnotation(OneToMany.class);
   if (oneToMany != null && !"".equals(oneToMany.mappedBy())) {
     propertyData.setRelationMappedBy(oneToMany.mappedBy());
   }
 }