/**
  * Extract the field bridge from @Field.bridge or @FieldBridge. Return null if none is present.
  */
 private FieldBridge findExplicitFieldBridge(
     Field field, XMember member, ReflectionManager reflectionManager) {
   // TODO Should explicit FieldBridge also support the notion of container like numeric fields and
   // provider based fields?
   //     the main problem is that support for a bridge accepting a Map would break
   FieldBridge bridge = null;
   org.hibernate.search.annotations.FieldBridge bridgeAnn;
   // @Field bridge has priority over @FieldBridge
   if (field != null && void.class != field.bridge().impl()) {
     bridgeAnn = field.bridge();
   } else {
     bridgeAnn = member.getAnnotation(org.hibernate.search.annotations.FieldBridge.class);
   }
   if (bridgeAnn != null) {
     bridge = doExtractType(bridgeAnn, member, reflectionManager);
   }
   return bridge;
 }
예제 #2
0
  @SuppressWarnings({CompilerWarnings.UNCHECKED})
  private void buildEntityMetadatas() throws Exception {
    SessionFactoryImpl sessionFactory =
        ((SessionFactoryImpl) this.entityManagerFactory.getSessionFactory());
    Class<?> entityBindingMappedClass;
    Class<? extends SdcctEntity> entityMappedClass;
    String entityName, entityPropName, entityPropFieldName;
    EntityMetadata entityMetadata;
    Map<String, PropertyMetadata> entityPropMetadatas;
    IndexedTypeDescriptor indexedEntityDesc;
    Method entityPropGetterMethod;
    boolean entityIndexed, entityPropIndexed;
    PropertyDescriptor indexedEntityPropDesc;
    PropertyMetadata entityPropMetadata;
    BidiMap<Integer, String> entityPropOrder;
    String[] entityPropOrderNames;

    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
      if (((entityBindingMappedClass = entityBinding.getMappedClass()) == null)
          || !SdcctEntity.class.isAssignableFrom(entityBindingMappedClass)) {
        continue;
      }

      entityPropMetadatas =
          (entityMetadata =
                  new EntityMetadataImpl(
                      (entityName = entityBinding.getEntityName()),
                      (entityIndexed =
                          (indexedEntityDesc =
                                  searchIntegrator.getIndexedTypeDescriptor(
                                      (entityMappedClass =
                                          ((Class<? extends SdcctEntity>)
                                              entityBindingMappedClass))))
                              .isIndexed()),
                      entityMappedClass,
                      entityBinding.getTable().getName()))
              .getProperties();

      this.entityMetadatas.put(
          ((Class<? extends SdcctEntity>) entityMappedClass.getInterfaces()[0]), entityMetadata);

      for (Property entityProp :
          IteratorUtils.asIterable(
              IteratorUtils.chainedIterator(
                  ((Iterator<Property>) entityBinding.getRootClass().getPropertyIterator()),
                  ((Iterator<Property>) entityBinding.getPropertyIterator())))) {
        entityPropName = entityProp.getName();
        entityPropGetterMethod = entityProp.getGetter(entityMappedClass).getMethod();

        if (entityProp.getColumnSpan() == 0) {
          continue;
        }

        entityPropIndexed =
            (entityIndexed
                && entityPropGetterMethod.isAnnotationPresent(Fields.class)
                && ((indexedEntityPropDesc = indexedEntityDesc.getProperty(entityPropName)) != null)
                && !indexedEntityPropDesc.isId());

        entityPropMetadatas.put(
            entityPropName,
            (entityPropMetadata =
                new PropertyMetadataImpl(
                    entityPropName,
                    entityPropIndexed,
                    ((Column) entityProp.getColumnIterator().next()).getName(),
                    entityProp.getType())));

        if (entityPropIndexed) {
          for (Field entityPropFieldAnno :
              entityPropGetterMethod.getAnnotation(Fields.class).value()) {
            if (entityPropFieldAnno.analyze() == Analyze.NO) {
              continue;
            }

            entityPropFieldName = entityPropFieldAnno.name();

            switch (entityPropFieldAnno.analyzer().definition()) {
              case DbAnalyzerNames.EDGE_NGRAM:
                entityPropMetadata.setEdgeNgramFieldName(entityPropFieldName);
                break;

              case DbAnalyzerNames.LOWERCASE:
                entityPropMetadata.setLowercaseFieldName(entityPropFieldName);
                break;

              case DbAnalyzerNames.NGRAM:
                entityPropMetadata.setNgramFieldName(entityPropFieldName);
                break;

              case DbAnalyzerNames.PHONETIC:
                entityPropMetadata.setPhoneticFieldName(entityPropFieldName);
                break;
            }
          }
        }
      }

      entityMetadata.setIdProperty(
          entityPropMetadatas.get(entityBinding.getIdentifierProperty().getName()));

      entityPropOrder = entityMetadata.getPropertyOrder();
      entityPropOrderNames = sessionFactory.getEntityPersister(entityName).getPropertyNames();

      for (int a = 0; a < entityPropOrderNames.length; a++) {
        entityPropOrder.put(a, entityPropOrderNames[a]);
      }
    }

    LOGGER.debug(
        String.format(
            "Processed metadata for %d entities: [%s]",
            this.entityMetadatas.size(),
            this.entityMetadatas
                .values()
                .stream()
                .map(NamedBean::getName)
                .collect(Collectors.joining(", "))));
  }