@Override public Set<Attribute<? super X, ?>> getAttributes() { Set<Attribute<? super X, ?>> attributes = new HashSet<Attribute<? super X, ?>>(); Set<Attribute<X, ?>> declaredAttribs = getDeclaredAttributes(); if (declaredAttribs != null) { attributes.addAll(declaredAttribs); } if (superClazzType != null) { attributes.addAll(superClazzType.getAttributes()); } return attributes; }
/** * INTERNAL: * Return a List of all attributes for all ManagedTypes. * @return */ public List<Attribute> getAllManagedTypeAttributes() { List<Attribute> attributeList = new ArrayList<Attribute>(); for(ManagedType managedType : this.managedTypes.values()) { attributeList.addAll(managedType.getAttributes()); } return attributeList; }
/** * Gets the attributes of the given type in defined order. * @param type */ public static List<Attribute<?,?>> getAttributesInOrder(ManagedType<?> type) { List<Attribute<?,?>> list = new ArrayList<Attribute<?,?>>(type.getAttributes()); Collections.sort(list, new AttributeComparator()); return list; }
/** * Verifies if a class metamodel has the specified property. * * @param property Property name. * @param classMetadata Class metamodel that may hold that property. * @return <tt>true</tt> if the class has that property, <tt>false</tt> otherwise. */ private static <T> boolean hasPropertyName(String property, ManagedType<T> classMetadata) { Set<Attribute<? super T, ?>> names = classMetadata.getAttributes(); for (Attribute<? super T, ?> name : names) { if (name.getName().equals(property)) return true; } return false; }
/** * Delete the managed entities. Self referencing rows are set to NULL before the deletion. * * @param beanTypes * the ordered set to clean. */ public void cleanup(final Class<?>... beanTypes) { // Clean the data for (int i = beanTypes.length; i-- > 0;) { final Class<?> entityClass = beanTypes[i]; final String update = em.getMetamodel().managedType(entityClass).getAttributes().stream() .filter(a -> a.getJavaType().equals(entityClass)).map(Attribute::getName) .map(name -> name + "=NULL").collect(Collectors.joining(", ")); if (update.length() > 0) { // Clear the self referencing rows em.createQuery("UPDATE " + entityClass.getName() + " SET " + update).executeUpdate(); } em.createQuery("DELETE FROM " + entityClass.getName()).executeUpdate(); } em.flush(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) private void discoverEnumTypes(Set<Class<?>> seenTypesForEnumResolving, Map<String, Class<Enum<?>>> enumTypes, ManagedType<?> t) { if (!(t instanceof EntityType<?>)) { // Only discover entity types return; } if (!seenTypesForEnumResolving.add(t.getJavaType())) { return; } for (Attribute<?, ?> attribute : (Set<Attribute<?, ?>>) (Set) t.getAttributes()) { discoverEnumTypes(seenTypesForEnumResolving, enumTypes, t.getJavaType(), attribute); } }
public Set<Attribute<? super X, ?>> getAttributes() { Set<Attribute<? super X, ?>> set = new HashSet<Attribute<? super X,?>>(); set.addAll(attributes.values()); if (cmd.getSuperAbstractClassMetaData() != null) { // Relay to the supertype Class supercls = model.getClassLoaderResolver().classForName(cmd.getSuperAbstractClassMetaData().getFullClassName()); ManagedType supertype = model.managedType(supercls); Set<Attribute<? super X, ?>> superattrs = supertype.getAttributes(); set.addAll(superattrs); } return set; }
ManagedType<X> jpaType = metamodel.managedType((Class<X>) lhs.getClass()); for (Attribute<? super X, ?> attr : jpaType.getAttributes()) { Object lhsVal = attributeAccessor.get(attr, lhs); Object rhsVal = attributeAccessor.get(attr, rhs);
/** * Return JPA managed properties. * * @param <T> * Bean type. * @param beanType * the bean type. * @return the headers built from given type. */ public <T> String[] getJpaHeaders(final Class<T> beanType) { // Build descriptor list respecting the declaration order final OrderedFieldCallback fieldCallBack = new OrderedFieldCallback(); ReflectionUtils.doWithFields(beanType, fieldCallBack); final List<String> orderedDescriptors = fieldCallBack.descriptorsOrdered; // Now filter the properties final List<String> descriptorsFiltered = new ArrayList<>(); final ManagedType<T> managedType = transactionManager.getEntityManagerFactory().getMetamodel() .managedType(beanType); for (final String propertyDescriptor : orderedDescriptors) { for (final Attribute<?, ?> attribute : managedType.getAttributes()) { // Match only basic attributes if (attribute instanceof SingularAttribute<?, ?> && propertyDescriptor.equals(attribute.getName())) { descriptorsFiltered.add(attribute.getName()); break; } } } // Initialize the CSV reader return descriptorsFiltered.toArray(new String[descriptorsFiltered.size()]); }
} else { ManagedType<?> managedType = ((BasicTypeImpl<?>) type).getManagedType(); for (Attribute<?, ?> attribute : managedType.getAttributes()) { if (attribute.getName().equals(mapping)) { attributeEntry.possibleAttributes.add(new AttributeEntry(this, managedType, attribute));
static OEntityKey toOEntityKey(Object jpaEntity, SingularAttribute<?, ?> idAtt) { boolean hasEmbeddedCompositeKey = idAtt.getPersistentAttributeType() == PersistentAttributeType.EMBEDDED; if (!hasEmbeddedCompositeKey) { Object id = SetResponseCommand.getIdValue(jpaEntity, idAtt, null); return OEntityKey.create(id); } ManagedType<?> keyType = (ManagedType<?>) idAtt.getType(); Map<String, Object> nameValues = new HashMap<String, Object>(); for (Attribute<?, ?> att : keyType.getAttributes()) nameValues.put(att.getName(), SetResponseCommand.getIdValue(jpaEntity, idAtt, att.getName())); return OEntityKey.create(nameValues); }
protected List<EdmProperty.Builder> getProperties(String modelNamespace, ManagedType<?> et) { List<EdmProperty.Builder> properties = new ArrayList<EdmProperty.Builder>(); for (Attribute<?, ?> att : et.getAttributes()) { if (att.isCollection()) {} else { SingularAttribute<?, ?> sa = (SingularAttribute<?, ?>) att; Type<?> type = sa.getType(); // Do we have an embedded composite key here? If so, we have to flatten the @EmbeddedId since // only any set of non-nullable, immutable, <EDMSimpleType> declared properties MAY serve as the key. if (sa.isId() && type.getPersistenceType() == PersistenceType.EMBEDDABLE) { properties.addAll(getProperties(modelNamespace, (ManagedType<?>) sa.getType())); } else if (type.getPersistenceType().equals(PersistenceType.BASIC) || type.getPersistenceType().equals(PersistenceType.EMBEDDABLE)) { EdmProperty.Builder prop = toEdmProperty(modelNamespace, sa); properties.add(prop); } } } return properties; }
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; }
Set<Attribute> attributes = type.getAttributes(); for (Attribute attribute : attributes) { if (attribute instanceof SingularAttribute) {
@SuppressWarnings({ "unchecked", "rawtypes" }) private TemporaryExtendedManagedType collectColumnNames(EntityType<?> e, Map<String, AttributeEntry<?, ?>> attributeMap, String parent, List<Attribute<?, ?>> parents, String elementCollectionPath, ManagedType<?> type, Map<String, TemporaryExtendedManagedType> temporaryExtendedManagedTypes, Set<Class<?>> seenTypesForEnumResolving, Map<String, Class<Enum<?>>> enumTypes) { Set<Attribute<?, ?>> attributes = (Set<Attribute<?, ?>>) (Set) type.getAttributes(); TemporaryExtendedManagedType extendedManagedType = temporaryExtendedManagedTypes.get(JpaMetamodelUtils.getTypeName(type)); if (extendedManagedType == null) {
.build() .fields(managedType.getAttributes().stream() .filter(this::isValidInput) .filter(this::isNotIgnored)
Set<Attribute<?, ?>> attributes = (Set) type.getManagedType().getAttributes(); Map<AttributeAccessor, BasicAttributeFlusher> componentFlushers = new HashMap<>(attributes.size()); buildComponentFlushers(evm, viewType.getEntityClass(), type.getJavaType(), attributeName + "_", attributeMapping + ".", "", attributes, componentFlushers);
Set<Attribute<?, ?>> subAttributes; if (managedType instanceof EmbeddableType<?>) { subAttributes = (Set) managedType.getAttributes(); } else { subAttributes = new HashSet<>();
private void addSingularAttributes(MetadataFactory mf, Metamodel model, ManagedType<?> entity, Table entityTable, List<String> path) throws TranslatorException { List<Attribute<?,?>> attributes = new ArrayList<>(entity.getAttributes()); Collections.sort(attributes, Comparator.comparing(Attribute::getName));
if (elementDescriptor.isJpaEmbeddable()) { if (!jpaProvider.supportsUpdateSetEmbeddable()) { Set<Attribute<?, ?>> attributes = (Set) attributeType.getManagedType().getAttributes(); Map<AttributeAccessor, BasicAttributeFlusher> componentFlushers = new HashMap<>(attributes.size()); buildComponentFlushers(evm, viewType.getEntityClass(), attributeType.getJavaType(), attributeName + "_", attributeMapping + ".", "", attributes, componentFlushers);