本文整理汇总了Java中javax.persistence.metamodel.Attribute.getJavaType方法的典型用法代码示例。如果您正苦于以下问题:Java Attribute.getJavaType方法的具体用法?Java Attribute.getJavaType怎么用?Java Attribute.getJavaType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.persistence.metamodel.Attribute
的用法示例。
在下文中一共展示了Attribute.getJavaType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: byPattern
import javax.persistence.metamodel.Attribute; //导入方法依赖的package包/类
/**
* Lookup entities having at least one String attribute matching the passed sp's pattern
*/
@SuppressWarnings("unused")
public <T> Predicate byPattern(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder, final SearchParameters sp, final Class<T> type) {
if (!sp.hasSearchPattern()) {
return null;
}
List<Predicate> predicates = newArrayList();
EntityType<T> entity = em.getMetamodel().entity(type);
String pattern = sp.getSearchPattern();
for (Attribute<T, ?> attr : entity.getDeclaredSingularAttributes()) {
if (attr.getPersistentAttributeType() == MANY_TO_ONE || attr.getPersistentAttributeType() == ONE_TO_ONE) {
continue;
}
if (attr.getJavaType() == String.class) {
predicates.add(JpaUtil.stringPredicate(root.get(attribute(entity, attr)), pattern, sp, builder));
}
}
return JpaUtil.orPredicate(builder, predicates);
}
示例2: visit
import javax.persistence.metamodel.Attribute; //导入方法依赖的package包/类
public boolean visit(JpqlPath node, Set<TypeDefinition> typeDefinitions) {
Alias alias = new Alias(node.jjtGetChild(0).getValue());
Class<?> type = getType(alias, typeDefinitions);
for (int i = 1; i < node.jjtGetNumChildren(); i++) {
ManagedType<?> managedType = forModel(metamodel).filter(type);
String attributeName = node.jjtGetChild(i).getValue();
Attribute<?, ?> attribute = managedType.getAttribute(attributeName);
if (attribute instanceof SingularAttribute
&& ((SingularAttribute<?, ?>)attribute).getType().getPersistenceType() == PersistenceType.BASIC
&& i < node.jjtGetNumChildren() - 1) {
String error = "Cannot navigate through simple property "
+ attributeName + " in class " + type.getName();
throw new PersistenceException(error);
}
type = attribute.getJavaType();
}
return false;
}
示例3: verifyPath
import javax.persistence.metamodel.Attribute; //导入方法依赖的package包/类
public void verifyPath(List<Attribute<?, ?>> path) {
List<Attribute<?, ?>> attributes = newArrayList(path);
Class<?> from = null;
if (attributes.get(0).isCollection()) {
from = ((PluralAttribute) attributes.get(0)).getElementType().getJavaType();
} else {
from = attributes.get(0).getJavaType();
}
attributes.remove(0);
for (Attribute<?, ?> attribute : attributes) {
if (!attribute.getDeclaringType().getJavaType().isAssignableFrom(from)) {
throw new IllegalStateException("Wrong path.");
}
from = attribute.getJavaType();
}
}
示例4: toAttributes
import javax.persistence.metamodel.Attribute; //导入方法依赖的package包/类
public List<Attribute<?, ?>> toAttributes(String path, Class<?> from) {
try {
List<Attribute<?, ?>> attributes = newArrayList();
Class<?> current = from;
for (String pathItem : Splitter.on(".").split(path)) {
Class<?> metamodelClass = getCachedClass(current);
Field field = metamodelClass.getField(pathItem);
Attribute<?, ?> attribute = (Attribute<?, ?>) field.get(null);
attributes.add(attribute);
if (attribute instanceof PluralAttribute) {
current = ((PluralAttribute<?, ?, ?>) attribute).getElementType().getJavaType();
} else {
current = attribute.getJavaType();
}
}
return attributes;
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
}
示例5: verifyPath
import javax.persistence.metamodel.Attribute; //导入方法依赖的package包/类
private void verifyPath(List<Attribute<?, ?>> attributes) {
Class<?> from = attributes.get(0).getJavaType();
attributes.remove(0);
for (Attribute<?, ?> attribute : attributes) {
if (!attribute.getDeclaringType().getJavaType().isAssignableFrom(from)) {
throw new IllegalStateException("Wrong path.");
}
from = attribute.getJavaType();
}
}
示例6: getAttributeClass
import javax.persistence.metamodel.Attribute; //导入方法依赖的package包/类
public static Class<?> getAttributeClass(final Attribute<?, ?> attribute) {
if (attribute == null) {
throw new NullPointerException(ATTRIBUTE_CANNOT_BE_NULL);
}
if (attribute instanceof PluralAttribute) {
return ((PluralAttribute) attribute).getBindableJavaType();
}
return attribute.getJavaType();
}
示例7: getJavaType
import javax.persistence.metamodel.Attribute; //导入方法依赖的package包/类
private Class getJavaType(DataFetchingEnvironment environment, Argument argument) {
Attribute argumentEntityAttribute = getAttribute(environment, argument);
if (argumentEntityAttribute instanceof PluralAttribute)
return ((PluralAttribute) argumentEntityAttribute).getElementType().getJavaType();
return argumentEntityAttribute.getJavaType();
}