Example usage for org.hibernate Session update

List of usage examples for org.hibernate Session update

Introduction

In this page you can find the example usage for org.hibernate Session update.

Prototype

void update(Object object);

Source Link

Document

Update the persistent instance with the identifier of the given detached instance.

Usage

From source file:au.org.theark.lims.model.dao.InventoryDao.java

License:Open Source License

public void updateInvSite(LimsVO modelObject) {

    InvSite invSite = modelObject.getInvSite();
    Session session = getSession();
    session.update(invSite);
    session.flush();/*from w ww.j av a2 s  .com*/
    session.refresh(invSite);
    List<StudyInvSite> existingInvSites = invSite.getStudyInvSites();

    //for (StudyInvSite sis : modelObject.getInvSite().getStudyInvSites()) {
    //      session.delete(sis);
    //      session.flush();
    //}

    List<Long> selectedAndExistingStudies = new ArrayList<Long>();
    List<Study> selectedStudies = modelObject.getSelectedStudies();

    for (Study selectedStudy : selectedStudies) {
        boolean studyAlreadyLinked = false;
        log.info("selected =" + selectedStudy.getId());

        for (StudyInvSite sis : existingInvSites) {
            Study existingStudy = sis.getStudy();
            log.info("  existing=" + selectedStudy.getId());
            if (existingStudy.getId().equals(selectedStudy.getId())) {
                log.info("found a match for " + selectedStudy.getId());
                studyAlreadyLinked = true;
                selectedAndExistingStudies.add(selectedStudy.getId());
                break; // leave it along
            }
        }

        if (!studyAlreadyLinked) {
            log.info("about to create" + selectedStudy.getId());
            StudyInvSite studyInvSite = new StudyInvSite();
            studyInvSite.setStudy(selectedStudy);
            studyInvSite.setInvSite(invSite);
            session.save(studyInvSite);
        }

    }

    for (StudyInvSite sis : existingInvSites) {
        log.info("about to investigate for deletion existing study " + sis.getStudy().getId());
        boolean deletePreviouslyExistingSiteAsItWasNotSelected = true;
        for (Long selectedId : selectedAndExistingStudies) {
            log.info("compare it to selected " + selectedId);
            if (selectedId.equals(sis.getStudy().getId())) {
                log.info("recommending you don't delete");
                deletePreviouslyExistingSiteAsItWasNotSelected = false;
            } else {
                log.info("match not found.");
            }
        }
        if (deletePreviouslyExistingSiteAsItWasNotSelected) {
            log.info("deleting " + sis.getStudy().getId());
            session.delete(sis);
        }
    }
    session.flush();
    session.refresh(invSite);

    //List<StudyInvSite> existingInvSites = invSite.getStudyInvSites();

    //for (StudyInvSite sis : modelObject.getInvSite().getStudyInvSites()) {
    //   session.delete(sis);
    //   session.flush();
    //}

    /*
            
    List<Study> selectedAndExistingStudies = new ArrayList<Study>();
    List<Study> selectedStudies = modelObject.getSelectedStudies();
            
    for (Study selectedStudy : selectedStudies) {
       boolean studyAlreadyLinked = false;
       for(StudyInvSite sis: existingInvSites){
    Study existingStudy = sis.getStudy();
    if(existingStudy.equals(selectedStudy)){
       studyAlreadyLinked = true;
       selectedAndExistingStudies.add(selectedStudy);
       break; // leave it along
    }
       }
               
       if(!studyAlreadyLinked){
    StudyInvSite studyInvSite = new StudyInvSite();
    studyInvSite.setStudy(selectedStudy);
    studyInvSite.setInvSite(modelObject.getInvSite());
    session.save(studyInvSite);
       }
               
    }
            
    for(StudyInvSite sis: existingInvSites){
       if(!selectedAndExistingStudies.contains(sis.getStudy())){
    session.delete(sis);
       }
    }
    */
}

From source file:au.org.theark.lims.model.dao.InventoryDao.java

License:Open Source License

public void unallocateBox(InvBox invBox) {
    Session session = getSession();
    for (InvCell invCell : invBox.getInvCells()) {
        invCell.setBiospecimen(null);//  ww  w  . j  a  va2 s .com
        session.update(invCell);
    }
    session.refresh(invBox);
}

From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

/**
 * Update CustomFieldGroup and its related CustomFields(Add or remove)
 *//*from w w w.j a v a 2 s .co  m*/
public void updateCustomFieldGroup(CustomFieldGroupVO customFieldGroupVO)
        throws EntityExistsException, ArkSystemException {

    CustomFieldGroup customFieldGroup = customFieldGroupVO.getCustomFieldGroup();
    Session session = getSession();
    session.update(customFieldGroup);//Update

    if (!customFieldGroup.getPublished()) {//Allow Removal only if the form is not published
        Collection<CustomFieldDisplay> customFieldDisplayToRemove = getCustomFieldDisplayToRemove(
                customFieldGroupVO.getSelectedCustomFields(), customFieldGroup);
        for (CustomFieldDisplay cfd : customFieldDisplayToRemove) {
            session.delete(cfd);
        }
    }

    ArrayList<CustomFieldDisplay> customFieldsToAdd = getCustomFieldsToAdd(
            customFieldGroupVO.getSelectedCustomFields(), customFieldGroup);
    for (CustomFieldDisplay fieldToAdd : customFieldsToAdd) {
        session.saveOrUpdate(fieldToAdd);//Add a new CustomFieldDisplay field that is linked to the CustomField   
    }

    ArrayList<CustomField> list = customFieldGroupVO.getSelectedCustomFields();
    int position = 0;

    for (CustomField customField : list) {
        ++position;
        CustomFieldDisplay cfd = iArkCommonService.getCustomFieldDisplayByCustomField(customField,
                customFieldGroupVO.getCustomFieldGroup());
        cfd.setSequence(new Long(position));
        session.update(cfd);
    }

}

