Subversion Repositories hibernate-spatial

Compare Revisions

Ignore whitespace Rev 79 → Rev 80

/tags/1.0-M1/hibernate-spatial-mysql/src/test/java/org/hibernatespatial/mysql/test/TestMySQLSpatialQueries.java
New file
0,0 → 1,241
/**
* $Id$
*
* This file is part of Hibernate Spatial, an extension to the
* hibernate ORM solution for geographic data.
*
* Copyright © 2007 Geovise BVBA
* Copyright © 2007 K.U. Leuven LRD, Spatial Applications Division, Belgium
*
* This work was partially supported by the European Commission,
* under the 6th Framework Programme, contract IST-2-004688-STP.
*
* 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
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernatespatial.mysql.test;
 
import java.sql.Connection;
import java.sql.DriverManager;
 
import junit.framework.JUnit4TestAdapter;
 
import org.hibernatespatial.test.TestSpatialQueries;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
 
public class TestMySQLSpatialQueries {
 
private final static String DBNAME = "testhbs";
 
private final static String DBHOST = "test.geovise.com";
 
private final static String DBUSER = "hibernate";
 
private final static String DBPWD = "hibernate";
 
private static Connection conn;
 
private static TestSpatialQueries delegate;
 
static {
String url = "jdbc:mysql://" + DBHOST + "/" + DBNAME;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url, DBUSER, DBPWD);
delegate = new TestSpatialQueries();
} catch (Exception e) {
e.printStackTrace();
}
// create the delegate
 
}
 
@BeforeClass
public static void setUpBeforeClass() throws Exception {
delegate.setUpBeforeClass(conn);
}
 
@AfterClass
public static void tearDownAfterClass() throws Exception {
delegate.tearDownAfterClass();
}
 
@Test
public void testHQLGeometryType() throws Exception {
delegate.testHQLGeometryType();
}
 
@Test
public void testHQLAsBinary() throws Exception {
delegate.testHQLAsBinary();
}
 
@Test
public void testHQLAsText() throws Exception {
delegate.testHQLAsText();
}
 
@Test
public void testHQLDimension() throws Exception {
delegate.testHQLDimension();
}
 
@Test
public void testHQLEnvelope() throws Exception {
delegate.testHQLEnvelope();
}
 
@Test
public void testHQLIntersectsLineString() throws Exception {
String sqlString = "select count(*) from $table$ where intersects(geomfromtext(?, 31370), geom)";
delegate.testHQLIntersectsLineString(sqlString);
}
 
@Test
public void testHQLIsEmpty() throws Exception {
String sql = "select count(*) from $table$ where geom is not null and isempty(geom)";
delegate.testHQLIsEmpty(sql);
}
 
@Test
public void testHQLIsSimple() throws Exception {
String sql = "select count(*) from $table$ where geom is not null and issimple(geom)";
delegate.testHQLIsSimple(sql);
}
 
@Test
public void testHQLOverlaps() throws Exception {
String sql = "select count(*) from $table$ where overlaps(geomfromtext(?, 31370), geom) and geom is not null";
delegate.testHQLOverlaps(sql);
}
 
@Test
public void testHQLSRID() throws Exception {
delegate.testHQLSRID();
}
 
@Test
public void testFiltering() throws Exception {
String sql = "select count(*) from $table$ where MBRIntersects(geom, geomFromText(?,31370))";
delegate.testFiltering(sql);
}
 
@Test
public void testContains() throws Exception {
String sql = "select count(*) from $table$ where contains(geom, geomFromText(?, 31370))";
delegate.testContains(sql);
}
 
@Test
public void testCrosses() throws Exception {
String sql = "select count(*) from $table$ where crosses(geom, geomFromText(?, 31370))";
delegate.testCrosses(sql);
}
 
@Test
public void testDisjoint() throws Exception {
String sql = "select count(*) from $table$ where disjoint(geom, geomFromText(?, 31370))";
delegate.testDisjoint(sql);
}
 
@Test
public void testHQLDisjoint() throws Exception {
String sql = "select count(*) from $table$ where disjoint(geomfromtext(?, 31370), geom) and geom is not null";
delegate.testHQLDisjoint(sql);
}
 
@Test
public void testEquals() throws Exception {
String sql = "select count(*) from $table$ where equals(geom, geomFromText(?, 31370))";
delegate.testEquals(sql);
}
 
@Test
public void testIntersects() throws Exception {
String sql = "select count(*) from $table$ where intersects(geom, geomFromText(?, 31370))";
delegate.testIntersects(sql);
}
 
@Test
public void testOverlaps() throws Exception {
String sql = "select count(*) from $table$ where overlaps(geom, geomFromText(?, 31370))";
delegate.testOverlaps(sql);
}
 
@Test
public void testTouches() throws Exception {
String sql = "select count(*) from $table$ where touches(geom, geomFromText(?, 31370))";
delegate.testTouches(sql);
}
 
@Test
public void testWithin() throws Exception {
String sql = "select count(*) from $table$ where within(geom, geomFromText(?, 31370))";
delegate.testWithin(sql);
}
 
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(TestMySQLSpatialQueries.class);
}
 
@Test
public void testHQLBoundary() throws Exception {
delegate.testHQLBoundary();
}
 
@Test
public void testHQLRelateLineString() throws Exception {
delegate.testHQLRelateLineString();
}
 
@Test
public void testHQLDistance() throws Exception {
delegate.testHQLDistance();
}
 
@Test
public void testHQLBuffer() throws Exception {
delegate.testHQLBuffer();
}
 
@Test
public void testHQLConvexHull() throws Exception {
delegate.testHQLConvexHull();
}
 
@Test
public void testHQLIntersection() throws Exception {
delegate.testHQLIntersection();
}
 
@Test
public void testHQLDifference() throws Exception {
delegate.testHQLDifference();
}
 
@Test
public void testHQLSymDifference() throws Exception {
delegate.testHQLSymDifference();
}
 
@Test
public void testHQLUnion() throws Exception {
delegate.testHQLUnion();
}
 
}
Property changes:
Added: svn:keywords
+ Id
/tags/1.0-M1/hibernate-spatial-mysql/src/test/java/org/hibernatespatial/mysql/test/TestMySQLCRUD.java
New file
0,0 → 1,70
/**
* $Id$
*
* This file is part of Hibernate Spatial, an extension to the
* hibernate ORM solution for geographic data.
*
* Copyright © 2007 Geovise BVBA
* Copyright © 2007 K.U. Leuven LRD, Spatial Applications Division, Belgium
*
* This work was partially supported by the European Commission,
* under the 6th Framework Programme, contract IST-2-004688-STP.
*
* 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
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernatespatial.mysql.test;
 
import junit.framework.JUnit4TestAdapter;
 
import org.hibernatespatial.test.TestCRUD;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
 
public class TestMySQLCRUD {
 
private final static TestCRUD delegate;
 
static {
delegate = new TestCRUD();
}
 
@BeforeClass
public static void setUpBeforeClass() throws Exception {
delegate.setUpBeforeClass();
}
 
@AfterClass
public static void tearDownAfterClass() throws Exception {
delegate.tearDownAfterClass();
}
 
@Test
public void testSaveLineStringEntity() throws Exception {
delegate.testSaveLineStringEntity();
}
 
@Test
public void testSaveNullLineStringEntity() throws Exception {
delegate.testSaveNullLineStringEntity();
}
 
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(TestMySQLCRUD.class);
}
 
}
Property changes:
Added: svn:keywords
+ Id
/tags/1.0-M1/hibernate-spatial-mysql/src/test/java/org/hibernatespatial/mysql/test/GenerateData.java
New file
0,0 → 1,40
/**
* $Id$
*
* This file is part of Hibernate Spatial, an extension to the
* hibernate ORM solution for geographic data.
*
* Copyright © 2007 Geovise BVBA
* Copyright © 2007 K.U. Leuven LRD, Spatial Applications Division, Belgium
*
* This work was partially supported by the European Commission,
* under the 6th Framework Programme, contract IST-2-004688-STP.
*
* 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
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernatespatial.mysql.test;
 
import org.hibernatespatial.test.model.DataGenerator;
 
public class GenerateData {
 
public static void main(String[] args) {
DataGenerator generator = new DataGenerator();
generator.generate();
}
 
}
Property changes:
Added: svn:keywords
+ Id
/tags/1.0-M1/hibernate-spatial-mysql/src/test/java/log4j.properties
New file
0,0 → 1,49
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
 
### direct messages to file hibernate.log ###
#log4j.appender.file=org.apache.log4j.FileAppender
#log4j.appender.file.File=hibernate.log
#log4j.appender.file.layout=org.apache.log4j.PatternLayout
#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
 
### set log levels - for more verbose logging change 'info' to 'debug' ###
 
log4j.rootLogger=debug, stdout
 
log4j.logger.org.hibernatespatial.test=debug
 
log4j.logger.org.hibernate=info
#log4j.logger.org.hibernate=debug
 
### log HQL query parser activity
#log4j.logger.org.hibernate.hql.ast.AST=debug
 
### log just the SQL
#log4j.logger.org.hibernate.SQL=debug
 
### log JDBC bind parameters ###
log4j.logger.org.hibernate.type=info
#log4j.logger.org.hibernate.type=debug
 
### log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=debug
 
### log HQL parse trees
#log4j.logger.org.hibernate.hql=debug
 
### log cache activity ###
#log4j.logger.org.hibernate.cache=debug
 
### log transaction activity
#log4j.logger.org.hibernate.transaction=debug
 
### log JDBC resource acquisition
#log4j.logger.org.hibernate.jdbc=debug
 
### enable the following line if you want to track down connection ###
### leakages when using DriverManagerConnectionProvider ###
#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace
Property changes:
Added: svn:executable
+ *
Added: svn:keywords
+ Id
/tags/1.0-M1/hibernate-spatial-mysql/src/test/java/hibernate.cfg.xml
New file
0,0 → 1,29
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://test.geovise.com/testhbs</property>
<property name="hibernate.connection.username">hibernate</property>
<property name="hibernate.connection.password">hibernate</property>
<property name="hibernate.dialect">org.hibernatespatial.mysql.MySQLSpatialDialect</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
 
 
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
 
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
 
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
Property changes:
Added: svn:executable
+ *
Added: svn:keywords
+ Id
/tags/1.0-M1/hibernate-spatial-mysql/src/test/resources/create-db.sh
New file
0,0 → 1,26
#! /bin/sh
 
# A very simple database creation script.
 
# the host computer
export DBHOST=test.geovise.com
# the account information used by Hibernate
export DBASE=testhbs
export DBUSER=hibernate
 
# ==To be removed==
export TMP=/tmp/mysql-hibernate-test-create.sql
export CREATE_TABLE_SCRIPT=./create-tables.sql
 
# The account that has the privileges to create the database
export DBADMIN=admin
export DBADMINPWD=nimad
 
echo "CREATE DATABASE $DBASE;" > $TMP
echo "GRANT ALL PRIVILEGES ON $DBASE.* TO '$DBUSER'@'%' IDENTIFIED BY '$DBUSER';" >> $TMP
echo "\q" >> $TMP
 
mysql --user=$DBADMIN --password=$DBADMINPWD --host=$DBHOST mysql < $TMP
mysql --user=$DBADMIN --password=$DBADMINPWD --host=$DBHOST $DBASE < $CREATE_TABLE_SCRIPT
rm $TMP
 
Property changes:
Added: svn:executable
+ *
Added: svn:keywords
+ Id
/tags/1.0-M1/hibernate-spatial-mysql/src/test/resources/create-tables.sql
New file
0,0 → 1,32
-- Change database
USE testhbs
 
--
-- Create test tables
--
 
CREATE TABLE linestringtest (
id DECIMAL(10,0),
name VARCHAR(50),
geom geometry
);
 
CREATE TABLE multilinestringtest(
id DECIMAL(10,0),
name VARCHAR(50),
geom geometry
);
 
CREATE TABLE polygontest(
id DECIMAL(10,0),
name VARCHAR(50),
geom geometry
);
 
-- Currently, MySQL requires not-null geometries for spatial indexing.
-- Therefore we disable the spatial index for now.
-- CREATE SPATIAL INDEX ls_sp_idx ON linestringtest (geom);
-- CREATE SPATIAL INDEX mls_sp_idx ON multilinestringtest(geom);
-- CREATE SPATIAL INDEX pl_sp_idx ON polygontest(geom);
 
Property changes:
Added: svn:keywords
+ Id
/tags/1.0-M1/hibernate-spatial-mysql/src/main/java/META-INF/MANIFEST.MF
New file
0,0 → 1,3
Manifest-Version: 1.0
Class-Path:
 
Property changes:
Added: svn:keywords
+ Id
/tags/1.0-M1/hibernate-spatial-mysql/src/main/java/org/hibernatespatial/mysql/DialectProvider.java
New file
0,0 → 1,74
/**
* $Id$
*
* This file is part of Hibernate Spatial, an extension to the
* hibernate ORM solution for geographic data.
*
* Copyright © 2007 Geovise BVBA
* Copyright © 2007 K.U. Leuven LRD, Spatial Applications Division, Belgium
*
* This work was partially supported by the European Commission,
* under the 6th Framework Programme, contract IST-2-004688-STP.
*
* 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
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernatespatial.mysql;
 
import org.hibernatespatial.SpatialDialect;
import org.hibernatespatial.spi.SpatialDialectProvider;
 
/**
* MySQL DialectProvider
*
* @author Karel Maesen
*/
public class DialectProvider implements SpatialDialectProvider {
 
/*
* (non-Javadoc)
*
* @see org.hibernatespatial.spi.SpatialDialectProvider#createSpatialDialect(java.lang.String,
* java.util.Map)
*/
public SpatialDialect createSpatialDialect(String dialect) {
if (dialect.equals(MySQLSpatialDialect.class.getCanonicalName())
|| dialect.equals("org.hibernate.dialect.MySQLSQLDialect")
|| dialect.equals("mysql"))
return new MySQLSpatialDialect();
else
return null;
}
 
/*
* (non-Javadoc)
*
* @see org.hibernatespatial.spi.SpatialDialectProvider#getDefaultDialect()
*/
public SpatialDialect getDefaultDialect() {
return new MySQLSpatialDialect();
}
 
/*
* (non-Javadoc)
*
* @see org.hibernatespatial.spi.SpatialDialectProvider#getSupportedDialects()
*/
public String[] getSupportedDialects() {
return new String[] { MySQLSpatialDialect.class.getCanonicalName() };
}
 
}
Property changes:
Added: svn:keywords
+ Id
/tags/1.0-M1/hibernate-spatial-mysql/src/main/java/org/hibernatespatial/mysql/MySQLGeometryUserType.java
New file
0,0 → 1,113
/**
* $Id$
*
* This file is part of Hibernate Spatial, an extension to the
* hibernate ORM solution for geographic data.
*
* Copyright © 2007 Geovise BVBA
* Copyright © 2007 K.U. Leuven LRD, Spatial Applications Division, Belgium
*
* This work was partially supported by the European Commission,
* under the 6th Framework Programme, contract IST-2-004688-STP.
*
* 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
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernatespatial.mysql;
 
import java.sql.Connection;
import java.sql.Types;
 
import org.hibernatespatial.AbstractDBGeometryType;
 
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.io.ByteOrderValues;
import com.vividsolutions.jts.io.WKBReader;
import com.vividsolutions.jts.io.WKBWriter;
 
/**
* Specific <code>GeometryType</code> for MySQL geometry type
*
* @author Karel Maesen
*/
public class MySQLGeometryUserType extends AbstractDBGeometryType {
 
private static final int SRIDLEN = 4;
 
private final WKBReader reader = new WKBReader();
 
private final WKBWriter writer = new WKBWriter(2,
ByteOrderValues.LITTLE_ENDIAN);
 
private static final int[] geometryTypes = new int[] { Types.ARRAY };
 
public int[] sqlTypes() {
return geometryTypes;
}
 
/**
* Converts the native geometry object to a JTS <code>Geometry</code>.
*
* @param object
* native database geometry object (depends on the JDBC spatial
* extension of the database)
* @return JTS geometry corresponding to geomObj.
*/
public Geometry convert2JTS(Object object) {
if (object == null) {
return null;
}
byte[] data = (byte[]) object;
byte[] wkb = new byte[data.length - SRIDLEN];
System.arraycopy(data, SRIDLEN, wkb, 0, wkb.length);
int srid = 0;
// WKB in MySQL Spatial is always little endian.
srid = data[3] << 24 | (data[2] & 0xff) << 16 | (data[1] & 0xff) << 8
| (data[0] & 0xff);
Geometry geom = null;
try {
geom = reader.read(wkb);
} catch (Exception e) {
throw new RuntimeException(
"Couldn't parse incoming MySQL Spatial data.");
}
geom.setSRID(srid);
return geom;
}
 
/**
* Converts a JTS <code>Geometry</code> to a native geometry object.
*
* @param jtsGeom
* JTS Geometry to convert
* @param connection
* the current database connection
* @return native database geometry object corresponding to jtsGeom.
*/
public Object conv2DBGeometry(Geometry jtsGeom, Connection connection) {
int srid = jtsGeom.getSRID();
byte[] wkb = writer.write(jtsGeom);
 
byte[] byteArr = new byte[wkb.length + SRIDLEN];
byteArr[3] = (byte) ((srid >> 24) & 0xFF);
byteArr[2] = (byte) ((srid >> 16) & 0xFF);
byteArr[1] = (byte) ((srid >> 8) & 0xFF);
byteArr[0] = (byte) (srid & 0xFF);
System.arraycopy(wkb, 0, byteArr, SRIDLEN, wkb.length);
return byteArr;
}
 
}
Property changes:
Added: svn:keywords
+ Id
/tags/1.0-M1/hibernate-spatial-mysql/src/main/java/org/hibernatespatial/mysql/MySQLSpatialDialect.java
New file
0,0 → 1,171
/**
* $Id$
*
* This file is part of Hibernate Spatial, an extension to the
* hibernate ORM solution for geographic data.
*
* Copyright © 2007 Geovise BVBA
* Copyright © 2007 K.U. Leuven LRD, Spatial Applications Division, Belgium
*
* This work was partially supported by the European Commission,
* under the 6th Framework Programme, contract IST-2-004688-STP.
*
* 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
*
* For more information, visit: http://www.hibernatespatial.org/
*/
package org.hibernatespatial.mysql;
 
