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

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

源代码1 项目: lams   文件: AttributeFactory.java
@SuppressWarnings({"unchecked"})
public <X, Y> SingularAttributeImpl<X, Y> buildIdAttribute(
		AbstractIdentifiableType<X> ownerType,
		Property property) {
	LOG.trace( "Building identifier attribute [" + ownerType.getTypeName() + "." + property.getName() + "]" );
	final AttributeContext<X> attributeContext = wrap( ownerType, property );
	final SingularAttributeMetadata<X, Y> attributeMetadata =
			(SingularAttributeMetadata<X, Y>) determineAttributeMetadata(
					attributeContext,
					identifierMemberResolver
			);
	final Type<Y> metaModelType = getMetaModelType( attributeMetadata.getValueContext() );
	return new SingularAttributeImpl.Identifier(
			property.getName(),
			attributeMetadata.getJavaType(),
			ownerType,
			attributeMetadata.getMember(),
			metaModelType,
			attributeMetadata.getPersistentAttributeType()
	);
}
 
源代码2 项目: lams   文件: AttributeFactory.java
@SuppressWarnings({"unchecked"})
public <X, Y> SingularAttributeImpl<X, Y> buildVersionAttribute(
		AbstractIdentifiableType<X> ownerType,
		Property property) {
	LOG.trace( "Building version attribute [ownerType.getTypeName()" + "." + "property.getName()]" );
	final AttributeContext<X> attributeContext = wrap( ownerType, property );
	final SingularAttributeMetadata<X, Y> attributeMetadata =
			(SingularAttributeMetadata<X, Y>) determineAttributeMetadata( attributeContext, versionMemberResolver );
	final Type<Y> metaModelType = getMetaModelType( attributeMetadata.getValueContext() );
	return new SingularAttributeImpl.Version(
			property.getName(),
			attributeMetadata.getJavaType(),
			ownerType,
			attributeMetadata.getMember(),
			metaModelType,
			attributeMetadata.getPersistentAttributeType()
	);
}
 
源代码3 项目: lams   文件: AttributeFactory.java
private EntityMetamodel getDeclarerEntityMetamodel(AbstractIdentifiableType<?> ownerType) {
	final Type.PersistenceType persistenceType = ownerType.getPersistenceType();
	if ( persistenceType == Type.PersistenceType.ENTITY ) {
		return context.getSessionFactory()
				.getMetamodel()
				.entityPersister( ownerType.getTypeName() )
				.getEntityMetamodel();
	}
	else if ( persistenceType == Type.PersistenceType.MAPPED_SUPERCLASS ) {
		PersistentClass persistentClass =
				context.getPersistentClassHostingProperties( (MappedSuperclassTypeImpl<?>) ownerType );
		return context.getSessionFactory()
				.getMetamodel()
				.entityPersister( persistentClass.getClassName() )
				.getEntityMetamodel();
	}
	else {
		throw new AssertionFailure( "Cannot get the metamodel for PersistenceType: " + persistenceType );
	}
}
 
源代码4 项目: lams   文件: AttributeFactory.java
public static ParameterizedType getSignatureType(Member member) {
	final java.lang.reflect.Type type;
	if ( Field.class.isInstance( member ) ) {
		type = ( (Field) member ).getGenericType();
	}
	else if ( Method.class.isInstance( member ) ) {
		type = ( (Method) member ).getGenericReturnType();
	}
	else {
		type = ( (MapMember) member ).getType();
	}
	//this is a raw type
	if ( type instanceof Class ) {
		return null;
	}
	return (ParameterizedType) type;
}
 
源代码5 项目: lams   文件: SingularAttributeImpl.java
public SingularAttributeImpl(
		String name,
		Class<Y> javaType,
		AbstractManagedType<X> declaringType,
		Member member,
		boolean isIdentifier,
		boolean isVersion,
		boolean isOptional,
		Type<Y> attributeType,
		PersistentAttributeType persistentAttributeType) {
	super( name, javaType, declaringType, member, persistentAttributeType );
	this.isIdentifier = isIdentifier;
	this.isVersion = isVersion;
	this.isOptional = isOptional;
	this.attributeType = attributeType;
}
 
源代码6 项目: lams   文件: AbstractIdentifiableType.java
@Override
@SuppressWarnings("unchecked")
public Type<?> getIdType() {
	final SingularAttributeImpl id = locateIdAttribute();
	if ( id != null ) {
		return id.getType();
	}

	Set<SingularAttribute<? super X, ?>> idClassAttributes = getIdClassAttributesSafely();
	if ( idClassAttributes != null ) {
		if ( idClassAttributes.size() == 1 ) {
			return idClassAttributes.iterator().next().getType();
		}
	}

	return null;
}
 
