1 |
78c2bf74
|
Katja Luther
|
/**
|
2 |
|
|
* Copyright (C) 2009 EDIT
|
3 |
|
|
* European Distributed Institute of Taxonomy
|
4 |
|
|
* http://www.e-taxonomy.eu
|
5 |
|
|
*
|
6 |
|
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7 |
|
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8 |
e4d66102
|
Andreas Müller
|
*/
|
9 |
78c2bf74
|
Katja Luther
|
|
10 |
9af0ba1b
|
ben.clark
|
package eu.etaxonomy.cdm.persistence.dao.hibernate.occurrence;
|
11 |
|
|
|
12 |
|
|
import java.util.List;
|
13 |
|
|
|
14 |
|
|
import org.hibernate.Criteria;
|
15 |
|
|
import org.hibernate.Hibernate;
|
16 |
|
|
import org.hibernate.criterion.Restrictions;
|
17 |
|
|
import org.hibernate.envers.query.AuditEntity;
|
18 |
|
|
import org.hibernate.envers.query.AuditQuery;
|
19 |
|
|
import org.hibernate.search.FullTextSession;
|
20 |
|
|
import org.hibernate.search.Search;
|
21 |
|
|
import org.springframework.stereotype.Repository;
|
22 |
|
|
|
23 |
|
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
24 |
|
|
import eu.etaxonomy.cdm.model.view.AuditEvent;
|
25 |
|
|
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.IdentifiableDaoBase;
|
26 |
|
|
import eu.etaxonomy.cdm.persistence.dao.occurrence.ICollectionDao;
|
27 |
|
|
|
28 |
|
|
@Repository
|
29 |
|
|
public class CollectionDaoHibernateImpl extends IdentifiableDaoBase<Collection> implements
|
30 |
|
|
ICollectionDao {
|
31 |
e4d66102
|
Andreas Müller
|
|
32 |
9af0ba1b
|
ben.clark
|
public CollectionDaoHibernateImpl() {
|
33 |
|
|
super(Collection.class);
|
34 |
4532d825
|
ben.clark
|
indexedClasses = new Class[1];
|
35 |
|
|
indexedClasses[0] = Collection.class;
|
36 |
9af0ba1b
|
ben.clark
|
}
|
37 |
|
|
|
38 |
e4d66102
|
Andreas Müller
|
@Override
|
39 |
|
|
public List<Collection> getCollectionByCode(String code) {
|
40 |
9af0ba1b
|
ben.clark
|
AuditEvent auditEvent = getAuditEventFromContext();
|
41 |
|
|
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
|
42 |
|
|
Criteria crit = getSession().createCriteria(Collection.class);
|
43 |
|
|
crit.add(Restrictions.eq("code", code));
|
44 |
e4d66102
|
Andreas Müller
|
|
45 |
|
|
return crit.list();
|
46 |
9af0ba1b
|
ben.clark
|
} else {
|
47 |
|
|
AuditQuery query = getAuditReader().createQuery().forEntitiesAtRevision(Collection.class,auditEvent.getRevisionNumber());
|
48 |
|
|
query.add(AuditEntity.property("code").eq(code));
|
49 |
e4d66102
|
Andreas Müller
|
return query.getResultList();
|
50 |
9af0ba1b
|
ben.clark
|
}
|
51 |
|
|
}
|
52 |
|
|
|
53 |
4532d825
|
ben.clark
|
@Override
|
54 |
9af0ba1b
|
ben.clark
|
public void rebuildIndex() {
|
55 |
e4d66102
|
Andreas Müller
|
FullTextSession fullTextSession = Search.getFullTextSession(getSession());
|
56 |
9af0ba1b
|
ben.clark
|
|
57 |
e4d66102
|
Andreas Müller
|
for(Collection collection : list(null,null)) { // re-index all taxon base
|
58 |
|
|
|
59 |
|
|
Hibernate.initialize(collection.getSuperCollection());
|
60 |
|
|
Hibernate.initialize(collection.getInstitute());
|
61 |
|
|
fullTextSession.index(collection);
|
62 |
|
|
}
|
63 |
|
|
fullTextSession.flushToIndexes();
|
64 |
9af0ba1b
|
ben.clark
|
}
|
65 |
d45008d0
|
Andreas Kohlbecker
|
}
|