import org.hibernate.Hibernate;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.dialect.function.StandardSQLFunction;
import org.hibernate.type.CustomType;
import org.hibernate.usertype.UserType;
import org.hibernatespatial.SpatialDialect;
import org.hibernatespatial.SpatialRelation;
 
/**
* Extends the MySQLDialect by also including information on spatial operators,
* constructors and processing functions.
*
* @author Karel Maesen
*/
public class MySQLSpatialDialect extends MySQLDialect implements SpatialDialect {
 
public MySQLSpatialDialect() {
super();
registerColumnType(java.sql.Types.BINARY, "geometry");
 
// registering OGC functions
// (spec_simplefeatures_sql_99-04.pdf)
 
// section 2.1.1.1
// Registerfunction calls for registering geometry functions:
// first argument is the OGC standard functionname, second the name as
// it occurs in the spatial dialect
registerFunction("dimension", new StandardSQLFunction("dimension",
Hibernate.INTEGER));
registerFunction("geometrytype", new StandardSQLFunction(
"geometrytype", Hibernate.STRING));
registerFunction("srid", new StandardSQLFunction("srid",
Hibernate.INTEGER));
registerFunction("envelope", new StandardSQLFunction("envelope",
new CustomType(MySQLGeometryUserType.class, null)));
registerFunction("astext", new StandardSQLFunction("astext",
Hibernate.STRING));
registerFunction("asbinary", new StandardSQLFunction("asbinary",
Hibernate.BINARY));
// registerFunction("isempty", new StandardSQLFunction("isempty",
// Hibernate.BOOLEAN));
// registerFunction("issimple", new StandardSQLFunction("issimple",
// Hibernate.BOOLEAN));
// registerFunction("boundary", new StandardSQLFunction("boundary",
// new CustomType(MySQLGeometryUserType.class, null)));
 
// Register functions for spatial relation constructs
registerFunction("overlaps", new StandardSQLFunction("overlaps",
Hibernate.BOOLEAN));
registerFunction("intersects", new StandardSQLFunction("intersects",
Hibernate.BOOLEAN));
registerFunction("equals", new StandardSQLFunction("equals",
Hibernate.BOOLEAN));
registerFunction("contains", new StandardSQLFunction("contains",
Hibernate.BOOLEAN));
registerFunction("crosses", new StandardSQLFunction("crosses",
Hibernate.BOOLEAN));
registerFunction("disjoint", new StandardSQLFunction("disjoint",
Hibernate.BOOLEAN));
registerFunction("touches", new StandardSQLFunction("touches",
Hibernate.BOOLEAN));
registerFunction("within", new StandardSQLFunction("within",
Hibernate.BOOLEAN));
registerFunction("relate", new StandardSQLFunction("relate",
Hibernate.BOOLEAN));
 
// register the spatial analysis functions
registerFunction("distance", new StandardSQLFunction("distance",
Hibernate.DOUBLE));
registerFunction("buffer", new StandardSQLFunction("buffer",
new CustomType(MySQLGeometryUserType.class, null)));
registerFunction("convexhull", new StandardSQLFunction("convexhull",
new CustomType(MySQLGeometryUserType.class, null)));
registerFunction("difference", new StandardSQLFunction("difference",
new CustomType(MySQLGeometryUserType.class, null)));
registerFunction("intersection", new StandardSQLFunction(
"intersection", new CustomType(MySQLGeometryUserType.class,
null)));
registerFunction("symdifference", new StandardSQLFunction(
"symdifference", new CustomType(MySQLGeometryUserType.class,
null)));
registerFunction("geomunion", new StandardSQLFunction("union",
new CustomType(MySQLGeometryUserType.class, null)));
 
}
 
/*
* (non-Javadoc)
*
* @see org.walkonweb.spatial.dialect.SpatialEnabledDialect#getSpatialRelateExpression(java.lang.String,
* int, boolean)
*/
public String getSpatialRelateSQL(String columnName, int spatialRelation,
boolean hasFilter) {
switch (spatialRelation) {
case SpatialRelation.WITHIN:
return " within(" + columnName + ",?)";
case SpatialRelation.CONTAINS:
return " contains(" + columnName + ", ?)";
case SpatialRelation.CROSSES:
return " crosses(" + columnName + ", ?)";
case SpatialRelation.OVERLAPS:
return " overlaps(" + columnName + ", ?)";
case SpatialRelation.DISJOINT:
return " disjoint(" + columnName + ", ?)";
case SpatialRelation.INTERSECTS:
return " intersects(" + columnName + ", ?)";
case SpatialRelation.TOUCHES:
return " touches(" + columnName + ", ?)";
case SpatialRelation.EQUALS:
return " equals(" + columnName + ", ?)";
default:
throw new IllegalArgumentException(
"Spatial relation is not known by this dialect");
}
 
}
 
/*
* (non-Javadoc)
*
* @see org.walkonweb.spatial.dialect.SpatialEnabledDialect#getSpatialFilterExpression(java.lang.String)
*/
public String getSpatialFilterExpression(String columnName) {
return "MBRIntersects(" + columnName + ", ? ) ";
}
 
/*
* (non-Javadoc)
*
* @see org.hibernatespatial.SpatialDialect#getGeometryUserType()
*/
public UserType getGeometryUserType() {
return new MySQLGeometryUserType();
}
 
public String getSpatialAggregateSQL(String columnName, int aggregation) {
throw new UnsupportedOperationException("Mysql has no spatial aggregate SQL functions.");
}
 
}
Property changes:
Added: svn:keywords
+ Id
/tags/1.0-M1/hibernate-spatial-mysql/src/main/resources/META-INF/services/org.hibernatespatial.spi.SpatialDialectProvider
New file
0,0 → 1,0
org.hibernatespatial.mysql.DialectProvider
Property changes:
Added: svn:keywords
+ Id
/tags/1.0-M1/hibernate-spatial-mysql/src/site/site.xml
New file
0,0 → 1,25
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="Hibernate Spatial Postgis provider">
<bannerLeft>
<name>Hibernate Spatial MySQL Provider</name>
<href>http://www.cadrie.com/projects/majas-hibernate</href>
</bannerLeft>
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-default-skin</artifactId>
</skin>
 
