类javax.persistence.metamodel.PluralAttribute源码实例Demo

下面列出了怎么用javax.persistence.metamodel.PluralAttribute的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lams   文件: AbstractManagedType.java
public Builder<X> getBuilder() {
	if ( locked ) {
		throw new IllegalStateException( "Type has been locked" );
	}
	return new Builder<X>() {
		@Override
		@SuppressWarnings("unchecked")
		public void addAttribute(Attribute<X,?> attribute) {
			declaredAttributes.put( attribute.getName(), attribute );
			final Bindable.BindableType bindableType = ( ( Bindable ) attribute ).getBindableType();
			switch ( bindableType ) {
				case SINGULAR_ATTRIBUTE : {
					declaredSingularAttributes.put( attribute.getName(), (SingularAttribute<X,?>) attribute );
					break;
				}
				case PLURAL_ATTRIBUTE : {
					declaredPluralAttributes.put(attribute.getName(), (PluralAttribute<X,?,?>) attribute );
					break;
				}
				default : {
					throw new AssertionFailure( "unknown bindable type: " + bindableType );
				}
			}
		}
	};
}
 
源代码2 项目: lams   文件: AbstractManagedType.java
private <E> void checkTypeForPluralAttributes(
		String attributeType,
		PluralAttribute<?,?,?> attribute,
		String name,
		Class<E> elementType,
		PluralAttribute.CollectionType collectionType) {
	if ( attribute == null
			|| ( elementType != null && !attribute.getBindableJavaType().equals( elementType ) )
			|| attribute.getCollectionType() != collectionType ) {
		throw new IllegalArgumentException(
				attributeType + " named " + name
				+ ( elementType != null ? " and of element type " + elementType : "" )
				+ " is not present"
		);
	}
}
 
源代码3 项目: lams   文件: AttributeFactory.java
public static PluralAttribute.CollectionType determineCollectionType(Class javaType) {
	if ( java.util.List.class.isAssignableFrom( javaType ) ) {
		return PluralAttribute.CollectionType.LIST;
	}
	else if ( java.util.Set.class.isAssignableFrom( javaType ) ) {
		return PluralAttribute.CollectionType.SET;
	}
	else if ( java.util.Map.class.isAssignableFrom( javaType ) ) {
		return PluralAttribute.CollectionType.MAP;
	}
	else if ( java.util.Collection.class.isAssignableFrom( javaType ) ) {
		return PluralAttribute.CollectionType.COLLECTION;
	}
	else if ( javaType.isArray() ) {
		return PluralAttribute.CollectionType.LIST;
	}
	else {
		throw new IllegalArgumentException( "Expecting collection type [" + javaType.getName() + "]" );
	}
}
 
源代码4 项目: lams   文件: AbstractPathImpl.java
@Override
@SuppressWarnings({ "unchecked" })
public <Y> Path<Y> get(String attributeName) {
	if ( ! canBeDereferenced() ) {
		throw illegalDereference();
	}

	final Attribute attribute = locateAttribute( attributeName );

	if ( attribute.isCollection() ) {
		final PluralAttribute<X,Y,?> pluralAttribute = (PluralAttribute<X,Y,?>) attribute;
		if ( PluralAttribute.CollectionType.MAP.equals( pluralAttribute.getCollectionType() ) ) {
			return (PluralAttributePath<Y>) this.<Object,Object,Map<Object, Object>>get( (MapAttribute) pluralAttribute );
		}
		else {
			return (PluralAttributePath<Y>) this.get( (PluralAttribute) pluralAttribute );
		}
	}
	else {
		return get( (SingularAttribute<X,Y>) attribute );
	}
}
 
源代码5 项目: javaee-lab   文件: JpaUtil.java
@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;
}
 
源代码6 项目: javaee-lab   文件: GenericRepository.java
@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);
                }
            }
        }
    }
}
 
源代码7 项目: javaee-lab   文件: MetamodelUtil.java
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);
    }
}
 
源代码8 项目: lams   文件: AbstractManagedType.java
@Override
@SuppressWarnings({ "unchecked" })
public Set<PluralAttribute<? super X, ?, ?>> getPluralAttributes() {
	HashSet attributes = new HashSet<PluralAttribute<? super X, ?, ?>>( declaredPluralAttributes.values() );
	if ( getSupertype() != null ) {
		attributes.addAll( getSupertype().getPluralAttributes() );
	}
	return attributes;
}
 
