コード例 #1
0
  /**
   * @param member the java member of attribute
   * @param name the name of the attribute
   * @param parsed set of annotations parsed
   * @since $version
   * @author hceylan
   */
  public EmbeddedAttributeMetadataImpl(
      Member member, String name, Set<Class<? extends Annotation>> parsed) {
    super(member, name);

    parsed.add(Embedded.class);

    // if there is AttributesOverrides annotation use it
    final AttributeOverrides attributeOverrides =
        ReflectHelper.getAnnotation(member, AttributeOverrides.class);
    final AttributeOverride attributeOverride =
        ReflectHelper.getAnnotation(member, AttributeOverride.class);

    if ((attributeOverrides != null)
        && (attributeOverrides.value() != null)
        && (attributeOverrides.value().length > 0)) {
      parsed.add(AttributeOverrides.class);

      for (final AttributeOverride a : attributeOverrides.value()) {
        this.attributeOverrides.add(new AttributeOverrideMetadataImpl(this.getLocator(), a));
      }
    } else if (attributeOverride != null) {
      parsed.add(AttributeOverride.class);

      this.attributeOverrides.add(
          new AttributeOverrideMetadataImpl(this.getLocator(), attributeOverride));
    }

    // if there is AssociationsOverrides annotation use it
    final AssociationOverrides associationOverrides =
        ReflectHelper.getAnnotation(member, AssociationOverrides.class);
    final AssociationOverride associationOverride =
        ReflectHelper.getAnnotation(member, AssociationOverride.class);

    if ((associationOverrides != null)
        && (associationOverrides.value() != null)
        && (associationOverrides.value().length > 0)) {
      parsed.add(AssociationOverrides.class);

      for (final AssociationOverride a : associationOverrides.value()) {
        this.associationOverrides.add(new AssociationOverrideMetadataImpl(this.getLocator(), a));
      }
    } else if (associationOverride != null) {
      parsed.add(AssociationOverride.class);

      this.associationOverrides.add(
          new AssociationOverrideMetadataImpl(this.getLocator(), associationOverride));
    }
  }
コード例 #2
0
  private void introspectAttributeOverrides(EntityType entityType, Class type) {
    EntityType parent = entityType.getParentType();

    if (parent == null) return;

    boolean isAbstract = Modifier.isAbstract(parent.getBeanClass().getModifiers());

    if (parent.isEntity() && !isAbstract) return;

    HashMap<String, ColumnConfig> overrideMap = new HashMap<String, ColumnConfig>();

    getInternalAttributeOverrideConfig(type, _annotationCfg);
    AttributeOverride attributeOverrideAnn = (AttributeOverride) _annotationCfg.getAnnotation();

    boolean hasAttributeOverride = (attributeOverrideAnn != null);

    AttributeOverrides attributeOverridesAnn =
        (AttributeOverrides) type.getAnnotation(AttributeOverrides.class);

    ArrayList<AttributeOverrideConfig> attributeOverrideList = null;

    EntityConfig entityConfig = getEntityConfig(type.getName());

    if (entityConfig != null) attributeOverrideList = entityConfig.getAttributeOverrideList();

    boolean hasAttributeOverrides = false;

    if ((attributeOverrideList != null) && (attributeOverrideList.size() > 0)) {
      hasAttributeOverrides = true;
    } else if (attributeOverridesAnn != null) hasAttributeOverrides = true;

    if (hasAttributeOverride && hasAttributeOverrides)
      throw new ConfigException(
          L.l("{0} may not have both @AttributeOverride and @AttributeOverrides", type));

    if (attributeOverrideList == null)
      attributeOverrideList = new ArrayList<AttributeOverrideConfig>();

    if (hasAttributeOverride) {
      // Convert annotation to configuration.

      AttributeOverrideConfig attOverrideConfig =
          convertAttributeOverrideAnnotationToConfig(attributeOverrideAnn);

      attributeOverrideList.add(attOverrideConfig);
    } else if (hasAttributeOverrides) {
      if (attributeOverrideList.size() > 0) {
        // OK: attributeOverrideList came from orm.xml
      } else {
        // Convert annotations to configurations.

        AttributeOverride attOverridesAnn[] = attributeOverridesAnn.value();

        AttributeOverrideConfig attOverrideConfig;

        /* XXX:
        for (int i = 0; i < attOverridesAnn.length; i++) {
          attOverrideConfig
            = convertAttributeOverrideAnnotationToConfig((JAnnotation) attOverridesAnn[i]);

          attributeOverrideList.add(attOverrideConfig);
        }
                * */
      }
    }

    for (AttributeOverrideConfig override : attributeOverrideList) {
      overrideMap.put(override.getName(), override.getColumn());
    }

    _depCompletions.add(new AttributeOverrideCompletion(this, entityType, type, overrideMap));
  }