1
|
/**
|
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
|
*/
|
9
|
|
10
|
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
|
|
32
|
public CollectionDaoHibernateImpl() {
|
33
|
super(Collection.class);
|
34
|
indexedClasses = new Class[1];
|
35
|
indexedClasses[0] = Collection.class;
|
36
|
}
|
37
|
|
38
|
public List<Collection> getCollectionByCode(String code) {
|
39
|
AuditEvent auditEvent = getAuditEventFromContext();
|
40
|
if(auditEvent.equals(AuditEvent.CURRENT_VIEW)) {
|
41
|
Criteria crit = getSession().createCriteria(Collection.class);
|
42
|
crit.add(Restrictions.eq("code", code));
|
43
|
|
44
|
return (List<Collection>)crit.list();
|
45
|
} else {
|
46
|
AuditQuery query = getAuditReader().createQuery().forEntitiesAtRevision(Collection.class,auditEvent.getRevisionNumber());
|
47
|
query.add(AuditEntity.property("code").eq(code));
|
48
|
return (List<Collection>)query.getResultList();
|
49
|
}
|
50
|
}
|
51
|
|
52
|
@Override
|
53
|
public void rebuildIndex() {
|
54
|
FullTextSession fullTextSession = Search.getFullTextSession(getSession());
|
55
|
|
56
|
for(Collection collection : list(null,null)) { // re-index all taxon base
|
57
|
|
58
|
Hibernate.initialize(collection.getSuperCollection());
|
59
|
Hibernate.initialize(collection.getInstitute());
|
60
|
fullTextSession.index(collection);
|
61
|
}
|
62
|
fullTextSession.flushToIndexes();
|
63
|
}
|
64
|
}
|