本文整理汇总了Java中javax.persistence.metamodel.SingularAttribute.getPersistentAttributeType方法的典型用法代码示例。如果您正苦于以下问题:Java SingularAttribute.getPersistentAttributeType方法的具体用法?Java SingularAttribute.getPersistentAttributeType怎么用?Java SingularAttribute.getPersistentAttributeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.persistence.metamodel.SingularAttribute
的用法示例。
在下文中一共展示了SingularAttribute.getPersistentAttributeType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: byExample
import javax.persistence.metamodel.SingularAttribute; //导入方法依赖的package包/类
/**
* Add a predicate for each simple property whose value is not null.
*/
public <T> List<Predicate> byExample(ManagedType<T> mt, Path<T> mtPath, final T mtValue, SearchParameters sp, CriteriaBuilder builder) {
List<Predicate> predicates = newArrayList();
for (SingularAttribute<? super T, ?> attr : mt.getSingularAttributes()) {
if (attr.getPersistentAttributeType() == MANY_TO_ONE //
|| attr.getPersistentAttributeType() == ONE_TO_ONE //
|| attr.getPersistentAttributeType() == EMBEDDED) {
continue;
}
Object attrValue = getValue(mtValue, attr);
if (attrValue != null) {
if (attr.getJavaType() == String.class) {
if (isNotEmpty((String) attrValue)) {
predicates.add(JpaUtil.stringPredicate(mtPath.get(stringAttribute(mt, attr)), attrValue, sp, builder));
}
} else {
predicates.add(builder.equal(mtPath.get(attribute(mt, attr)), attrValue));
}
}
}
return predicates;
}
示例2: byExampleOnXToOne
import javax.persistence.metamodel.SingularAttribute; //导入方法依赖的package包/类
/**
* Invoke byExample method for each not null x-to-one association when their pk is not set. This allows you to search entities based on an associated
* entity's properties value.
*/
@SuppressWarnings("unchecked")
public <T extends Identifiable<?>, M2O extends Identifiable<?>> List<Predicate> byExampleOnXToOne(ManagedType<T> mt, Root<T> mtPath, final T mtValue,
SearchParameters sp, CriteriaBuilder builder) {
List<Predicate> predicates = newArrayList();
for (SingularAttribute<? super T, ?> attr : mt.getSingularAttributes()) {
if (attr.getPersistentAttributeType() == MANY_TO_ONE || attr.getPersistentAttributeType() == ONE_TO_ONE) { //
M2O m2oValue = (M2O) getValue(mtValue, mt.getAttribute(attr.getName()));
if (m2oValue != null && !m2oValue.isIdSet()) {
Class<M2O> m2oType = (Class<M2O>) attr.getBindableJavaType();
ManagedType<M2O> m2oMt = em.getMetamodel().entity(m2oType);
Path<M2O> m2oPath = (Path<M2O>) mtPath.get(attr);
predicates.addAll(byExample(m2oMt, m2oPath, m2oValue, sp, builder));
}
}
}
return predicates;
}