Example usage for org.hibernate Session delete

List of usage examples for org.hibernate Session delete

Introduction

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

Prototype

void delete(Object object);

Source Link

Document

Remove a persistent instance from the datastore.

Usage

From source file:au.gov.naa.digipres.spyd.dao.hibernate.HibernateItemRecordDAO.java

License:Open Source License

@Override
public void removeItemRecord(ItemRecord itemRecord) {
    logger.fine("Removing Item Record");
    Session session = HibernateUtil.getSession();
    session.delete(itemRecord);
    session.flush();//  w ww. j  av a  2 s. co  m
    session.clear();
    logger.fine("Item Record Removed.");
}

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

public void createOrUpdateArkModuleFunction(ArkModule arkModule, Collection<ArkFunction> selectedArkFunctions) {
    Session session = getSession();

    // Remove previous list of ArkFunctions
    Collection<ArkModuleFunction> arkModuleFunctions = getArkModuleFunctionByArkModule(arkModule);
    for (ArkModuleFunction arkModuleFunctionToRemove : arkModuleFunctions) {
        session.delete(arkModuleFunctionToRemove);
    }/*from  w  ww .  j  a  v  a2s .  co m*/

    // Insert the ArkFunctions for the ArkModule
    Long functionSequence = new Long(1);
    for (Iterator<ArkFunction> iterator = selectedArkFunctions.iterator(); iterator.hasNext();) {
        ArkModuleFunction arkModuleFunction = new ArkModuleFunction();
        ArkFunction arkFunction = iterator.next();
        arkModuleFunction.setArkModule(arkModule);
        arkModuleFunction.setArkFunction(arkFunction);
        arkModuleFunction.setFunctionSequence(functionSequence++);
        session.save(arkModuleFunction);
    }

    // Flush must be the last thing to call. If there is any other code/logic to be added make sure session.flush() is invoked after that.
    session.flush();
}

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

public void createArkModuleRole(ArkModule arkModule, Collection<ArkRole> selectedArkRoles) {
    Session session = getSession();

    // Remove previous list of ArkRoles
    List<ArkModuleRole> arkModuleRoles = getArkModuleRoleByArkModule(arkModule);
    for (ArkModuleRole arkModuleRoleToRemove : arkModuleRoles) {
        session.delete(arkModuleRoleToRemove);
    }//  w  w  w.j  a  v a2 s.c om

    ArkPermission arkPermission = getArkPermissionByName("READ");

    // Insert the ArkRoles for the ArkModule
    for (Iterator<ArkRole> iterator = selectedArkRoles.iterator(); iterator.hasNext();) {
        ArkModuleRole arkModuleRole = new ArkModuleRole();
        ArkRole arkRole = iterator.next();
        arkModuleRole.setArkModule(arkModule);
        arkModuleRole.setArkRole(arkRole);

        session.save(arkModuleRole);

        // Add a default READ permission to NEW module/roles
        List<ArkFunction> arkFunctions = getArkFunctionListByArkModule(arkModule);
        for (Iterator iterator2 = arkFunctions.iterator(); iterator2.hasNext();) {
            ArkFunction arkFunction = (ArkFunction) iterator2.next();
            ArkRolePolicyTemplate arkRolePolicyTemplate = new ArkRolePolicyTemplate();
            arkRolePolicyTemplate.setArkRole(arkRole);
            arkRolePolicyTemplate.setArkModule(arkModule);
            arkRolePolicyTemplate.setArkFunction(arkFunction);
            arkRolePolicyTemplate.setArkPermission(arkPermission);

            session.save(arkRolePolicyTemplate);
        }
    }

    // Flush must be the last thing to call. If there is any other code/logic to be added make sure session.flush() is invoked after that.
    session.flush();
}

From source file:au.org.theark.admin.model.dao.AdminDao.java

License:Open Source License

public void updateArkModuleRole(ArkModule arkModule, Collection<ArkRole> selectedArkRoles) {
    Session session = getSession();

    // Remove previous list of ArkRoles
    List<ArkModuleRole> arkModuleRoles = getArkModuleRoleByArkModule(arkModule);
    for (ArkModuleRole arkModuleRoleToRemove : arkModuleRoles) {
        session.delete(arkModuleRoleToRemove);
    }//w w  w .  j  av  a 2  s .c  o  m

    // Insert the ArkRoles for the ArkModule
    for (Iterator<ArkRole> iterator = selectedArkRoles.iterator(); iterator.hasNext();) {
        ArkModuleRole arkModuleRole = new ArkModuleRole();
        ArkRole arkRole = iterator.next();
        arkModuleRole.setArkModule(arkModule);
        arkModuleRole.setArkRole(arkRole);
        session.save(arkModuleRole);
    }

    // Flush must be the last thing to call. If there is any other code/logic to be added make sure session.flush() is invoked after that.
    session.flush();
}

