Example usage for org.hibernate Query setEntity

List of usage examples for org.hibernate Query setEntity

Introduction

In this page you can find the example usage for org.hibernate Query setEntity.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
Query<R> setEntity(String name, Object val);

Source Link

Document

Bind an instance of a mapped persistent class to a named query parameter.

Usage

From source file:de.xirp.db.ChartDatabaseUtil.java

License:Open Source License

/**
 * Returns all {@link de.xirp.db.Observed} for the
 * given record and key name.//  ww  w.java2  s  .c om
 * 
 * @param record
 *            The record to look in.
 * @param keyname
 *            The name of the observed key.
 * @return A list with all <code>Observed</code> for the record
 *         and key.
 * @see de.xirp.db.Observed
 */
@SuppressWarnings("unchecked")
public static List<Observed> getObservedList(Record record, String keyname) {
    Session session = DatabaseManager.getCurrentHibernateSession();
    session.getTransaction().begin();

    Query query = session.createQuery("FROM Observed as obs WHERE obs.record = ? and obs.observedKey = ?"); //$NON-NLS-1$
    query.setEntity(0, record);
    query.setString(1, keyname);
    List<Observed> obs = query.list();

    session.close();
    return Collections.unmodifiableList(obs);
}

From source file:de.xirp.db.ChartDatabaseUtil.java

License:Open Source License

/**
 * Returns all {@link de.xirp.db.Observed} for the
 * given record, key name and time interval.
 * //from   www. j  a v  a  2  s.c om
 * @param record
 *            The record to look in.
 * @param keyname
 *            The name of the observed key.
 * @param startTime
 *            The start time of the time interval.
 * @param stopTime
 *            the stop tine of the time interval.
 * @return A list with all <code>Observed</code> for the record,
 *         key and time interval.
 * @see de.xirp.db.Observed
 */
@SuppressWarnings("unchecked")
public static List<Observed> getObservedList(Record record, String keyname, long startTime, long stopTime) {
    Session session = DatabaseManager.getCurrentHibernateSession();
    session.getTransaction().begin();

    Query query = session.createQuery(
            "FROM Observed as obs WHERE obs.record = ? and obs.observedKey = ? and obs.timestamp >= ? and obs.timestamp <= ?"); //$NON-NLS-1$
    query.setEntity(0, record);
    query.setString(1, keyname);
    query.setLong(2, startTime);
    query.setLong(3, stopTime);
    List<Observed> obs = query.list();

    session.close();
    return Collections.unmodifiableList(obs);
}

From source file:de.xirp.db.ChartDatabaseUtil.java

License:Open Source License

/**
 * Returns the keys that all of the given records have in common.
 * /*from w w w. java2  s.c  o m*/
 * @param records
 *            The records.
 * @return A list with the common keys.
 * @see de.xirp.db.Observed
 */
@SuppressWarnings("unchecked")
public static List<String> getCommonObservedKeysForRecordList(List<Record> records) {
    List<String> commonKeys = new ArrayList<String>();

    List<List<String>> lists = new ArrayList<List<String>>();

    Session session = DatabaseManager.getCurrentHibernateSession();
    session.getTransaction().begin();

    Query query;
    for (Record record : records) {
        query = session
                .createQuery("SELECT DISTINCT obs.observedKey FROM Observed as obs WHERE obs.record = ?"); //$NON-NLS-1$
        query.setEntity(0, record);
        lists.add(query.list());
    }
    session.close();

    commonKeys = lists.get(0);
    for (List<String> list : lists) {
        commonKeys = ListUtils.intersection(commonKeys, list);
    }

    return Collections.unmodifiableList(commonKeys);
}

From source file:de.xirp.db.ChartDatabaseUtil.java

License:Open Source License

