com.haulmont.chile.core.model.MetaClass类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中com.haulmont.chile.core.model.MetaClass类的一些代码示例,展示了MetaClass类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MetaClass类的具体详情如下:
包路径:com.haulmont.chile.core.model.MetaClass
类名称:MetaClass

MetaClass介绍

[英]Metadata object representing an entity.
[中]表示实体的元数据对象。

代码示例

代码示例来源:origin: com.haulmont.cuba/cuba-global

/**
   * INTERNAL. Import replaced meta class from metadata.
   */
  public void registerReplacedMetaClass(MetaClass metaClass) {
    replacedMetaClasses.put(metaClass.getJavaClass(), metaClass);
  }
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

@Override
  public String toString() {
    String key = stringKey ? "{" + id + "}" : id.toString();
    return metaClass.getName() + "-" + key + (viewName == null ? "" : "-" + viewName);
  }
}

代码示例来源:origin: com.haulmont.cuba/cuba-gui

@Nullable
  public MetaProperty getMetaProperty() {
    MetaPropertyPath propertyPath = datasourceMetaClass.getPropertyPath(name);
    return propertyPath != null ? propertyPath.getMetaProperty() : null;
  }
}

代码示例来源:origin: com.haulmont.cuba/cuba-rest-api

public MetaClassInfo(MetaClass metaClass) {
    this.entityName = metaClass.getName();
    this.ancestor = metaClass.getAncestor() != null ? metaClass.getAncestor().getName() : null;
    properties.addAll(metaClass.getProperties().stream()
        .map(MetaPropertyInfo::new)
        .collect(Collectors.toList()));
  }
}

代码示例来源:origin: com.haulmont.charts/charts-gui

protected boolean isEmbeddedIdProperty(String property, MetaClass metaClass) {
  MetaClass embeddedMetaClass = getEmbeddedIdMetaClass(metaClass);
  if (embeddedMetaClass == null) {
    return false;
  }
  String[] propertyPathParts = property.split("\\.");
  String propertyName = propertyPathParts[propertyPathParts.length - 1];
  MetaProperty metaProperty = embeddedMetaClass.getProperty(propertyName);
  return embeddedMetaClass.getOwnProperties().contains(metaProperty);
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

/**
 * Determine whether the given metaclass represents a persistent entity.
 * <p>
 * A persistent entity is an entity that is managed by ORM (i.e. registered in a persistence.xml file)
 * and is not a MappedSuperclass or Embeddable.
 */
public boolean isPersistent(MetaClass metaClass) {
  checkNotNullArgument(metaClass, "metaClass is null");
  return Boolean.TRUE.equals(metaClass.getAnnotations().get(PERSISTENT_ANN_NAME))
      && metaClass.getJavaClass().isAnnotationPresent(javax.persistence.Entity.class);
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

@Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    if ("hashCode".equals(method.getName())) {
      return hashCode();
    }
    if (metaProperty == null) {
      synchronized (this) {
        if (metaProperty == null) {
          metaProperty = domain.getProperty(name);
        }
      }
    }
    return method.invoke(metaProperty, args);
  }
}

代码示例来源:origin: com.haulmont.addon.dashboard/dashboard-web

protected void loadEntities(MetaClass metaClass) {
  LoadContext loadContext = LoadContext.create(metaClass.getJavaClass())
      .setQuery(LoadContext.createQuery(format("select e from %s e", metaClass.getName())));
  List entities = dataManager.loadList(loadContext);
  entitiesLookup.setOptionsList(entities);
}

代码示例来源:origin: com.haulmont.cuba/cuba-rest-api

protected Map<String, String> getLocalizationForEntity(MetaClass metaClass) {
  Map<String, String> locMap = new TreeMap<>();
  locMap.put(metaClass.getName(), messageTools.getEntityCaption(metaClass));
  metaClass.getProperties().forEach(metaProperty -> {
    String msgKey = metaClass.getName() + "." + metaProperty.getName();
    String msgValue = messageTools.getPropertyCaption(metaProperty);
    locMap.put(msgKey, msgValue);
  });
  return locMap;
}

代码示例来源:origin: com.haulmont.cuba/cuba-rest-api