源代码9 项目: lams   文件: AbstractManagedType.java
@Override
@SuppressWarnings({ "unchecked" })
public CollectionAttribute<? super X, ?> getCollection(String name) {
	PluralAttribute<? super X, ?, ?> attribute = getPluralAttribute( name );
	if ( attribute == null && getSupertype() != null ) {
		attribute = getSupertype().getPluralAttribute( name );
	}
	basicCollectionCheck( attribute, name );
	return ( CollectionAttribute<X, ?> ) attribute;
}
 
源代码10 项目: lams   文件: AbstractManagedType.java
@Override
@SuppressWarnings( "unchecked")
public CollectionAttribute<X, ?> getDeclaredCollection(String name) {
	final PluralAttribute<X,?,?> attribute = declaredPluralAttributes.get( name );
	basicCollectionCheck( attribute, name );
	return ( CollectionAttribute<X, ?> ) attribute;
}
 
源代码11 项目: lams   文件: AbstractManagedType.java
@Override
@SuppressWarnings({ "unchecked" })
public SetAttribute<? super X, ?> getSet(String name) {
	PluralAttribute<? super X, ?, ?> attribute = getPluralAttribute( name );
	if ( attribute == null && getSupertype() != null ) {
		attribute = getSupertype().getPluralAttribute( name );
	}
	basicSetCheck( attribute, name );
	return (SetAttribute<? super X, ?>) attribute;
}
 
源代码12 项目: lams   文件: AbstractManagedType.java
@Override
@SuppressWarnings( "unchecked")
public SetAttribute<X, ?> getDeclaredSet(String name) {
	final PluralAttribute<X,?,?> attribute = declaredPluralAttributes.get( name );
	basicSetCheck( attribute, name );
	return ( SetAttribute<X, ?> ) attribute;
}
 
源代码13 项目: lams   文件: AbstractManagedType.java
@Override
@SuppressWarnings({ "unchecked" })
public ListAttribute<? super X, ?> getList(String name) {
	PluralAttribute<? super X, ?, ?> attribute = getPluralAttribute( name );
	if ( attribute == null && getSupertype() != null ) {
		attribute = getSupertype().getPluralAttribute( name );
	}
	basicListCheck( attribute, name );
	return (ListAttribute<? super X, ?>) attribute;
}
 
源代码14 项目: lams   文件: AbstractManagedType.java
@Override
@SuppressWarnings("unchecked")
public ListAttribute<X, ?> getDeclaredList(String name) {
	final PluralAttribute<X,?,?> attribute = declaredPluralAttributes.get( name );
	basicListCheck( attribute, name );
	return ( ListAttribute<X, ?> ) attribute;
}
 
源代码15 项目: lams   文件: AbstractManagedType.java
@Override
@SuppressWarnings({ "unchecked" })
public MapAttribute<? super X, ?, ?> getMap(String name) {
	PluralAttribute<? super X, ?, ?> attribute = getPluralAttribute( name );
	if ( attribute == null && getSupertype() != null ) {
		attribute = getSupertype().getPluralAttribute( name );
	}
	basicMapCheck( attribute, name );
	return (MapAttribute<? super X, ?, ?>) attribute;
}
 
源代码16 项目: lams   文件: AbstractManagedType.java
@Override
@SuppressWarnings("unchecked")
public MapAttribute<X, ?, ?> getDeclaredMap(String name) {
	final PluralAttribute<X,?,?> attribute = declaredPluralAttributes.get( name );
	basicMapCheck( attribute, name );
	return ( MapAttribute<X,?,?> ) attribute;
}
 
源代码17 项目: lams   文件: AbstractManagedType.java
@Override
@SuppressWarnings({ "unchecked" })
public <E> CollectionAttribute<? super X, E> getCollection(String name, Class<E> elementType) {
	PluralAttribute<? super X, ?, ?> attribute = declaredPluralAttributes.get( name );
	if ( attribute == null && getSupertype() != null ) {
		attribute = getSupertype().getPluralAttribute( name );
	}
	checkCollectionElementType( attribute, name, elementType );
	return ( CollectionAttribute<? super X, E> ) attribute;
}
 
