List of usage examples for org.hibernate StatelessSession close
void close();
From source file:au.org.theark.lims.model.dao.BioCollectionDao.java
License:Open Source License
public Boolean hasBioCollections(LinkSubjectStudy linkSubjectStudy) { // Use WHERE EXIST to optimise query even further StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(LinkSubjectStudy.class, "lss"); DetachedCriteria sizeCriteria = DetachedCriteria.forClass(BioCollection.class, "bc"); criteria.add(Restrictions.eq("lss.id", linkSubjectStudy.getId())); sizeCriteria.add(Property.forName("lss.id").eqProperty("bc.linkSubjectStudy.id")); criteria.add(Subqueries.exists(sizeCriteria.setProjection(Projections.property("bc.id")))); criteria.setProjection(Projections.rowCount()); Boolean result = ((Long) criteria.uniqueResult()) > 0L; session.close(); return result; }
From source file:au.org.theark.lims.model.dao.BioCollectionDao.java
License:Open Source License
public Boolean hasBiospecimens(BioCollection bioCollection) { // Use WHERE EXIST to optimise query even further StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(BioCollection.class, "bc"); DetachedCriteria sizeCriteria = DetachedCriteria.forClass(Biospecimen.class, "b"); criteria.add(Restrictions.eq("bc.id", bioCollection.getId())); sizeCriteria.add(Property.forName("bc.id").eqProperty("b.bioCollection.id")); criteria.add(Subqueries.exists(sizeCriteria.setProjection(Projections.property("b.id")))); criteria.setProjection(Projections.rowCount()); Boolean result = ((Long) criteria.uniqueResult()) > 0L; session.close(); return result; }
From source file:au.org.theark.lims.model.dao.BiospecimenDao.java
License:Open Source License
protected BiospecimenUidSequence getBiospecimenUidSequence(Study study) { // Stateless sessions should be used to avoid locking the record for future update // by getSession(), which relies on the "open session filter" mechanism StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(BiospecimenUidSequence.class); criteria.add(Restrictions.eq(Constants.SUBJECTUIDSEQ_STUDYNAMEID, study.getName())); criteria.setMaxResults(1);//from www .j a v a 2 s . c o m BiospecimenUidSequence result = (BiospecimenUidSequence) criteria.uniqueResult(); session.close(); return result; }
From source file:au.org.theark.lims.model.dao.BiospecimenDao.java
License:Open Source License
protected void setSubjectUidSequenceLock(Study study, boolean lock) { // Stateless sessions should be used to avoid locking the record for future update // by getSession(), which relies on the "open session filter" mechanism StatelessSession session = getStatelessSession(); Transaction tx = session.getTransaction(); tx.begin();//from w w w.j a v a2 s. com BiospecimenUidSequence biospecimenUidSeq = getBiospecimenUidSequence(study); if (biospecimenUidSeq == null) { // create a new record if it doens't exist biospecimenUidSeq = new BiospecimenUidSequence(); biospecimenUidSeq.setStudyNameId(study.getName()); biospecimenUidSeq.setUidSequence(new Integer(0)); biospecimenUidSeq.setInsertLock(lock); session.insert(biospecimenUidSeq); } else { biospecimenUidSeq.setInsertLock(lock); session.update(biospecimenUidSeq); } tx.commit(); session.close(); }
From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java
License:Open Source License
@Override public boolean isPhenoDataSetCategoryUnique(String phenoDataSetCategoryName, Study study, PhenoDataSetCategory phenoDataSetCategoryToUpdate) { boolean isUnique = true; StatelessSession stateLessSession = getStatelessSession(); Criteria criteria = stateLessSession.createCriteria(CustomFieldCategory.class); criteria.add(Restrictions.eq("name", phenoDataSetCategoryName)); criteria.add(Restrictions.eq("study", study)); criteria.add(Restrictions.eq("arkFunction", phenoDataSetCategoryToUpdate.getArkFunction())); criteria.setMaxResults(1);// www . j a v a2s . c om PhenoDataSetCategory existingPhenoDataSetCategory = (PhenoDataSetCategory) criteria.uniqueResult(); if ((phenoDataSetCategoryToUpdate.getId() != null && phenoDataSetCategoryToUpdate.getId() > 0)) { if (existingPhenoDataSetCategory != null && !phenoDataSetCategoryToUpdate.getId().equals(existingPhenoDataSetCategory.getId())) { isUnique = false; } } else { if (existingPhenoDataSetCategory != null) { isUnique = false; } } stateLessSession.close(); return isUnique; }
From source file:au.org.theark.phenotypic.model.dao.PhenotypicDao.java
License:Open Source License
public boolean isPhenoDataSetFieldUnqiue(String phenoFieldName, Study study, PhenoDataSetField phenoFieldToUpdate) { boolean isUnique = true; StatelessSession stateLessSession = getStatelessSession(); Criteria criteria = stateLessSession.createCriteria(PhenoDataSetField.class); criteria.add(Restrictions.eq("name", phenoFieldName)); criteria.add(Restrictions.eq("study", study)); criteria.add(Restrictions.eq("arkFunction", phenoFieldToUpdate.getArkFunction())); criteria.setMaxResults(1);/*from w ww. j av a 2 s. c o m*/ PhenoDataSetField existingField = (PhenoDataSetField) criteria.uniqueResult(); if ((phenoFieldToUpdate.getId() != null && phenoFieldToUpdate.getId() > 0)) { if (existingField != null && !phenoFieldToUpdate.getId().equals(existingField.getId())) { isUnique = false; } } else { if (existingField != null) { isUnique = false; } } stateLessSession.close(); return isUnique; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
protected SubjectUidSequence getSubjectUidSequence(Study study) { // log.info("Getting uid seq entity for study " + study.getName()); // Stateless sessions should be used to avoid locking the record for future update // by getSession(), which relies on the "open session filter" mechanism StatelessSession session = getStatelessSession(); Criteria criteria = session.createCriteria(SubjectUidSequence.class); criteria.add(Restrictions.eq(Constants.SUBJECTUIDSEQ_STUDYNAMEID, study.getName())); criteria.setMaxResults(1);//from w w w . ja v a 2 s . c o m SubjectUidSequence result = (SubjectUidSequence) criteria.uniqueResult(); session.close(); log.warn("and got entity with lock = " + result.getInsertLock() + " for study " + study.getName()); return result; }
From source file:au.org.theark.study.model.dao.StudyDao.java
License:Open Source License
public boolean isStudyCompUnique(String studyComponentName, Study study, StudyComp studyComponentToUpdate) { boolean isUnique = true; StatelessSession stateLessSession = getStatelessSession(); Criteria criteria = stateLessSession.createCriteria(StudyComp.class); criteria.add(Restrictions.eq("name", studyComponentName)); criteria.add(Restrictions.eq("study", study)); criteria.setMaxResults(1);// w ww.j a va 2s. c o m StudyComp existingComponent = (StudyComp) criteria.uniqueResult(); if ((studyComponentToUpdate.getId() != null && studyComponentToUpdate.getId() > 0)) { if (existingComponent != null && !studyComponentToUpdate.getId().equals(existingComponent.getId())) { isUnique = false; } } else { if (existingComponent != null) { isUnique = false; } } stateLessSession.close(); return isUnique; }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateChannelSeverityDao.java
License:Mozilla Public License
@Override public void insert(List<ChannelSeverity> channelSeverities) { StatelessSession statelessSession = sessionFactory.openStatelessSession(); try {//from ww w . j a v a 2 s .c o m for (ChannelSeverity channelSeverity : channelSeverities) { statelessSession.insert(channelSeverity); } } finally { statelessSession.close(); } }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateChannelVulnerabilityDao.java
License:Mozilla Public License
@Override public void saveOrUpdateStateless(ChannelVulnerability channelVulnerability) { StatelessSession statelessSession = sessionFactory.openStatelessSession(); statelessSession.insert(channelVulnerability); statelessSession.close(); }