Refine search
String original = ((SingularAttributePath) path).getAttribute().getDeclaringType().getJavaType().getName() + "." + ((SingularAttributePath) path).getAttribute().getName() + "." + piece; String copy = path.getJavaType().getName() + "." + piece; copyCollectionPersister(original, copy, ((CriteriaBuilderImpl) builder).getEntityManagerFactory().getSessionFactory()); ManagedType mt = mm.managedType(clazz); try { Attribute attr = mt.getAttribute(piece); if (attr != null) { Root additionalRoot = criteria.from(clazz);
private String tryFindSingularIdAttributeNameOrUseFallback(Class<? extends Object> idPropertyValueType, String fallbackIdTypePropertyName) { ManagedType<? extends Object> idPropertyType = metamodel.managedType(idPropertyValueType); for (SingularAttribute<?, ?> sa : idPropertyType.getSingularAttributes()) { if (sa.isId()) { return sa.getName(); } } return fallbackIdTypePropertyName; }
private String resolveRole(PluralAttribute attribute) { switch ( attribute.getDeclaringType().getPersistenceType() ) { case ENTITY: { return attribute.getDeclaringType().getJavaType().getName() + '.' + attribute.getName(); role.insert( 1, singularAttributePath.getAttribute().getName() ); parentPath = singularAttributePath.getPathSource(); } while ( ( SingularAttributePath.class.isInstance( parentPath ) ) ); final EntityType entityType; if ( singularAttribute.getDeclaringType().getPersistenceType() == Type.PersistenceType.ENTITY ) { entityType = (EntityType) singularAttribute.getDeclaringType(); else if ( singularAttribute.getDeclaringType().getPersistenceType() == Type.PersistenceType.MAPPED_SUPERCLASS ){ String.format( "Unexpected PersistenceType: [%s]", singularAttribute.getDeclaringType().getPersistenceType() String.format( "Unexpected PersistenceType: [%s]", attribute.getDeclaringType().getPersistenceType()
.getAttribute("association"); Assert.assertNotNull(associationAttribute); Assert.assertEquals(PersistentAttributeType.ONE_TO_ONE, associationAttribute.getPersistentAttributeType()); Assert.assertEquals(AssociationEntity.class, associationAttribute.getJavaType()); Assert.assertEquals(true, associationAttribute.isAssociation()); Assert.assertEquals(OToOOwnerEntity.class, associationAttribute.getDeclaringType().getJavaType()); Assert.assertEquals("association", associationAttribute.getName());
.getAttribute("association"); Assert.assertNotNull(associationAttribute); Assert.assertEquals(PersistentAttributeType.ONE_TO_ONE, associationAttribute.getPersistentAttributeType()); Assert.assertEquals(AssociationBiEntity.class, associationAttribute.getJavaType()); Assert.assertEquals(true, associationAttribute.isAssociation()); Assert.assertEquals(OToOOwnerBiEntity.class, associationAttribute.getDeclaringType().getJavaType()); Assert.assertEquals("association", associationAttribute.getName()); Assert.assertEquals(OToOOwnerBiEntity.class, ownerAttribute.getJavaType()); Assert.assertEquals(true, ownerAttribute.isAssociation()); Assert.assertEquals(AssociationBiEntity.class, ownerAttribute.getDeclaringType().getJavaType()); Assert.assertEquals("owner", ownerAttribute.getName()); Assert.assertEquals(managedTypes.get(AssociationBiEntity.class), ownerAttribute.getDeclaringType()); Assert.assertEquals(OToOOwnerBiEntity.class, ownerAttribute.getJavaType()); Assert.assertEquals(managedTypes.get(OToOOwnerBiEntity.class), ((SingularAttribute<? super X, ?>) ownerAttribute).getType());
/** * Gets a new path that represents the given single-valued attribute from this path. */ public <Y> Path<Y> get(SingularAttribute<? super X, Y> attr) { if (getType() != attr.getDeclaringType()) { attr = (SingularAttribute)((ManagedType)getType()).getAttribute(attr.getName()); } return new PathImpl<X,Y>(this, (Members.SingularAttributeImpl<? super X, Y>)attr, attr.getJavaType()); }
@SuppressWarnings("unchecked") public <T extends Identifiable<?>, M2O extends Identifiable<?>> List<Predicate> byExampleOnXToOne(ManagedType<T> mt, Root<T> mtPath, T mtValue, SearchParameters sp, CriteriaBuilder builder) { List<Predicate> predicates = newArrayList(); for (SingularAttribute<? super T, ?> attr : mt.getSingularAttributes()) { if (attr.getPersistentAttributeType() == MANY_TO_ONE || attr.getPersistentAttributeType() == ONE_TO_ONE) { M2O m2oValue = (M2O) jpaUtil.getValue(mtValue, mt.getAttribute(attr.getName())); Class<M2O> m2oType = (Class<M2O>) attr.getBindableJavaType(); Path<M2O> m2oPath = (Path<M2O>) mtPath.get(attr); ManagedType<M2O> m2oMt = em.getMetamodel().entity(m2oType); if (m2oValue != null) { if (m2oValue.isIdSet()) { // we have an id, let's restrict only on this field predicates.add(builder.equal(m2oPath.get("id"), m2oValue.getId())); } else { predicates.addAll(byExample(m2oMt, m2oPath, m2oValue, sp, builder)); } } } } return predicates; }
? new ArrayList<Attribute<?,?>>() : Arrays.asList(excludes); Set<SingularAttribute<? super T, ?>> attrs = type.getSingularAttributes(); for (SingularAttribute<? super T, ?> attr : attrs) { if (excludeAttr.contains(attr) || (style.excludeIdentity() && attr.isId()) || (style.excludeVersion() && attr.isVersion())) { continue; || (style.excludeDefault() && isDefaultValue(attr.getJavaType(), value))) continue;
public <T> boolean isPk(ManagedType<T> mt, SingularAttribute<? super T, ?> attr) { try { Method m = MethodUtils.getAccessibleMethod(mt.getJavaType(), "get" + WordUtils.capitalize(attr.getName()), (Class<?>) null); if (m != null && m.getAnnotation(Id.class) != null) { return true; } Field field = mt.getJavaType().getField(attr.getName()); return field.getAnnotation(Id.class) != null; } catch (Exception e) { return false; } }
private void findMetamodelEntityGetters(ManagedType<?> entity, Collection<String> subclassNames) for (SingularAttribute<?,?> singularAttrib: entity.getDeclaredSingularAttributes()) Class<?> fieldJavaType = singularAttrib.getJavaType(); Member javaMember = singularAttrib.getJavaMember(); String name = javaMember.getName(); String altName = null; name = singularAttrib.getName(); String entityClassName = Type.getInternalName(entity.getJavaType()); if (entityClassName.equals(declaredClassName)) entityClassName = null; for (PluralAttribute<?,?,?> pluralAttrib: entity.getDeclaredPluralAttributes()) String entityClassName = Type.getInternalName(entity.getJavaType()); if (entityClassName.equals(declaredClassName)) entityClassName = null; String className = Type.getInternalName(entity.getJavaType()); List<String> newSubclasses = new ArrayList<>(subclassNames); newSubclasses.add(className);
toAttrJoinType = parentJoinAttr.getJavaType(); } else if( parentJoinAttr instanceof PluralAttribute ) { toAttrJoinType = ((PluralAttribute) parentJoinAttr).getElementType().getJavaType(); } else { String joinName = parentJoinAttr.getDeclaringType().getJavaType().getSimpleName() + "." + parentJoinAttr.getName(); throw new IllegalStateException("Unknown attribute type encountered when trying to join " + joinName );
for (Attribute<?, ?> attribute : attributes) { if (!(attribute instanceof SingularAttribute<?, ?>)) { throw new IllegalArgumentException("Plural attributes in embedded ids aren't supported yet! Remove attribute " + attribute.getName() + " of type " + attribute.getDeclaringType().getJavaType().getName()); if (attr.getType() instanceof javax.persistence.metamodel.BasicType<?>) { String attributeName = attributePrefix + attribute.getName(); String attributeMapping = mappingPrefix + attribute.getName(); String parameterName = attributeName; )); } else { ManagedType<?> managedType = (ManagedType<?>) attr.getType(); Set<Attribute<?, ?>> subAttributes; if (managedType instanceof EmbeddableType<?>) { subAttributes = (Set) managedType.getAttributes(); } else { subAttributes = new HashSet<>(); EntityType<?> entity = evm.getMetamodel().getEntityMetamodel().getEntity(entityClass); for (String propertyName : evm.getJpaProvider().getIdentifierOrUniqueKeyEmbeddedPropertyNames(entity, mappingPrefix + attribute.getName())) { subAttributes.add(managedType.getAttribute(propertyName));
/** * Creates a new {@link DefaultJpaContext} for the given {@link Set} of {@link EntityManager}s. * * @param entityManagers must not be {@literal null}. */ public DefaultJpaContext(Set<EntityManager> entityManagers) { Assert.notNull(entityManagers, "EntityManagers must not be null!"); Assert.notEmpty(entityManagers, "EntityManagers must not be empty!"); this.entityManagers = new LinkedMultiValueMap<Class<?>, EntityManager>(); for (EntityManager em : entityManagers) { for (ManagedType<?> managedType : em.getMetamodel().getManagedTypes()) { this.entityManagers.add(managedType.getJavaType(), em); } } }
DirectFieldAccessFallbackBeanWrapper beanWrapper = new DirectFieldAccessFallbackBeanWrapper(value); for (SingularAttribute attribute : type.getSingularAttributes()) { String currentPath = !StringUtils.hasText(path) ? attribute.getName() : path + "." + attribute.getName(); .apply(Optional.ofNullable(beanWrapper.getPropertyValue(attribute.getName())));
public static JPAMember create(Attribute<?, ?> jpaAttribute, Object target) { Member javaMember = jpaAttribute.getJavaMember(); if (javaMember instanceof Field) return new FieldMember((Field) javaMember, target); if (javaMember instanceof Method) return new GetterSetterMember((Method) javaMember, null, target); // http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_95:_20091017:_Attribute.getJavaMember.28.29_returns_null_for_a_BasicType_on_a_MappedSuperclass_because_of_an_uninitialized_accessor JPAMember rt = reverseEngineerJPAMember(jpaAttribute.getDeclaringType().getJavaType(), jpaAttribute.getName(), target); if (rt == null) throw new IllegalArgumentException("Could not find java member for: " + jpaAttribute); return rt; }
private String [] createOriginalAndExpectedKeys(Attribute embeddedAttr, PluralAttribute listAttr) { String originalKey = embeddedAttr.getDeclaringType().getJavaType().getName() + "." + embeddedAttr.getName() + "." + listAttr.getName(); String copyKey = listAttr.getDeclaringType().getJavaType().getName() + "." + listAttr.getName(); String [] keys = { originalKey, copyKey }; return keys; }
private Attribute<?, ?> findCorrespondingAssociation(final IntermediateStructuredType sourceType, final String sourceRelationshipName) { Class<?> targetClass = null; for (final Attribute<?, ?> jpaAttribute : jpaManagedType.getAttributes()) { if (jpaAttribute.getPersistentAttributeType() != null && jpaAttribute.getJavaMember() instanceof AnnotatedElement && !sourceRelationshipName.equals(IntNameBuilder.buildAssociationName(jpaAttribute))) { if (jpaAttribute.isCollection()) { targetClass = ((PluralAttribute<?, ?, ?>) jpaAttribute).getElementType().getJavaType(); } else { targetClass = jpaAttribute.getJavaType(); } if (targetClass.equals(sourceType.getTypeClass())) { final OneToMany cardinalityOtM = ((AnnotatedElement) jpaAttribute.getJavaMember()).getAnnotation( OneToMany.class); if (cardinalityOtM != null && cardinalityOtM.mappedBy() != null && cardinalityOtM.mappedBy().equals(sourceRelationshipName)) return jpaAttribute; } } } return null; }
private Attribute<?, ?> getAttribute(ManagedType<?> ownerType, String attributeName) { if (attributeName.indexOf('.') == -1) { return ownerType.getAttribute(attributeName); } ManagedType<?> t = ownerType; SingularAttribute<?, ?> attr = null; String[] parts = attributeName.split("\\."); for (int i = 0; i < parts.length; i++) { attr = t.getSingularAttribute(parts[i]); if (attr.getType().getPersistenceType() != Type.PersistenceType.BASIC) { t = (ManagedType<?>) attr.getType(); } else if (i + 1 != parts.length) { throw new IllegalArgumentException("Illegal attribute name for type [" + ownerType.getJavaType().getName() + "]: " + attributeName); } } return attr; }
public <X,Y> Fetch<X, Y> fetch(String name, JoinType jt) { assertJoinable(type); Attribute<? super X,?> attr = ((ManagedType<X>)type).getAttribute(name); if (attr.isCollection()) { return fetch((PluralAttribute)attr, jt); } else { return fetch(((SingularAttribute)attr), jt); } }
@Override @SuppressWarnings("unchecked") default Class<J> getClassType() { return getGraphedType().getJavaType(); } }