Subversion Repositories hibernate-spatial

Compare Revisions

Ignore whitespace Rev 301 → Rev 302

/trunk/hibernate-spatial-sqlserver/src/main/java/org/hibernatespatial/sqlserver/SQLServerGeometryUserType.java
30,7 → 30,9
import org.hibernatespatial.sqlserver.convertors.Decoders;
import org.hibernatespatial.sqlserver.convertors.Encoders;
 
import java.sql.Blob;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
 
/**
41,15 → 43,27
public class SQLServerGeometryUserType extends AbstractDBGeometryType {
 
public Geometry convert2JTS(Object obj) {
byte[] raw = null;
if (obj == null)
return null;
if (!(obj instanceof byte[])) {
if ((obj instanceof byte[])) {
raw = (byte[]) obj;
} else if (obj instanceof Blob){
raw = toByteArray((Blob)obj);
} else {
throw new IllegalArgumentException("Expected byte array.");
}
byte[] raw = (byte[]) obj;
return Decoders.decode(raw);
}
 
private byte[] toByteArray(Blob blob){
try {
return blob.getBytes(1,(int)blob.length());
} catch (SQLException e) {
throw new RuntimeException("Error on transforming blob into array.", e);
}
}
 
public Object conv2DBGeometry(Geometry geom, Connection connection) {
if (geom == null)
throw new IllegalArgumentException("Null geometry passed.");
/trunk/hibernate-spatial-sqlserver/src/main/java/org/hibernatespatial/sqlserver/SQLServerSpatialDialect.java
45,6 → 45,8
 
public final static String COLUMN_TYPE = "GEOMETRY";
 
protected static CustomType geomType = new CustomType(new SQLServerGeometryUserType(), new String[]{"sqlserver_geometry"});
 
public SQLServerSpatialDialect() {
super();
registerColumnType(java.sql.Types.ARRAY, COLUMN_TYPE);
52,9 → 54,6
// registering OGC functions
// (spec_simplefeatures_sql_99-04.pdf)
 
// CustomType for GeometryUserType
CustomType geomType = new CustomType(new SQLServerGeometryUserType(), new String[]{"sqlserver_geometry"});
 
// section 2.1.1.1
// Registerfunction calls for registering geometry functions:
// first argument is the OGC standard functionname,