示例#1
0
  public void atClassObject(Expr expr) throws CompileError {
    ASTree op1 = expr.oprand1();
    if (!(op1 instanceof Symbol)) throw new CompileError("fatal error: badly parsed .class expr");

    String cname = ((Symbol) op1).get();
    if (cname.startsWith("[")) {
      int i = cname.indexOf("[L");
      if (i >= 0) {
        String name = cname.substring(i + 2, cname.length() - 1);
        String name2 = resolveClassName(name);
        if (!name.equals(name2)) {
          /* For example, to obtain String[].class,
           * "[Ljava.lang.String;" (not "[Ljava/lang/String"!)
           * must be passed to Class.forName().
           */
          name2 = MemberResolver.jvmToJavaName(name2);
          StringBuffer sbuf = new StringBuffer();
          while (i-- >= 0) sbuf.append('[');

          sbuf.append('L').append(name2).append(';');
          cname = sbuf.toString();
        }
      }
    } else {
      cname = resolveClassName(MemberResolver.javaToJvmName(cname));
      cname = MemberResolver.jvmToJavaName(cname);
    }

    atClassObject2(cname);
    exprType = CLASS;
    arrayDim = 0;
    className = "java/lang/Class";
  }
 public Member resolveMember(AttributeContext attributeContext) {
   final IdentifiableType identifiableType =
       (IdentifiableType) attributeContext.getOwnerType();
   final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel(identifiableType);
   if (!attributeContext
       .getPropertyMapping()
       .getName()
       .equals(entityMetamodel.getIdentifierProperty().getName())) {
     // this *should* indicate processing part of an IdClass...
     return VIRTUAL_IDENTIFIER_MEMBER_RESOLVER.resolveMember(attributeContext);
   }
   return entityMetamodel.getTuplizer().getIdentifierGetter().getMember();
 }
 /** {@inheritDoc} */
 public Member resolveMember(AttributeContext attributeContext) {
   final AbstractManagedType ownerType = attributeContext.getOwnerType();
   final Property property = attributeContext.getPropertyMapping();
   final Type.PersistenceType persistenceType = ownerType.getPersistenceType();
   if (Type.PersistenceType.EMBEDDABLE == persistenceType) {
     return EMBEDDED_MEMBER_RESOLVER.resolveMember(attributeContext);
   } else if (Type.PersistenceType.ENTITY == persistenceType
       || Type.PersistenceType.MAPPED_SUPERCLASS == persistenceType) {
     final IdentifiableType identifiableType = (IdentifiableType) ownerType;
     final EntityMetamodel entityMetamodel = getDeclarerEntityMetamodel(identifiableType);
     final String propertyName = property.getName();
     final Integer index = entityMetamodel.getPropertyIndexOrNull(propertyName);
     if (index == null) {
       // just like in #determineIdentifierJavaMember , this *should* indicate we have an
       // IdClass mapping
       return VIRTUAL_IDENTIFIER_MEMBER_RESOLVER.resolveMember(attributeContext);
     } else {
       return entityMetamodel.getTuplizer().getGetter(index).getMember();
     }
   } else {
     throw new IllegalArgumentException("Unexpected owner type : " + persistenceType);
   }
 }
  /**
   * Here is most of the nuts and bolts of this factory, where we interpret the known JPA metadata
   * against the known Hibernate metadata and build a descriptor for the attribute.
   *
   * @param attributeContext The attribute to be described
   * @param memberResolver Strategy for how to resolve the member defining the attribute.
   * @param <X> The owner type
   * @param <Y> The attribute type
   * @return The attribute description
   */
  @SuppressWarnings({"unchecked"})
  private <X, Y> AttributeMetadata<X, Y> determineAttributeMetadata(
      AttributeContext<X> attributeContext, MemberResolver memberResolver) {
    LOG.trace(
        "Starting attribute metadata determination ["
            + attributeContext.getPropertyMapping().getName()
            + "]");
    final Member member = memberResolver.resolveMember(attributeContext);
    LOG.trace("    Determined member [" + member + "]");

    final Value value = attributeContext.getPropertyMapping().getValue();
    final org.hibernate.type.Type type = value.getType();
    LOG.trace(
        "    Determined type [name="
            + type.getName()
            + ", class="
            + type.getClass().getName()
            + "]");

    if (type.isAnyType()) {
      // ANY mappings are currently not supported in the JPA metamodel; see HHH-6589
      if (context.isIgnoreUnsupported()) {
        return null;
      } else {
        throw new UnsupportedOperationException("ANY not supported");
      }
    } else if (type.isAssociationType()) {
      // collection or entity
      if (type.isEntityType()) {
        // entity
        return new SingularAttributeMetadataImpl<X, Y>(
            attributeContext.getPropertyMapping(),
            attributeContext.getOwnerType(),
            member,
            determineSingularAssociationAttributeType(member));
      }
      // collection
      if (value instanceof Collection) {
        final Collection collValue = (Collection) value;
        final Value elementValue = collValue.getElement();
        final org.hibernate.type.Type elementType = elementValue.getType();

        // First, determine the type of the elements and use that to help determine the
        // collection type)
        final Attribute.PersistentAttributeType elementPersistentAttributeType;
        final Attribute.PersistentAttributeType persistentAttributeType;
        if (elementType.isAnyType()) {
          throw new UnsupportedOperationException("collection of any not supported yet");
        }
        final boolean isManyToMany = isManyToMany(member);
        if (elementValue instanceof Component) {
          elementPersistentAttributeType = Attribute.PersistentAttributeType.EMBEDDED;
          persistentAttributeType = Attribute.PersistentAttributeType.ELEMENT_COLLECTION;
        } else if (elementType.isAssociationType()) {
          elementPersistentAttributeType =
              isManyToMany
                  ? Attribute.PersistentAttributeType.MANY_TO_MANY
                  : Attribute.PersistentAttributeType.ONE_TO_MANY;
          persistentAttributeType = elementPersistentAttributeType;
        } else {
          elementPersistentAttributeType = Attribute.PersistentAttributeType.BASIC;
          persistentAttributeType = Attribute.PersistentAttributeType.ELEMENT_COLLECTION;
        }

        final Attribute.PersistentAttributeType keyPersistentAttributeType;

        // Finally, we determine the type of the map key (if needed)
        if (value instanceof Map) {
          final Value keyValue = ((Map) value).getIndex();
          final org.hibernate.type.Type keyType = keyValue.getType();

          if (keyType.isAnyType())
            throw new UnsupportedOperationException("collection of any not supported yet");
          if (keyValue instanceof Component)
            keyPersistentAttributeType = Attribute.PersistentAttributeType.EMBEDDED;
          else if (keyType.isAssociationType())
            keyPersistentAttributeType = Attribute.PersistentAttributeType.MANY_TO_ONE;
          else keyPersistentAttributeType = Attribute.PersistentAttributeType.BASIC;
        } else keyPersistentAttributeType = null;
        return new PluralAttributeMetadataImpl(
            attributeContext.getPropertyMapping(),
            attributeContext.getOwnerType(),
            member,
            persistentAttributeType,
            elementPersistentAttributeType,
            keyPersistentAttributeType);
      } else if (value instanceof OneToMany) {
        // TODO : is this even possible??? Really OneToMany should be describing the
        // element value within a o.h.mapping.Collection (see logic branch above)
        throw new IllegalArgumentException("HUH???");
        //					final boolean isManyToMany = isManyToMany( member );
        //					//one to many with FK => entity
        //					return new PluralAttributeMetadataImpl(
        //							attributeContext.getPropertyMapping(),
        //							attributeContext.getOwnerType(),
        //							member,
        //							isManyToMany
        //									? Attribute.PersistentAttributeType.MANY_TO_MANY
        //									: Attribute.PersistentAttributeType.ONE_TO_MANY
        //							value,
        //							AttributeContext.TypeStatus.ENTITY,
        //							Attribute.PersistentAttributeType.ONE_TO_MANY,
        //							null, null, null
        //					);
      }
    } else if (attributeContext.getPropertyMapping().isComposite()) {
      // component
      return new SingularAttributeMetadataImpl<X, Y>(
          attributeContext.getPropertyMapping(),
          attributeContext.getOwnerType(),
          member,
          Attribute.PersistentAttributeType.EMBEDDED);
    } else {
      // basic type
      return new SingularAttributeMetadataImpl<X, Y>(
          attributeContext.getPropertyMapping(),
          attributeContext.getOwnerType(),
          member,
          Attribute.PersistentAttributeType.BASIC);
    }
    throw new UnsupportedOperationException(
        "oops, we are missing something: " + attributeContext.getPropertyMapping());
  }