Example usage for org.hibernate LockOptions NONE

List of usage examples for org.hibernate LockOptions NONE

Introduction

In this page you can find the example usage for org.hibernate LockOptions NONE.

Prototype

LockOptions NONE

To view the source code for org.hibernate LockOptions NONE.

Click Source Link

Document

Represents LockMode.NONE (timeout + scope do not apply).

Usage

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 a  v a 2  s  .  c  o  m*/
        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);/*from w  w w  .java 2 s  .  c  om*/
    }
}

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;/*from   www.  j  a va 2 s  .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.service.genome.taxon.TaxonDaoImpl.java

License:Apache License

@Override
public void thaw(final Taxon taxon) {
    this.getSessionFactory().getCurrentSession().doWork(new Work() {
        @Override//w  w w  . j av  a  2  s  .  c  om
        public void execute(Connection connection) {
            TaxonDaoImpl.this.getSession().buildLockRequest(LockOptions.NONE).lock(taxon);
            Hibernate.initialize(taxon.getExternalDatabase());
            TaxonDaoImpl.this.getSession().evict(taxon);
        }
    });
}

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/*from   w  w w . ja v  a 2 s.  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);
}

From source file:ubic.gemma.security.audit.AuditAdvice.java

License:Apache License

/**
 * @param auditTrail/*from ww w  .  j a va 2 s.  c  o  m*/
 */
private void ensureInSession(AuditTrail auditTrail) {
    if (auditTrail == null)
        return;
    /*
     * Ensure we have the object in the session. It might not be, if we have flushed the session.
     */
    Session session = sessionFactory.getCurrentSession();
    if (!session.contains(auditTrail)) {
        session.buildLockRequest(LockOptions.NONE).lock(auditTrail);
    }
}