源代码7 项目: lams   文件: AbstractFromImpl.java
private <Y> JoinImplementor<X, Y> constructJoin(SingularAttribute<? super X, Y> attribute, JoinType jt) {
	if ( Type.PersistenceType.BASIC.equals( attribute.getType().getPersistenceType() ) ) {
		throw new BasicPathUsageException( "Cannot join to attribute of basic type", attribute );
	}

	// TODO : runtime check that the attribute in fact belongs to this From's model/bindable

	if ( jt.equals( JoinType.RIGHT ) ) {
		throw new UnsupportedOperationException( "RIGHT JOIN not supported" );
	}

	final Class<Y> attributeType = attribute.getBindableJavaType();
	return new SingularAttributeJoin<X, Y>(
			criteriaBuilder(),
			attributeType,
			this,
			attribute,
			jt
	);
}
 
源代码8 项目: lams   文件: MapKeyHelpers.java
public MapKeyAttribute(CriteriaBuilderImpl criteriaBuilder, MapAttribute<?, K, ?> attribute) {
	this.attribute = attribute;
	this.jpaType = attribute.getKeyType();
	this.jpaBinableJavaType = attribute.getKeyJavaType();
	this.jpaBindableType = Type.PersistenceType
			.ENTITY.equals( jpaType.getPersistenceType() )
			? BindableType.ENTITY_TYPE
			: BindableType.SINGULAR_ATTRIBUTE;

	String guessedRoleName = determineRole( attribute );
	SessionFactoryImplementor sfi = criteriaBuilder.getEntityManagerFactory().getSessionFactory();
	mapPersister = sfi.getCollectionPersister( guessedRoleName );
	if ( mapPersister == null ) {
		throw new IllegalStateException( "Could not locate collection persister [" + guessedRoleName + "]" );
	}
	mapKeyType = mapPersister.getIndexType();
	if ( mapKeyType == null ) {
		throw new IllegalStateException( "Could not determine map-key type [" + guessedRoleName + "]" );
	}

	this.persistentAttributeType = mapKeyType.isEntityType()
			? PersistentAttributeType.MANY_TO_ONE
			: mapKeyType.isComponentType()
					? PersistentAttributeType.EMBEDDED
					: PersistentAttributeType.BASIC;
}
 
源代码9 项目: olingo-odata2   文件: JPAEdmPropertyTest.java
@Override
public Type<java.lang.String> getElementType() {
  return new Type<java.lang.String>() {

    @Override
    public Class<java.lang.String> getJavaType() {
      return java.lang.String.class;
    }

    @Override
    public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() {
      return null;
    }

  };
}
 
源代码10 项目: lams   文件: AttributeFactory.java
@SuppressWarnings({"unchecked"})
public <X, Y> AttributeImplementor<X, Y> buildAttribute(AbstractManagedType<X> ownerType, Property property) {
	if ( property.isSynthetic() ) {
		// hide synthetic/virtual properties (fabricated by Hibernate) from the JPA metamodel.
		LOG.tracef( "Skipping synthetic property %s(%s)", ownerType.getTypeName(), property.getName() );
		return null;
	}
	LOG.trace( "Building attribute [" + ownerType.getTypeName() + "." + property.getName() + "]" );
	final AttributeContext<X> attributeContext = wrap( ownerType, property );
	final AttributeMetadata<X, Y> attributeMetadata =
			determineAttributeMetadata( attributeContext, normalMemberResolver );
	if ( attributeMetadata == null ) {
		return null;
	}
	if ( attributeMetadata.isPlural() ) {
		return buildPluralAttribute( (PluralAttributeMetadata) attributeMetadata );
	}
	final SingularAttributeMetadata<X, Y> singularAttributeMetadata = (SingularAttributeMetadata<X, Y>) attributeMetadata;
	final Type<Y> metaModelType = getMetaModelType( singularAttributeMetadata.getValueContext() );
	return new SingularAttributeImpl<X, Y>(
			attributeMetadata.getName(),
			attributeMetadata.getJavaType(),
			ownerType,
			attributeMetadata.getMember(),
			false,
			false,
			property.isOptional(),
			metaModelType,
			attributeMetadata.getPersistentAttributeType()
	);
}
 
源代码11 项目: lams   文件: AttributeFactory.java
@SuppressWarnings("unchecked")
private <X, Y, E, K> AttributeImplementor<X, Y> buildPluralAttribute(PluralAttributeMetadata<X, Y, E> attributeMetadata) {
	final Type<E> elementType = getMetaModelType( attributeMetadata.getElementValueContext() );
	if ( java.util.Map.class.isAssignableFrom( attributeMetadata.getJavaType() ) ) {
		final Type<K> keyType = getMetaModelType( attributeMetadata.getMapKeyValueContext() );
		return PluralAttributeImpl.create(
				attributeMetadata.getOwnerType(),
				elementType,
				attributeMetadata.getJavaType(),
				keyType
		)
				.member( attributeMetadata.getMember() )
				.property( attributeMetadata.getPropertyMapping() )
				.persistentAttributeType( attributeMetadata.getPersistentAttributeType() )
				.build();
	}
	return PluralAttributeImpl.create(
			attributeMetadata.getOwnerType(),
			elementType,
			attributeMetadata.getJavaType(),
			null
	)
			.member( attributeMetadata.getMember() )
			.property( attributeMetadata.getPropertyMapping() )
			.persistentAttributeType( attributeMetadata.getPersistentAttributeType() )
			.build();
}
 
