javax.persistence.metamodel.Type Java Examples
The following examples show how to use
javax.persistence.metamodel.Type.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AttributeFactory.java From lams with GNU General Public License v2.0 | 6 votes |
@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() ); }
Example #2
Source File: JPAEdmPropertyTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@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; } }; }
Example #3
Source File: MapKeyHelpers.java From lams with GNU General Public License v2.0 | 6 votes |
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; }
Example #4
Source File: AbstractFromImpl.java From lams with GNU General Public License v2.0 | 6 votes |
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 ); }
Example #5
Source File: AbstractIdentifiableType.java From lams with GNU General Public License v2.0 | 6 votes |
@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; }
Example #6
Source File: SingularAttributeImpl.java From lams with GNU General Public License v2.0 | 6 votes |
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; }
Example #7
Source File: AttributeFactory.java From lams with GNU General Public License v2.0 | 6 votes |
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 ); } }
Example #8
Source File: AttributeFactory.java From lams with GNU General Public License v2.0 | 6 votes |
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; }
Example #9
Source File: AttributeFactory.java From lams with GNU General Public License v2.0 | 6 votes |
@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() ); }
Example #10
Source File: SingularAttributeImpl.java From lams with GNU General Public License v2.0 | 5 votes |
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 ); }
Example #11
Source File: SingularAttributeImpl.java From lams with GNU General Public License v2.0 | 5 votes |
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 ); }
Example #12
Source File: PluralAttributeImpl.java From lams with GNU General Public License v2.0 | 5 votes |
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); }
Example #13
Source File: AttributeFactory.java From lams with GNU General Public License v2.0 | 5 votes |
@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() ); }
Example #14
Source File: SingularAttributeJoin.java From lams with GNU General Public License v2.0 | 5 votes |
@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(); }
Example #15
Source File: AttributeFactory.java From lams with GNU General Public License v2.0 | 5 votes |
@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(); }
Example #16
Source File: JPAPluralAttributeMock.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Override public Type<String> getElementType() { // TODO Auto-generated method stub return null; }
Example #17
Source File: JPAEdmNavigationPropertyTest.java From cloud-odata-java with Apache License 2.0 | 4 votes |
@Override public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() { return PersistenceType.BASIC; }
Example #18
Source File: JPAEdmNavigationPropertyTest.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Override public Type<java.lang.String> getElementType() { return new ElementType(); }
Example #19
Source File: JPAEdmNavigationPropertyTest.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Override public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() { return PersistenceType.BASIC; }
Example #20
Source File: JPAEntityTypeMock.java From cloud-odata-java with Apache License 2.0 | 4 votes |
@Override public Type<?> getIdType() { return null; }
Example #21
Source File: JPAEntityTypeMock.java From cloud-odata-java with Apache License 2.0 | 4 votes |
@Override public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() { return null; }
Example #22
Source File: JPASingularAttributeMock.java From cloud-odata-java with Apache License 2.0 | 4 votes |
@Override public Type<T> getType() { return null; }
Example #23
Source File: JPAPluralAttributeMock.java From cloud-odata-java with Apache License 2.0 | 4 votes |
@Override public Type<String> getElementType() { // TODO Auto-generated method stub return null; }
Example #24
Source File: JPAEdmNavigationPropertyTest.java From cloud-odata-java with Apache License 2.0 | 4 votes |
@Override public Type<java.lang.String> getElementType() { return new ElementType(); }
Example #25
Source File: JPASingularAttributeMock.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Override public Type<T> getType() { return null; }
Example #26
Source File: JPAEntityTypeMock.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Override public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() { return null; }
Example #27
Source File: JPAEntityTypeMock.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Override public Type<?> getIdType() { return null; }
Example #28
Source File: PluralAttributeJoinSupport.java From lams with GNU General Public License v2.0 | 4 votes |
public boolean isBasicCollection() { return Type.PersistenceType.BASIC.equals( getAttribute().getElementType().getPersistenceType() ); }
Example #29
Source File: MapKeyHelpers.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public Type<K> getType() { return jpaType; }
Example #30
Source File: AttributeFactory.java From lams with GNU General Public License v2.0 | 4 votes |
@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() ); } } }