当前位置: 首页>>代码示例>>Java>>正文


Java Attribute.getName方法代码示例

本文整理汇总了Java中javax.persistence.metamodel.Attribute.getName方法的典型用法代码示例。如果您正苦于以下问题:Java Attribute.getName方法的具体用法?Java Attribute.getName怎么用?Java Attribute.getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.persistence.metamodel.Attribute的用法示例。


在下文中一共展示了Attribute.getName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractNativeSqlColumnName

import javax.persistence.metamodel.Attribute; //导入方法依赖的package包/类
public static String extractNativeSqlColumnName(final Attribute<?, ?> attr) {
    switch (attr.getPersistentAttributeType()) {
    case BASIC:
    case EMBEDDED:
        return attr.getName();
    case ELEMENT_COLLECTION:
    case ONE_TO_ONE:
    case MANY_TO_ONE:
        return attr.getName() + ID_SUFFIX;
    case MANY_TO_MANY:
    case ONE_TO_MANY:
        throw new IllegalArgumentException(PersistentAttributeType.class.getSimpleName() + " ["
                + attr.getPersistentAttributeType() + "] is not supported!");
    default:
        throw UnknownArgumentException.newInstance(PersistentAttributeType.class, attr.getPersistentAttributeType());
    }
}
 
开发者ID:subes,项目名称:invesdwin-context-persistence,代码行数:18,代码来源:Attributes.java

示例2: getName

import javax.persistence.metamodel.Attribute; //导入方法依赖的package包/类
private String getName(Bindable<?> bindable) {
    if (bindable.getBindableType() == BindableType.ENTITY_TYPE) {
        EntityType<?> entityType = (EntityType<?>)bindable;
        return entityType.getName();
    } else {
        Attribute<?, ?> attribute = (Attribute<?, ?>)bindable;
        return attribute.getName();
    }
}
 
开发者ID:ArneLimburg,项目名称:jpasecurity,代码行数:10,代码来源:CriteriaEntityFilter.java

示例3: queryByExample

import javax.persistence.metamodel.Attribute; //导入方法依赖的package包/类
/**
 * When and=false, all criteria are combined with OR, else AND is used.
 * 
 * @see <a href="http://stackoverflow.com/questions/2880209/jpa-findbyexample">Source</a>
 */
public TypedQuery<E> queryByExample(final String persistenceUnitName, final EntityManager em,
        final Class<E> genericType, final E example, final boolean and, final QueryConfig config) {
    assertEntityExampleWithoutId(example);
    final CriteriaBuilder cb = em.getCriteriaBuilder();
    final CriteriaQuery<E> cq = cb.createQuery(genericType);
    final Root<E> r = cq.from(genericType);
    Predicate p = cb.conjunction();
    final EntityType<E> et = em.getMetamodel().entity(genericType);
    final Set<Attribute<? super E, ?>> attrs = et.getAttributes();
    boolean firstField = true;
    for (final Attribute<? super E, ?> attr : attrs) {
        final String name = attr.getName();
        final String javaName = attr.getJavaMember().getName();
        final Field f = Reflections.findField(genericType, javaName);
        Reflections.makeAccessible(f);
        final Object value = Reflections.getField(f, example);
        if (value != null) {
            final Predicate pred = cb.equal(r.get(name), value);
            if (and || firstField) {
                p = cb.and(p, pred);
            } else {
                p = cb.or(p, pred);
            }
            firstField = false;
        }
    }
    cq.select(r).where(p);
    final TypedQuery<E> query = em.createQuery(cq);
    QueryConfig.configure(persistenceUnitName, query, config);
    return query;
}
 
开发者ID:subes,项目名称:invesdwin-context-persistence,代码行数:37,代码来源:QueryByExampleHelper.java

示例4: xByExample

import javax.persistence.metamodel.Attribute; //导入方法依赖的package包/类
private Query xByExample(final EntityManager em, final String queryStart, final Class<E> genericType,
        final E example, final boolean and) {
    assertEntityExampleWithoutId(example);
    final StringBuilder sb = new StringBuilder(queryStart);
    sb.append(" FROM ");
    sb.append(extractEntityName(genericType));
    sb.append(" e WHERE 1 = 1");
    final Map<String, Object> params = new HashMap<String, Object>();
    final EntityType<E> et = em.getMetamodel().entity(genericType);
    final Set<Attribute<? super E, ?>> attrs = et.getAttributes();
    boolean firstField = true;
    for (final Attribute<? super E, ?> attr : attrs) {
        final String name = attr.getName();
        final String javaName = attr.getJavaMember().getName();
        final Field f = Reflections.findField(genericType, javaName);
        Reflections.makeAccessible(f);
        final Object value = Reflections.getField(f, example);
        if (value != null) {
            params.put(name, value);
            if (and || firstField) {
                sb.append(" AND ");
            } else {
                sb.append(" OR ");
            }
            sb.append("e.");
            sb.append(name);
            sb.append(" = :");
            sb.append(name);
            firstField = false;
        }
    }
    final Query query = em.createQuery(sb.toString());
    for (final Entry<String, Object> param : params.entrySet()) {
        query.setParameter(param.getKey(), param.getValue());
    }
    return query;
}
 
开发者ID:subes,项目名称:invesdwin-context-persistence,代码行数:38,代码来源:QueryByExampleHelper.java


注:本文中的javax.persistence.metamodel.Attribute.getName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。