/
AbstractGeometryValueBinder.java
59 lines (49 loc) · 2.17 KB
/
AbstractGeometryValueBinder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* This file is part of Hibernate Spatial, an extension to the
* hibernate ORM solution for spatial (geographic) data.
*
* Copyright © 2007-2012 Geovise BVBA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.hibernate.spatial.dialect;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.sql.BasicBinder;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
/**
* @author Karel Maesen, Geovise BVBA
* creation-date: 1/19/12
*/
public abstract class AbstractGeometryValueBinder<X> extends BasicBinder<X> {
private static GeometryFactory geometryFactory = new GeometryFactory();
public AbstractGeometryValueBinder(JavaTypeDescriptor<X> javaDescriptor, SqlTypeDescriptor sqlDescriptor) {
super( javaDescriptor, sqlDescriptor );
}
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
Geometry jtsGeom = getJavaDescriptor().unwrap( value, Geometry.class, options );
Object dbGeom = toNative( jtsGeom, st.getConnection() );
st.setObject( index, dbGeom );
}
protected GeometryFactory getGeometryFactory() {
return geometryFactory;
}
protected abstract Object toNative(Geometry jtsGeom, Connection connection);
}