Example usage for org.hibernate.criterion DetachedCriteria forClass

List of usage examples for org.hibernate.criterion DetachedCriteria forClass

Introduction

In this page you can find the example usage for org.hibernate.criterion DetachedCriteria forClass.

Prototype

public static DetachedCriteria forClass(Class clazz) 

Source Link

Document

Static builder to create a DetachedCriteria for the given entity, by its Class.

Usage

From source file:com.emergya.persistenceGeo.dao.impl.AbstractGenericDaoHibernateImpl.java

License:Open Source License

/**
* Use this inside subclasses as a convenience method.
*//*from w  ww .jav  a2  s  .  c o m*/
@SuppressWarnings("unchecked")
protected List<T> findByCriteria(Criterion... detachedCriterias) {
    DetachedCriteria crit = DetachedCriteria.forClass(persistentClass);
    for (Criterion c : detachedCriterias) {
        crit.add(c);
    }
    return getHibernateTemplate().findByCriteria(crit);
}

From source file:com.emergya.persistenceGeo.dao.impl.AbstractGenericDaoHibernateImpl.java

License:Open Source License

/**
* Use this inside subclasses as a convenience method.
* 
* @param orders//from  www. j  ava 2s  .  com
* @param detachedCriterias
* 
* @return List with detachedCriterias ordered by orders[0..N]
*/
@SuppressWarnings("unchecked")
protected List<T> findByCriteriaOrdered(Order[] orders, Criterion... detachedCriterias) {
    DetachedCriteria crit = DetachedCriteria.forClass(persistentClass);
    for (Criterion c : detachedCriterias) {
        crit.add(c);
    }
    if (orders != null) {
        for (Order order : orders) {
            crit.addOrder(order);
        }
    }
    return getHibernateTemplate().findByCriteria(crit);
}

From source file:com.emergya.persistenceGeo.dao.impl.AbstractGenericDaoHibernateImpl.java

License:Open Source License

/**
* Use this inside subclasses as a convenience method.
*//* w  w w .j  a  v  a2  s .  c o m*/
@SuppressWarnings("unchecked")
protected List<T> findByCriteria(int firstResult, int maxResults, Order order, Criterion... detachedCriterias) {
    DetachedCriteria crit = DetachedCriteria.forClass(persistentClass);
    for (Criterion c : detachedCriterias) {
        crit.add(c);
    }
    crit.addOrder(order);
    return getHibernateTemplate().findByCriteria(crit, firstResult, maxResults);
}

From source file:com.emergya.persistenceGeo.dao.impl.AbstractGenericDaoHibernateImpl.java

License:Open Source License

/**
* Use this inside subclasses as a convenience method.
*///from w ww  . ja  v  a 2 s . com
@SuppressWarnings("unchecked")
protected List<T> findByCriteria(int firstResult, int maxResults, Order[] orders,
        Criterion... detachedCriterias) {
    DetachedCriteria crit = DetachedCriteria.forClass(persistentClass);
    for (Criterion c : detachedCriterias) {
        crit.add(c);
    }
    if (orders != null) {
        for (Order order : orders) {
            crit.addOrder(order);
        }
    }
    return getHibernateTemplate().findByCriteria(crit, firstResult, maxResults);
}

From source file:com.emergya.persistenceGeo.dao.impl.AbstractGenericDaoHibernateImpl.java

License:Open Source License

/**
* Use this inside subclasses as a convenience method.
*///from   ww  w  .  j a  v  a  2 s. co  m
@SuppressWarnings("unchecked")
protected List<T> findByCriteria(Set<Criterion> criterions) {
    DetachedCriteria crit = DetachedCriteria.forClass(persistentClass);
    for (Criterion c : criterions) {
        crit.add(c);
    }
    return getHibernateTemplate().findByCriteria(crit);
}

From source file:com.emergya.persistenceGeo.dao.impl.GenericHibernateDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<T> findByExample(T exampleInstance, String[] excludeProperty) {
    DetachedCriteria crit = DetachedCriteria.forClass(persistentClass);
    Example example = Example.create(exampleInstance);
    for (String exclude : excludeProperty) {
        example.excludeProperty(exclude);
    }/*from   w w  w  .  j  a v  a 2  s . co m*/
    crit.add(example);
    return getHibernateTemplate().findByCriteria(crit);
}

