Example usage for org.hibernate Criteria createAlias

List of usage examples for org.hibernate Criteria createAlias

Introduction

In this page you can find the example usage for org.hibernate Criteria createAlias.

Prototype

public Criteria createAlias(String associationPath, String alias) throws HibernateException;

Source Link

Document

Join an association, assigning an alias to the joined association.

Usage

From source file:com.gp.cong.logisoft.hibernate.dao.lcl.LclBookingHotCodeDAO.java

public LclBookingHotCode getHotCodeByFileIDCode(Long fileId, String code) throws Exception {
    Criteria criteria = getSession().createCriteria(LclBookingHotCode.class, "lclHotCode");
    criteria.createAlias("lclHotCode.lclFileNumber", "lclFileNumber");
    if (!CommonUtils.isEmpty(fileId)) {
        criteria.add(Restrictions.eq("lclFileNumber.id", fileId));
    }//from  w w  w.  j  a  va 2  s.c om
    if (!CommonUtils.isEmpty(code)) {
        criteria.add(Restrictions.eq("code", code));
    }
    return (LclBookingHotCode) criteria.setMaxResults(1).uniqueResult();
}

From source file:com.hmsinc.epicenter.model.surveillance.impl.SurveillanceRepositoryImpl.java

License:Open Source License

/**
 * @param c//w w w. ja  v  a 2  s  . c  om
 * @param startDate
 * @param endDate
 * @param includeAll
 * @param includeFacilityLocation
 * @param filter
 * @return
 */
private Criteria applyAnomalyCriteria(final Criteria c, final DateTime startDate, final DateTime endDate,
        final boolean includeAll, final Geometry filter, final Geometry excludeFacilityEventsFilter) {

    if (startDate == null && endDate != null) {
        c.add(Restrictions.lt("analysisTimestamp", endDate));
    } else if (startDate != null && endDate == null) {
        c.add(Restrictions.gt("analysisTimestamp", startDate));
    } else if (startDate != null && endDate != null) {
        c.add(Restrictions.between("analysisTimestamp", startDate, endDate));
    }

    if (!includeAll) {
        c.add(Restrictions.isEmpty("investigations")).createCriteria("disposition")
                .add(Restrictions.eq("type", WorkflowStateType.INITIAL));
    }

    if (filter != null && excludeFacilityEventsFilter == null) {

        c.createCriteria("geography").add(SpatialRestrictions.withinOrFilter("geometry", filter, 1000, true));

    } else if (filter == null && excludeFacilityEventsFilter != null) {

        final Conjunction conjunction = Restrictions.conjunction();
        c.createAlias("geography", "eventGeography");
        c.createAlias("task", "eventTask");

        conjunction.add(Restrictions.eq("eventTask.location", AnalysisLocation.FACILITY));
        conjunction.add(SpatialRestrictions.withinOrFilter("eventGeography.geometry",
                excludeFacilityEventsFilter, 1000, true));

        c.add(Restrictions.not(conjunction));

    } else if (filter != null && excludeFacilityEventsFilter != null) {

        final Conjunction conjunction = Restrictions.conjunction();
        c.createAlias("geography", "eventGeography");
        c.createAlias("task", "eventTask");

        // Find events where we have unlimited access
        conjunction.add(SpatialRestrictions.withinOrFilter("eventGeography.geometry", filter, 1000, true));

        // Filter events in the limited region
        final Conjunction facilityEventsConjunction = Restrictions.conjunction();
        facilityEventsConjunction.add(Restrictions.eq("eventTask.location", AnalysisLocation.FACILITY));
        facilityEventsConjunction.add(SpatialRestrictions.withinOrFilter("eventGeography.geometry",
                excludeFacilityEventsFilter, 1000, true));

        conjunction.add(Restrictions.not(facilityEventsConjunction));

        c.add(conjunction);
    }

    return c;
}

From source file:com.ibm.asset.trails.dao.jpa.VSoftwareLparDAOJpa.java

