use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method ignoreCaseShouldEscapeSource.
// DATAMONGO-1232
@Test
void ignoreCaseShouldEscapeSource() {
PartTree tree = new PartTree("findByUsernameIgnoreCase", User.class);
ConvertingParameterAccessor accessor = getAccessor(converter, "con.flux+");
Query query = new MongoQueryCreator(tree, accessor, context).createQuery();
assertThat(query).isEqualTo(query(where("username").regex("^\\Qcon.flux+\\E$", "i")));
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method shouldCreateNearSphereQueryForSphericalPropertyHavingDistanceWithDefaultMetric.
// DATAMONGO-1110
@Test
void shouldCreateNearSphereQueryForSphericalPropertyHavingDistanceWithDefaultMetric() {
Point point = new Point(1.0, 1.0);
Distance distance = new Distance(1.0);
PartTree tree = new PartTree("findByAddress2dSphere_GeoNear", User.class);
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, point, distance), context);
Query query = creator.createQuery();
assertThat(query).isEqualTo(query(where("address2dSphere.geo").nearSphere(point).maxDistance(1.0)));
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method createsOrQueryCorrectly.
// DATAMONGO-413
@Test
void createsOrQueryCorrectly() {
PartTree tree = new PartTree("findByFirstNameOrAge", Person.class);
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "Dave", 42), context);
Query query = creator.createQuery();
assertThat(query).isEqualTo(query(new Criteria().orOperator(where("firstName").is("Dave"), where("age").is(42))));
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method createsQueryWithFindByStartingWithIgnoreCaseCorrectly.
// DATAMONGO-770
@Test
void createsQueryWithFindByStartingWithIgnoreCaseCorrectly() {
PartTree tree = new PartTree("findByFirstNameStartingWithIgnoreCase", Person.class);
MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "dave"), context);
Query query = creator.createQuery();
assertThat(query).isEqualTo(query(where("firstName").regex("^dave", "i")));
}
use of org.springframework.data.repository.query.parser.PartTree in project spring-data-jdbc by spring-projects.
the class JdbcQueryCreator method validate.
/**
* Validate parameters for the derived query. Specifically checking that the query method defines scalar parameters
* and collection parameters where required and that invalid parameter declarations are rejected.
*
* @param tree the tree structure defining the predicate of the query.
* @param parameters parameters for the predicate.
*/
static void validate(PartTree tree, Parameters<?, ?> parameters, MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> context) {
RelationalQueryCreator.validate(tree, parameters);
for (PartTree.OrPart parts : tree) {
for (Part part : parts) {
PersistentPropertyPath<? extends RelationalPersistentProperty> propertyPath = context.getPersistentPropertyPath(part.getProperty());
PersistentPropertyPathExtension path = new PersistentPropertyPathExtension(context, propertyPath);
for (PersistentPropertyPathExtension pathToValidate = path; path.getLength() > 0; path = path.getParentPath()) {
validateProperty(pathToValidate);
}
}
}
}
Aggregations