use of org.apache.deltaspike.data.impl.property.query.NamedPropertyCriteria in project deltaspike by apache.
the class EntityUtils method primaryKeyPropertyCriteriaList.
private static List<PropertyCriteria> primaryKeyPropertyCriteriaList(Class<?> entityClass) {
List<PropertyCriteria> criteria = new LinkedList<PropertyCriteria>();
criteria.add(new AnnotatedPropertyCriteria(Id.class));
criteria.add(new AnnotatedPropertyCriteria(EmbeddedId.class));
String[] fromMappingFiles = PersistenceUnitDescriptorProvider.getInstance().primaryKeyFields(entityClass);
if (fromMappingFiles != null) {
for (String id : fromMappingFiles) {
criteria.add(new NamedPropertyCriteria(id));
}
}
return criteria;
}
use of org.apache.deltaspike.data.impl.property.query.NamedPropertyCriteria in project deltaspike by apache.
the class BasePropertyQueryPart method validate.
void validate(String name, String method, RepositoryMetadata repo) {
Class<?> current = repo.getEntityMetadata().getEntityClass();
if (name == null) {
throw new MethodExpressionException(null, repo.getRepositoryClass(), method);
}
for (String property : name.split(SEPARATOR)) {
PropertyQuery<?> query = PropertyQueries.createQuery(current).addCriteria(new NamedPropertyCriteria(property));
Property<?> result = query.getFirstResult();
if (result == null) {
throw new MethodExpressionException(property, repo.getRepositoryClass(), method);
}
current = result.getJavaClass();
}
}
use of org.apache.deltaspike.data.impl.property.query.NamedPropertyCriteria in project deltaspike by apache.
the class EntityUtils method getVersionProperty.
public static Property<Serializable> getVersionProperty(Class<?> entityClass) {
List<PropertyCriteria> criteriaList = new LinkedList<PropertyCriteria>();
criteriaList.add(new AnnotatedPropertyCriteria(Version.class));
String fromMappingFiles = PersistenceUnitDescriptorProvider.getInstance().versionField(entityClass);
if (fromMappingFiles != null) {
criteriaList.add(new NamedPropertyCriteria(fromMappingFiles));
}
for (PropertyCriteria criteria : criteriaList) {
PropertyQuery<Serializable> query = PropertyQueries.<Serializable>createQuery(entityClass).addCriteria(criteria);
Property<Serializable> result = query.getFirstResult();
if (result != null) {
return result;
}
}
return null;
}
use of org.apache.deltaspike.data.impl.property.query.NamedPropertyCriteria in project deltaspike by apache.
the class PropertyQueryTest method testSingleResult.
/**
* Querying for a single result with a criterai that matches exactly one property should return the property.
*
* @see PropertyQuery#getSingleResult()
*/
@Test
public void testSingleResult() {
PropertyQuery<String> q = PropertyQueries.<String>createQuery(Person.class);
q.addCriteria(new NamedPropertyCriteria("name"));
Property<String> p = q.getSingleResult();
assertNotNull(p);
Person o = new Person();
o.setName("Trap");
assertEquals("Trap", p.getValue(o));
}
Aggregations