/**
 * Returns a map from string to long for the given record and key
 * array. The map contains the count of occurences for each given
 * key name. If the flag <code>relative</code> is
 * <code>true</code> the map contains the percentage of the
 * occurences for each given key name.//  w  w  w  .j  ava 2s.c  om
 * 
 * @param record
 *            The record.
 * @param keys
 *            The keys to use.
 * @param relative
 *            A flag indicating if relative values should be used.
 * @return A map with key->value pairs.
 * @see de.xirp.db.Observed
 */
public static Map<String, Long> getValuesForRecord(Record record, String[] keys, boolean relative) {
    Session session = DatabaseManager.getCurrentHibernateSession();
    session.getTransaction().begin();

    Map<String, Long> map = new HashMap<String, Long>();

    Query query;
    Long onePercent = null;
    if (relative) {
        query = session.createQuery("SELECT COUNT(obs.value) FROM Observed as obs WHERE obs.record = ?"); //$NON-NLS-1$
        query.setEntity(0, record);
        onePercent = (Long) query.uniqueResult();
        onePercent /= 100;
    }

    query = session.createQuery(
            "SELECT COUNT(obs.value) FROM Observed as obs WHERE obs.record = ? and obs.observedKey = ?"); //$NON-NLS-1$
    query.setEntity(0, record);
    for (String key : keys) {
        query.setString(1, key);
        Long val = (Long) query.uniqueResult();
        if (!relative) {
            map.put(key, val);
        } else {
            map.put(key, val / onePercent);
        }
    }

    session.close();
    return Collections.unmodifiableMap(map);
}

From source file:edu.harvard.med.screensaver.db.ScreenDAOImpl.java

License:Open Source License

/**
 * Quickly delete the study by first removing all of the AnnotationTypes and AnnotationValues manually.
 * Uses HQL.//w  w w.  j a  v  a2  s  .  c om
 * Note: standard delete takes too long, as hibernate generates *many* delete statements.
 */
public void deleteStudy(Screen study) throws DataModelViolationException {
    log.info("delete annotation values and and types for the study: " + study.getFacilityId());
    final Screen finalStudy = _dao.reloadEntity(study);

    // TODO: see if we can delete these using the entity delete
    String hql = "delete from AnnotationValue av "
            + "where av.annotationType in (select at from AnnotationType at where at.study = ?)";
    Query query = getHibernateSession().createQuery(hql);
    query.setEntity(0, finalStudy);
    int count = query.executeUpdate();
    log.info("Executed: " + hql + ", count: " + count);

    hql = "delete from AnnotationType at " + "where at.study = ?)";
    query = getHibernateSession().createQuery(hql);
    query.setEntity(0, finalStudy);
    count = query.executeUpdate();
    log.info("Executed: " + hql + ", count: " + count);

    // TODO: reimplement this in the proper (performant) HQL!
    log.info("delete the study: " + finalStudy.getFacilityId());
    String sql = "delete from study_reagent_link where study_id = :studyId";
    log.info("sql: " + sql);
    javax.persistence.Query sqlQuery = getEntityManager().createNativeQuery(sql);
    sqlQuery.setParameter("studyId", finalStudy.getScreenId());
    count = sqlQuery.executeUpdate();
    log.info("study_reagent_link updated: " + count);

    //study.getReagents().clear();
    //_dao.flush();
    _dao.deleteEntity(finalStudy);
    _dao.flush();
    log.info("study deleted");
}

From source file:edu.utah.further.core.data.hibernate.hql.HqlQueryBuilderImpl.java

License:Apache License

/**
 * Produce the HQL query.// w  w  w  .  jav  a  2s.c  o m
 *
 * @param session
 *            Hibernate session
 * @return HQL query
 * @see edu.utah.further.core.data.hibernate.hql.HqlQueryBuilder#toHqlQuery(org.hibernate.Session)
 */
@Override
public Query toHqlQuery(final Session session) {
    final Query query = session.createQuery(hqlBuilder.toString());
    for (final Map.Entry<String, PersistentEntity<?>> entry : entitiesToSet.entrySet()) {
        query.setEntity(entry.getKey(), entry.getValue());
    }
    return query;
}

From source file:es.sm2.openppm.core.dao.EmployeeDAO.java

