use of org.hibernate.criterion.Criterion in project opennms by OpenNMS.
the class CategoryDaoHibernate method getCriterionForCategorySetsUnion.
/**
* <p>getCriterionForCategorySetsUnion</p>
*
* @param categories an array of {@link java.lang.String} objects.
* @return a {@link java.util.List} object.
*/
@Override
public List<Criterion> getCriterionForCategorySetsUnion(String[]... categories) {
Assert.notNull(categories, "categories argument must not be null");
Assert.isTrue(categories.length >= 1, "categories must have at least one set of categories");
// Build a list a list of category IDs to use when building the restrictions
List<List<Integer>> categoryIdsList = new ArrayList<List<Integer>>(categories.length);
for (String[] categoryStrings : categories) {
List<Integer> categoryIds = new ArrayList<Integer>(categoryStrings.length);
for (String categoryString : categoryStrings) {
OnmsCategory category = findByName(categoryString);
if (category == null) {
throw new IllegalArgumentException("Could not find category for name '" + categoryString + "'");
}
categoryIds.add(category.getId());
}
categoryIdsList.add(categoryIds);
}
List<Criterion> criteria = new ArrayList<Criterion>(categoryIdsList.size());
for (List<Integer> categoryIds : categoryIdsList) {
Type[] types = new Type[categoryIds.size()];
String[] questionMarks = new String[categoryIds.size()];
Type theOneAndOnlyType = new IntegerType();
for (int i = 0; i < categoryIds.size(); i++) {
types[i] = theOneAndOnlyType;
questionMarks[i] = "?";
}
String sql = "{alias}.nodeId in (select distinct cn.nodeId from category_node cn where cn.categoryId in (" + StringUtils.arrayToCommaDelimitedString(questionMarks) + "))";
criteria.add(Restrictions.sqlRestriction(sql, categoryIds.toArray(new Integer[categoryIds.size()]), types));
}
return criteria;
}
use of org.hibernate.criterion.Criterion in project dhis2-core by dhis2.
the class CriteriaQueryEngine method addCriterion.
private void addCriterion(DetachedCriteria criteria, org.hisp.dhis.query.Criterion criterion) {
if (Restriction.class.isInstance(criterion)) {
Restriction restriction = (Restriction) criterion;
Criterion hibernateCriterion = getHibernateCriterion(restriction);
if (hibernateCriterion != null) {
criteria.add(hibernateCriterion);
}
} else if (Junction.class.isInstance(criterion)) {
org.hibernate.criterion.Junction junction = null;
if (Disjunction.class.isInstance(criterion)) {
junction = Restrictions.disjunction();
} else if (Conjunction.class.isInstance(criterion)) {
junction = Restrictions.conjunction();
}
criteria.add(junction);
for (org.hisp.dhis.query.Criterion c : ((Junction) criterion).getCriterions()) {
addJunction(junction, c);
}
}
}
use of org.hibernate.criterion.Criterion in project hibernate-orm by hibernate.
the class CriterionTest method testIlikeRendering.
@Test
public void testIlikeRendering() {
SessionFactory sf = new Configuration().addAnnotatedClass(IrrelevantEntity.class).setProperty(AvailableSettings.DIALECT, IlikeSupportingDialect.class.getName()).setProperty(Environment.HBM2DDL_AUTO, "create-drop").buildSessionFactory();
try {
final Criteria criteria = sf.openSession().createCriteria(IrrelevantEntity.class);
final CriteriaQueryTranslator translator = new CriteriaQueryTranslator((SessionFactoryImplementor) sf, (CriteriaImpl) criteria, IrrelevantEntity.class.getName(), "a");
final Criterion ilikeExpression = Restrictions.ilike("name", "abc");
final String ilikeExpressionSqlFragment = ilikeExpression.toSqlString(criteria, translator);
assertEquals("a.name insensitiveLike ?", ilikeExpressionSqlFragment);
} finally {
sf.close();
}
}
use of org.hibernate.criterion.Criterion in project hibernate-orm by hibernate.
the class CriterionTest method testIlikeMimicing.
@Test
public void testIlikeMimicing() {
SessionFactory sf = new Configuration().addAnnotatedClass(IrrelevantEntity.class).setProperty(AvailableSettings.DIALECT, NonIlikeSupportingDialect.class.getName()).setProperty(Environment.HBM2DDL_AUTO, "create-drop").buildSessionFactory();
try {
final Criteria criteria = sf.openSession().createCriteria(IrrelevantEntity.class);
final CriteriaQueryTranslator translator = new CriteriaQueryTranslator((SessionFactoryImplementor) sf, (CriteriaImpl) criteria, IrrelevantEntity.class.getName(), "a");
final Criterion ilikeExpression = Restrictions.ilike("name", "abc");
final String ilikeExpressionSqlFragment = ilikeExpression.toSqlString(criteria, translator);
assertEquals("lowLowLow(a.name) like ?", ilikeExpressionSqlFragment);
} finally {
sf.close();
}
}
use of org.hibernate.criterion.Criterion in project hibernate-orm by hibernate.
the class TestSpatialRestrictions method contains.
@Test
public void contains() throws SQLException {
if (!isSupportedByDialect(SpatialFunction.contains)) {
return;
}
Map<Integer, Boolean> dbexpected = expectationsFactory.getContains(expectationsFactory.getTestPolygon());
Criterion spatialCriterion = SpatialRestrictions.contains("geom", expectationsFactory.getTestPolygon());
retrieveAndCompare(dbexpected, spatialCriterion);
}
Aggregations