Example usage for javax.persistence.metamodel ManagedType getAttributes

List of usage examples for javax.persistence.metamodel ManagedType getAttributes

Introduction

In this page you can find the example usage for javax.persistence.metamodel ManagedType getAttributes.

Prototype

Set<Attribute<? super X, ?>> getAttributes();

Source Link

Document

Return the attributes of the managed type.

Usage

From source file:de.micromata.genome.jpa.metainf.MetaInfoUtils.java

/**
 * To entity meta data./*  www . j a  v  a  2s.  c o  m*/
 *
 * @param mt the mt
 * @return the entity metadata
 */
private static EntityMetadata toEntityMetaData(ManagedType<?> mt) {
    EntityMetadataBean ret = new EntityMetadataBean();
    ret.setJavaType(mt.getJavaType());
    if (mt instanceof EntityType) {
        EntityType ift = (EntityType) mt;
        ret.setDatabaseName(ift.getName());
    }
    // TODO RK delete propDesc
    List<PropertyDescriptor> propDescs = Arrays.asList(PropertyUtils.getPropertyDescriptors(ret.getJavaType()));
    Set<?> attr = mt.getAttributes();
    for (Object oa : attr) {

        Attribute<?, ?> at = (Attribute<?, ?>) oa;
        Optional<PropertyDescriptor> pdo = propDescs.stream().filter((el) -> el.getName().equals(at.getName()))
                .findFirst();
        ColumnMetadata colm = getColumnMetaData(ret, mt.getJavaType(), at, pdo);
        if (colm != null) {
            ret.getColumns().put(colm.getName(), colm);
        }
    }
    /// EntityType.getName() is not correct.
    Table[] tabs = mt.getJavaType().getAnnotationsByType(Table.class);
    if (tabs != null && tabs.length > 0) {
        for (Table tab : tabs) {
            if (StringUtils.isNotBlank(tab.name()) == true) {
                ret.setDatabaseName(tab.name());
                break;
            }
        }
    }
    return ret;
}