License:Open Source License

/**
 * Find Approvals TimeSheet//from   ww  w.j av a2  s  .c  o  m
 * object[0] == idEmployee
 * object[1] == Name employee
 * object[2] == idProject
 * object[3] == Project Name 
 * @param pm
 * @param initDate
 * @param endDate
 * @param minStatus
 * @param maxStatus
 * @param statusResource
 * @param includeClosed
 * @return
 */
@SuppressWarnings("unchecked")
public List<Object[]> findApprovalsTimeByPM(Employee pm, Date initDate, Date endDate, String minStatus,
        String maxStatus, String statusResource, boolean includeClosed) {

    String orts2StatusApp2 = "";
    String ortsStatusApp2 = "";

    if (minStatus != null && maxStatus != null) {

        ortsStatusApp2 = "and (ts.status = :minStatus or ts.status = :maxStatus ";
        orts2StatusApp2 = "and (ts2.status = :minStatus or ts2.status = :maxStatus ";

        if (Constants.TIMESTATUS_APP0.equals(minStatus) && (Constants.TIMESTATUS_APP2.equals(maxStatus)
                || Constants.TIMESTATUS_APP3.equals(maxStatus))) {

            ortsStatusApp2 += "or ts.status = :app1 ";
            orts2StatusApp2 += "or ts2.status = :app1 ";
        }

        if (Constants.TIMESTATUS_APP3.equals(maxStatus) && (Constants.TIMESTATUS_APP0.equals(minStatus)
                || Constants.TIMESTATUS_APP1.equals(minStatus))) {

            ortsStatusApp2 += "or ts.status = :app2 ";
            orts2StatusApp2 += "or ts2.status = :app2 ";
        }

        ortsStatusApp2 += ") ";
        orts2StatusApp2 += ") ";
    }

    Query query = getSession().createQuery(
            "select distinct e.idEmployee,c.fullName ,p.idProject, p.projectName " + "from Employee as e "
                    + "join e.timesheets as ts " + "join e.contact as c " + "join ts.projectactivity as pa "
                    + "join pa.teammembers tm " + "join pa.project as p " + "where " + "tm.employee = e and "
                    + (ValidateUtil.isNotNull(statusResource) ? "tm.status = :statusResource and " : "")
                    + "(p.employeeByProjectManager = :pm or " + "(ts.projectactivity is null "
                    + "and e.performingorg = :po " + "and e.idEmployee not in "
                    + "(select distinct e2.idEmployee " + "from Employee as e2 " + "join e2.timesheets as ts2 "
                    + "join ts2.projectactivity as pa2 " + "join pa2.project as p2 "
                    + "where p2.employeeByProjectManager = :pm " + "and ts2.initDate = :initDate "
                    + "and ts2.endDate = :endDate " + orts2StatusApp2 + ")" + ")" + "and e.idEmployee in "
                    + "(select distinct e3.idEmployee " + "from Employee as e3 " + "join e3.timesheets as ts3 "
                    + "join ts3.projectactivity as pa3 " + "join pa3.project as p3 "
                    + "where p3.employeeByProjectManager = :pm " + "and ts3.initDate = :initDate "
                    + "and ts3.endDate = :endDate " + "and ts3.status = :app0" + ")" + ") "
                    + "and ts.initDate = :initDate " + "and ts.endDate = :endDate " + ortsStatusApp2
                    + (!includeClosed ? "and p.status != :statusClosed and p.status != :statusArchived " : ""));

    query.setInteger("pm", pm.getIdEmployee());
    query.setDate("initDate", initDate);
    query.setDate("endDate", endDate);
    query.setEntity("po", pm.getPerformingorg());
    query.setString("app0", Constants.TIMESTATUS_APP0);

    if (!includeClosed) {
        query.setString("statusClosed", Constants.STATUS_CLOSED);
        query.setString("statusArchived", Constants.STATUS_ARCHIVED);
    }

    if (ValidateUtil.isNotNull(statusResource)) {
        query.setString("statusResource", statusResource);
    }

    if (minStatus != null && maxStatus != null) {

        query.setString("maxStatus", maxStatus);
        query.setString("minStatus", minStatus);

        if (Constants.TIMESTATUS_APP0.equals(minStatus) && (Constants.TIMESTATUS_APP2.equals(maxStatus)
                || Constants.TIMESTATUS_APP3.equals(maxStatus))) {

            query.setString("app1", Constants.TIMESTATUS_APP1);
        }

        if (Constants.TIMESTATUS_APP3.equals(maxStatus) && (Constants.TIMESTATUS_APP0.equals(minStatus)
                || Constants.TIMESTATUS_APP1.equals(minStatus))) {

            query.setString("app2", Constants.TIMESTATUS_APP2);
        }
    }

    return query.list();
}

