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:org.yamj.core.database.dao.StagingDao.java

License:Open Source License

public List<VideoData> findVideoDatas(String baseName, Library library) {
    if (library == null) {
        return Collections.emptyList();
    }/*from w  w  w .j a  v a2 s .  co  m*/

    StringBuilder sb = new StringBuilder();
    sb.append("SELECT distinct vd ");
    sb.append("FROM VideoData vd ");
    sb.append("JOIN vd.mediaFiles mf ");
    sb.append("JOIN mf.stageFiles sf ");
    sb.append("JOIN sf.stageDirectory sd ");
    sb.append("WHERE sf.fileType=:fileType ");
    sb.append("AND mf.extra=:extra ");
    sb.append("AND lower(sf.baseName)=:baseName ");
    sb.append("AND sd.library=:library ");
    sb.append("AND sf.status != :deleted ");

    Query query = currentSession().createQuery(sb.toString());
    query.setParameter("fileType", FileType.VIDEO);
    query.setBoolean("extra", Boolean.FALSE);
    query.setString("baseName", baseName.toLowerCase());
    query.setParameter("library", library);
    query.setParameter("deleted", StatusType.DELETED);
    query.setCacheable(true);
    query.setCacheMode(CacheMode.NORMAL);
    return query.list();
}

From source file:org.yamj.core.database.dao.StagingDao.java

License:Open Source License

public List<VideoData> findVideoDatas(Collection<StageDirectory> stageDirectories) {
    if (CollectionUtils.isEmpty(stageDirectories)) {
        return Collections.emptyList();
    }/* w ww . j  a  va 2 s .  co  m*/

    StringBuilder sb = new StringBuilder();
    sb.append("SELECT distinct vd ");
    sb.append("FROM VideoData vd ");
    sb.append("JOIN vd.mediaFiles mf ");
    sb.append("JOIN mf.stageFiles sf ");
    sb.append("WHERE sf.fileType=:fileType ");
    sb.append("AND mf.extra=:extra ");
    sb.append("AND sf.stageDirectory in (:stageDirectories) ");
    sb.append("AND sf.status != :deleted ");

    Query query = currentSession().createQuery(sb.toString());
    query.setParameter("fileType", FileType.VIDEO);
    query.setBoolean("extra", Boolean.FALSE);
    query.setParameterList("stageDirectories", stageDirectories);
    query.setParameter("deleted", StatusType.DELETED);
    query.setCacheable(true);
    query.setCacheMode(CacheMode.NORMAL);
    return query.list();
}

From source file:org.yamj.core.database.dao.StagingDao.java

License:Open Source License

public List<StageFile> findVideoStageFiles(Artwork artwork) {
    StringBuilder sb = new StringBuilder();
    sb.append("SELECT distinct sf ");

    long id;/* ww  w.  ja va2s.c  o  m*/
    if (artwork.getSeries() != null) {
        id = artwork.getSeries().getId();
        sb.append("FROM Series ser ");
        sb.append("JOIN ser.seasons sea ");
        sb.append("JOIN sea.videoDatas vd ");
        sb.append("JOIN vd.mediaFiles mf ");
        sb.append("JOIN mf.stageFiles sf ");
        sb.append("WHERE sea.id=:id ");
    } else if (artwork.getSeason() != null) {
        id = artwork.getSeason().getId();
        sb.append("FROM Season sea ");
        sb.append("JOIN sea.videoDatas vd ");
        sb.append("JOIN vd.mediaFiles mf ");
        sb.append("JOIN mf.stageFiles sf ");
        sb.append("WHERE sea.id=:id ");
    } else {
        id = artwork.getVideoData().getId();
        sb.append("FROM VideoData vd ");
        sb.append("JOIN vd.mediaFiles mf ");
        sb.append("JOIN mf.stageFiles sf ");
        sb.append("WHERE vd.id=:id ");
    }
    sb.append("AND sf.fileType=:fileType ");
    sb.append("AND sf.status != :deleted ");

    Query query = currentSession().createQuery(sb.toString());
    query.setLong("id", id);
    query.setParameter("fileType", FileType.VIDEO);
    query.setBoolean("extra", Boolean.FALSE);
    query.setParameter("deleted", StatusType.DELETED);
    query.setCacheable(true);
    query.setCacheMode(CacheMode.NORMAL);
    return query.list();
}

From source file:org.zanata.dao.TextFlowTargetHistoryDAO.java

License:Open Source License

