List of usage examples for org.hibernate Session buildLockRequest
LockRequest buildLockRequest(LockOptions lockOptions);
From source file:ubic.gemma.persistence.service.expression.bioAssayData.BioAssayDimensionDaoImpl.java
License:Apache License
@Override public BioAssayDimension thawLite(final BioAssayDimension bioAssayDimension) { if (bioAssayDimension == null) return null; if (bioAssayDimension.getId() == null) return bioAssayDimension; this.getHibernateTemplate().execute(new org.springframework.orm.hibernate3.HibernateCallback<Object>() { @Override// ww w . ja va 2 s . co m public Object doInHibernate(org.hibernate.Session session) throws org.hibernate.HibernateException { session.buildLockRequest(LockOptions.NONE).lock(bioAssayDimension); Hibernate.initialize(bioAssayDimension); Hibernate.initialize(bioAssayDimension.getBioAssays()); return null; } }); return bioAssayDimension; }
From source file:ubic.gemma.persistence.service.expression.bioAssayData.BioAssayDimensionDaoImpl.java
License:Apache License
@Override public BioAssayDimension thaw(final BioAssayDimension bioAssayDimension) { if (bioAssayDimension == null) return null; if (bioAssayDimension.getId() == null) return bioAssayDimension; this.getHibernateTemplate().execute(new org.springframework.orm.hibernate3.HibernateCallback<Object>() { @Override//from w ww . ja va 2 s . c o m public Object doInHibernate(org.hibernate.Session session) throws org.hibernate.HibernateException { session.buildLockRequest(LockOptions.NONE).lock(bioAssayDimension); Hibernate.initialize(bioAssayDimension); Hibernate.initialize(bioAssayDimension.getBioAssays()); for (BioAssay ba : bioAssayDimension.getBioAssays()) { if (ba != null) { session.buildLockRequest(LockOptions.NONE).lock(ba); Hibernate.initialize(ba); Hibernate.initialize(ba.getSampleUsed()); Hibernate.initialize(ba.getArrayDesignUsed()); Hibernate.initialize(ba.getOriginalPlatform()); BioMaterial bm = ba.getSampleUsed(); session.buildLockRequest(LockOptions.NONE).lock(bm); Hibernate.initialize(bm); Hibernate.initialize(bm.getBioAssaysUsedIn()); Hibernate.initialize(bm.getFactorValues()); } } return null; } }); return bioAssayDimension; }
From source file:ubic.gemma.persistence.service.expression.bioAssayData.DesignElementDataVectorDaoImpl.java
License:Apache License
@Override public void thawRawAndProcessed(Collection<DesignElementDataVector> designElementDataVectors) { if (designElementDataVectors == null) return;//from www.j a v a2 s . c o m Session session = this.getSessionFactory().getCurrentSession(); Hibernate.initialize(designElementDataVectors); StopWatch timer = new StopWatch(); timer.start(); Collection<ExpressionExperiment> ees = new HashSet<>(); Map<BioAssayDimension, Collection<DesignElementDataVector>> dims = new HashMap<>(); Collection<CompositeSequence> cs = new HashSet<>(); for (DesignElementDataVector vector : designElementDataVectors) { session.buildLockRequest(LockOptions.NONE).lock(vector); Hibernate.initialize(vector); Hibernate.initialize(vector.getQuantitationType()); BioAssayDimension bad = vector.getBioAssayDimension(); if (!dims.containsKey(bad)) { dims.put(bad, new HashSet<DesignElementDataVector>()); } dims.get(bad).add(vector); cs.add(vector.getDesignElement()); ees.add(vector.getExpressionExperiment()); session.evict(vector.getQuantitationType()); session.evict(vector); } if (timer.getTime() > designElementDataVectors.size()) { AbstractDao.log.info("Thaw phase 1, " + designElementDataVectors.size() + " vectors initialized in " + timer.getTime() + "ms "); } timer.reset(); timer.start(); // lightly thaw the EEs we saw for (ExpressionExperiment ee : ees) { Hibernate.initialize(ee); session.evict(ee); } if (timer.getTime() > 200) { AbstractDao.log.info("Thaw phase 2, " + ees.size() + " vector-associated expression experiments in " + timer.getTime() + "ms "); } timer.reset(); timer.start(); // thaw the bioassayDimensions we saw -- usually one, more rarely two. for (BioAssayDimension bad : dims.keySet()) { BioAssayDimension tbad = (BioAssayDimension) this.getSessionFactory().getCurrentSession().createQuery( "select distinct bad from BioAssayDimension bad join fetch bad.bioAssays ba join fetch ba.sampleUsed " + "bm join fetch ba.arrayDesignUsed left join fetch bm.factorValues fetch all properties where bad.id= :bad ") .setParameter("bad", bad.getId()).uniqueResult(); assert tbad != null; assert !dims.get(tbad).isEmpty(); for (DesignElementDataVector v : designElementDataVectors) { if (v.getBioAssayDimension().getId().equals(tbad.getId())) { v.setBioAssayDimension(tbad); } } } if (timer.getTime() > 1000) { AbstractDao.log.info("Thaw phase 3, " + dims.size() + " vector-associated bioassaydimensions in " + timer.getTime() + "ms "); } timer.reset(); timer.start(); // thaw the designelements we saw. SLOW long lastTime = 0; int count = 0; for (CompositeSequence de : cs) { BioSequence seq = de.getBiologicalCharacteristic(); if (seq == null) continue; session.buildLockRequest(LockOptions.NONE).lock(seq); Hibernate.initialize(seq); // is this really necessary? ArrayDesign arrayDesign = de.getArrayDesign(); Hibernate.initialize(arrayDesign); if (++count % 10000 == 0) { if (timer.getTime() - lastTime > 1000) { AbstractDao.log .info("Thawed " + count + " vector-associated probes " + timer.getTime() + " ms"); } lastTime = timer.getTime(); } } timer.stop(); if (designElementDataVectors.size() >= 2000 || timer.getTime() > 200) { AbstractDao.log.info( "Thaw phase 4 " + cs.size() + " vector-associated probes thawed in " + timer.getTime() + "ms"); } }
From source file:ubic.gemma.persistence.service.expression.bioAssayData.DesignElementDataVectorDaoImpl.java
License:Apache License
@Override public void thaw(T designElementDataVector) { Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession(); BioSequence seq = designElementDataVector.getDesignElement().getBiologicalCharacteristic(); if (seq != null) { session.buildLockRequest(LockOptions.NONE).lock(seq); Hibernate.initialize(seq);/*from ww w . j a va2 s . c o m*/ } ArrayDesign arrayDesign = designElementDataVector.getDesignElement().getArrayDesign(); Hibernate.initialize(arrayDesign); // thaw the bioassays. for (BioAssay ba : designElementDataVector.getBioAssayDimension().getBioAssays()) { ba = (BioAssay) session.get(BioAssay.class, ba.getId()); Hibernate.initialize(ba.getArrayDesignUsed()); Hibernate.initialize(ba.getSampleUsed()); Hibernate.initialize(ba.getOriginalPlatform()); } }
From source file:ubic.gemma.persistence.service.expression.biomaterial.BioMaterialDaoImpl.java
License:Apache License
@Override public void thaw(final BioMaterial bioMaterial) { Session session = this.getSessionFactory().getCurrentSession(); session.buildLockRequest(LockOptions.NONE).lock(bioMaterial); Hibernate.initialize(bioMaterial);//from w ww. ja v a2s. c om Hibernate.initialize(bioMaterial.getSourceTaxon()); Hibernate.initialize(bioMaterial.getBioAssaysUsedIn()); Hibernate.initialize(bioMaterial.getTreatments()); Hibernate.initialize(bioMaterial.getFactorValues()); }
From source file:ubic.gemma.persistence.service.expression.designElement.CompositeSequenceDaoImpl.java
License:Apache License
@Override public void thaw(final Collection<CompositeSequence> compositeSequences) { HibernateTemplate templ = this.getHibernateTemplate(); templ.executeWithNativeSession(new org.springframework.orm.hibernate3.HibernateCallback<Object>() { @Override//from w w w .j av a 2 s. com public Object doInHibernate(org.hibernate.Session session) throws org.hibernate.HibernateException { int i = 0; int numToDo = compositeSequences.size(); for (CompositeSequence cs : compositeSequences) { session.buildLockRequest(LockOptions.NONE).lock(cs); Hibernate.initialize(cs.getArrayDesign()); session.buildLockRequest(LockOptions.NONE).lock(cs.getArrayDesign()); Hibernate.initialize(cs.getArrayDesign().getPrimaryTaxon()); BioSequence bs = cs.getBiologicalCharacteristic(); if (bs == null) { continue; } session.buildLockRequest(LockOptions.NONE).lock(bs); Hibernate.initialize(bs); Hibernate.initialize(bs.getTaxon()); DatabaseEntry dbEntry = bs.getSequenceDatabaseEntry(); if (dbEntry != null) { Hibernate.initialize(dbEntry); Hibernate.initialize(dbEntry.getExternalDatabase()); session.evict(dbEntry); session.evict(dbEntry.getExternalDatabase()); } if (bs.getBioSequence2GeneProduct() == null) { continue; } for (BioSequence2GeneProduct bs2gp : bs.getBioSequence2GeneProduct()) { if (bs2gp == null) { continue; } GeneProduct geneProduct = bs2gp.getGeneProduct(); if (geneProduct != null && geneProduct.getGene() != null) { Gene g = geneProduct.getGene(); g.getAliases().size(); session.evict(g); session.evict(geneProduct); } } if (++i % 2000 == 0) { AbstractDao.log.info("Progress: " + i + "/" + numToDo + "..."); try { Thread.sleep(10); } catch (InterruptedException e) { // } } session.evict(bs); } session.clear(); return null; } }); }
From source file:ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentDaoImpl.java
License:Apache License
private void removeBioAssays(Session session, Map<BioAssay, BioMaterial> copyOfRelations, Collection<BioMaterial> bioMaterialsToDelete, Collection<BioAssay> bioAssays) { for (BioAssay ba : bioAssays) { // relations to files cascade, so we only have to worry about biomaterials, which aren't cascaded from // anywhere. BioAssay -> BioMaterial is many-to-one, but bioassaySet (experiment) owns the bioAssay. BioMaterial biomaterial = ba.getSampleUsed(); if (biomaterial == null) continue; // shouldn't... bioMaterialsToDelete.add(biomaterial); copyOfRelations.put(ba, biomaterial); session.buildLockRequest(LockOptions.NONE).lock(biomaterial); Hibernate.initialize(biomaterial); // this can easily end up with an unattached object. Hibernate.initialize(biomaterial.getBioAssaysUsedIn()); biomaterial.getFactorValues().clear(); biomaterial.getBioAssaysUsedIn().clear(); ba.setSampleUsed(null);/*w w w .j a v a 2 s.c o m*/ } }
From source file:ubic.gemma.persistence.service.genome.gene.GeneSetDaoImpl.java
License:Apache License
@Override public void thaw(final GeneSet geneSet) { if (geneSet == null || geneSet.getId() == null) return;/*ww w . ja v a 2s . co m*/ HibernateTemplate templ = this.getHibernateTemplate(); templ.executeWithNativeSession(new org.springframework.orm.hibernate3.HibernateCallback<Object>() { @Override public Object doInHibernate(org.hibernate.Session session) throws org.hibernate.HibernateException { session.buildLockRequest(LockOptions.NONE).lock(geneSet); Hibernate.initialize(geneSet); Hibernate.initialize(geneSet.getMembers()); for (GeneSetMember gsm : geneSet.getMembers()) { Hibernate.initialize(gsm.getGene()); } return null; } }); }
From source file:ubic.gemma.persistence.service.genome.sequenceAnalysis.BlatAssociationDaoImpl.java
License:Apache License
private void thawBlatAssociation(org.hibernate.Session session, BlatAssociation blatAssociation) { session.buildLockRequest(LockOptions.NONE).lock(blatAssociation); Hibernate.initialize(blatAssociation.getBioSequence()); Hibernate.initialize(blatAssociation.getGeneProduct()); Hibernate.initialize(blatAssociation.getBlatResult()); Hibernate.initialize(blatAssociation.getBlatResult().getTargetChromosome()); }
From source file:ubic.gemma.persistence.util.EntityUtils.java
License:Apache License
/** * Expert only. Put the given entity into the Session, with LockMode.NONE * Based on idea from https://forum.hibernate.org/viewtopic.php?p=2284826#p2284826 * * @param session Hibernate Session (use factory.getCurrentSession()) * @param obj the entity/* w w w. ja va 2s . co m*/ * @param clazz the class type of the persisted entity. Don't use obj.getClass() as this might return a proxy type. * @param id identifier of the obj */ public static void attach(Session session, Object obj, Class<?> clazz, Long id) { if (obj == null || id == null) return; if (!session.isOpen()) throw new IllegalArgumentException("Illegal attempt to use a closed session"); if (!session.contains(obj)) { Object oldObj = session.get(clazz, id); if (oldObj != null) { session.evict(oldObj); } } session.buildLockRequest(LockOptions.NONE).lock(obj); }