com.haulmont.chile.core.model.MetaClass.getAncestor()方法的使用及代码示例

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

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

MetaClass.getAncestor介绍

[英]Immediate ancestor of the object, or null if there is no one.
[中]对象的直接祖先,如果没有,则为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.cuba/cuba-global

public static String printClassHierarchy(MetaModel model) {
  StringBuilder builder = new StringBuilder();
  Collection<MetaClass> topLevelClasses = new LinkedList<>();
  for (MetaClass metaClass : model.getClasses()) {
    if (metaClass.getAncestor() == null) {
      topLevelClasses.add(metaClass);
    }
  }
  for (MetaClass topLevelClass : topLevelClasses) {
    builder.append(printClassHierarchy(topLevelClass));
  }
  return builder.toString();
}

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

/**
 * @return name of a primary key attribute, or null if the entity has no primary key (e.g. embeddable)
 */
@Nullable
public String getPrimaryKeyName(MetaClass metaClass) {
  String pkProperty = (String) metaClass.getAnnotations().get(PRIMARY_KEY_ANN_NAME);
  if (pkProperty != null) {
    return pkProperty;
  } else {
    MetaClass ancestor = metaClass.getAncestor();
    while (ancestor != null) {
      pkProperty = (String) ancestor.getAnnotations().get(PRIMARY_KEY_ANN_NAME);
      if (pkProperty != null)
        return pkProperty;
      ancestor = ancestor.getAncestor();
    }
  }
  return null;
}

代码示例来源: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

/**
 * @return table name for the given entity, or null if the entity is Embeddable, MappedSuperclass or non-persistent
 */
@Nullable
public String getDatabaseTable(MetaClass metaClass) {
  if (isEmbeddable(metaClass) || !isPersistent(metaClass))
    return null;
  Class<?> javaClass = metaClass.getJavaClass();
  javax.persistence.Table annotation = javaClass.getAnnotation(javax.persistence.Table.class);
  if (annotation != null && StringUtils.isNotEmpty(annotation.name())) {
    return annotation.name();
  } else if (metaClass.getAncestor() != null) {
    return getDatabaseTable(metaClass.getAncestor());
  }
  return null;
}

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

public String getParent() {
  MetaClass ancestor = meta.getAncestor();
  if (ancestor == null ||
      !ancestor.getName().contains("$") && !ancestor.getName().contains("_") ||
      ancestor.getJavaClass().isAnnotationPresent(MappedSuperclass.class))
    return "";
  if (!readPermitted(ancestor)) {
    return null;
  }
  return "Parent is " + asHref(ancestor.getName());
}

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

protected void collectTableMetadata(MetaClass metaClass, Table table) {
  Class<?> javaClass = metaClass.getJavaClass();
  javax.persistence.Table annotation = javaClass.getAnnotation(javax.persistence.Table.class);
  MetaClass ancestor = metaClass.getAncestor();
  if (annotation != null && StringUtils.isNotEmpty(annotation.name())) {
    if (table.name == null) {
      table.name = annotation.name();
      tables.add(0, table);
    } else {
      Table newTable = new Table(annotation.name());
      tables.add(0, newTable);
      table.parent = newTable;
      table = newTable;
    }
  }
  if (ancestor != null) {
    collectTableMetadata(ancestor, table);
  }
  table.collectMetadata(javaClass);
}

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

protected void hardSetReferenceNull(Entity entity, MetaProperty property) {
  ((PersistenceImpl) persistence).addBeforeCommitAction(() -> {
    MetadataTools metadataTools = metadata.getTools();
    MetaClass entityMetaClass = metadata.getClassNN(entity.getClass());
    while (!entityMetaClass.equals(property.getDomain())) {
      MetaClass ancestor = entityMetaClass.getAncestor();
      if (ancestor == null)
        throw new IllegalStateException("Cannot determine a persistent entity for property " + property);
      if (metadataTools.isPersistent(ancestor)) {
        entityMetaClass = ancestor;
      } else {
        break;
      }
    }
    String sql = String.format("update %s set %s = null where %s = ?",
        metadataTools.getDatabaseTable(entityMetaClass),
        metadataTools.getDatabaseColumn(property),
        metadataTools.getPrimaryKeyName(entityMetaClass));
    try {
      log.debug("Set reference to null: {}, bind: [{}]", sql, entity.getId());
      QueryRunner queryRunner = new QueryRunner();
      queryRunner.update(entityManager.getConnection(), sql, persistence.getDbTypeConverter().getSqlObject(entity.getId()));
    } catch (SQLException e) {
      throw new RuntimeException("Error processing deletion of " + entity, e);
    }
  });
}

相关文章