@Override
public Long total(Account account, ReconSetting reconSetting) {
    // TODO Auto-generated method stub
    Criteria criteria = getHibernateSessionCriteria();

    criteria.createAlias("hardwareLpar", "hl")
            .createAlias("hl.hardwareLparEff", "hle", CriteriaSpecification.LEFT_JOIN)
            .createAlias("hl.hardware", "h").createAlias("h.machineType", "mt")
            .createAlias("installedSoftwares", "is")
            .createAlias("is.scheduleF", "sf", CriteriaSpecification.LEFT_JOIN)
            .createAlias("sf.scope", "scope", CriteriaSpecification.LEFT_JOIN)
            .createAlias("is.softwareLpar", "sl").createAlias("is.alert", "aus")
            .createAlias("aus.reconcile", "r", CriteriaSpecification.LEFT_JOIN)
            .createAlias("r.usedLicenses", "ul", CriteriaSpecification.LEFT_JOIN)
            .createAlias("ul.license", "license", CriteriaSpecification.LEFT_JOIN)
            .createAlias("r.reconcileType", "rt", CriteriaSpecification.LEFT_JOIN)
            .createAlias("is.software", "sw").add(Restrictions.eq("account", account));

    if (reconSetting.getReconcileType() != null) {
        criteria.add(Restrictions.eq("rt.id", reconSetting.getReconcileType()));
    }/* w  ww  .  j av a2  s  . com*/

    if (StringUtils.isNotBlank(reconSetting.getAlertStatus())) {
        boolean open = false;
        if (reconSetting.getAlertStatus().equals("OPEN")) {
            open = true;
            criteria.add(Restrictions.eq("aus.open", open));
        } else {
            criteria.add(Restrictions.and(Restrictions.eq("aus.open", false),
                    Restrictions.eqProperty("is.id", "r.installedSoftware.id")));
        }

    } else {
        criteria.add(Restrictions.or(Restrictions.eq("aus.open", true),
                Restrictions.and(Restrictions.eq("aus.open", false),
                        Restrictions.eqProperty("is.id", "r.installedSoftware.id"))));
    }

    if (null != reconSetting.getAlertFrom() && reconSetting.getAlertFrom().intValue() >= 0) {
        criteria.add(Restrictions.ge("aus.alertAge", reconSetting.getAlertFrom()));
    }

    if (null != reconSetting.getAlertTo() && reconSetting.getAlertTo().intValue() >= 0) {
        criteria.add(Restrictions.le("aus.alertAge", reconSetting.getAlertTo()));
    }

    if (StringUtils.isNotBlank(reconSetting.getAssigned())) {
        if (reconSetting.getAssigned().equals("Assigned")) {
            criteria.add(Restrictions.ne("aus.remoteUser", "STAGING"));
        }
        if (reconSetting.getAssigned().equals("Unassigned")) {
            criteria.add(Restrictions.eq("aus.remoteUser", "STAGING"));
        }
    }

    if (StringUtils.isNotBlank(reconSetting.getAssignee())) {
        criteria.add(Restrictions.eq("aus.remoteUser", reconSetting.getAssignee()).ignoreCase());
    }

    if (StringUtils.isNotBlank(reconSetting.getOwner())) {
        if (reconSetting.getOwner().equalsIgnoreCase("IBM")) {
            criteria.add(Restrictions.eq("h.owner", reconSetting.getOwner()).ignoreCase());
        } else if (reconSetting.getOwner().equalsIgnoreCase("Customer")) {
            ArrayList<String> lalOwner = new ArrayList<String>();

            lalOwner.add("CUST");
            lalOwner.add("CUSTO");
            criteria.add(Restrictions.in("h.owner", lalOwner));
        }
    }

    // I'm not sure why the heck we aren't just getting a list of strings?
    if (reconSetting.getCountries().length > 0) {
        List<String> list = new ArrayList<String>();
        for (int i = 0; i < reconSetting.getCountries().length; i++) {
            if (StringUtils.isNotBlank(reconSetting.getCountries()[i])) {
                list.add(reconSetting.getCountries()[i].toUpperCase());
            }
        }

        if (list.size() > 0) {
            criteria.add(Restrictions.in("h.country", list));
        }
    }

    if (reconSetting.getNames().length > 0) {
        List<String> list = new ArrayList<String>();
        for (int i = 0; i < reconSetting.getNames().length; i++) {
            if (StringUtils.isNotBlank(reconSetting.getNames()[i])) {
                list.add(reconSetting.getNames()[i].toUpperCase());
            }
        }

        if (list.size() > 0) {
            criteria.add(Restrictions.in("hl.name", list));
        }
    }

    if (reconSetting.getSwcmIDs().length > 0) {
        List<String> list = new ArrayList<String>();
        for (int i = 0; i < reconSetting.getSwcmIDs().length; i++) {
            if (StringUtils.isNotBlank(reconSetting.getSwcmIDs()[i])) {
                list.add(reconSetting.getSwcmIDs()[i].toUpperCase());
            }
        }
        if (list.size() > 0) {
            criteria.add(Restrictions.in("license.extSrcId", list));
        }
    }

    if (reconSetting.getSerialNumbers().length > 0) {
        List<String> list = new ArrayList<String>();
        for (int i = 0; i < reconSetting.getSerialNumbers().length; i++) {
            if (StringUtils.isNotBlank(reconSetting.getSerialNumbers()[i])) {
                list.add(reconSetting.getSerialNumbers()[i].toUpperCase());
            }
        }

        if (list.size() > 0) {
            criteria.add(Restrictions.in("h.serial", list));
        }
    }

    if (reconSetting.getProductInfoNames().length > 0) {
        List<String> list = new ArrayList<String>();
        for (int i = 0; i < reconSetting.getProductInfoNames().length; i++) {
            if (StringUtils.isNotBlank(reconSetting.getProductInfoNames()[i])) {
                list.add(reconSetting.getProductInfoNames()[i]);
            }
        }

        if (list.size() > 0) {
            criteria.add(Restrictions.in("sw.softwareName", list));
        }
    }

    if (StringUtils.isNotBlank(reconSetting.getScope())) {
        if ("Not specified".equalsIgnoreCase(reconSetting.getScope())) {
            criteria.add(Restrictions.isNull("scope.description"));
        } else {
            criteria.add(Restrictions.eq("scope.description", reconSetting.getScope()));
        }
    }

    if (StringUtils.isNotBlank(reconSetting.getFinanResp())) {
        if ("Not Specified".trim().equalsIgnoreCase(reconSetting.getFinanResp())) {
            criteria.add(Restrictions.isNull("sf.SWFinanceResp"));
        } else {
            criteria.add(Restrictions.eq("sf.SWFinanceResp", reconSetting.getFinanResp()));
        }
    }

    criteria.setProjection(Projections.projectionList().add(Projections.rowCount()));

    Long total = (Long) criteria.uniqueResult();
    return total;
}

