use of org.hibernate.collection.PersistentCollection in project Gemma by PavlidisLab.
the class ArrayDesignDaoImpl method thaw.
@Override
public ArrayDesign thaw(final ArrayDesign arrayDesign) {
if (arrayDesign.getId() == null) {
throw new IllegalArgumentException("Cannot thawRawAndProcessed a non-persistent array design");
}
/*
* Thaw basic stuff
*/
StopWatch timer = new StopWatch();
timer.start();
ArrayDesign result = this.thawLite(arrayDesign);
if (timer.getTime() > 1000) {
AbstractDao.log.info("Thaw array design stage 1: " + timer.getTime() + "ms");
}
timer.stop();
timer.reset();
timer.start();
/*
* Thaw the composite sequences.
*/
AbstractDao.log.info("Start initialize composite sequences");
Hibernate.initialize(result.getCompositeSequences());
if (timer.getTime() > 1000) {
AbstractDao.log.info("Thaw array design stage 2: " + timer.getTime() + "ms");
}
timer.stop();
timer.reset();
timer.start();
/*
* Thaw the biosequences in batches
*/
Collection<CompositeSequence> thawed = new HashSet<>();
Collection<CompositeSequence> batch = new HashSet<>();
long lastTime = timer.getTime();
for (CompositeSequence cs : result.getCompositeSequences()) {
batch.add(cs);
if (batch.size() == 1000) {
long t = timer.getTime();
if (t > 10000 && t - lastTime > 1000) {
AbstractDao.log.info("Thaw Batch : " + t);
}
List bb = this.thawBatchOfProbes(batch);
// noinspection unchecked
thawed.addAll((Collection<? extends CompositeSequence>) bb);
lastTime = timer.getTime();
batch.clear();
}
this.getSessionFactory().getCurrentSession().evict(cs);
}
if (!batch.isEmpty()) {
// tail end
List bb = this.thawBatchOfProbes(batch);
// noinspection unchecked
thawed.addAll((Collection<? extends CompositeSequence>) bb);
}
result.getCompositeSequences().clear();
result.getCompositeSequences().addAll(thawed);
/*
* This is a bit ugly, but necessary to avoid 'dirty collection' errors later.
*/
if (result.getCompositeSequences() instanceof PersistentCollection)
((PersistentCollection) result.getCompositeSequences()).clearDirty();
if (timer.getTime() > 1000) {
AbstractDao.log.info("Thaw array design stage 3: " + timer.getTime());
}
return result;
}
Aggregations