源代码18 项目: lams   文件: AbstractManagedType.java
@Override
@SuppressWarnings({ "unchecked" })
public <E> SetAttribute<? super X, E> getSet(String name, Class<E> elementType) {
	PluralAttribute<? super X, ?, ?> attribute = declaredPluralAttributes.get( name );
	if ( attribute == null && getSupertype() != null ) {
		attribute = getSupertype().getPluralAttribute( name );
	}
	checkSetElementType( attribute, name, elementType );
	return ( SetAttribute<? super X, E> ) attribute;
}
 
源代码19 项目: lams   文件: AbstractManagedType.java
@Override
@SuppressWarnings("unchecked")
public <E> SetAttribute<X, E> getDeclaredSet(String name, Class<E> elementType) {
	final PluralAttribute<X,?,?> attribute = declaredPluralAttributes.get( name );
	checkSetElementType( attribute, name, elementType );
	return ( SetAttribute<X, E> ) attribute;
}
 
源代码20 项目: lams   文件: AbstractManagedType.java
@Override
@SuppressWarnings("unchecked")
public <E> ListAttribute<X, E> getDeclaredList(String name, Class<E> elementType) {
	final PluralAttribute<X,?,?> attribute = declaredPluralAttributes.get( name );
	checkListElementType( attribute, name, elementType );
	return ( ListAttribute<X, E> ) attribute;
}
 
源代码21 项目: lams   文件: AbstractManagedType.java
@Override
@SuppressWarnings({ "unchecked" })
public <K, V> MapAttribute<? super X, K, V> getMap(String name, Class<K> keyType, Class<V> valueType) {
	PluralAttribute<? super X, ?, ?> attribute = getPluralAttribute( name );
	if ( attribute == null && getSupertype() != null ) {
		attribute = getSupertype().getPluralAttribute( name );
	}
	checkMapValueType( attribute, name, valueType );
	final MapAttribute<? super X, K, V> mapAttribute = ( MapAttribute<? super X, K, V> ) attribute;
	checkMapKeyType( mapAttribute, name, keyType );
	return mapAttribute;
}
 
源代码22 项目: lams   文件: AbstractManagedType.java
@Override
@SuppressWarnings("unchecked")
public <K, V> MapAttribute<X, K, V> getDeclaredMap(String name, Class<K> keyType, Class<V> valueType) {
	final PluralAttribute<X,?,?> attribute = declaredPluralAttributes.get( name );
	checkMapValueType( attribute, name, valueType );
	final MapAttribute<X, K, V> mapAttribute = ( MapAttribute<X, K, V> ) attribute;
	checkMapKeyType( mapAttribute, name, keyType );
	return mapAttribute;
}
 
源代码23 项目: lams   文件: SingularAttributeJoin.java
@Override
@SuppressWarnings("unchecked")
protected ManagedType<? super X> locateManagedType() {
	if ( getModel().getBindableType() == Bindable.BindableType.ENTITY_TYPE ) {
		return (ManagedType<? super X>) getModel();
	}
	else if ( getModel().getBindableType() == Bindable.BindableType.SINGULAR_ATTRIBUTE ) {
		final Type joinedAttributeType = ( (SingularAttribute) getAttribute() ).getType();
		if ( !ManagedType.class.isInstance( joinedAttributeType ) ) {
			throw new UnsupportedOperationException(
					"Cannot further dereference attribute join [" + getPathIdentifier() + "] as its type is not a ManagedType"
			);
		}
		return (ManagedType<? super X>) joinedAttributeType;
	}
	else if ( getModel().getBindableType() == Bindable.BindableType.PLURAL_ATTRIBUTE ) {
		final Type elementType = ( (PluralAttribute) getAttribute() ).getElementType();
		if ( !ManagedType.class.isInstance( elementType ) ) {
			throw new UnsupportedOperationException(
					"Cannot further dereference attribute join [" + getPathIdentifier() + "] (plural) as its element type is not a ManagedType"
			);
		}
		return (ManagedType<? super X>) elementType;
	}

	return super.locateManagedType();
}
 
