use of org.hibernate.type.IntegerType 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.type.IntegerType in project jbosstools-hibernate by jbosstools.
the class TypeFacadeTest method testIsIntegerType.
@Test
public void testIsIntegerType() {
IType typeFacade = null;
ClassType classType = new ClassType();
typeFacade = FACADE_FACTORY.createType(classType);
Assert.assertFalse(typeFacade.isIntegerType());
IntegerType integerType = new IntegerType();
typeFacade = FACADE_FACTORY.createType(integerType);
Assert.assertTrue(typeFacade.isIntegerType());
}
use of org.hibernate.type.IntegerType in project jbosstools-hibernate by jbosstools.
the class TypeFacadeTest method testGetPrimitiveClass.
@Test
public void testGetPrimitiveClass() {
IType typeFacade = null;
ClassType classType = new ClassType();
typeFacade = FACADE_FACTORY.createType(classType);
Assert.assertNull(typeFacade.getPrimitiveClass());
IntegerType integerType = new IntegerType();
typeFacade = FACADE_FACTORY.createType(integerType);
Assert.assertEquals(int.class, typeFacade.getPrimitiveClass());
}
use of org.hibernate.type.IntegerType in project jbosstools-hibernate by jbosstools.
the class TypeFacadeTest method testIsInstanceOfPrimitiveType.
@Test
public void testIsInstanceOfPrimitiveType() {
IType typeFacade = null;
ClassType classType = new ClassType();
typeFacade = FACADE_FACTORY.createType(classType);
Assert.assertFalse(typeFacade.isInstanceOfPrimitiveType());
StringType stringType = new StringType();
typeFacade = FACADE_FACTORY.createType(stringType);
Assert.assertFalse(typeFacade.isInstanceOfPrimitiveType());
IntegerType integerType = new IntegerType();
typeFacade = FACADE_FACTORY.createType(integerType);
Assert.assertTrue(typeFacade.isInstanceOfPrimitiveType());
}
use of org.hibernate.type.IntegerType in project jbosstools-hibernate by jbosstools.
the class TypeFacadeTest method testIsIntegerType.
@Test
public void testIsIntegerType() {
IType typeFacade = null;
ClassType classType = new ClassType();
typeFacade = FACADE_FACTORY.createType(classType);
Assert.assertFalse(typeFacade.isIntegerType());
IntegerType integerType = new IntegerType();
typeFacade = FACADE_FACTORY.createType(integerType);
Assert.assertTrue(typeFacade.isIntegerType());
}
Aggregations