From source file:com.emergya.persistenceGeo.dao.impl.MultiSirDatabaseGenericHibernateDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/* ww w . j a  va 2 s . c o  m*/
public List<T> findByExample(T exampleInstance, String[] excludedProperties, boolean ignoreCase) {
    DetachedCriteria crit = DetachedCriteria.forClass(persistentClass);
    Example example = Example.create(exampleInstance);

    if (excludedProperties != null) {
        for (String exclude : excludedProperties) {
            example.excludeProperty(exclude);
        }
    }

    if (ignoreCase) {
        crit.add(example.ignoreCase());
    } else {
        crit.add(example);
    }

    return getHibernateTemplate().findByCriteria(crit);
}

From source file:com.eucalyptus.autoscaling.common.internal.groups.PersistenceAutoScalingGroups.java

License:Open Source License

@Override
public <T> List<T> listRequiringInstanceReplacement(final Function<? super AutoScalingGroup, T> transform)
        throws AutoScalingMetadataException {
    final DetachedCriteria criteria = DetachedCriteria.forClass(AutoScalingInstance.class)
            .add(Example.create(AutoScalingInstance.withHealthStatus(HealthStatus.Unhealthy)))
            .setProjection(Projections.property("autoScalingGroup"));

    return persistenceSupport.listByExample(AutoScalingGroup.withOwner(null), Predicates.alwaysTrue(),
            Property.forName("id").in(criteria), Collections.<String, String>emptyMap(), transform);
}

From source file:com.eucalyptus.autoscaling.common.internal.tags.TagSupport.java

License:Open Source License

/**
 * Get the tags for the given resources, grouped by ID and ordered for display.
 *
 * @param owner The account for the tags
 * @param identifiers The resource identifiers for the tags
 * @param tagPredicate Predicate for filtering tags
 * @return The tag map with an entry for each requested resource
 *//*from   ww w.j  a v a  2 s.co m*/
public Map<String, List<Tag>> getResourceTagMap(final OwnerFullName owner, final Iterable<String> identifiers,
        final Predicate<? super Tag> tagPredicate) {
    final Map<String, List<Tag>> tagMap = Maps.newHashMap();
    for (final String id : identifiers) {
        tagMap.put(id, Lists.<Tag>newArrayList());
    }
    if (!tagMap.isEmpty()) {
        final Tag example = example(owner);
        final DetachedCriteria detachedCriteria = DetachedCriteria.forClass(resourceClass)
                .add(Restrictions.in(resourceClassIdField, Lists.newArrayList(identifiers)))
                .setProjection(Projections.id());
        final Criterion idRestriction = Property.forName(tagClassResourceField).in(detachedCriteria);
        try {
            final List<Tag> tags = Tags.list(example, tagPredicate, idRestriction,
                    Collections.<String, String>emptyMap());
            for (final Tag tag : tags) {
                tagMap.get(tag.getResourceId()).add(tag);
            }
        } catch (AutoScalingMetadataNotFoundException e) {
            log.error(e, e);
        }
        Ordering<Tag> order = Ordering.natural().onResultOf(Tags.key());
        for (final String id : identifiers) {
            Collections.sort(tagMap.get(id), order);
        }
    }
    return tagMap;
}

From source file:com.eucalyptus.compute.common.internal.tags.FilterSupport.java

License:Open Source License

/**
 * Build a criterion that uses sub-selects to match the given tag restrictions
 *///from  ww  w . j ava  2  s  . co m
private Criterion tagCriterion(final String accountId, final List<Junction> junctions) {
    final Junction conjunction = Restrictions.conjunction();

    for (final Junction criterion : junctions) {
        final DetachedCriteria criteria = DetachedCriteria.forClass(tagClass)
                .add(Restrictions.eq("ownerAccountNumber", accountId)).add(criterion)
                .setProjection(Projections.property(resourceFieldName));
        conjunction.add(Property.forName(tagFieldName).in(criteria));
    }

    return conjunction;
}