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.common;
|
11
|
|
12
|
import org.hibernate.Criteria;
|
13
|
import org.hibernate.Session;
|
14
|
import org.hibernate.criterion.Projections;
|
15
|
import org.springframework.stereotype.Repository;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
|
18
|
import eu.etaxonomy.cdm.persistence.dao.common.IPreferenceDao;
|
19
|
|
20
|
/**
|
21
|
* @author a.mueller
|
22
|
* @created 2013-09-09
|
23
|
*/
|
24
|
@Repository
|
25
|
public class PreferenceDaoImpl extends DaoBase implements IPreferenceDao {
|
26
|
|
27
|
@Override
|
28
|
public CdmPreference get(CdmPreference.PrefKey key){
|
29
|
Session session = getSession();
|
30
|
return (CdmPreference)session.get(CdmPreference.class, key);
|
31
|
|
32
|
//old
|
33
|
// StatelessSession session = getSessionFactory().openStatelessSession();
|
34
|
// return (CdmPreference) session.get(CdmPreference.class, key);
|
35
|
|
36
|
}
|
37
|
|
38
|
@Override
|
39
|
public void set(CdmPreference preference){
|
40
|
CdmPreference pref = get(preference.getKey());
|
41
|
//maybe
|
42
|
//TODO maybe there is better way to allow updates without allowing to write CdmPref.value
|
43
|
if (pref != null){
|
44
|
getSession().delete(pref);
|
45
|
}
|
46
|
getSession().save(preference);
|
47
|
|
48
|
//old
|
49
|
// if (pref == null){
|
50
|
// getSessionFactory().openStatelessSession().insert(preference);
|
51
|
// }else{
|
52
|
// getSessionFactory().openStatelessSession().update(preference);
|
53
|
// }
|
54
|
}
|
55
|
|
56
|
@Override
|
57
|
public int count(){
|
58
|
Criteria crit = getSession().createCriteria(CdmPreference.class);
|
59
|
crit.setProjection(Projections.rowCount());
|
60
|
int result = ((Number)crit.list().get(0)).intValue();
|
61
|
return result;
|
62
|
}
|
63
|
|
64
|
}
|