From source file:com.indicator_engine.dao.GLAEntityDaoImpl.java

License:Open Source License

/**
 * Loads all GLA Entity Objects present in the Database.
 * @param colName Sort the Results using this Column Name.
 * @param sortDirection Specify Sort Direction : asc/desc.
 * @param sort Turn Sorting ON/OFF//  ww  w .  ja v a2 s  .c  o  m
 * @return Returns all GLA Entity Objects present in Database and sorted if specified.
 **/
@Override
@Transactional(readOnly = true)
public List<GLAEntity> loadAll(String colName, String sortDirection, boolean sort) {
    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(GLAEntity.class);
    criteria.createAlias("glaEvent", "events");
    criteria.setFetchMode("events", FetchMode.JOIN);
    criteria.createAlias("events.glaCategory", "category");
    criteria.setFetchMode("category", FetchMode.JOIN);
    criteria.createAlias("events.glaUser", "users");
    criteria.setFetchMode("users", FetchMode.JOIN);
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    if (sort) {
        if (sortDirection.equals("asc"))
            criteria.addOrder(Order.asc(colName));
        else
            criteria.addOrder(Order.desc(colName));
    }
    return criteria.list();

}

From source file:com.indicator_engine.dao.GLAEntityDaoImpl.java

License:Open Source License

/**
 * Loads all GLA Entity Objects present in the Database based on a specific Category ID.
 * @param categoryID Category ID used for selecting relevant GLA Entity Objects.
 * @return Returns all GLA Entity Objects present in Database and matching the specified Category ID.
 **///from ww w  .  j a va2  s.  co  m
@Override
@Transactional(readOnly = true)
public List<String> loadEntitiesByCategoryID(Long categoryID) {
    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(GLAEntity.class);
    criteria.setProjection(Projections.distinct(Projections.property("key")));
    criteria.createAlias("glaEvent", "events");
    criteria.setFetchMode("events", FetchMode.JOIN);
    criteria.createAlias("events.glaCategory", "category");
    criteria.setFetchMode("category", FetchMode.JOIN);
    criteria.add(Restrictions.eq("category.id", categoryID));
    return criteria.list();

}

From source file:com.indicator_engine.dao.GLAEntityDaoImpl.java

License:Open Source License

/**
 * Loads all GLA Entity Keys present in the Database based on a specific Category ID.
 * @param categoryID Category ID used for selecting relevant GLA Entity Objects.
 * @return Returns all GLA Entity Keys present in Database and matching the specified Category ID.
 **///ww w .j  a v  a 2  s  .co m
@Override
@Transactional(readOnly = true)
public List<String> loadEntityKeyValuesByCategoryID(Long categoryID, String key) {
    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(GLAEntity.class);
    criteria.createAlias("glaEvent", "events");
    criteria.setFetchMode("events", FetchMode.JOIN);
    criteria.createAlias("events.glaCategory", "category");
    criteria.setFetchMode("category", FetchMode.JOIN);
    criteria.add(Restrictions.eq("category.id", categoryID));
    criteria.add(Restrictions.eq("key", key));
    criteria.setProjection(Projections.property("value"));
    return criteria.list();

}

From source file:com.indicator_engine.dao.GLAEntityDaoImpl.java

License:Open Source License

/**
 * Loads all GLA Entity Objects present in the Database based on a specific Category ID.
 * @param categoryID Category ID used for selecting relevant GLA Entity Objects.
 * @return Returns all GLA Entity Objects present in Database and matching the specified Category ID.
 **//*w w  w.j  a  v a2 s .c  om*/
