Example usage for org.hibernate.criterion Restrictions isNull

List of usage examples for org.hibernate.criterion Restrictions isNull

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions isNull.

Prototype

public static Criterion isNull(String propertyName) 

Source Link

Document

Apply an "is null" constraint to the named property

Usage

From source file:com.ephesoft.dcma.da.dao.hibernate.BatchInstanceDaoImpl.java

License:Open Source License

/**
 * This API performs a fetch over all the batch instances on the basis of status, priority and for the given user role.
 * /*ww  w .  ja v a2 s  .c  o  m*/
 * @param statusList batch status list
 * @param batchPriorities batch priorities
 * @param userRoles batch class id's for the role for which the current user is logged in
 * @return List<{@link BatchInstance}>
 */
@Override
public List<BatchInstance> getBatchInstancesForStatusPriority(List<BatchInstanceStatus> statusList,
        final List<BatchPriority> batchPriorities, final Set<String> userRoles) {
    EphesoftCriteria criteria = criteria();
    criteria.add(Restrictions.isNull(CURRENT_USER));
    return getBatchInstances(statusList, -1, -1, null, null, batchPriorities, null, userRoles,
            EphesoftUser.ADMIN_USER, criteria, null);
}

From source file:com.ephesoft.dcma.da.dao.hibernate.ConnectionDaoImpl.java

License:Open Source License

@Override
public List<Connections> getAllConnectionsExcludingDeleted() {
    DetachedCriteria criteria = criteria();
    criteria.add(Restrictions.or(Restrictions.isNull(IS_DELETED), Restrictions.eq(IS_DELETED, false)));
    return this.find(criteria);
}

From source file:com.ephesoft.dcma.da.dao.hibernate.ModuleConfigDaoImpl.java

License:Open Source License

/**
 * API to get module by child name.//from ww w. j  a  v  a  2s  .c  o m
 * 
 * @param childName String
 * @return List<ModuleConfig>
 */
@Override
public List<ModuleConfig> getModuleByChildName(String childName) {
    DetachedCriteria criteria = criteria();
    if (childName != null) {
        criteria.add(Restrictions.eq(CHILD_KEY, childName));
    } else {
        criteria.add(Restrictions.isNull(CHILD_KEY));
    }
    return this.find(criteria);
}

From source file:com.ephesoft.dcma.da.dao.hibernate.ModuleConfigDaoImpl.java

License:Open Source License

/**
 * API to get the module configuration by key and mandatory.
 * /*w ww  .ja  v  a2 s  .  c  om*/
 * @param moduleConfigKey String
 * @param isMandatory boolean
 * @return ModuleConfig
 */
@Override
public ModuleConfig getModuleConfigByKeyAndMandatory(String moduleConfigKey, boolean isMandatory) {
    LOGGER.debug(moduleConfigKey);
    LOGGER.debug(String.valueOf(isMandatory));
    DetachedCriteria criteria = criteria();
    if (moduleConfigKey != null) {
        criteria.add(Restrictions.eq(CHILD_KEY, moduleConfigKey));
    } else {
        criteria.add(Restrictions.isNull(CHILD_KEY));
    }
    criteria.add(Restrictions.eq(IS_MANDATORY, isMandatory));
    return this.findSingle(criteria);
}

From source file:com.ephesoft.dcma.da.dao.hibernate.TableRuleInfoDaoImpl.java

License:Open Source License

/**
 * API to retrieve list of all the table rules.
 * //from  w  ww  . j a v  a 2s  .  com
 * @return {@link List}< {@link TableRuleInfo}> The list of table rules.
 */
@Override
public List<TableRuleInfo> getAllTableRules() {
    DetachedCriteria criteria = criteria();
    criteria.add(Restrictions.isNull(TABLE_INFO));
    return find(criteria);
}

From source file:com.eryansky.common.orm.core.hibernate.restriction.support.EqRestriction.java

License:Apache License

public Criterion build(String propertyName, Object value) {

    return value == null ? Restrictions.isNull(propertyName) : Restrictions.eq(propertyName, value);

}

From source file:com.eucalyptus.blockstorage.util.BlockStorageUtil.java

License:Open Source License

public static final Criterion getFailedCriterion() {
    return Restrictions.and(Restrictions.like("status", StorageProperties.Status.failed.toString()),
            Restrictions.isNull("deletionTime"));
}

From source file:com.eucalyptus.cloudwatch.common.internal.domain.alarms.AlarmManager.java

License:Open Source License