public static List<MetaProperty> getOrderedProperties(MetaClass metaClass) {
  List<MetaProperty> result = new ArrayList<MetaProperty>(metaClass.getProperties());
  Collections.sort(result, PROPERTY_COMPARATOR);
  return result;
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

/**
 * @return MetaProperty representing a primary key attribute, or null if the entity has no primary key (e.g.
 * embeddable)
 */
@Nullable
public MetaProperty getPrimaryKeyProperty(MetaClass metaClass) {
  String primaryKeyName = getPrimaryKeyName(metaClass);
  return primaryKeyName == null ? null : metaClass.getPropertyNN(primaryKeyName);
}

代码示例来源:origin: com.haulmont.fts/fts-core

public void addProperty(String name) {
  MetaPropertyPath propertyPath = metaClass.getPropertyPath(name);
  if (propertyPath == null)
    throw new RuntimeException("Property " + name + " doesn't exist for entity " + metaClass.getName());
  if (propertyPath.getMetaProperties().length > 1
      && !propertyPath.getRange().isClass()
      && !AppBeans.get(MetadataTools.class).isEmbedded(propertyPath.getMetaProperties()[0]))
    throw new RuntimeException("Property " + name + " must be an entity (" + metaClass.getName() + ")");
  properties.put(name, propertyPath.getRange().isClass());
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

protected void initMetaAnnotations(MetaClass metaClass) {
    for (Annotation annotation : metaClass.getJavaClass().getAnnotations()) {
      MetaAnnotation metaAnnotation = AnnotationUtils.findAnnotation(annotation.getClass(), MetaAnnotation.class);
      if (metaAnnotation != null) {
        String name = annotation.annotationType().getName();

        Map<String, Object> attributes = new LinkedHashMap<>(AnnotationUtils.getAnnotationAttributes(metaClass.getJavaClass(), annotation));
        metaClass.getAnnotations().put(name, attributes);

        Object propagateToSubclasses = attributes.get("propagateToSubclasses");
        if (propagateToSubclasses == null || Boolean.TRUE.equals(propagateToSubclasses)) {
          for (MetaClass descMetaClass : metaClass.getDescendants()) {
            Annotation descAnnotation = descMetaClass.getJavaClass().getAnnotation(annotation.annotationType());
            if (descAnnotation == null) {
              descMetaClass.getAnnotations().put(name, attributes);
            }
          }
        }
      }
    }
  }
}

代码示例来源:origin: com.haulmont.fts/fts-core

@Override
public MetaProperty getPrimaryKeyPropertyForFts(MetaClass metaClass) {
  if (metadata.getTools().hasCompositePrimaryKey(metaClass) && HasUuid.class.isAssignableFrom(metaClass.getJavaClass())) {
    return metaClass.getPropertyNN("uuid");
  }
  return metadata.getTools().getPrimaryKeyProperty(metaClass);
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

public static String printClassHierarchy(MetaClass metaClass) {
  StringBuilder builder = new StringBuilder();
  builder.append(metaClass.getName()).append("\n");
  for (MetaClass descendantClass : metaClass.getDescendants()) {
    builder.append(shift(printClassHierarchy(descendantClass)));
  }
  return builder.toString();
}

代码示例来源:origin: com.haulmont.cuba/cuba-core

protected View createFullView(MetaClass metaClass) {
  View view = new View(metaClass.getJavaClass());
  for (MetaProperty metaProperty : metaClass.getProperties()) {
    if (metadataTools.isEmbedded(metaProperty)) {
      view.addProperty(metaProperty.getName(), createFullView(metaProperty.getRange().asClass()));
    } else if (isReferenceField(metaProperty)) {
      view.addProperty(metaProperty.getName(), viewRepository.getView(metaProperty.getRange().asClass(), View.MINIMAL));
    } else if (isDataField(metaProperty)) {
      view.addProperty(metaProperty.getName());
    }
  }
  return view;
}

代码示例来源:origin: com.haulmont.cuba/cuba-core

protected Set<String> getDescendants(Set<String> relatedTypes) {
  if (relatedTypes == null) return null;
  Set<String> newRelatedTypes = new HashSet<>();
  relatedTypes.forEach(type -> {
    newRelatedTypes.add(type);
    MetaClass metaClass = metadata.getClassNN(type);
    if (metaClass.getDescendants() != null) {
      Set<String> descendants = metaClass.getDescendants().stream()
          .filter(it -> it.getJavaClass() != null && !it.getJavaClass().isAnnotationPresent(MappedSuperclass.class))
          .map(MetadataObject::getName).collect(Collectors.toSet());
      newRelatedTypes.addAll(descendants);
    }
  });
  return newRelatedTypes;
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

public static String printClass(MetaClass metaClass) {
  StringBuilder builder = new StringBuilder();
  builder.append(metaClass.getName()).append("\n");
  for (MetaProperty metaProperty : metaClass.getOwnProperties()) {
    builder.append(shift(metaProperty.getName() + ": " + metaProperty.getRange()));
  }
  return builder.toString();
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

protected void postProcessClass(MetaClass metaClass) {
  for (MetaProperty property : metaClass.getOwnProperties()) {
    postProcessProperty(metaClass, property);
  }
  Collection<MetaClass> missingDescendants = new HashSet<>(1);
  findMissingDescendants(metaClass, missingDescendants);
  if (!missingDescendants.isEmpty()) {
    CollectionUtils.addAll(metaClass.getDescendants(), missingDescendants.iterator());
    MetaClass ancestorMetaClass = metaClass.getAncestor();
    while (ancestorMetaClass != null) {
      CollectionUtils.addAll(ancestorMetaClass.getDescendants(), missingDescendants.iterator());
      ancestorMetaClass = ancestorMetaClass.getAncestor();
    }
  }
  MetaClass ancestorMetaClass = metaClass.getAncestor();
  while (ancestorMetaClass != null) {
    ((MetaClassImpl) metaClass).addAncestor(ancestorMetaClass);
    ancestorMetaClass = ancestorMetaClass.getAncestor();
  }
}

代码示例来源:origin: com.haulmont.cuba/cuba-global

protected void findMissingDescendants(MetaClass ancestor, Collection<MetaClass> missingDescendants) {
  Collection<MetaClass> descendants = ancestor.getDescendants();
  for (Object descendant : descendants) {
    missingDescendants.add((MetaClass) descendant);
    findMissingDescendants((MetaClass) descendant, missingDescendants);
  }
}

相关文章