@Override
@Transactional(readOnly = true)
public List<String> loadEntitiesByCategoryIDName(Long categoryID, String name) {
    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(GLAEntity.class);
    criteria.createAlias("glaEvent", "events");
    criteria.setFetchMode("events", FetchMode.JOIN);
    criteria.createAlias("events.glaCategory", "category");
    criteria.setFetchMode("category", FetchMode.JOIN);
    criteria.add(Restrictions.eq("category.id", categoryID));
    criteria.add(Restrictions.eq("key", name));
    return criteria.list();

}

From source file:com.indicator_engine.dao.GLAEntityDaoImpl.java

License:Open Source License

/**
 * Search GLA Entity Objects based on Entity Key
 * @param searchParameter Entity Key used for searching
 * @param exactSearch Search Pattern : Exact or Likewise
 * @param colName Sort Results based on this Column Name
 * @param sortDirection Specify Sort Direction ASC/DESC
 * @param sort Turn Sorting ON/OFF./*  w  w w  . j a  v  a2 s .  c  o m*/
 * @return Returns all GLA Entity Objects present in Database and matching the Search Criteria.
 **/
@Override
@Transactional(readOnly = true)
public List<GLAEntity> searchEntitiesByKey(String searchParameter, boolean exactSearch, String colName,
        String sortDirection, boolean sort) {
    if (!exactSearch)
        searchParameter = "%" + searchParameter + "%";
    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(GLAEntity.class);
    criteria.createAlias("glaEvent", "events");
    criteria.setFetchMode("events", FetchMode.JOIN);
    criteria.createAlias("events.glaCategory", "category");
    criteria.setFetchMode("category", FetchMode.JOIN);
    criteria.createAlias("events.glaUser", "users");
    criteria.setFetchMode("users", FetchMode.JOIN);
    if (!exactSearch)
        criteria.add(Restrictions.ilike("key", searchParameter));
    else
        criteria.add(Restrictions.eq("key", searchParameter));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    if (sort) {
        if (sortDirection.equals("asc"))
            criteria.addOrder(Order.asc(colName));
        else
            criteria.addOrder(Order.desc(colName));
    }
    return criteria.list();
}

From source file:com.indicator_engine.dao.GLAEventDaoImpl.java

License:Open Source License

/**
 * Adds a new GLA Entity Object to the Database.
 * @param glaEntity New GLA Entity Object to be saved.
 * @return ID of the Newly Created GLA Entity object in DB.
 **//*from w w w .  j  av  a2  s. c o m*/
@Override
@Transactional(readOnly = true)
public List<String> loadEventByCategoryID(Long categoryID) {
    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(GLAEvent.class);
    criteria.createAlias("glaCategory", "category");
    criteria.setFetchMode("entities", FetchMode.JOIN);
    criteria.setFetchMode("glaUser", FetchMode.JOIN);
    criteria.setFetchMode("category", FetchMode.JOIN);
    criteria.add(Restrictions.eq("category.id", categoryID));
    log.info("Dumping criteria" + criteria.list());
    List<GLAEvent> list = criteria.list();
    log.info("Dumping List<GLAEvent> list" + list);
    List<String> selectedEvents = new ArrayList<>();
    for (GLAEvent data : list) {
        selectedEvents.add(data.getAction());
        log.info("Dumping List<GLAEvent>.Actions list" + data.getAction());
    }
    log.info("Dumping Events By Category ID" + selectedEvents);
    return selectedEvents;
}

From source file:com.indicator_engine.dao.GLAIndicatorDaoImpl.java

License:Open Source License

/**
 * Lists all the Non-Composite Indicators present in the Database.
 * @param colName//from   ww  w  . jav  a2 s  .co m
 *            Column Name to be used for Sorting the results
 * @param sortDirection
 *            Sort Direction : Ascending/Descending
 * @param sort
 *            True for sorting Required and False to set sorting of results off.
 * @return
 *           Listing of all the Non-Composite Indicators.
 *
 */
@Override
@Transactional
public List<GLAIndicator> displayAllNonComposite(String colName, String sortDirection, boolean sort) {
    Session session = factory.getCurrentSession();
    Criteria criteria = session.createCriteria(GLAIndicator.class);
    criteria.createAlias("glaIndicatorProps", "indProps");
    criteria.setFetchMode("indProps", FetchMode.JOIN);
    criteria.setFetchMode("glaQuestions", FetchMode.JOIN);
    criteria.add(Restrictions.eq("indProps.isComposite", false));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    if (sort) {
        if (sortDirection.equals("asc"))
            criteria.addOrder(Order.asc(colName));
        else
            criteria.addOrder(Order.desc(colName));
    }
    return criteria.list();
}