private Query buildContributionStatisticQuery(boolean translations, Long versionId, Long personId,
        Date fromDate, Date toDate, boolean automatedEntry) {
    String lastModifiedColumn = translations ? "translated_by_id" : "reviewed_by_id";

    StringBuilder queryString = new StringBuilder();
    queryString.append("select sum(wordCount), state, localeId from ")
            .append("(select wordCount, id, state, localeId from ").append("(select h.state, tft.id, h.")
            .append(lastModifiedColumn).append(", tf.wordCount, locale.localeId ")
            .append("from HTextFlowTargetHistory h ")
            .append("JOIN HTextFlowTarget tft ON tft.id = h.target_id ")
            .append("JOIN HLocale locale ON locale.id = tft.locale ")
            .append("JOIN HTextFlow tf ON tf.id = tft.tf_id ")
            .append("JOIN HDocument doc ON doc.id = tf.document_Id ")
            .append("where doc.project_iteration_id =:versionId ").append("and h.state in (:states) ")
            .append("and h.").append(lastModifiedColumn).append(" =:personId ")
            .append("and h.lastChanged between :fromDate and :toDate ")
            .append("and h.automatedEntry =:automatedEntry ").append("and tft.").append(lastModifiedColumn)
            .append(" <> h.").append(lastModifiedColumn).append(" ").append("and h.lastChanged = ")
            .append("(select max(lastChanged) from HTextFlowTargetHistory where h.target_id = target_id) ")
            .append("union all ").append("select tft.state, tft.id, tft.").append(lastModifiedColumn)
            .append(", tf.wordCount, locale.localeId ").append("from HTextFlowTarget tft ")
            .append("JOIN HLocale locale ON locale.id = tft.locale ")
            .append("JOIN HTextFlow tf ON tf.id = tft.tf_id ")
            .append("JOIN HDocument doc ON doc.id = tf.document_Id ")
            .append("where doc.project_iteration_id =:versionId ").append("and tft.state in (:states) ")
            .append("and tft.automatedEntry =:automatedEntry ").append("and tft.").append(lastModifiedColumn)
            .append(" =:personId ").append("and tft.lastChanged between :fromDate and :toDate ")
            .append(") as target_history_union ")
            .append("group by state, id, localeId, wordCount) as target_history_group ")
            .append("group by state, localeId");

    Query query = getSession().createSQLQuery(queryString.toString());
    query.setParameter("versionId", versionId);
    query.setParameter("personId", personId);
    if (translations) {
        query.setParameterList("states",
                getContentStateOrdinal(ContentState.TRANSLATED_STATES, ContentState.DRAFT_STATES));
    } else {//  www  .  ja v  a  2 s. com
        query.setParameterList("states", getContentStateOrdinal(ContentState.REVIEWED_STATES));
    }
    query.setBoolean("automatedEntry", automatedEntry);
    query.setTimestamp("fromDate", fromDate);
    query.setTimestamp("toDate", toDate);
    return query;
}

From source file:uk.ac.ucl.chime.examples.ArchetypeSaveLoadExample.java

License:Apache License

public List<ArchetypeData> getArchetypeDataList(String pSessionId, String pContextId) {
    ArchetypeDataDAO dao = new ArchetypeDataDAO();
    Query q = dao.getSession()
            .createQuery("from ArchetypeData where sessionId = ? and contextId = ? and deleted = ?");
    q.setString(0, pSessionId);/*from ww w  . j ava2  s. co  m*/
    q.setString(1, pContextId);
    q.setBoolean(2, false);
    return q.list();
}

From source file:uk.ac.ucl.chime.main.TestCodesMain.java

License:Apache License

private void testHibernateBasedUpdates() {
    ArchetypeDataDAO dao = new ArchetypeDataDAO();
    dao.getSession().getTransaction().begin();
    ArchetypeData d = new ArchetypeData();
    Query q = dao.getSession().createQuery(
            "UPDATE ArchetypeData SET deleted = ? where archetypePath = ? and contextId = ? and sessionId = ?");
    q.setBoolean(0, true);
    q.setString(1, "/data[at0001]/events[at0002]/data[at0003]/items[at0004]/items[at0049]/items[at0050]/value");
    q.setString(2, "Test patient Id22");
    q.setString(3, "84d2a249-f3dc-4766-8669-99b867c8b6b4");
    q.executeUpdate();//from  www  .j av  a2s.co  m
    dao.getSession().getTransaction().commit();

}

From source file:uk.ac.ucl.chime.web.ConnectorBean.java

License:Apache License

protected List<ArchetypeData> getArchetypeDataList(String pSessionId, String pContextId) {
    ArchetypeDataDAO dao = new ArchetypeDataDAO();
    Query q = dao.getSession()
            .createQuery("from ArchetypeData where sessionId = ? and contextId = ? and deleted = ?");
    q.setString(0, pSessionId);/*from  w  w  w .  j a va2s .c o  m*/
    q.setString(1, pContextId);
    q.setBoolean(2, false);
    return q.list();
}

From source file:uk.ac.ucl.chime.wrappers.archetypewrappers.ArchetypeWrapper.java

License:Apache License

protected List<ArchetypeData> getArchetypeDataList() {
    ArchetypeDataDAO dao = new ArchetypeDataDAO();
    Query q = dao.getSession()
            .createQuery("from ArchetypeData where sessionId = ? and contextId = ? and deleted = ?");
    q.setString(0, persistenceSessionId);
    q.setString(1, contextId);/* w w w. j  av a2  s.  co m*/
    q.setBoolean(2, false);
    return q.list();
}

