Пример #1
0
    /**
     * For each of the fields contained in this {@link Locks} object, parse out the type and the
     * field name and store those as the key and value in the "value" argument.
     */
    public void fillRelationships(SessionFactoryImplementor sfi, Map<String, Relationship> value) {

      final Type[] types = cm.getPropertyTypes();
      for (int t = 0; t < types.length; t++) {

        final Type type = types[t];
        final String name = type.getName();

        String to = null;
        Relationship field = null;
        if (type instanceof EntityType) {
          final EntityType entType = (EntityType) type;
          to = entType.getAssociatedEntityName();
          field = new Relationship(cm.getPropertyNames()[t], false);

        } else if (types[t] instanceof CollectionType) {
          final CollectionType colType = (CollectionType) types[t];
          final Type elemType = colType.getElementType(sfi);
          if (!elemType.isEntityType()) {
            continue; // The case for count maps and other primitives.
          }
          to = elemType.getName();

          int open = name.indexOf("(");
          int close = name.lastIndexOf(")");
          String role = name.substring(open + 1, close);
          int dot = role.lastIndexOf(".");
          field = new Relationship(role.substring(dot + 1), true);
        }

        if (to != null && field != null) {
          Map<String, ClassMetadata> m = sfi.getAllClassMetadata();
          for (Class<?> c : Impl.hierarchy(m, to)) {
            value.put(c.getName(), field);
          }
        }
      }
    }
  private Document generateDefaultRevisionInfoXmlMapping() {
    Document document = XMLHelper.getDocumentFactory().createDocument();

    Element class_mapping =
        MetadataTools.createEntity(
            document,
            new AuditTableData(
                null, null, globalCfg.getDefaultSchemaName(), globalCfg.getDefaultCatalogName()),
            null);

    class_mapping.addAttribute("name", revisionInfoEntityName);
    class_mapping.addAttribute("table", "REVINFO");

    Element idProperty =
        MetadataTools.addNativelyGeneratedId(
            class_mapping, revisionInfoIdData.getName(), revisionPropType);
    MetadataTools.addColumn(idProperty, "REV", null, 0, 0, null, null, null, false);

    Element timestampProperty =
        MetadataTools.addProperty(
            class_mapping,
            revisionInfoTimestampData.getName(),
            revisionInfoTimestampType.getName(),
            true,
            false);
    MetadataTools.addColumn(timestampProperty, "REVTSTMP", null, 0, 0, null, null, null, false);

    if (globalCfg.isTrackEntitiesChangedInRevisionEnabled()) {
      generateEntityNamesTrackingTableMapping(
          class_mapping,
          "modifiedEntityNames",
          globalCfg.getDefaultSchemaName(),
          globalCfg.getDefaultCatalogName(),
          "REVCHANGES",
          "REV",
          "ENTITYNAME",
          "string");
    }

    return document;
  }
Пример #3
0
  /**
   * 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());
  }
Пример #4
0
 public String toString() {
   return "Property(" + name + ':' + type.getName() + ')';
 }
 private boolean isTimestampAsDate() {
   String typename = revisionInfoTimestampType.getName();
   return "date".equals(typename) || "time".equals(typename) || "timestamp".equals(typename);
 }