public static Collection<AlarmEntity> describeAlarmsForMetric(@Nullable final String accountId,
        @Nonnull final Map<String, String> dimensionMap, @Nullable final String metricName,
        @Nullable final String namespace, @Nullable final Integer period, @Nullable final Statistic statistic,
        @Nullable final Units unit, @Nonnull final Predicate<? super CloudWatchMetadata.AlarmMetadata> filter) {
    final List<AlarmEntity> results = Lists.newArrayList();
    try (final TransactionResource db = Entities.transactionFor(AlarmEntity.class)) {
        final Criteria criteria = Entities.createCriteria(AlarmEntity.class);
        if (accountId != null) {
            criteria.add(Restrictions.eq("accountId", accountId));
        }//from w  ww.  j a  v a2 s. com
        final Set<DimensionEntity> dimensions = Sets.newTreeSet();
        for (final Map.Entry<String, String> entry : dimensionMap.entrySet()) {
            final DimensionEntity d = new DimensionEntity();
            d.setName(entry.getKey());
            d.setValue(entry.getValue());
            dimensions.add(d);
        }
        int dimIndex = 1;
        for (final DimensionEntity d : dimensions) {
            criteria.add(Restrictions.eq("dim" + dimIndex + "Name", d.getName()));
            criteria.add(Restrictions.eq("dim" + dimIndex + "Value", d.getValue()));
            dimIndex++;
        }
        while (dimIndex <= AlarmEntity.MAX_DIM_NUM) {
            criteria.add(Restrictions.isNull("dim" + dimIndex + "Name"));
            criteria.add(Restrictions.isNull("dim" + dimIndex + "Value"));
            dimIndex++;
        }

        if (metricName != null) {
            criteria.add(Restrictions.eq("metricName", metricName));
        }
        if (namespace != null) {
            criteria.add(Restrictions.eq("namespace", namespace));
        }
        if (period != null) {
            criteria.add(Restrictions.eq("period", period));
        }
        if (statistic != null) {
            criteria.add(Restrictions.eq("statistic", statistic));
        }
        if (unit != null) {
            criteria.add(Restrictions.eq("unit", unit));
        }
        final List<AlarmEntity> alarmEntities = (List<AlarmEntity>) criteria.list();
        Iterables.addAll(results, Iterables.filter(alarmEntities, filter));
        db.commit();
    }
    return results;
}

From source file:com.eucalyptus.cloudwatch.common.internal.domain.listmetrics.ListMetricManager.java

License:Open Source License

private static void addMetric(EntityTransaction db, String accountId, String metricName, String namespace,
        Map<String, String> dimensionMap, MetricType metricType) {
    ListMetric metric = createMetric(accountId, metricName, namespace, dimensionMap, metricType);
    Criteria criteria = Entities.createCriteria(ListMetric.class)
            .add(Restrictions.eq("accountId", metric.getAccountId()))
            .add(Restrictions.eq("metricName", metric.getMetricName()))
            .add(Restrictions.eq("namespace", metric.getNamespace()));

    // add dimension restrictions
    int dimIndex = 1;
    for (DimensionEntity d : metric.getDimensions()) {
        criteria.add(Restrictions.eq("dim" + dimIndex + "Name", d.getName()));
        criteria.add(Restrictions.eq("dim" + dimIndex + "Value", d.getValue()));
        dimIndex++;//from   w w w.  java 2  s.co  m
    }
    while (dimIndex <= ListMetric.MAX_DIM_NUM) {
        criteria.add(Restrictions.isNull("dim" + dimIndex + "Name"));
        criteria.add(Restrictions.isNull("dim" + dimIndex + "Value"));
        dimIndex++;
    }
    ListMetric inDbMetric = (ListMetric) criteria.uniqueResult();
    if (inDbMetric != null) {
        inDbMetric.setVersion(1 + inDbMetric.getVersion());
    } else {
        Entities.persist(metric);
    }
}

From source file:com.eucalyptus.cloudwatch.domain.alarms.AlarmManager.java

License:Open Source License

public static Collection<AlarmEntity> describeAlarmsForMetric(@Nullable final String accountId,
        @Nonnull final Map<String, String> dimensionMap, @Nullable final String metricName,
        @Nullable final String namespace, @Nullable final Integer period, @Nullable final Statistic statistic,
        @Nullable final Units unit, @Nonnull final Predicate<CloudWatchMetadata.AlarmMetadata> filter) {
    final List<AlarmEntity> results = Lists.newArrayList();
    final EntityTransaction db = Entities.get(AlarmEntity.class);
    try {/*from www .  j  a  v  a 2  s. com*/
        final Criteria criteria = Entities.createCriteria(AlarmEntity.class);
        if (accountId != null) {
            criteria.add(Restrictions.eq("accountId", accountId));
        }
        final Set<DimensionEntity> dimensions = Sets.newTreeSet();
        for (final Map.Entry<String, String> entry : dimensionMap.entrySet()) {
            final DimensionEntity d = new DimensionEntity();
            d.setName(entry.getKey());
            d.setValue(entry.getValue());
            dimensions.add(d);
        }
        int dimIndex = 1;
        for (final DimensionEntity d : dimensions) {
            criteria.add(Restrictions.eq("dim" + dimIndex + "Name", d.getName()));
            criteria.add(Restrictions.eq("dim" + dimIndex + "Value", d.getValue()));
            dimIndex++;
        }
        while (dimIndex <= AlarmEntity.MAX_DIM_NUM) {
            criteria.add(Restrictions.isNull("dim" + dimIndex + "Name"));
            criteria.add(Restrictions.isNull("dim" + dimIndex + "Value"));
            dimIndex++;
        }

        if (metricName != null) {
            criteria.add(Restrictions.eq("metricName", metricName));
        }
        if (namespace != null) {
            criteria.add(Restrictions.eq("namespace", namespace));
        }
        if (period != null) {
            criteria.add(Restrictions.eq("period", period));
        }
        if (statistic != null) {
            criteria.add(Restrictions.eq("statistic", statistic));
        }
        if (unit != null) {
            criteria.add(Restrictions.eq("unit", unit));
        }
        final List<AlarmEntity> alarmEntities = (List<AlarmEntity>) criteria.list();
        Iterables.addAll(results, Iterables.filter(alarmEntities, filter));
        db.commit();
    } catch (RuntimeException ex) {
        Logs.extreme().error(ex, ex);
        throw ex;
    } finally {
        if (db.isActive())
            db.rollback();
    }
    return results;
}