Example usage for org.hibernate Query setBoolean

List of usage examples for org.hibernate Query setBoolean

Introduction

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

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setBoolean(String name, boolean val) 

Source Link

Document

Bind a named boolean-valued parameter.

Usage

From source file:it.eng.spagobi.tools.dataset.dao.DataSetDAOImpl.java

License:Mozilla Public License

/**
 * Delete all inactive versions of dataset whose id is equal to <code>datasetId</code>
 * /*from  w  w w  . j av  a 2  s  .  c o m*/
 * @param datasetId the id of the of the dataset whose incative version must be deleted
 * 
 * @return true if the incative versions of dataset whose id is equal to  <code>datasetId</code> have
 * been succesfully deleted from database. false otherwise (i.e. the dtaset does not have any inactive versions)
 */
public boolean deleteAllInactiveDataSetVersions(Integer datasetId) {
    Session session;
    Transaction transaction;
    boolean deleted;

    logger.debug("IN");

    session = null;
    transaction = null;
    deleted = false;
    try {
        if (datasetId == null) {
            throw new IllegalArgumentException("Input parameter [datasetId] cannot be null");
        }

        try {
            session = getSession();
            Assert.assertNotNull(session, "session cannot be null");
            transaction = session.beginTransaction();
            Assert.assertNotNull(transaction, "transaction cannot be null");
        } catch (Throwable t) {
            throw new SpagoBIDOAException("An error occured while creating the new transaction", t);
        }

        Query query = session.createQuery("from SbiDataSetHistory h where h.active = ? and h.sbiDsConfig = ?");
        query.setBoolean(0, false);
        query.setInteger(1, datasetId);

        List toBeDeleted = query.list();

        if (toBeDeleted != null && toBeDeleted.isEmpty() == false) {
            Iterator it = toBeDeleted.iterator();
            while (it.hasNext()) {
                SbiDataSetHistory sbiDataSetHistory = (SbiDataSetHistory) it.next();
                if (sbiDataSetHistory != null && !sbiDataSetHistory.isActive()) {
                    session.delete(sbiDataSetHistory);
                }
            }
            transaction.commit();
            deleted = true;
        }

    } catch (Throwable t) {
        if (transaction != null && transaction.isActive()) {
            transaction.rollback();
        }
        throw new SpagoBIDOAException("An unexpected error occured while deleting inactive versions of dataset "
                + "whose id is equal to [" + datasetId + "]", t);
    } finally {
        if (session != null && session.isOpen()) {
            session.close();
        }
        logger.debug("OUT");
    }

    return deleted;
}

From source file:it.eng.spagobi.tools.importexport.ImportUtilities.java

License:Mozilla Public License

/**
 * Load an existing dataset and make modifications as per the exported dataset in input
 * For what concern the history keep track of the previous one and insert the new one
 * //w  w  w . j av  a2 s  . c o m
 * @param exportedDataset the exported dataset
 * @param sessionCurrDB the session curr db
 * @param existingId the existing id
 * 
 * @return the existing dataset modified as per the exported dataset in input
 * 
 * @throws EMFUserError     */
public static SbiDataSetConfig modifyExisting(SbiDataSetConfig exportedDataset, Session sessionCurrDB,
        Integer existingId, Session sessionExpDB, IEngUserProfile profile) {
    logger.debug("IN");
    SbiDataSetConfig existingDataset = null;
    try {
        existingDataset = (SbiDataSetConfig) sessionCurrDB.load(SbiDataSetConfig.class, existingId);
        existingDataset.setLabel(exportedDataset.getLabel());
        existingDataset.setName(exportedDataset.getName());
        existingDataset.setDescription(exportedDataset.getDescription());
        existingDataset.setLabel(exportedDataset.getLabel());
        existingDataset.setName(exportedDataset.getName());
        existingDataset.setDescription(exportedDataset.getDescription());
        SbiCommonInfo i = new SbiCommonInfo();
        String userid = "biadmin";
        if (profile != null) {
            userid = (String) profile.getUserUniqueIdentifier();
        }
        i.setTimeIn(new Date());
        i.setUserIn(userid);
        i.setSbiVersionIn(SbiCommonInfo.SBI_VERSION);
        existingDataset.setCommonInfo(i);

        // Make precedent active inactive, new one will be active
        Query hibQueryPreActive = sessionCurrDB
                .createQuery("from SbiDataSetHistory h where h.active = ? and h.sbiDsConfig = ?");
        hibQueryPreActive.setBoolean(0, true);
        hibQueryPreActive.setInteger(1, existingId);
        SbiDataSetHistory preActive = (SbiDataSetHistory) hibQueryPreActive.uniqueResult();
        preActive.setActive(false);
        sessionCurrDB.update(preActive);

        //         // finally save the new exported history
        //         // insert new Active dataset: in the export DB there is only one for each datasetConfig
        //         Query hibQuery = sessionExpDB.createQuery(" from SbiDataSetHistory where dsId = '" + exportedDataset.getDsId() + "'");
        //         SbiDataSetHistory dsHistory = (SbiDataSetHistory)hibQuery.uniqueResult();
        //
        //
        //         // create a copy for current dataset (cannot modify the one retieved frome export DB
        //         SbiDataSetHistory dsnewHistory = DAOFactory.getDataSetDAO().copyDataSetHistory(dsHistory );
        //
        //         dsnewHistory.setDsId(existingDataset);
        //         sessionCurrDB.save(dsnewHistory);

    } catch (Exception e) {
        logger.error("Error in modifying exported dataset " + exportedDataset.getLabel(), e);
    } finally {
        logger.debug("OUT");
    }
    return existingDataset;
}

