Refine search
SingularAttribute<?, ?> id = root.getModel().getId(root.getModel().getIdType().getJavaType()); query = query.multiselect(root.get((SingularAttribute) id).alias(id.getName())); .map(it -> (Selection<?>) root.get((SingularAttribute) it).alias(it.getName())) .collect(Collectors.toList()));
public boolean isBasicCollection() { return Type.PersistenceType.BASIC.equals( getAttribute().getElementType().getPersistenceType() ); }
private String getIdAttribute(Class<?> entityClass) { EntityType<?> entityType = entityManager.getMetamodel().entity(entityClass); return entityType.getDeclaredId(entityType.getIdType().getJavaType()).getName(); }
public <Y> Join<X, Y> join(SingularAttribute<? super X, Y> attribute, JoinType jt) { if (((SingularAttribute)attribute).getType().getPersistenceType().equals(PersistenceType.BASIC)){ throw new IllegalStateException(ExceptionLocalization.buildMessage("CAN_NOT_JOIN_TO_BASIC")); } Class clazz = attribute.getBindableJavaType(); Join<X, Y> join = null; ObjectExpression exp = ((ObjectExpression)this.currentNode).newDerivedExpressionNamed(attribute.getName()); if (jt.equals(JoinType.LEFT)){ exp.doUseOuterJoin(); }else if(jt.equals(JoinType.RIGHT)){ throw new UnsupportedOperationException(ExceptionLocalization.buildMessage("RIGHT_JOIN_NOT_SUPPORTED")); }else{ exp.doNotUseOuterJoin(); } join = new JoinImpl<X, Y>(this, this.metamodel.managedType(clazz), this.metamodel, clazz, exp, attribute, jt); this.joins.add(join); ((FromImpl)join).isJoin = true; return join; }
protected boolean isValidKeyType(Object key) { return emf.getMetamodel().entity(configuration.entityClass()).getIdType().getJavaType().isAssignableFrom(key.getClass()); }
toAttrJoinType = parentJoinAttr.getJavaType(); } else if( parentJoinAttr instanceof PluralAttribute ) { toAttrJoinType = ((PluralAttribute) parentJoinAttr).getElementType().getJavaType(); } else { String joinName = parentJoinAttr.getDeclaringType().getJavaType().getSimpleName() + "." + parentJoinAttr.getName();
EntityManager entityManager = Em.get(); Metamodel metamodel = entityManager.getMetamodel(); ManagedType<T> managedType = metamodel.managedType(paramTypeToCreate); EntityTypeImpl<T> entityType = (EntityTypeImpl<T>) managedType; Class<?> idClazz = entityType.getIdType().getJavaType(); SingularAttribute<? super T, ?> idAttribute = entityType.getId(idClazz); String name = idAttribute.getName(); ParamNode paramNode = tree.get(name);
private void addPrimaryKey(MetadataFactory mf, Metamodel model, EntityType<?> entity, Table entityTable) throws TranslatorException { if (entity.getIdType().getPersistenceType().equals(PersistenceType.BASIC)) { SingularAttribute<?, ?> pkattr = entity.getId(entity.getIdType().getJavaType()); addColumn(mf, pkattr.getName(), TypeFacility.getDataTypeName(getJavaDataType(pkattr.getJavaType())), entityTable); mf.addPrimaryKey("PK_"+entity.getName(), Arrays.asList(pkattr.getName()), entityTable); //$NON-NLS-1$ else if (entity.getIdType().getPersistenceType().equals(PersistenceType.EMBEDDABLE)) { SingularAttribute<?, ?> pkattr = entity.getId(entity.getIdType().getJavaType()); for (EmbeddableType<?> embeddable:model.getEmbeddables()) { if (embeddable.getJavaType().equals(pkattr.getJavaType())) { addSingularAttributes(mf, model, embeddable, entityTable, Collections.singletonList(pkattr.getName()));
@Nullable private Class<?> tryExtractIdTypeWithFallbackToIdTypeLookup() { try { Type<?> idType2 = type.getIdType(); return idType2 == null ? fallbackIdTypeLookup(type) : idType2.getJavaType(); } catch (IllegalStateException e) { // see https://hibernate.onjira.com/browse/HHH-6951 return fallbackIdTypeLookup(type); } }
private <T> Query createFinderQuery(final EntityManager entityManager, final String methodName, final Class<T> entityType, final Object[] args) { final List<String> conditions = parseMethodName(methodName); final EntityType<T> et = entityManager.getMetamodel().entity(entityType); final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); final SingularAttribute<? super T, ?> attribute = et.getSingularAttribute(condition); final Path<?> path = from.get(attribute); final Class<?> javaType = attribute.getType().getJavaType();
@Override public Class<?> validate(Class<?> parent, String property, Class<?> propertyType) { try { ManagedType managedType = metamodel.managedType(parent); Attribute attribute = managedType.getAttribute(property); if (attribute instanceof PluralAttribute) { return ((PluralAttribute) attribute).getElementType().getJavaType(); } else { return Primitives.wrap(attribute.getJavaType()); } } catch (IllegalArgumentException e) { return null; } } }
/** * Assert on embeddable. * * @param embeddableAttrib * the embeddable attrib * @param clazz * the clazz */ @SuppressWarnings({ "rawtypes", "unchecked" }) private void assertOnEmbeddable(SingularAttribute embeddableAttrib, Class clazz) { Assert.assertNotNull(embeddableAttrib); Assert.assertEquals(PersistentAttributeType.EMBEDDED, embeddableAttrib.getPersistentAttributeType()); Assert.assertEquals(PersistenceType.EMBEDDABLE, embeddableAttrib.getType().getPersistenceType()); Assert.assertEquals(clazz, embeddableAttrib.getType().getJavaType()); }
private <Y> AbstractJoin<X, Y> constructJoin(SingularAttribute<? super X, Y> attribute, String alias, JoinType jt) { if (Type.PersistenceType.BASIC.equals(attribute.getType().getPersistenceType())) { throw new IllegalArgumentException("Cannot join to attribute of basic type: " + attribute.getJavaType().getName()); } checkJoin(attribute, jt); final Class<Y> attributeType = attribute.getBindableJavaType(); SingularAttributeJoin<X, Y> join = new SingularAttributeJoin<X, Y>(criteriaBuilder, attributeType, this, attribute, jt); join.setAlias(alias); return join; }
Class<?> collectionElementClass = cd.getElementType().getJavaType(); EntityType<?> elementEntityType = entityManager.getMetamodel().entity(collectionElementClass); collection.setName(cd.getName()); collection.setRelatedType(collectionElementClass); populateImplementationSpecificCollectionLevelMetadata(collection, cd); PersistentAttributeType persistentAttributeType = cd.getPersistentAttributeType();
@Override public List<String> getIdentifierOrUniqueKeyEmbeddedPropertyNames(EntityType<?> ownerType, String attributeName) { Attribute<?, ?> attribute = getAttribute(ownerType, attributeName); if (((SingularAttribute<?, ?>) attribute).getType() instanceof EntityType<?>) { EntityType<?> entityType = (EntityType<?>) ((SingularAttribute<?, ?>) attribute).getType(); if (entityType.hasSingleIdAttribute()) { return Collections.singletonList(entityType.getId(entityType.getIdType().getJavaType()).getName()); } else { Set<SingularAttribute<?, ?>> attributes = (Set<SingularAttribute<?, ?>>) (Set) entityType.getIdClassAttributes(); List<String> attributeNames = new ArrayList<>(attributes.size()); for (Attribute<?, ?> attr : attributes) { attributeNames.add(attr.getName()); } return attributeNames; } } return Collections.emptyList(); }
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); Class 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{
@Override public boolean isCompositeNode(Attribute<?, ?> attr) { if (attr.isCollection()) { PluralAttribute<?, ?, ?> pluralAttribute = (PluralAttribute<?, ?, ?>) attr; if (pluralAttribute.getElementType().getPersistenceType() == Type.PersistenceType.BASIC) { return false; } return true; } SingularAttribute<?, ?> singularAttribute = (SingularAttribute<?, ?>) attr; // This is a special case for datanucleus... apparently an embedded id is an ONE_TO_ONE association although I think it should be an embedded // TODO: create a test case for datanucleus and report the problem if (singularAttribute.isId()) { return false; } return attr.getPersistentAttributeType() == Attribute.PersistentAttributeType.MANY_TO_ONE || attr.getPersistentAttributeType() == Attribute.PersistentAttributeType.ONE_TO_ONE; }
private Type<?> getType(Type<?> baseType, Attribute<?, ?> attribute) { if (attribute instanceof PluralAttribute<?, ?, ?>) { return metamodel.type(((PluralAttribute<?, ?, ?>) attribute).getJavaType()); } Class<?> baseClass = baseType.getJavaType(); if (baseClass != null) { Class<?> clazz = JpaMetamodelUtils.resolveFieldClass(baseType.getJavaType(), attribute); if (clazz != null) { return metamodel.type(clazz); } } return ((SingularAttribute<?, ?>) attribute).getType(); }
public JPACollectionType(PluralAttribute<?,?,?> collection, SecureEntity secureEntity) { super(collection.getName(), collection.getJavaType(), collection.getElementType().getJavaType(), secureEntity); String relName = StringUtilities.singularize(collection.getName()); this.idsFieldDefinition = new FieldDefinition( relName + AdaptrexEntityType.COLLECTION_IDS_NAME, ExtTypeFormatter.AUTO ); String capName = StringUtilities.capitalize(getName()); Class<?> declaringClass = collection.getDeclaringType().getJavaType(); try { getter = declaringClass.getMethod("get" + capName); } catch (Exception e) {} if (getter == null) return; try { setter = declaringClass.getMethod("set" + capName, getter.getReturnType()); } catch (Exception e) {} }
org.eclipse.persistence.expressions.Expression node; if (jt.equals(JoinType.INNER)) { node = this.currentNode.anyOf(((PluralAttribute) attribute).getName()); } else if (jt.equals(JoinType.RIGHT)) { throw new UnsupportedOperationException(ExceptionLocalization.buildMessage("RIGHT_JOIN_NOT_SUPPORTED")); } else { node = this.currentNode.anyOfAllowingNone(((PluralAttribute) attribute).getName()); 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); 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);