源代码12 项目: lams   文件: SingularAttributeImpl.java
public Identifier(
		String name,
		Class<Y> javaType,
		AbstractManagedType<X> declaringType,
		Member member,
		Type<Y> attributeType,
		PersistentAttributeType persistentAttributeType) {
	super( name, javaType, declaringType, member, true, false, false, attributeType, persistentAttributeType );
}
 
源代码13 项目: lams   文件: SingularAttributeImpl.java
public Version(
		String name,
		Class<Y> javaType,
		AbstractManagedType<X> declaringType,
		Member member,
		Type<Y> attributeType,
		PersistentAttributeType persistentAttributeType) {
	super( name, javaType, declaringType, member, false, true, false, attributeType, persistentAttributeType );
}
 
源代码14 项目: lams   文件: PluralAttributeImpl.java
public static <X,C,E,K> Builder<X,C,E,K> create(
		AbstractManagedType<X> ownerType,
		Type<E> attrType,
		Class<C> collectionClass,
		Type<K> keyType) {
	return new Builder<X,C,E,K>(ownerType, attrType, collectionClass, keyType);
}
 
源代码15 项目: 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();
}
 
源代码16 项目: lams   文件: AttributeFactory.java
@SuppressWarnings("unchecked")
private <Y> Type<Y> getMetaModelType(ValueContext typeContext) {
	switch ( typeContext.getValueClassification() ) {
		case BASIC: {
			return new BasicTypeImpl<Y>(
					typeContext.getBindableType(),
					Type.PersistenceType.BASIC
			);
		}
		case ENTITY: {
			final org.hibernate.type.EntityType type = (EntityType) typeContext.getValue().getType();
			return (Type<Y>) context.locateEntityType( type.getAssociatedEntityName() );
		}
		case EMBEDDABLE: {
			final Component component = (Component) typeContext.getValue();
			Class javaType;
			if ( component.getComponentClassName() == null ) {
				javaType = typeContext.getBindableType();
			}
			else {
				javaType = component.getComponentClass();
			}
			final EmbeddableTypeImpl<Y> embeddableType = new EmbeddableTypeImpl<Y>(
					javaType,
					typeContext.getAttributeMetadata().getOwnerType(),
					(ComponentType) typeContext.getValue().getType()
			);
			context.registerEmbeddedableType( embeddableType );
			final Iterator<Property> subProperties = component.getPropertyIterator();
			while ( subProperties.hasNext() ) {
				final Property property = subProperties.next();
				final AttributeImplementor<Y, Object> attribute = buildAttribute( embeddableType, property );
				if ( attribute != null ) {
					embeddableType.getBuilder().addAttribute( attribute );
				}
			}
			embeddableType.lock();
			return embeddableType;
		}
		default: {
			throw new AssertionFailure( "Unknown type : " + typeContext.getValueClassification() );
		}
	}
}
 
源代码17 项目: lams   文件: SingularAttributeImpl.java
@Override
public Type<Y> getType() {
	return attributeType;
}
 
源代码18 项目: lams   文件: PluralAttributeImpl.java
private Builder(AbstractManagedType<X> ownerType, Type<E> attrType, Class<C> collectionClass, Type<K> keyType) {
	this.type = ownerType;
	this.attributeType = attrType;
	this.collectionClass = collectionClass;
	this.keyType = keyType;
}
 
源代码19 项目: lams   文件: PluralAttributeImpl.java
@Override
public Type<E> getElementType() {
	return elementType;
}
 
源代码20 项目: lams   文件: PluralAttributeImpl.java
@Override
public Type<K> getKeyType() {
	return keyType;
}
 
源代码21 项目: lams   文件: MapKeyHelpers.java
@Override
public Type<K> getType() {
	return jpaType;
}
 
源代码22 项目: lams   文件: PluralAttributeJoinSupport.java
public boolean isBasicCollection() {
	return Type.PersistenceType.BASIC.equals( getAttribute().getElementType().getPersistenceType() );
}
 
源代码23 项目: olingo-odata2   文件: JPAEntityTypeMock.java
@Override
public Type<?> getIdType() {
  return null;
}
 
源代码24 项目: olingo-odata2   文件: JPAEntityTypeMock.java
@Override
public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() {
  return null;
}
 
源代码25 项目: olingo-odata2   文件: JPASingularAttributeMock.java
@Override
public Type<T> getType() {
  return null;
}
 
源代码26 项目: olingo-odata2   文件: JPAPluralAttributeMock.java
@Override
public Type<String> getElementType() {
  // TODO Auto-generated method stub
  return null;
}
 
@Override
public Type<java.lang.String> getElementType() {
  return new ElementType();
}
 
@Override
public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() {
  return PersistenceType.BASIC;
}
 
源代码29 项目: cloud-odata-java   文件: JPAEntityTypeMock.java
@Override
public Type<?> getIdType() {
  return null;
}
 
源代码30 项目: cloud-odata-java   文件: JPAEntityTypeMock.java
@Override
public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() {
  return null;
}
 
 类所在包
 同包方法