From source file:au.org.theark.study.model.dao.StudyDao.java

License:Open Source License

public void create(Study study, Collection<ArkModule> selectedModules, Study parentStudy) {
    Session session = getSession();
    session.save(study);//from  w  ww.j a  v a  2 s . co m
    linkStudyToArkModule(study, selectedModules, session, au.org.theark.core.Constants.MODE_NEW);

    // Update parent study accordingly
    if (parentStudy != null) {
        parentStudy.setParentStudy(parentStudy);
        session.update(parentStudy);
    }
}

From source file:au.org.theark.study.model.dao.StudyDao.java

License:Open Source License

public void create(Study study, ArkUserVO arkUserVo, Collection<ArkModule> selectedModules) {
    Session session = getSession();
    session.save(study);/*from w  ww.jav a 2  s.c  o m*/
    linkStudyToArkModule(study, selectedModules, session, au.org.theark.core.Constants.MODE_NEW);

    // Update parent study accordingly
    Study parentStudy = study.getParentStudy();
    if (parentStudy != null) {
        parentStudy.setParentStudy(parentStudy);
        session.update(parentStudy);
    }

    // Assign user to newly created study
    try {
        iArkAuthorisationService.updateArkUser(arkUserVo);
    } catch (ArkSystemException e) {
        log.error(e.getMessage());
    } catch (EntityNotFoundException e) {
        log.error(e.getMessage());
    }
}

From source file:au.org.theark.study.model.dao.StudyDao.java

License:Open Source License

private void linkStudyToArkModule(Study study, Collection<ArkModule> selectedModules, Session session,
        int mode) {
    for (ArkModule arkModule : selectedModules) {
        LinkStudyArkModule linkStudyArkModule = new LinkStudyArkModule();
        linkStudyArkModule.setStudy(study);
        linkStudyArkModule.setArkModule(arkModule);
        if (mode == au.org.theark.core.Constants.MODE_NEW) {
            session.save(linkStudyArkModule);
        } else {/*w  w w . ja v  a  2 s .  c  o m*/
            session.update(linkStudyArkModule);
        }
    }
}

From source file:au.org.theark.study.model.dao.StudyDao.java

License:Open Source License

public void updateStudy(Study studyEntity) {
    // session.update and session.flush required as Blob read/writes are used, and InputStream may cause NullPointers when closed incorrectly
    Session session = getSession();
    session.update(studyEntity);
    // session.refresh(studyEntity);

    session.flush();//from w w  w.  java2 s  .  c om
}

From source file:au.org.theark.study.model.dao.StudyDao.java

License:Open Source License

public void updateSubject(SubjectVO subjectVO) throws ArkUniqueException {
    Session session = getSession();

    Person person = subjectVO.getLinkSubjectStudy().getPerson();
    String currentLastNameFromDB = getCurrentLastnameFromDB(person);// may need to test this effect of a reget

    session.update(person);// Update Person and associated Phones

    PersonLastnameHistory personLastNameHistory = null;

    if (currentLastNameFromDB != null && !currentLastNameFromDB.isEmpty()
            && !currentLastNameFromDB.equalsIgnoreCase(person.getLastName())) {
        if (person.getLastName() != null) {
            personLastNameHistory = new PersonLastnameHistory();
            personLastNameHistory.setPerson(person);
            personLastNameHistory.setLastName(currentLastNameFromDB);
            session.save(personLastNameHistory);
        }/*from www  .  j a v  a 2s  .com*/
    }

    // Update subjectPreviousLastname
    if (personLastNameHistory != null) {
        subjectVO.setSubjectPreviousLastname(getPreviousLastname(person));
    }

    LinkSubjectStudy linkSubjectStudy = subjectVO.getLinkSubjectStudy();
    session.merge(linkSubjectStudy);
}

From source file:au.org.theark.study.model.dao.StudyDao.java

License:Open Source License

public void update(Address address) throws ArkSystemException {
    Session session = getSession();
    session.update(address);
}

From source file:au.org.theark.study.model.dao.StudyDao.java

License:Open Source License

public void update(ConsentFile consentFile) throws ArkSystemException, EntityNotFoundException {
    Session session = getSession();

    dateNow = new Date(System.currentTimeMillis());
    consentFile.setUpdateTime(dateNow);//  w  ww.  ja v  a 2  s.  c  o  m

    if ((ConsentFile) session.get(ConsentFile.class, consentFile.getId()) != null) {
        session.update(consentFile);
    } else {
        throw new EntityNotFoundException(
                "The Consent file record you tried to update does not exist in the Ark System");
    }
}