<publishDate format="yyyy MMM dd" />
<body>
<menu name="Overview" inherit="top">
<item name="Introduction" href="hibernate-spatial-mysql/index.html"/>
<item name="Usage" href="hibernate-spatial-mysql/usage.html"/>
</menu>
 
</body>
</project>
Property changes:
Added: svn:keywords
+ Id
/tags/1.0-M1/hibernate-spatial-mysql/src/site/xdoc/usage.xml
New file
0,0 → 1,50
<?xml version="1.0" encoding="UTF-8"?>
 
<document>
<header />
 
 
<body>
<section name="Hibernate Spatial MySQL Provider Usage">
<p>
To have Hibernate Spatial use this provider, simply drop
the jar on the class-path alongside the
hibernate-spatial.jar. When the Hibernate Spatial
library is loaded it will find the provider and use it
to retrieve the Hibernate dialect for MySQL. This dialect is a subclass of
<code>org.hibernate.dialect.MySQLDialect</code>
</p>
<p>
With the provider installed, you can use it by setting
the dialect in the Hibernate configuration file as in
the following snippet.
</p>
<source>
...
&lt;property name="hibernate.dialect"&gt;
org.hibernatespatial.mysql.MySQLSpatialDialect
&lt;/property&gt;
...
</source>
 
