1
package org.hisp.dhis.gis.hibernate;
4
* Copyright (c) 2004-2007, University of Oslo
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright notice, this
10
* list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright notice,
12
* this list of conditions and the following disclaimer in the documentation
13
* and/or other materials provided with the distribution.
14
* * Neither the name of the HISP project nor the names of its contributors may
15
* be used to endorse or promote products derived from this software without
16
* specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
import java.util.Collection;
32
import org.hibernate.Criteria;
33
import org.hibernate.Session;
34
import org.hibernate.criterion.Restrictions;
35
import org.hisp.dhis.gis.Feature;
36
import org.hisp.dhis.gis.FeatureStore;
37
import org.hisp.dhis.gis.MapFile;
38
import org.hisp.dhis.hibernate.HibernateSessionManager;
39
import org.hisp.dhis.organisationunit.OrganisationUnit;
42
* @author Tran Thanh Tri
43
* @version $Id: Feature.java 28-01-2008 16:06:00 $
45
public class HibernateFeatureStore
46
implements FeatureStore
48
// -------------------------------------------------------------------------
50
// -------------------------------------------------------------------------
52
private HibernateSessionManager sessionManager;
54
public HibernateSessionManager getSessionManager()
56
return sessionManager;
59
// -------------------------------------------------------------------------
60
// FeatureStore implementation
61
// -------------------------------------------------------------------------
63
public void setSessionManager( HibernateSessionManager sessionManager )
65
this.sessionManager = sessionManager;
68
public void add( Feature feature )
70
Session session = sessionManager.getCurrentSession();
71
session.save( feature );
74
public void delete( Feature feature )
76
Session session = sessionManager.getCurrentSession();
77
session.delete( feature );
80
public Feature get( int id )
82
Session session = sessionManager.getCurrentSession();
84
return (Feature) session.get( Feature.class, new Integer( id ) );
87
public Feature get( String featureCode )
89
Session session = sessionManager.getCurrentSession();
90
Criteria criteria = session.createCriteria( Feature.class );
91
criteria.add( Restrictions.eq( "featureCode", featureCode ) );
92
return (Feature) criteria.uniqueResult();
95
public Feature get( OrganisationUnit organisationUnit )
97
Session session = sessionManager.getCurrentSession();
99
return (Feature) session.createQuery( "from Feature as f where f.organisationUnit = ?" ).setEntity( 0,
100
organisationUnit ).uniqueResult();
103
@SuppressWarnings( "unchecked" )
104
public Collection<Feature> getAll()
106
Session session = sessionManager.getCurrentSession();
108
return session.createCriteria( Feature.class ).list();
111
public void update( Feature feature )
113
Session session = sessionManager.getCurrentSession();
115
session.update( feature );
118
public void delete( String featureCode )
120
Session session = sessionManager.getCurrentSession();
122
session.createQuery( "delete Feature as f where f.featureCode = ?" ).setEntity( 0, featureCode );
125
public void addMapFile( MapFile arg0 )
127
Session session = sessionManager.getCurrentSession();
129
session.save( arg0 );
132
public void deleteMapFile( MapFile arg0 )
134
Session session = sessionManager.getCurrentSession();
136
session.delete( arg0 );
139
@SuppressWarnings( "unchecked" )
140
public Collection<MapFile> getAllMapFile()
142
Session session = sessionManager.getCurrentSession();
144
return session.createCriteria( MapFile.class ).list();
147
public MapFile getMapFile( int id )
149
Session session = sessionManager.getCurrentSession();
151
return (MapFile) session.get( MapFile.class, new Integer( id ) );
154
public MapFile getMapFile( OrganisationUnit organisationUnit )
156
Session session = sessionManager.getCurrentSession();
158
return (MapFile) session.createQuery( "from MapFile as f where f.organisationUnit = ?" ).setEntity( 0,
159
organisationUnit ).uniqueResult();
162
public void updateMapFile( MapFile arg0 )
164
Session session = sessionManager.getCurrentSession();
166
session.update( arg0 );