本文整理汇总了Java中javax.persistence.metamodel.PluralAttribute类的典型用法代码示例。如果您正苦于以下问题:Java PluralAttribute类的具体用法?Java PluralAttribute怎么用?Java PluralAttribute使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PluralAttribute类属于javax.persistence.metamodel包,在下文中一共展示了PluralAttribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import javax.persistence.metamodel.PluralAttribute; //导入依赖的package包/类
@Override
public Method load(final PluralAttribute<?, ?, ?> attribute) {
final Class<?> declaringClass = attribute.getDeclaringType().getJavaType();
final String getterName = getGetterName(attribute);
final Method readMethod = BeanUtils.findDeclaredMethod(declaringClass, getterName);
if (readMethod == null) {
throw new IllegalStateException(String.format(
"Class %s does not declare method named '%s'",
declaringClass.getName(),
getterName));
}
readMethod.setAccessible(true);
return readMethod;
}
示例2: jpaCollection
import javax.persistence.metamodel.PluralAttribute; //导入依赖的package包/类
@Nonnull
static <T, U, C extends Collection<U>> Function<T, C> jpaCollection(
@Nonnull final PluralAttribute<? super T, C, U> attribute) {
Objects.requireNonNull(attribute);
final Class<C> collectionType = attribute.getJavaType();
try {
final Method readMethod = ENTITY_COLLECTION_GETTERS.get(attribute);
return obj -> invokeAndCast(readMethod, obj, collectionType);
} catch (final ExecutionException e) {
throw new RuntimeException(e);
}
}
示例3: updateInverseCollection
import javax.persistence.metamodel.PluralAttribute; //导入依赖的package包/类
public static <T, U, C extends Collection<U>> void updateInverseCollection(
@Nonnull final PluralAttribute<? super T, C, U> inverseAttribute,
@Nonnull final U entity,
@Nullable final T currentAssociation,
@Nullable final T newAssociation) {
Objects.requireNonNull(inverseAttribute, "inverseAttribute is null");
Objects.requireNonNull(entity, "entity is null");
final Function<T, C> fn = getCollectionIfInitialized(inverseAttribute);
final C oldCollection = fn.apply(currentAssociation);
if (oldCollection != null) {
oldCollection.remove(entity);
}
final C newCollection = fn.apply(newAssociation);
if (newCollection != null) {
newCollection.add(entity);
}
}
示例4: join
import javax.persistence.metamodel.PluralAttribute; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Nonnull
public static <T, U> Join<T, U> join(
@Nonnull final From<?, T> from, @Nonnull final PluralAttribute<? super T, ?, U> attribute) {
Objects.requireNonNull(from, "from is null");
Objects.requireNonNull(attribute, "attribute is null");
if (attribute instanceof CollectionAttribute) {
return from.join((CollectionAttribute<T, U>) attribute);
}
if (attribute instanceof SetAttribute) {
return from.join((SetAttribute<T, U>) attribute);
}
if (attribute instanceof ListAttribute) {
return from.join((ListAttribute<T, U>) attribute);
}
if (attribute instanceof MapAttribute) {
return from.join((MapAttribute<T, ?, U>) attribute);
}
// Should never end up here.
throw new IllegalArgumentException();
}
示例5: cacheManager
import javax.persistence.metamodel.PluralAttribute; //导入依赖的package包/类
@Bean
public CacheManager cacheManager(JHipsterProperties jHipsterProperties) {
log.debug("Starting Ehcache");
cacheManager = net.sf.ehcache.CacheManager.create();
cacheManager.getConfiguration().setMaxBytesLocalHeap(jHipsterProperties.getCache().getEhcache().getMaxBytesLocalHeap());
log.debug("Registering Ehcache Metrics gauges");
Set<EntityType<?>> entities = entityManager.getMetamodel().getEntities();
for (EntityType<?> entity : entities) {
String name = entity.getName();
if (name == null || entity.getJavaType() != null) {
name = entity.getJavaType().getName();
}
Assert.notNull(name, "entity cannot exist without an identifier");
reconfigureCache(name, jHipsterProperties);
for (PluralAttribute pluralAttribute : entity.getPluralAttributes()) {
reconfigureCache(name + "." + pluralAttribute.getName(), jHipsterProperties);
}
}
EhCacheCacheManager ehCacheManager = new EhCacheCacheManager();
ehCacheManager.setCacheManager(cacheManager);
return ehCacheManager;
}
示例6: filter
import javax.persistence.metamodel.PluralAttribute; //导入依赖的package包/类
public Attribute<?, ?> filter() {
Type<?> type = forModel(metamodel).filter(rootType);
Attribute<?, ?> result = null;
for (int i = 1; i < pathElements.length; i++) {
if (!(type instanceof ManagedType)) {
throw new PersistenceException("Cannot navigate through simple property "
+ pathElements[i] + " of type " + type.getJavaType());
}
result = ((ManagedType<?>)type).getAttribute(pathElements[i]);
if (result.isCollection()) {
type = ((PluralAttribute<?, ?, ?>)result).getElementType();
} else {
type = ((SingularAttribute<?, ?>)result).getType();
}
}
return result;
}
示例7: visitJoin
import javax.persistence.metamodel.PluralAttribute; //导入依赖的package包/类
public boolean visitJoin(Node node, Set<TypeDefinition> typeDefinitions) {
if (node.jjtGetNumChildren() != 2) {
return false;
}
Node pathNode = node.jjtGetChild(0);
Node aliasNode = node.jjtGetChild(1);
Alias rootAlias = new Alias(pathNode.jjtGetChild(0).toString());
Class<?> rootType = getType(rootAlias, typeDefinitions);
ManagedType<?> managedType = forModel(metamodel).filter(rootType);
for (int i = 1; i < pathNode.jjtGetNumChildren(); i++) {
Attribute<?, ?> attribute = managedType.getAttribute(pathNode.jjtGetChild(i).toString());
if (attribute.getPersistentAttributeType() == PersistentAttributeType.BASIC) {
throw new PersistenceException("Cannot navigate through basic property "
+ pathNode.jjtGetChild(i) + " of path " + pathNode);
}
if (attribute.isCollection()) {
PluralAttribute<?, ?, ?> pluralAttribute = (PluralAttribute<?, ?, ?>)attribute;
managedType = (ManagedType<?>)pluralAttribute.getElementType();
} else {
managedType = (ManagedType<?>)((SingularAttribute)attribute).getType();
}
}
typeDefinitions.add(new TypeDefinition(new Alias(aliasNode.toString()), managedType.getJavaType()));
return false;
}
示例8: toType
import javax.persistence.metamodel.PluralAttribute; //导入依赖的package包/类
public static Type toType(Bindable bindable) {
switch ( bindable.getBindableType() ) {
case ENTITY_TYPE: {
return (EntityType) bindable;
}
case SINGULAR_ATTRIBUTE: {
return ( (SingularAttribute) bindable ).getType();
}
case PLURAL_ATTRIBUTE: {
return ( (PluralAttribute) bindable ).getElementType();
}
default: {
throw new ParsingException( "Unexpected Bindable type : " + bindable );
}
}
}
示例9: fetch
import javax.persistence.metamodel.PluralAttribute; //导入依赖的package包/类
@Override
public <Y> JpaFetch<X, Y> fetch(PluralAttribute<? super X, ?, Y> pluralAttribute, JoinType jt) {
// if ( !canBeFetchSource() ) {
// throw illegalFetch();
// }
//
// final Fetch<X, Y> fetch;
// // TODO : combine Fetch and Join hierarchies (JoinImplementor extends Join,Fetch???)
// if ( PluralAttribute.CollectionType.COLLECTION.equals( pluralAttribute.getCollectionType() ) ) {
// fetch = constructJoin( (CollectionAttribute<X, Y>) pluralAttribute, jt );
// }
// else if ( PluralAttribute.CollectionType.LIST.equals( pluralAttribute.getCollectionType() ) ) {
// fetch = constructJoin( (ListAttribute<X, Y>) pluralAttribute, jt );
// }
// else if ( PluralAttribute.CollectionType.SET.equals( pluralAttribute.getCollectionType() ) ) {
// fetch = constructJoin( (SetAttribute<X, Y>) pluralAttribute, jt );
// }
// else {
// fetch = constructJoin( (MapAttribute<X, ?, Y>) pluralAttribute, jt );
// }
// joinScope.addFetch( fetch );
// return fetch;
throw new NotYetImplementedException( );
}
示例10: get
import javax.persistence.metamodel.PluralAttribute; //导入依赖的package包/类
@Override
@SuppressWarnings({ "unchecked" })
public <E, C extends Collection<E>> JpaExpression<C> get(PluralAttribute<X, C, E> attribute) {
// if ( ! canBeDereferenced() ) {
// throw illegalDereference();
// }
//
// PluralAttributePath<C> path = (PluralAttributePath<C>) resolveCachedAttributePath( attribute.getName() );
// if ( path == null ) {
// path = new PluralAttributePath<C>( criteriaBuilder(), this, attribute );
// registerAttributePath( attribute.getName(), path );
// }
// return path;
throw new NotYetImplementedException( );
}
示例11: getPath
import javax.persistence.metamodel.PluralAttribute; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <E, F> Path<F> getPath(Root<E> root, List<Attribute<?, ?>> attributes) {
Path<?> path = root;
for (Attribute<?, ?> attribute : attributes) {
boolean found = false;
if (path instanceof FetchParent) {
for (Fetch<E, ?> fetch : ((FetchParent<?, E>) path).getFetches()) {
if (attribute.getName().equals(fetch.getAttribute().getName()) && (fetch instanceof Join<?, ?>)) {
path = (Join<E, ?>) fetch;
found = true;
break;
}
}
}
if (!found) {
if (attribute instanceof PluralAttribute) {
path = ((From<?, ?>) path).join(attribute.getName(), JoinType.LEFT);
} else {
path = path.get(attribute.getName());
}
}
}
return (Path<F>) path;
}
示例12: verifyPath
import javax.persistence.metamodel.PluralAttribute; //导入依赖的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();
}
}
示例13: fetches
import javax.persistence.metamodel.PluralAttribute; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
protected void fetches(SearchParameters sp, Root<E> root) {
for (List<Attribute<?, ?>> args : sp.getFetches()) {
FetchParent<?, ?> from = root;
for (Attribute<?, ?> arg : args) {
boolean found = false;
for (Fetch<?, ?> fetch : from.getFetches()) {
if (arg.equals(fetch.getAttribute())) {
from = fetch;
found = true;
break;
}
}
if (!found) {
if (arg instanceof PluralAttribute) {
from = from.fetch((PluralAttribute) arg, JoinType.LEFT);
} else {
from = from.fetch((SingularAttribute) arg, JoinType.LEFT);
}
}
}
}
}
示例14: toAttributes
import javax.persistence.metamodel.PluralAttribute; //导入依赖的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);
}
}
示例15: fetches
import javax.persistence.metamodel.PluralAttribute; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public <E> void fetches(SearchParameters<E> sp, Root<E> root) {
for (jpasearch.repository.query.Path<E, ?> path : sp.getFetches()) {
FetchParent<?, ?> from = root;
for (Attribute<?, ?> arg : metamodelUtil.toAttributes(root.getJavaType(), path.getPath())) {
boolean found = false;
for (Fetch<?, ?> fetch : from.getFetches()) {
if (arg.equals(fetch.getAttribute())) {
from = fetch;
found = true;
break;
}
}
if (!found) {
if (arg instanceof PluralAttribute) {
from = from.fetch((PluralAttribute) arg, JoinType.LEFT);
} else {
from = from.fetch((SingularAttribute) arg, JoinType.LEFT);
}
}
}
}
}