From source file:es.sm2.openppm.core.dao.ProjectDAO.java

License:Open Source License

/**
 * Add parameters/*  w w w . j ava2 s.  c  om*/
 *
 * @param query
 * @param filter
 */
private void addParameters(Query query, ProjectSearch filter) {

    // Add parameter for priority
    if (!ValidateUtil.isNull(filter.getPriority())) {

        if ((ProjectSearch.GREATHER_EQUAL.equals(filter.getPriority())
                || ProjectSearch.LESS_EQUAL.equals(filter.getPriority())) && filter.getLastPriority() != null) {

            query.setInteger("lastPriority", filter.getLastPriority());
        } else if (ProjectSearch.BETWEEN.equals(filter.getPriority()) && filter.getLastPriority() != null
                && filter.getFirstPriority() != null) {

            query.setInteger("firstPriority", filter.getFirstPriority());
            query.setInteger("lastPriority", filter.getLastPriority());
        }
    }

    // Add parameter for risk rating
    if (ValidateUtil.isNotNull(filter.getRiskRating())) {

        if ((ProjectSearch.GREATHER_EQUAL.equals(filter.getRiskRating())
                || ProjectSearch.LESS_EQUAL.equals(filter.getRiskRating()))
                && filter.getLastRiskRating() != null) {

            query.setInteger("lastRiskRating", filter.getLastRiskRating());
        } else if (ProjectSearch.BETWEEN.equals(filter.getRiskRating()) && filter.getLastRiskRating() != null
                && filter.getFirstRiskRating() != null) {

            query.setInteger("firstRiskRating", filter.getFirstRiskRating());
            query.setInteger("lastRiskRating", filter.getLastRiskRating());
        }
    }

    if (filter.getIncludeDisabled() != null && !filter.getIncludeDisabled()) {
        query.setBoolean("disable", Boolean.TRUE);
    }

    if (filter.getSince() != null) {
        query.setDate("since", filter.getSince());
    }
    if (filter.getUntil() != null) {
        query.setDate("until", filter.getUntil());
    }
    if (filter.getInternalProject() != null) {
        query.setBoolean("internalProject", filter.getInternalProject());
    }
    if (filter.getIsGeoSelling() != null) {
        query.setBoolean("isGeoSelling", filter.getIsGeoSelling());
    }
    if (filter.getBudgetYear() != null) {
        query.setInteger("budgetYear", filter.getBudgetYear());
    }
    if (ValidateUtil.isNotNull(filter.getProjectName())) {
        query.setString("projectName", "%" + filter.getProjectName().toUpperCase() + "%");
    }

    Integer[] idsProject = IntegerUtil.parseStringSequence(filter.getProjectName(), StringPool.COMMA);

    if (SettingUtil.getBoolean(filter.getSettings(), VisibilityProjectSetting.PROJECT_COLUMN_IDPROJECT)
            && idsProject != null) {

        query.setParameterList("projectNameID", idsProject);
    }

    if (ValidateUtil.isNotNull(filter.getRag())) {
        query.setCharacter("rag", filter.getRag().charAt(0));
    }
    if (filter.getCompany() != null) {
        query.setEntity("company", filter.getCompany());
    }
    if (filter.getEmployeeByInvestmentManager() != null) {
        query.setEntity("employeeByInvestmentManager", filter.getEmployeeByInvestmentManager());
    }
    if (filter.getStakeholder() != null) {
        query.setEntity("stakeholder", filter.getStakeholder());
    }
    if (filter.getProgramManager() != null) {
        query.setEntity("programManager", filter.getProgramManager());
    }
    if (filter.getIsIndirectSeller() != null) {
        query.setBoolean("isIndirectSeller", filter.getIsIndirectSeller());
    }

    if (ValidateUtil.isNotNull(filter.getPerformingorgs())) {
        query.setParameterList("performingorgs", filter.getPerformingorgs());
    }
    if (ValidateUtil.isNotNull(filter.getEmployeeBySponsors())) {
        query.setParameterList("employeeBySponsors", filter.getEmployeeBySponsors());
    }
    if (ValidateUtil.isNotNull(filter.getEmployeeByProjectManagers())) {
        query.setParameterList("employeeByProjectManagers", filter.getEmployeeByProjectManagers());
    }
    if (ValidateUtil.isNotNull(filter.getCustomers())) {
        query.setParameterList("customers", filter.getCustomers());
    }
    if (ValidateUtil.isNotNull(filter.getCustomertypes())) {
        query.setParameterList("customertypes", filter.getCustomertypes());
    }
    if (ValidateUtil.isNotNull(filter.getPrograms())) {
        query.setParameterList("programs", filter.getPrograms());
    }
    if (ValidateUtil.isNotNull(filter.getCategories())) {
        query.setParameterList("categories", filter.getCategories());
    }
    if (ValidateUtil.isNotNull(filter.getSellers())) {
        query.setParameterList("sellers", filter.getSellers());
    }
    if (ValidateUtil.isNotNull(filter.getGeography())) {
        query.setParameterList("geography", filter.getGeography());
    }
    if (ValidateUtil.isNotNull(filter.getFundingsources())) {
        query.setParameterList("fundingsources", filter.getFundingsources());
    }
    if (ValidateUtil.isNotNull(filter.getProjects())) {
        query.setParameterList("projects", filter.getProjects());
    }
    if (ValidateUtil.isNotNull(filter.getStatus())) {
        query.setParameterList("status", filter.getStatus());
    }
    if (ValidateUtil.isNotNull(filter.getInvestmentStatus())) {
        query.setParameterList("investmentStatus", filter.getInvestmentStatus());
    }
    if (ValidateUtil.isNotNull(filter.getLabels())) {
        query.setParameterList("labels", filter.getLabels());
    }
    if (ValidateUtil.isNotNull(filter.getTechnologies())) {
        query.setParameterList("technologies", filter.getTechnologies());
    }
    if (ValidateUtil.isNotNull(filter.getStageGates())) {
        query.setParameterList("stagegate", filter.getStageGates());
    }
    if (ValidateUtil.isNotNull(filter.getContractTypes())) {
        query.setParameterList("contractTypes", filter.getContractTypes());
    }
    if (ValidateUtil.isNotNull(filter.getEmployeeByFunctionalManagers())) {
        query.setParameterList("employeeByFunctionalManagers", filter.getEmployeeByFunctionalManagers());
    }
    if (ValidateUtil.isNotNull(filter.getClassificationsLevel())) {
        query.setParameterList("classificationsLevel", filter.getClassificationsLevel());
    }

    if (filter.getShowInactivated() != null && !filter.getShowInactivated()) {

        query.setString("hideInactivated", Constants.INVESTMENT_INACTIVATED);
    }
}