From source file:uk.ac.ucl.chime.wrappers.CodedTextValueConstraintBindingWrapper.java

License:Apache License

@Override
public void saveValueToDB() throws Exception {
    if (dataValue == null && oneOftheMultipleInstances) {
        //now save updates if there are any. this is going to be a set of inserts for our case
        if (dataValueList != null && dataValueList.size() > 0) {
            ArchetypeDataDAO insertDao = new ArchetypeDataDAO();
            insertDao.getSession().beginTransaction();
            for (DataValue dv : dataValueList) {
                ArchetypeData data = new ArchetypeData();
                data.setContextId(containerArchetype.getContextId());
                data.setArchetypeName(containerArchetype.getAdlFileName());
                data.setArchetypePath(wrappedObject.path());
                data.setSessionId(containerArchetype.getPersistenceSessionId());
                data.setArchetypeCreatedAt(containerArchetype.getArchetypeCreationDate());
                data.setFieldCreatedAt(containerArchetype.getArchetypeCreationDate());
                data.setInstanceIndex(0);
                data.setInstanceIndex(0);
                data.setDeleted(false);/*from w  w w .  ja v  a  2 s .c  o m*/
                data.setName("value");
                data.setValueString(((DvCodedText) dv).getDefiningCode().getCodeString());
                insertDao.save(data);
            }
            insertDao.getSession().getTransaction().commit();
        }
    } else if (dataValue == null && !oneOftheMultipleInstances && archetypeDataInstance != null) {
        //this means there is a db row corresponding to this node, but its value is now NULL
        //this is interpreted as deleting that db row
        ArchetypeDataDAO dao = new ArchetypeDataDAO();
        dao.getSession().getTransaction().begin();
        ArchetypeData d = new ArchetypeData();
        Query q = dao.getSession().createQuery(
                "UPDATE ArchetypeData SET deleted = ? where archetypePath = ? and contextId = ? and sessionId = ?");
        q.setBoolean(0, true);
        q.setString(1, wrappedObject.path());
        q.setString(2, containerArchetype.getContextId());
        q.setString(3, containerArchetype.getPersistenceSessionId());
        q.executeUpdate();
        dao.getSession().getTransaction().commit();
    } else if (dataValue != null) {
        ArchetypeData data = getContextBasedArcetypeData();
        data.setName("value");
        data.setValueString(((DvCodedText) dataValue).getDefiningCode().getCodeString());
        archetypeDataInstance = saveWithDelayedPersistenceCheck(data);
    }
}

From source file:uk.ac.ucl.chime.wrappers.CodedTextValueConstraintBindingWrapper.java

License:Apache License

@Override
public void updatePersistedValue() throws Exception {
    //there are values to add and remove, 
    if (oneOftheMultipleInstances && containerArchetype.getMode().equals(ArchetypeWrapper.MODE_UPDATE)) {
        //remove all existing ones, and add new ones from db, if no new ones, it means simply removing old ones.
        ArchetypeDataDAO dao = new ArchetypeDataDAO();
        dao.getSession().getTransaction().begin();
        ArchetypeData d = new ArchetypeData();
        Query q = dao.getSession().createQuery(
                "UPDATE ArchetypeData SET deleted = ? where archetypePath = ? and contextId = ? and sessionId = ?");
        q.setBoolean(0, true);
        q.setString(1, wrappedObject.path());
        q.setString(2, containerArchetype.getContextId());
        q.setString(3, containerArchetype.getPersistenceSessionId());
        q.executeUpdate();/*  w w  w  .  j av  a2s  . co m*/
        dao.getSession().getTransaction().commit();
        //now save updates if there are any. this is going to be a set of inserts for our case
        if (dataValueList != null && dataValueList.size() > 0) {
            ArchetypeDataDAO insertDao = new ArchetypeDataDAO();
            insertDao.getSession().beginTransaction();
            for (DataValue dv : dataValueList) {
                ArchetypeData data = new ArchetypeData();
                data.setContextId(containerArchetype.getContextId());
                data.setArchetypeName(containerArchetype.getAdlFileName());
                data.setArchetypePath(wrappedObject.path());
                data.setSessionId(containerArchetype.getPersistenceSessionId());
                data.setArchetypeCreatedAt(containerArchetype.getArchetypeCreationDate());
                data.setInstanceIndex(0);
                data.setInstanceIndex(0);
                data.setDeleted(false);
                data.setName("value");
                data.setValueString(((DvCodedText) dv).getDefiningCode().getCodeString());
                data.setFieldCreatedAt(containerArchetype.getArchetypeCreationDate());
                insertDao.save(data);
            }
            insertDao.getSession().getTransaction().commit();
        }
    } else if (containerArchetype.getMode().equals(ArchetypeWrapper.MODE_UPDATE))
        saveValueToDB();

}