List of usage examples for org.hibernate Session buildLockRequest
LockRequest buildLockRequest(LockOptions lockOptions);
From source file:org.springframework.orm.hibernate4.HibernateTemplate.java
License:Apache License
@Override public void update(final String entityName, final Object entity, final LockMode lockMode) throws DataAccessException { executeWithNativeSession(new HibernateCallback<Object>() { @Override//from w ww . java2s. co m public Object doInHibernate(Session session) throws HibernateException { checkWriteOperationAllowed(session); session.update(entityName, entity); if (lockMode != null) { session.buildLockRequest(new LockOptions(lockMode)).lock(entityName, entity); } return null; } }); }
From source file:org.springframework.orm.hibernate4.HibernateTemplate.java
License:Apache License
@Override public void delete(final Object entity, final LockMode lockMode) throws DataAccessException { executeWithNativeSession(new HibernateCallback<Object>() { @Override//from w w w . j a va2 s. c o m public Object doInHibernate(Session session) throws HibernateException { checkWriteOperationAllowed(session); if (lockMode != null) { session.buildLockRequest(new LockOptions(lockMode)).lock(entity); } session.delete(entity); return null; } }); }
From source file:org.springframework.orm.hibernate4.HibernateTemplate.java
License:Apache License
@Override public void delete(final String entityName, final Object entity, final LockMode lockMode) throws DataAccessException { executeWithNativeSession(new HibernateCallback<Object>() { @Override//from www.jav a2 s . com public Object doInHibernate(Session session) throws HibernateException { checkWriteOperationAllowed(session); if (lockMode != null) { session.buildLockRequest(new LockOptions(lockMode)).lock(entityName, entity); } session.delete(entityName, entity); return null; } }); }
From source file:podd.dataaccess.hibernate.AbstractHibernateDAOImpl.java
License:Open Source License
@Override public void reattach(T entity) { if (entity != null) { Session session = getSession(); try {//from w w w . j a v a 2 s .c o m if (PoddObject.class.isAssignableFrom(entity.getClass())) { PoddObject po = (PoddObject) entity; Long id = po.getId(); if (id != null) { try { session.buildLockRequest(LockOptions.NONE).lock(entity); } catch (NonUniqueObjectException e) { LOGGER.info("Merging entity instead of locking"); session.merge(entity); } catch (HibernateException e) { // Catch the following error // org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions LOGGER.info("Merging entity instead of locking"); session.merge(entity); } catch (HibernateSystemException e) { LOGGER.info("Merging entity instead of locking"); session.merge(entity); } } } } catch (HibernateException e) { LOGGER.warn("Found exception", e); } finally { releaseSession(session); } } }
From source file:ubic.gemma.persistence.service.analysis.expression.diff.DifferentialExpressionAnalysisDaoImpl.java
License:Apache License
@Override public void thaw(DifferentialExpressionAnalysis differentialExpressionAnalysis) { StopWatch timer = new StopWatch(); timer.start();// ww w. j a va 2 s. c om Session session = this.getSessionFactory().getCurrentSession(); session.clear(); session.buildLockRequest(LockOptions.NONE).lock(differentialExpressionAnalysis); Hibernate.initialize(differentialExpressionAnalysis); Hibernate.initialize(differentialExpressionAnalysis.getExperimentAnalyzed()); session.buildLockRequest(LockOptions.NONE).lock(differentialExpressionAnalysis.getExperimentAnalyzed()); Hibernate.initialize(differentialExpressionAnalysis.getExperimentAnalyzed().getBioAssays()); Hibernate.initialize(differentialExpressionAnalysis.getProtocol()); if (differentialExpressionAnalysis.getSubsetFactorValue() != null) { Hibernate.initialize(differentialExpressionAnalysis.getSubsetFactorValue()); } Collection<ExpressionAnalysisResultSet> ears = differentialExpressionAnalysis.getResultSets(); Hibernate.initialize(ears); for (ExpressionAnalysisResultSet ear : ears) { session.buildLockRequest(LockOptions.NONE).lock(ear); Hibernate.initialize(ear); Hibernate.initialize(ear.getExperimentalFactors()); } if (timer.getTime() > 1000) { AbstractDao.log.info("Thaw: " + timer.getTime() + "ms"); } }
From source file:ubic.gemma.persistence.service.analysis.expression.diff.DifferentialExpressionResultDaoImpl.java
License:Apache License
@Override public void thaw(final Collection<DifferentialExpressionAnalysisResult> results) { Session session = this.getSessionFactory().getCurrentSession(); for (DifferentialExpressionAnalysisResult result : results) { session.buildLockRequest(LockOptions.NONE).lock(result); Hibernate.initialize(result);// w w w. j a va2 s .co m CompositeSequence cs = result.getProbe(); Hibernate.initialize(cs); Hibernate.initialize(result.getContrasts()); } }
From source file:ubic.gemma.persistence.service.analysis.expression.diff.DifferentialExpressionResultDaoImpl.java
License:Apache License
@Override public void thaw(final DifferentialExpressionAnalysisResult result) { Session session = this.getSessionFactory().getCurrentSession(); session.buildLockRequest(LockOptions.NONE).lock(result); Hibernate.initialize(result);/*from w ww. ja va 2s.c om*/ CompositeSequence cs = result.getProbe(); Hibernate.initialize(cs); Collection<ContrastResult> contrasts = result.getContrasts(); for (ContrastResult contrast : contrasts) { FactorValue f = contrast.getFactorValue(); Hibernate.initialize(f); //noinspection ResultOfMethodCallIgnored f.getIsBaseline(); } }
From source file:ubic.gemma.persistence.service.analysis.expression.diff.ExpressionAnalysisResultSetDaoImpl.java
License:Apache License
@Override public void thawLite(final ExpressionAnalysisResultSet resultSet) { Session session = this.getSessionFactory().getCurrentSession(); session.buildLockRequest(LockOptions.NONE).lock(resultSet); for (ExperimentalFactor factor : resultSet.getExperimentalFactors()) { Hibernate.initialize(factor);/*from w w w . j a v a 2s. c om*/ } Hibernate.initialize(resultSet.getAnalysis()); Hibernate.initialize(resultSet.getAnalysis().getExperimentAnalyzed()); }
From source file:ubic.gemma.persistence.service.analysis.expression.diff.ExpressionAnalysisResultSetDaoImpl.java
License:Apache License
@Override public void remove(ExpressionAnalysisResultSet resultSet) { // Wipe references resultSet.setResults(new HashSet<DifferentialExpressionAnalysisResult>()); this.update(resultSet); // Clear session Session session = this.getSessionFactory().getCurrentSession(); session.flush();/*from w ww. ja v a 2s . c om*/ session.clear(); session.buildLockRequest(LockOptions.NONE).lock(resultSet); int contrastsDone = 0; int resultsDone = 0; // Remove results - Not using DifferentialExpressionResultDaoImpl.remove() for speed { AbstractDao.log.info("Bulk removing dea results..."); // Delete contrasts //language=MySQL final String nativeDeleteContrastsQuery = "DELETE c FROM CONTRAST_RESULT c, DIFFERENTIAL_EXPRESSION_ANALYSIS_RESULT d" + " WHERE d.RESULT_SET_FK = :rsid AND d.ID = c.DIFFERENTIAL_EXPRESSION_ANALYSIS_RESULT_FK"; SQLQuery q = session.createSQLQuery(nativeDeleteContrastsQuery); q.setParameter("rsid", resultSet.getId()); contrastsDone += q.executeUpdate(); // cannot use the limit clause for this multi-table remove. // Delete AnalysisResults //language=MySQL String nativeDeleteARQuery = "DELETE d FROM DIFFERENTIAL_EXPRESSION_ANALYSIS_RESULT d WHERE d.RESULT_SET_FK = :rsid "; q = session.createSQLQuery(nativeDeleteARQuery); q.setParameter("rsid", resultSet.getId()); resultsDone += q.executeUpdate(); AbstractDao.log .info("Deleted " + contrastsDone + " contrasts, " + resultsDone + " results. Flushing..."); session.flush(); session.clear(); } // Remove result set AbstractDao.log.info("Removing result set " + resultSet.getId()); super.remove(resultSet); this.getSessionFactory().getCurrentSession().flush(); }
From source file:ubic.gemma.persistence.service.expression.arrayDesign.ArrayDesignDaoImpl.java
License:Apache License
@Override public void removeBiologicalCharacteristics(final ArrayDesign arrayDesign) { if (arrayDesign == null) { throw new IllegalArgumentException("Array design cannot be null"); }/* ww w .j av a 2 s . c o m*/ Session session = this.getSessionFactory().getCurrentSession(); session.buildLockRequest(LockOptions.NONE).lock(arrayDesign); int count = 0; for (CompositeSequence cs : arrayDesign.getCompositeSequences()) { cs.setBiologicalCharacteristic(null); session.update(cs); session.evict(cs); if (++count % ArrayDesignDaoImpl.LOGGING_UPDATE_EVENT_COUNT == 0) { AbstractDao.log.info("Cleared sequence association for " + count + " composite sequences"); } } }