From source file:es.sm2.openppm.core.dao.ProjectDAO.java

License:Open Source License

/**
 * //  w w w .ja  v a2 s. c  o m
 * @param filter
 * @return
 */
@SuppressWarnings("unchecked")
public List<ProjectWrap> findProjectsForExecutiveReport(ProjectSearch filter) {

    String q = "SELECT DISTINCT NEW es.sm2.openppm.core.model.wrap.ProjectWrap(" + "p, "
            + "(SELECT CASE WHEN SUM(ch.cost) IS NULL THEN 0d ELSE SUM(ch.cost) END FROM Chargescosts ch WHERE ch.project = p AND (ch.idChargeType = 1 OR ch.idChargeType = 2 OR ch.idChargeType = 3)) "
            + ") " + "FROM Projectactivity pa " + "JOIN pa.project p " + "JOIN p.program pr "
            + "JOIN p.performingorg po " + "LEFT JOIN p.stakeholders stk "
            + "LEFT JOIN pa.activitysellers actSell " + "LEFT JOIN p.projectfundingsources fs "
            + "LEFT JOIN p.projectlabels pl " + "JOIN pa.wbsnode w ";

    String where = "";

    // Create filter for priority
    if (!ValidateUtil.isNull(filter.getPriority())) {

        if (ProjectSearch.GREATHER_EQUAL.equals(filter.getPriority()) && filter.getLastPriority() != null) {

            where += FilterUtil.addFilterAnd(where, "p.priority >= :lastPriority ");
        } else if (ProjectSearch.LESS_EQUAL.equals(filter.getPriority()) && filter.getLastPriority() != null) {

            where += FilterUtil.addFilterAnd(where, "p.priority <= :lastPriority ");
        } else if (ProjectSearch.BETWEEN.equals(filter.getPriority()) && filter.getLastPriority() != null
                && filter.getFirstPriority() != null) {

            where += FilterUtil.addFilterAnd(where, "(p.priority BETWEEN :firstPriority AND :lastPriority) ");
        }
    }

    // Filter by since and until dates
    if (filter.getSince() != null && filter.getUntil() != null) {
        where += FilterUtil.addFilterAnd(where,
                "((p.startDate BETWEEN :since AND :until) OR (p.finishDate BETWEEN :since AND :until) OR (p.startDate <= :since AND p.finishDate >= :until))");
    } else if (filter.getSince() != null) {
        where += FilterUtil.addFilterAnd(where, "p.startDate >= :since ");
    } else if (filter.getUntil() != null) {
        where += FilterUtil.addFilterAnd(where, "p.finishDate <= :since ");
    }

    where += FilterUtil.addFilterAnd(filter.getInternalProject(), where,
            "p.internalProject = :internalProject ");
    where += FilterUtil.addFilterAnd(filter.getBudgetYear(), where, "p.budgetYear = :budgetYear ");
    where += FilterUtil.addFilterAnd(filter.getProjectName(), where,
            "(UPPER(p.projectName) LIKE :projectName OR UPPER(p.chartLabel) LIKE :projectName OR UPPER(p.accountingCode) LIKE :projectName) ");
    where += FilterUtil.addFilterAnd(filter.getRag(), where, "p.rag = :rag ");
    where += FilterUtil.addFilterAnd(filter.getCompany(), where, "po.company = :company ");
    where += FilterUtil.addFilterAnd(filter.getEmployeeByInvestmentManager(), where,
            "p.employeeByInvestmentManager = :employeeByInvestmentManager ");
    if (ValidateUtil.isNotNull(filter.getEmployeeByFunctionalManagers())) {
        where += FilterUtil.addFilterAnd(where,
                "p.employeeByFunctionalManager.idEmployee IN (:employeeByFunctionalManagers) ");
    }
    where += FilterUtil.addFilterAnd(filter.getStakeholder(), where, "stk.employee = :stakeholder ");
    where += FilterUtil.addFilterAnd(filter.getProgramManager(), where, "pr.employee = :programManager ");

    if (ValidateUtil.isNotNull(filter.getPerformingorgs())) {
        where += FilterUtil.addFilterAnd(where, "po.idPerfOrg IN (:performingorgs) ");
    }
    if (ValidateUtil.isNotNull(filter.getEmployeeBySponsors())) {
        where += FilterUtil.addFilterAnd(where, "p.employeeBySponsor.idEmployee IN (:employeeBySponsors) ");
    }
    if (ValidateUtil.isNotNull(filter.getEmployeeByProjectManagers())) {
        where += FilterUtil.addFilterAnd(where,
                "p.employeeByProjectManager.idEmployee IN (:employeeByProjectManagers) ");
    }
    if (ValidateUtil.isNotNull(filter.getCustomers())) {
        where += FilterUtil.addFilterAnd(where, "p.customer.idCustomer IN (:customers) ");
    }
    if (ValidateUtil.isNotNull(filter.getCustomertypes())) {
        where += FilterUtil.addFilterAnd(where, "p.contracttype.idContractType IN (:customertypes) ");
    }
    if (ValidateUtil.isNotNull(filter.getPrograms())) {
        where += FilterUtil.addFilterAnd(where, "p.program.idProgram IN (:programs) ");
    }
    if (ValidateUtil.isNotNull(filter.getCategories())) {
        where += FilterUtil.addFilterAnd(where, "p.category.idCategory IN (:categories) ");
    }
    if (ValidateUtil.isNotNull(filter.getSellers())) {
        where += FilterUtil.addFilterAnd(where, "actSell.seller.idSeller IN (:sellers) ");
    }
    if (ValidateUtil.isNotNull(filter.getGeography())) {
        where += FilterUtil.addFilterAnd(where, "p.geography.idGeography IN (:geography) ");
    }
    if (ValidateUtil.isNotNull(filter.getFundingsources())) {
        where += FilterUtil.addFilterAnd(where, "fs.fundingsource.idFundingSource IN (:fundingsources) ");
    }
    if (ValidateUtil.isNotNull(filter.getProjects())) {
        where += FilterUtil.addFilterAnd(where, "p.idProject IN (:projects) ");
    }
    if (ValidateUtil.isNotNull(filter.getStatus())) {
        where += FilterUtil.addFilterAnd(where, "p.status IN (:status) ");
    }
    if (ValidateUtil.isNotNull(filter.getInvestmentStatus())) {
        where += FilterUtil.addFilterAnd(where, "p.investmentStatus IN (:investmentStatus) ");
    }
    if (ValidateUtil.isNotNull(filter.getLabels())) {
        where += FilterUtil.addFilterAnd(where, "pl.label.idLabel IN (:labels) ");
    }

    Query query = getSession().createQuery(q + where);

    // Add parameter for priority
    if (!ValidateUtil.isNull(filter.getPriority())) {

        if ((ProjectSearch.GREATHER_EQUAL.equals(filter.getPriority())
                || ProjectSearch.LESS_EQUAL.equals(filter.getPriority())) && filter.getLastPriority() != null) {

            query.setInteger("lastPriority", filter.getLastPriority());
        } else if (ProjectSearch.BETWEEN.equals(filter.getPriority()) && filter.getLastPriority() != null
                && filter.getFirstPriority() != null) {

            query.setInteger("firstPriority", filter.getFirstPriority());
            query.setInteger("lastPriority", filter.getLastPriority());
        }
    }

    if (filter.getSince() != null) {
        query.setDate("since", filter.getSince());
    }
    if (filter.getUntil() != null) {
        query.setDate("until", filter.getUntil());
    }
    if (filter.getInternalProject() != null) {
        query.setBoolean("internalProject", filter.getInternalProject());
    }
    if (filter.getBudgetYear() != null) {
        query.setInteger("budgetYear", filter.getBudgetYear());
    }
    if (ValidateUtil.isNotNull(filter.getProjectName())) {
        query.setString("projectName", "%" + filter.getProjectName().toUpperCase() + "%");
    }
    if (ValidateUtil.isNotNull(filter.getRag())) {
        query.setCharacter("rag", filter.getRag().charAt(0));
    }
    if (filter.getCompany() != null) {
        query.setEntity("company", filter.getCompany());
    }
    if (filter.getEmployeeByInvestmentManager() != null) {
        query.setEntity("employeeByInvestmentManager", filter.getEmployeeByInvestmentManager());
    }
    if (ValidateUtil.isNotNull(filter.getEmployeeByFunctionalManagers())) {
        query.setParameterList("employeeByFunctionalManagers", filter.getEmployeeByFunctionalManagers());
    }
    if (filter.getStakeholder() != null) {
        query.setEntity("stakeholder", filter.getStakeholder());
    }
    if (filter.getProgramManager() != null) {
        query.setEntity("programManager", filter.getProgramManager());
    }

    if (ValidateUtil.isNotNull(filter.getPerformingorgs())) {
        query.setParameterList("performingorgs", filter.getPerformingorgs());
    }
    if (ValidateUtil.isNotNull(filter.getEmployeeBySponsors())) {
        query.setParameterList("employeeBySponsors", filter.getEmployeeBySponsors());
    }
    if (ValidateUtil.isNotNull(filter.getEmployeeByProjectManagers())) {
        query.setParameterList("employeeByProjectManagers", filter.getEmployeeByProjectManagers());
    }
    if (ValidateUtil.isNotNull(filter.getCustomers())) {
        query.setParameterList("customers", filter.getCustomers());
    }
    if (ValidateUtil.isNotNull(filter.getCustomertypes())) {
        query.setParameterList("customertypes", filter.getCustomertypes());
    }
    if (ValidateUtil.isNotNull(filter.getPrograms())) {
        query.setParameterList("programs", filter.getPrograms());
    }
    if (ValidateUtil.isNotNull(filter.getCategories())) {
        query.setParameterList("categories", filter.getCategories());
    }
    if (ValidateUtil.isNotNull(filter.getSellers())) {
        query.setParameterList("sellers", filter.getSellers());
    }
    if (ValidateUtil.isNotNull(filter.getGeography())) {
        query.setParameterList("geography", filter.getGeography());
    }
    if (ValidateUtil.isNotNull(filter.getFundingsources())) {
        query.setParameterList("fundingsources", filter.getFundingsources());
    }
    if (ValidateUtil.isNotNull(filter.getProjects())) {
        query.setParameterList("projects", filter.getProjects());
    }
    if (ValidateUtil.isNotNull(filter.getStatus())) {
        query.setParameterList("status", filter.getStatus());
    }
    if (ValidateUtil.isNotNull(filter.getInvestmentStatus())) {
        query.setParameterList("investmentStatus", filter.getInvestmentStatus());
    }
    if (ValidateUtil.isNotNull(filter.getLabels())) {
        query.setParameterList("labels", filter.getLabels());
    }

    return query.list();
}

