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:uk.ac.ucl.chime.wrappers.CodedTextValueWrapper.java

License:Apache License

public void removeValue(String pValue) throws Exception {
    pValue = pValue.replaceAll("\\[", "").replaceAll("\\]", "");
    ArchetypeDataDAO dao = new ArchetypeDataDAO();
    Query q = dao.getSession().createQuery("from ArchetypeData where sessionId = ? and contextId = ? "
            + " and archetype_path = ?" + " and value_string = ?" + " and deleted = ?");
    q.setString(0, containerArchetype.getPersistenceSessionId());
    q.setString(1, containerArchetype.getContextId());
    q.setString(2, wrappedObject.path());
    q.setString(3, pValue);//from   w w  w  .ja v a 2s  .  co m
    q.setBoolean(4, false);
    List<ArchetypeData> rowsToDelete = q.list();
    if (rowsToDelete.size() > 1)
        throw new Exception("Multiple instances found for delete request");
    if (rowsToDelete.size() == 0)
        throw new Exception("No instances found for delete request");
    dao.getSession().getTransaction().begin();
    rowsToDelete.get(0).setDeleted(true);
    dao.attachDirty(rowsToDelete.get(0));
    dao.getSession().getTransaction().commit();
}

From source file:uk.ac.ucl.chime.wrappers.CodedTextValueWrapper.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();/*from w ww .j  a va 2  s  .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).getValue());
                data.setFieldCreatedAt(containerArchetype.getArchetypeCreationDate());
                insertDao.save(data);
            }
            insertDao.getSession().getTransaction().commit();
        }
    } else if (containerArchetype.getMode().equals(ArchetypeWrapper.MODE_UPDATE))
        saveValueToDB();

}