本文整理匯總了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;
}