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; }
DirectFieldAccessFallbackBeanWrapper beanWrapper = new DirectFieldAccessFallbackBeanWrapper(value); for (SingularAttribute attribute : type.getSingularAttributes()) {
@SuppressWarnings("unchecked") @Override public Set<SingularAttribute<? super X, ?>> getSingularAttributes() { Set<SingularAttribute<? super X, ?>> singularAttrib = new HashSet<SingularAttribute<? super X, ?>>(); if (superClazzType != null) { Set parentAttrib = superClazzType.getSingularAttributes(); if (parentAttrib != null) { singularAttrib.addAll(parentAttrib); } } Set<SingularAttribute<X, ?>> declaredAttribSet = getDeclaredSingularAttributes(); if (declaredAttribSet != null) { singularAttrib.addAll(declaredAttribSet); } return singularAttrib; }
public <T> List<Predicate> byExample(ManagedType<T> mt, Path<T> mtPath, T mtValue, SearchParameters sp, CriteriaBuilder builder) { List<Predicate> predicates = newArrayList(); for (SingularAttribute<? super T, ?> attr : mt.getSingularAttributes()) { if (!isPrimaryKey(mt, attr)) { continue; } Object attrValue = jpaUtil.getValue(mtValue, attr); if (attrValue != null) { predicates.add(builder.equal(mtPath.get(jpaUtil.attribute(mt, attr)), attrValue)); } } return predicates; }
/** * Add a predicate for each simple property whose value is not null. */ public <T> List<Predicate> byExample(ManagedType<T> mt, Path<T> mtPath, T mtValue, SearchParameters sp, CriteriaBuilder builder) { List<Predicate> predicates = newArrayList(); for (SingularAttribute<? super T, ?> attr : mt.getSingularAttributes()) { if (!isPrimaryKey(mt, attr)) { continue; } Object attrValue = jpaUtil.getValue(mtValue, attr); if (attrValue != null) { predicates.add(builder.equal(mtPath.get(jpaUtil.attribute(mt, attr)), attrValue)); } } return predicates; }
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; }
/** * Returns the property name on the given entity type which the given database column is mapped to. * * <p> * If no field on the given type is mapped to this field (which is common in cases of a JPA relationship without an * actual {@link javax.persistence.Column} annotated field to represent the foreign key) then this method will * return null. * </p> * * @param entityType the entity type on which to search for a property that is mapped to the given column * @param databaseColumnName the name of the database column * * @return the name of the property on the given entity type which maps to the given column, or null if no such * mapping exists */ @SuppressWarnings({ "unchecked", "rawtypes" }) protected String getPropertyNameFromDatabaseColumnName(ManagedType entityType, String databaseColumnName) { for (SingularAttributeImpl attr : (Set<SingularAttributeImpl>) entityType.getSingularAttributes()) { if (!attr.isAssociation()) { if (!(attr.getClass().isAssignableFrom(EmbeddableTypeImpl.class)) && !(attr.getMapping().getClass().isAssignableFrom(AggregateObjectMapping.class)) && attr.getMapping().getField().getName().equals(databaseColumnName)) { return attr.getName(); } } } return null; }
jpaAttributes = (Set<SingularAttribute<?, ?>>) jpaManagedType.getSingularAttributes(); jpaAttributes = (Set<SingularAttribute<?, ?>>) jpaManagedType.getSingularAttributes();
/** * Add a predicate for each simple property whose value is not null. */ public <T> List<Predicate> byExample(ManagedType<T> mt, Path<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 // || attr.getPersistentAttributeType() == EMBEDDED) { continue; } Object attrValue = jpaUtil.getValue(mtValue, attr); if (attrValue != null) { if (attr.getJavaType() == String.class) { if (isNotEmpty((String) attrValue)) { predicates.add(jpaUtil.stringPredicate(mtPath.get(jpaUtil.stringAttribute(mt, attr)), attrValue, sp, builder)); } } else { predicates.add(builder.equal(mtPath.get(jpaUtil.attribute(mt, attr)), attrValue)); } } } return predicates; }
public <T> List<Predicate> byExample(ManagedType<T> mt, Path<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 // || attr.getPersistentAttributeType() == EMBEDDED) { continue; } Object attrValue = jpaUtil.getValue(mtValue, attr); if (attrValue != null) { if (attr.getJavaType() == String.class) { if (isNotEmpty((String) attrValue)) { predicates.add(jpaUtil.stringPredicate(mtPath.get(jpaUtil.stringAttribute(mt, attr)), attrValue, sp, builder)); } } else { predicates.add(builder.equal(mtPath.get(jpaUtil.attribute(mt, attr)), attrValue)); } } } return predicates; }
@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; }
/** * Invoke byExample method for each not null x-to-one association when their pk is not set. This allows you to search entities based on an associated * entity's properties value. */ @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; }
DirectFieldAccessFallbackBeanWrapper beanWrapper = new DirectFieldAccessFallbackBeanWrapper(value); for (SingularAttribute attribute : type.getSingularAttributes()) {
? new ArrayList<Attribute<?,?>>() : Arrays.asList(excludes); Set<SingularAttribute<? super T, ?>> attrs = type.getSingularAttributes(); for (SingularAttribute<? super T, ?> attr : attrs) { if (excludeAttr.contains(attr)
? new ArrayList<Attribute<?,?>>() : Arrays.asList(excludes); Set<SingularAttribute<? super T, ?>> attrs = type.getSingularAttributes(); for (SingularAttribute<? super T, ?> attr : attrs) { if (excludeAttr.contains(attr)
? new ArrayList<Attribute<?,?>>() : Arrays.asList(excludes); Set<SingularAttribute<? super T, ?>> attrs = type.getSingularAttributes(); for (SingularAttribute<? super T, ?> attr : attrs) { if (excludeAttr.contains(attr)
? new ArrayList<Attribute<?,?>>() : Arrays.asList(excludes); Set<SingularAttribute<? super T, ?>> attrs = type.getSingularAttributes(); for (SingularAttribute<? super T, ?> attr : attrs) { if (excludeAttr.contains(attr)