use of jakarta.persistence.metamodel.PluralAttribute in project hibernate-orm by hibernate.
the class AbstractManagedType method getDeclaredSet.
@Override
@SuppressWarnings("unchecked")
public <E> SetAttribute<J, E> getDeclaredSet(String name, Class<E> elementType) {
final PluralAttribute attribute = findDeclaredPluralAttribute(name);
checkSetElementType(attribute, name, elementType);
return (SetAttribute<J, E>) attribute;
}
use of jakarta.persistence.metamodel.PluralAttribute in project hibernate-orm by hibernate.
the class AbstractManagedType method getDeclaredList.
@Override
@SuppressWarnings("unchecked")
public <E> ListAttribute<J, E> getDeclaredList(String name, Class<E> elementType) {
final PluralAttribute attribute = findDeclaredPluralAttribute(name);
checkListElementType(attribute, name, elementType);
return (ListAttribute<J, E>) attribute;
}
use of jakarta.persistence.metamodel.PluralAttribute in project eclipselink by eclipse-ee4j.
the class FromImpl method join.
@Override
public <T, Y> Join<T, Y> join(String attributeName, JoinType jt) {
Attribute attribute = this.managedType.getAttribute(attributeName);
if (attribute.isCollection()) {
org.eclipse.persistence.expressions.Expression node;
if (jt.equals(JoinType.INNER)) {
node = this.currentNode.anyOf(attribute.getName());
} else if (jt.equals(JoinType.RIGHT)) {
throw new UnsupportedOperationException(ExceptionLocalization.buildMessage("RIGHT_JOIN_NOT_SUPPORTED"));
} else {
node = this.currentNode.anyOfAllowingNone(attribute.getName());
}
Join join;
if (((PluralAttribute) attribute).getElementType().getPersistenceType().equals(PersistenceType.BASIC)) {
if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.COLLECTION)) {
join = new BasicCollectionJoinImpl(this, this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), node, (Bindable) attribute, jt);
} else if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.LIST)) {
join = new BasicListJoinImpl(this, this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), node, (Bindable) attribute, jt);
} else if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.SET)) {
join = new BasicSetJoinImpl(this, this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), node, (Bindable) attribute, jt);
} else {
join = new BasicMapJoinImpl(this, this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), node, (Bindable) attribute, jt);
}
} else {
if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.COLLECTION)) {
join = new CollectionJoinImpl(this, metamodel.managedType(((PluralAttribute) attribute).getBindableJavaType()), this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), node, (Bindable) attribute, jt);
} else if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.LIST)) {
join = new ListJoinImpl(this, metamodel.managedType(((PluralAttribute) attribute).getBindableJavaType()), this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), node, (Bindable) attribute, jt);
} else if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.SET)) {
join = new SetJoinImpl(this, metamodel.managedType(((PluralAttribute) attribute).getBindableJavaType()), this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), node, (Bindable) attribute, jt);
} else {
join = new MapJoinImpl(this, metamodel.managedType(((PluralAttribute) attribute).getBindableJavaType()), this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), node, (Bindable) attribute, jt);
}
}
this.joins.add(join);
((FromImpl) join).isJoin = true;
return join;
} else {
return join(((SingularAttribute) attribute), jt);
}
}
use of jakarta.persistence.metamodel.PluralAttribute in project eclipselink by eclipse-ee4j.
the class FromImpl method get.
@Override
public <Y> Path<Y> get(String attName) {
Attribute attribute = this.managedType.getAttribute(attName);
Join join;
if (attribute.isCollection()) {
if (!((PluralAttribute) attribute).getElementType().getPersistenceType().equals(PersistenceType.BASIC)) {
if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.COLLECTION)) {
join = new CollectionJoinImpl<X, Y>(this, metamodel.managedType(((PluralAttribute) attribute).getBindableJavaType()), this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), this.currentNode.anyOf(attribute.getName()), (Bindable) attribute);
} else if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.LIST)) {
join = new ListJoinImpl<X, Y>(this, metamodel.managedType(((PluralAttribute) attribute).getBindableJavaType()), this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), this.currentNode.anyOf(attribute.getName()), (Bindable) attribute);
} else if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.SET)) {
join = new SetJoinImpl<X, Y>(this, metamodel.managedType(((PluralAttribute) attribute).getBindableJavaType()), this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), this.currentNode.anyOf(attribute.getName()), (Bindable) attribute);
} else {
join = new MapJoinImpl(this, metamodel.managedType(((PluralAttribute) attribute).getBindableJavaType()), this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), this.currentNode.anyOf(attribute.getName()), (Bindable) attribute);
}
} else {
if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.COLLECTION)) {
join = new BasicCollectionJoinImpl<X, Y>(this, this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), this.currentNode.anyOf(attribute.getName()), (Bindable) attribute);
} else if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.LIST)) {
join = new BasicListJoinImpl<X, Y>(this, this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), this.currentNode.anyOf(attribute.getName()), (Bindable) attribute);
} else if (((PluralAttribute) attribute).getCollectionType().equals(CollectionType.SET)) {
join = new BasicSetJoinImpl<X, Y>(this, this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), this.currentNode.anyOf(attribute.getName()), (Bindable) attribute);
} else {
join = new BasicMapJoinImpl(this, this.metamodel, ((PluralAttribute) attribute).getBindableJavaType(), this.currentNode.anyOf(attribute.getName()), (Bindable) attribute);
}
}
} else {
Class<Y> clazz = ((SingularAttribute) attribute).getBindableJavaType();
if (((SingularAttribute) attribute).getType().getPersistenceType().equals(PersistenceType.BASIC)) {
return new PathImpl<Y>(this, this.metamodel, clazz, this.currentNode.get(attribute.getName()), (Bindable) attribute);
} else {
join = new JoinImpl(this, this.metamodel.managedType(clazz), this.metamodel, clazz, this.currentNode.get(attribute.getName()), (Bindable) attribute);
}
}
this.joins.add(join);
return join;
}
use of jakarta.persistence.metamodel.PluralAttribute in project eclipselink by eclipse-ee4j.
the class MetamodelMetamodelTest method testManagedType_getDeclaredPluralAttributes_root_entity_Method.
public void testManagedType_getDeclaredPluralAttributes_root_entity_Method() {
EntityManager em = null;
boolean expectedIAExceptionThrown = false;
try {
em = privateTestSetup();
assertNotNull(em);
Metamodel metamodel = em.getMetamodel();
assertNotNull("The metamodel should never be null after an em.getMetamodel() call here.", metamodel);
EntityTypeImpl<Computer> entityComputer_ = (EntityTypeImpl) metamodel.entity(Computer.class);
assertNotNull(entityComputer_);
// This also tests getCollections()
expectedIAExceptionThrown = false;
Set<PluralAttribute<Computer, ?, ?>> collections = entityComputer_.getDeclaredPluralAttributes();
assertNotNull(collections);
} catch (IllegalArgumentException iae) {
iae.printStackTrace();
expectedIAExceptionThrown = true;
} finally {
cleanup(em);
assertFalse("An IAE exception should not occur here.", expectedIAExceptionThrown);
}
}
Aggregations