From source file:main.java.Contexto.ContextoAlianza.java

@Override
public List<Alianza> seleccionarTodos() {
    Session ses = this.getFactory().openSession();
    Transaction tx = ses.beginTransaction();
    Query query = ses.createQuery("from Alianza p " + "where p.estado=:estado");
    query.setBoolean("estado", true);
    List<Alianza> alianzas = query.list();
    tx.commit();/*from   ww w.  j  a  v a 2s. c  o m*/
    ses.close();
    return alianzas;
}

From source file:main.java.Contexto.ContextoColegio.java

@Override
public List<Colegio> seleccionarTodos() {
    Session ses = this.getFactory().openSession();
    Transaction tx = ses.beginTransaction();
    Query query = ses.createQuery("from Colegio p " + "where p.estado=:estado");
    query.setBoolean("estado", true);
    List<Colegio> Colegios = query.list();
    tx.commit();/*from w  w w  .ja  va2s  .  c  om*/
    ses.close();
    return Colegios;
}

From source file:main.java.Contexto.ContextoMunicipio.java

@Override
public List<Municipio> seleccionarTodos() {
    Session ses = this.getFactory().openSession();
    Transaction tx = ses.beginTransaction();
    Query query = ses.createQuery("from Municipio p " + "where p.estado=:estado");
    query.setBoolean("estado", true);
    List<Municipio> Municipios = query.list();
    tx.commit();/*from   w ww .  java2 s . c  om*/
    ses.close();
    return Municipios;
}

From source file:main.java.Contexto.ContextoProvincia.java

@Override
public List<Provincia> seleccionarTodos() {
    Session ses = this.getFactory().openSession();
    Transaction tx = ses.beginTransaction();
    Query query = ses.createQuery("from Provincia p " + "where p.estado=:estado");
    query.setBoolean("estado", true);
    List<Provincia> Partidos = query.list();
    tx.commit();/*w  ww  .  java  2s  .  c o m*/
    ses.close();
    return Partidos;
}

From source file:main.java.Contexto.ContextoUsuario.java

@Override
public List<Empleado> seleccionarTodos() {
    Session ses = this.getFactory().openSession();
    Transaction tx = ses.beginTransaction();
    Query query = ses.createQuery("from Empleado p " + "where p.estado=:estado");
    query.setBoolean("estado", true);
    List<Empleado> empleados = query.list();
    tx.commit();//  ww w . ja v a2 s . com
    ses.close();
    return empleados;
}

From source file:net.sf.jguard.ext.authentication.manager.HibernateAuthenticationManager.java

License:Open Source License

private Set findUsers(JGuardCredential cred, boolean priv) {
    String q = " select subject from net.sf.jguard.ext.principals.PersistedSubject as subject ";
    if (cred.getName().equals(LOGIN) || cred.getName().equals(ACTIVE)) {
        q += "  where subject." + cred.getName() + "= :" + cred.getName();
    } else {/*from   w  ww .  j av a2s .c  o  m*/
        if (priv) {
            q += " inner join subject.privateCredentials as cred ";
        } else {
            q += " inner join subject.publicCredentials as cred ";
        }

        q += " where cred.name= :name and cred.value= :value ";
    }

    Query query = sessionProvider.get().createQuery(q);

    if (cred.getName().equals(LOGIN)) {
        query.setString(cred.getName(), cred.getValue().toString());
    } else if (cred.getName().equals(ACTIVE)) {
        query.setBoolean(cred.getName(), Boolean.valueOf(cred.getValue().toString()));
    } else {
        query.setString(NAME, cred.getName());
        query.setString(VALUE, cred.getValue().toString());
    }
    List results = query.list();
    return new HashSet(results);

}

