Search in sources :

Example 1 with IntegerType

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;
}
Also used : ArrayList(java.util.ArrayList) IntegerType(org.hibernate.type.IntegerType) IntegerType(org.hibernate.type.IntegerType) StringType(org.hibernate.type.StringType) Type(org.hibernate.type.Type) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) Criterion(org.hibernate.criterion.Criterion) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with IntegerType

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());
}
Also used : IntegerType(org.hibernate.type.IntegerType) ClassType(org.hibernate.type.ClassType) IType(org.jboss.tools.hibernate.runtime.spi.IType) Test(org.junit.Test)

Example 3 with IntegerType

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());
}
Also used : IntegerType(org.hibernate.type.IntegerType) ClassType(org.hibernate.type.ClassType) IType(org.jboss.tools.hibernate.runtime.spi.IType) Test(org.junit.Test)

Example 4 with IntegerType

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());
}
Also used : IntegerType(org.hibernate.type.IntegerType) StringType(org.hibernate.type.StringType) ClassType(org.hibernate.type.ClassType) IType(org.jboss.tools.hibernate.runtime.spi.IType) Test(org.junit.Test)

Example 5 with IntegerType

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());
}
Also used : IntegerType(org.hibernate.type.IntegerType) ClassType(org.hibernate.type.ClassType) IType(org.jboss.tools.hibernate.runtime.spi.IType) Test(org.junit.Test)

Aggregations

IntegerType (org.hibernate.type.IntegerType)27 ClassType (org.hibernate.type.ClassType)24 IType (org.jboss.tools.hibernate.runtime.spi.IType)24 Test (org.junit.Test)24 StringType (org.hibernate.type.StringType)9 LongType (org.hibernate.type.LongType)2 Type (org.hibernate.type.Type)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Criterion (org.hibernate.criterion.Criterion)1 Column (org.hibernate.mapping.Column)1 OneToMany (org.hibernate.mapping.OneToMany)1 AbstractSingleColumnStandardBasicType (org.hibernate.type.AbstractSingleColumnStandardBasicType)1 CollectionType (org.hibernate.type.CollectionType)1 CustomType (org.hibernate.type.CustomType)1 DoubleType (org.hibernate.type.DoubleType)1 ManyToOneType (org.hibernate.type.ManyToOneType)1 OneToOneType (org.hibernate.type.OneToOneType)1 SetType (org.hibernate.type.SetType)1 SingleColumnType (org.hibernate.type.SingleColumnType)1