源代码24 项目: lams   文件: AbstractFromImpl.java
@Override
@SuppressWarnings({"unchecked"})
public <X, Y> CollectionJoin<X, Y> joinCollection(String attributeName, JoinType jt) {
	final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute( attributeName );
	if ( !attribute.isCollection() ) {
		throw new IllegalArgumentException( "Requested attribute was not a collection" );
	}

	final PluralAttribute pluralAttribute = (PluralAttribute) attribute;
	if ( !PluralAttribute.CollectionType.COLLECTION.equals( pluralAttribute.getCollectionType() ) ) {
		throw new IllegalArgumentException( "Requested attribute was not a collection" );
	}

	return (CollectionJoin<X, Y>) join( (CollectionAttribute) attribute, jt );
}
 
源代码25 项目: lams   文件: AbstractFromImpl.java
@Override
@SuppressWarnings({"unchecked"})
public <X, Y> SetJoin<X, Y> joinSet(String attributeName, JoinType jt) {
	final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute( attributeName );
	if ( !attribute.isCollection() ) {
		throw new IllegalArgumentException( "Requested attribute was not a set" );
	}

	final PluralAttribute pluralAttribute = (PluralAttribute) attribute;
	if ( !PluralAttribute.CollectionType.SET.equals( pluralAttribute.getCollectionType() ) ) {
		throw new IllegalArgumentException( "Requested attribute was not a set" );
	}

	return (SetJoin<X, Y>) join( (SetAttribute) attribute, jt );
}
 
源代码26 项目: lams   文件: AbstractFromImpl.java
@Override
@SuppressWarnings({"unchecked"})
public <X, Y> ListJoin<X, Y> joinList(String attributeName, JoinType jt) {
	final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute( attributeName );
	if ( !attribute.isCollection() ) {
		throw new IllegalArgumentException( "Requested attribute was not a list" );
	}

	final PluralAttribute pluralAttribute = (PluralAttribute) attribute;
	if ( !PluralAttribute.CollectionType.LIST.equals( pluralAttribute.getCollectionType() ) ) {
		throw new IllegalArgumentException( "Requested attribute was not a list" );
	}

	return (ListJoin<X, Y>) join( (ListAttribute) attribute, jt );
}
 
源代码27 项目: lams   文件: AbstractFromImpl.java
@Override
@SuppressWarnings({"unchecked"})
public <X, Y> Fetch<X, Y> fetch(String attributeName, JoinType jt) {
	if ( !canBeFetchSource() ) {
		throw illegalFetch();
	}

	Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute( attributeName );
	if ( attribute.isCollection() ) {
		return (Fetch<X, Y>) fetch( (PluralAttribute) attribute, jt );
	}
	else {
		return (Fetch<X, Y>) fetch( (SingularAttribute) attribute, jt );
	}
}
 
源代码28 项目: lams   文件: PluralAttributePath.java
public PluralAttributePath(
		CriteriaBuilderImpl criteriaBuilder,
		PathSource source,
		PluralAttribute<?,X,?> attribute) {
	super( criteriaBuilder, attribute.getJavaType(), source );
	this.attribute = attribute;
	this.persister = resolvePersister( criteriaBuilder, attribute );
}
 
源代码29 项目: lams   文件: AbstractPathImpl.java
@Override
@SuppressWarnings({ "unchecked" })
public <E, C extends Collection<E>> Expression<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;
}
 
源代码30 项目: graphql-jpa   文件: JpaDataFetcher.java
private Predicate getPredicate(CriteriaBuilder cb, Root root, DataFetchingEnvironment environment, Argument argument) {
    Path path = null;
    if (!argument.getName().contains(".")) {
        Attribute argumentEntityAttribute = getAttribute(environment, argument);

        // If the argument is a list, let's assume we need to join and do an 'in' clause
        if (argumentEntityAttribute instanceof PluralAttribute) {
            Join join = root.join(argument.getName());
            return join.in(convertValue(environment, argument, argument.getValue()));
        }

        path = root.get(argument.getName());

        return cb.equal(path, convertValue(environment, argument, argument.getValue()));
    } else {
        List<String> parts = Arrays.asList(argument.getName().split("\\."));
        for (String part : parts) {
            if (path == null) {
                path = root.get(part);
            } else {
                path = path.get(part);
            }
        }

        return cb.equal(path, convertValue(environment, argument, argument.getValue()));
    }
}
 
 类所在包
 同包方法