From source file:org.egov.works.reports.service.WorkProgressRegisterService.java

License:Open Source License

private Query setParameterForDepartmentWiseReport(EstimateAbstractReport estimateAbstractReport, Query query) {
    if (estimateAbstractReport != null) {

        if (estimateAbstractReport.isSpillOverFlag()) {
            query.setBoolean("spilloverflag", true);
        }// w  w  w.  ja v a  2  s .  c om
        if (estimateAbstractReport.getDepartment() != null) {
            query.setLong("department", estimateAbstractReport.getDepartment());
        }

        if (estimateAbstractReport.getAdminSanctionFromDate() != null) {
            query.setDate("fromDate", estimateAbstractReport.getAdminSanctionFromDate());
        }

        if (estimateAbstractReport.getAdminSanctionToDate() != null) {
            query.setDate("toDate", estimateAbstractReport.getAdminSanctionToDate());
        }

        if (estimateAbstractReport.getScheme() != null) {
            query.setLong("scheme", estimateAbstractReport.getScheme());
        }

        if (estimateAbstractReport.getSubScheme() != null) {
            query.setLong("subScheme", estimateAbstractReport.getSubScheme());
        }

        if (estimateAbstractReport.getWorkCategory() != null) {
            query.setString("workcategory", estimateAbstractReport.getWorkCategory());
        }

        if (estimateAbstractReport.getBeneficiary() != null) {
            query.setString("beneficiary", estimateAbstractReport.getBeneficiary());
        }

        if (estimateAbstractReport.getNatureOfWork() != null) {
            query.setLong("natureofwork", estimateAbstractReport.getNatureOfWork());
        }

    }
    return query;
}

From source file:org.egov.works.reports.service.WorkProgressRegisterService.java

License:Open Source License

private Query setParameterForTypeOfWorkWiseReport(EstimateAbstractReport estimateAbstractReport, Query query) {

    if (estimateAbstractReport != null) {
        if (estimateAbstractReport.isSpillOverFlag()) {
            query.setBoolean("spilloverflag", true);

        }// ww w.  ja va 2 s  . c  om

        if (estimateAbstractReport.getTypeOfWork() != null) {
            query.setLong("typeofwork", estimateAbstractReport.getTypeOfWork());
        }

        if (estimateAbstractReport.getSubTypeOfWork() != null) {
            query.setLong("subtypeofwork", estimateAbstractReport.getSubTypeOfWork());
        }

        if (estimateAbstractReport.getDepartments() != null
                && !estimateAbstractReport.getDepartments().toString().equalsIgnoreCase("[null]")) {
            List<Long> departmentIds = new ArrayList<Long>();
            for (Department dept : estimateAbstractReport.getDepartments()) {
                departmentIds.add(dept.getId());
            }
            query.setParameterList("departmentIds", departmentIds);

        }
        if (estimateAbstractReport.getAdminSanctionFromDate() != null) {
            query.setDate("fromDate", estimateAbstractReport.getAdminSanctionFromDate());
        }

        if (estimateAbstractReport.getAdminSanctionToDate() != null) {
            query.setDate("toDate", estimateAbstractReport.getAdminSanctionToDate());
        }
        if (estimateAbstractReport.getScheme() != null) {
            query.setLong("scheme", estimateAbstractReport.getScheme());
        }

        if (estimateAbstractReport.getSubScheme() != null) {
            query.setLong("subScheme", estimateAbstractReport.getSubScheme());
        }

        if (estimateAbstractReport.getWorkCategory() != null) {
            query.setString("workcategory", estimateAbstractReport.getWorkCategory());
        }

        if (estimateAbstractReport.getBeneficiary() != null) {
            query.setString("beneficiary", estimateAbstractReport.getBeneficiary());
        }

        if (estimateAbstractReport.getNatureOfWork() != null) {
            query.setLong("natureofwork", estimateAbstractReport.getNatureOfWork());
        }

    }
    return query;
}