<p>
When there is more than one Hibernate Spatial provider
on the Class-Path, you should explicitly label the
dialect for the Geometry valued properties.
</p>
<source>
...
&lt;property name="geometry"&gt;
&lt;column name="geom" sql-type="MDSYS.SDO_GEOMETRY"&gt;
&lt;type name="org.hibernatespatial.GeometryUserType"&gt;
&lt;param name="dialect"&gt;
org.hibernatespatial.oracle.OracleSpatial10gDialect
&lt;/param&gt;
&lt;/type&gt;
&lt;/property&gt;
...
</source>
</section>
 
</body>
</document>
Property changes:
Added: svn:keywords
+ Id
/tags/1.0-M1/hibernate-spatial-mysql/src/site/xdoc/index.xml
New file
0,0 → 1,19
<?xml version="1.0" encoding="UTF-8"?>
 
<document>
<header />
 
<body>
<section name="The Hibernate Spatial MySQL Provider">
<p>
The MySQL Provider adds support for MySQL to
Hibernate Spatial. It has been tested with MySQL 5.0
and should work with any version later than that.
</p>
<p>
Note that MySQL does not completely implement the OGC Simple Feature Specification.
Some functions that work for PostGIS or Oracle may fail to work for MySQL.
</p>
</section>
</body>
</document>
Property changes:
Added: svn:keywords
+ Id
/tags/1.0-M1/hibernate-spatial-mysql/pom.xml
New file
0,0 → 1,41
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
<!-- $Id$ -->
 
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.hibernatespatial</groupId>
<artifactId>hibernate-spatial-maven</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../hibernate-spatial-maven</relativePath>
</parent>
<artifactId>hibernate-spatial-mysql</artifactId>
<packaging>jar</packaging>
<name>MySQL DialectProvider</name>
<url>http://www.hibernatespatial.org/hibernate-spatial-mysql</url>
<description>
MySQL dialect provider for Hibernate Spatial (for MySQL 5.0 or higher).
</description>
 
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.0.5</version>
</dependency>
</dependencies>
</project>
Property changes:
Added: svn:keywords
+ Id