From source file:au.org.theark.core.dao.ArkAuthorisationDao.java

License:Open Source License

/**
 * Will update the ArkUser or adds the user into ArkUser table. It determines the List of ArkUserRoles for insertion and removal and processes
 * these ArkUserRole lists./*  ww w .  ja va 2  s.co  m*/
 * 
 * @param arkUserVO
 * @throws EntityNotFoundException
 * @throws ArkSystemException
 */
public void updateArkUser(ArkUserVO arkUserVO) throws EntityNotFoundException, ArkSystemException {
    try {
        if (arkUserVO.getArkUserEntity() != null && arkUserVO.getArkUserEntity().getId() != null) {
            // Never update/delete Super User records
            Session session = getSession();
            if (!isUserAdminHelper(arkUserVO.getArkUserEntity().getLdapUserName(),
                    au.org.theark.core.security.RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR)) {
                // User is present in the ArkUserTable can go for update of the entity and related objects (ArkUserRoles)
                session.update(arkUserVO.getArkUserEntity());

                // Insert new ArkUserRole
                for (ArkUserRole arkUserRoleToAdd : getArkUserRolesToAdd(arkUserVO)) {
                    if (arkUserRoleToAdd.getArkRole() != null) {
                        arkUserRoleToAdd.setArkUser(arkUserVO.getArkUserEntity());
                        session.save(arkUserRoleToAdd);
                    }
                }

                for (ArkUserRole arkUserRoleToRemove : getArkUserRolesToRemove(arkUserVO)) {
                    session.delete(arkUserRoleToRemove);
                }
            }
            for (UserConfig config : arkUserVO.getArkUserConfigs()) {
                session.update(config);
            }
        } else {
            createArkUser(arkUserVO);
        }
    } catch (Exception exception) {
        StringBuffer sb = new StringBuffer();
        sb.append("There was an exception while updating the ArkUser in the backend.");
        sb.append(exception.getMessage());
        log.error(sb.toString());
        throw new ArkSystemException();
    }
}

From source file:au.org.theark.core.dao.ArkAuthorisationDao.java

License:Open Source License

public void deleteArkUser(ArkUserVO arkUserVO) throws ArkSystemException, EntityNotFoundException {

    Session session = getSession();
    // Remove all roles linked to this ark user
    for (ArkUserRole arkUserRole : arkUserVO.getArkUserRoleList()) {
        session.delete(arkUserRole);
    }/*from w  ww . j  av  a  2s. co  m*/

    List<ArkUserRole> listOfRoles = getArkRoleListByUser(arkUserVO);
    if (listOfRoles.size() <= 0) {
        // Remove the ArkUser From the database only
        session.delete(arkUserVO.getArkUserEntity());
    }
}

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);/*from   ww w .j  a v  a  2 s.  c  o m*/
    session.flush();
    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.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

/**
 * Update CustomFieldGroup and its related CustomFields(Add or remove)
 *//*from  ww  w  .  j a v  a 2 s  .  c om*/
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.phenotypic.model.dao.PhenotypicDao.java

License:Open Source License

public void deleteCustomFieldGroup(CustomFieldGroupVO customFieldGroupVO) {
    //Delete all the CustomFieldDisplay Items linked to the Group
    Session session = getSession();
    Collection<CustomFieldDisplay> customFieldDisplayList = getCustomFieldDisplayForCustomFieldGroup(
            customFieldGroupVO.getCustomFieldGroup());
    for (CustomFieldDisplay customFieldDisplay : customFieldDisplayList) {
        session.delete(customFieldDisplay);
    }/*  w  w w.j a v a2  s .c om*/
    session.delete(customFieldGroupVO.getCustomFieldGroup());
}

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

License:Open Source License

@Override
public void updatePhenoDataSetFieldGroup(PhenoDataSetFieldGroupVO phenoDataSetFieldGroupVO)
        throws EntityExistsException, ArkSystemException {
    PhenoDataSetGroup phenoDataSetGroup = phenoDataSetFieldGroupVO.getPhenoDataSetGroup();
    Session session = getSession();
    session.saveOrUpdate(phenoDataSetGroup);//Update phenoDataSetGroup
    Collection<PhenoDataSetFieldDisplay> phenoDataSetFieldDisplayToRemove = getPhenoFieldDisplayToRemove(
            phenoDataSetGroup);/*from w  ww.ja  v a2 s.  c  om*/
    for (PhenoDataSetFieldDisplay phenoDataSetFieldDisplay : phenoDataSetFieldDisplayToRemove) {
        session.delete(phenoDataSetFieldDisplay);
        session.flush();
    }
    insertToDispalyAndDeleteFromLinkAndPicked(phenoDataSetFieldGroupVO, phenoDataSetGroup, session);
    log.debug("Update PhenoDataSetFieldDisplay for PhenoDataSet Group");

}