From source file:es.sm2.openppm.core.dao.TimesheetDAO.java

License:Open Source License

/**
 * Hours assigned//from w w w.  j  a  va2s.  c  om
 * 
 * @param teammember
 * @param minStatus
 * @param maxStatus
 * @return
 */
public boolean hoursInState(Teammember teammember, String minStatus, String maxStatus) {

    String q = "SELECT COUNT(ts) FROM Timesheet ts " + "JOIN ts.employee e " + "JOIN e.teammembers tem "
            + "WHERE " + "ts.projectactivity = :projectactivity "
            + "AND ((ts.initDate between :since and :until) " + "OR (ts.endDate between :since and :until) "
            + "OR (:since between ts.initDate and ts.endDate) "
            + "OR (:until between ts.initDate and ts.endDate)) " + "AND tem = :teammember "
            + "AND (ts.status = :minStatus OR ts.status = :maxStatus)";

    Query query = getSession().createQuery(q);

    query.setEntity("teammember", teammember);
    query.setEntity("projectactivity", teammember.getProjectactivity());
    query.setDate("since", DateUtil.getFirstWeekDay(teammember.getDateIn()));
    query.setDate("until", DateUtil.getFirstWeekDay(teammember.getDateOut()));
    query.setString("minStatus", minStatus);
    query.setString("maxStatus", maxStatus);

    Long count = (Long) query.uniqueResult();

    return (count != null && count > 0);
}