Permalink
Browse files

Adapted to new test suite

  • Loading branch information...
1 parent 8e98046 commit d38140048d733109c0aeaaa99e6fbd6c2e2ff783 @maesenka maesenka committed Oct 25, 2010
@@ -98,7 +98,17 @@ public String getSpatialRelateSQL(String columnName, int spatialRelation,
* Postgis (up to version ??) supports explicit filtering. Oracle and MySQL
* don't.
*
- * @return
+ * @return *
+ */
+ @Deprecated
+ public boolean isTwoPhaseFiltering();
+
+ /**
+ * Does this dialect supports the specified <code>SpatialFunction</code>.
+ *
+ * @param function <code>SpatialFunction</code>
+ * @return true if this <code>SpatialDialect</code> supports the spatial function specified by the function parameter.
*/
- public boolean isTwoPhaseFiltering();
+ public boolean supports(SpatialFunction function);
+
}
@@ -0,0 +1,45 @@
+package org.hibernatespatial;
+
+/**
+ * Spatial functions that users generally expect in a database.
+ *
+ * @author Karel Maesen, Geovise BVBA
+ * creation-date: Oct 7, 2010
+ */
+public enum SpatialFunction {
+
+ dimension("SFS 1.1"),
+ geometrytype("SFS 1.1"),
+ srid("SFS 1.1"),
+ envelope("SFS 1.1"),
+ astext("SFS 1.1"),
+ asbinary("SFS 1.1"),
+ isempty("SFS 1.1"),
+ issimple("SFS 1.1"),
+ boundary("SFS 1.1"),
+ equals("SFS 1.1"),
+ disjoint("SFS 1.1"),
+ intersects("SFS 1.1"),
+ touches("SFS 1.1"),
+ crosses("SFS 1.1"),
+ within("SFS 1.1"),
+ contains("SFS 1.1"),
+ overlaps("SFS 1.1"),
+ relate("SFS 1.1"),
+ distance("SFS 1.1"),
+ buffer("SFS 1.1"),
+ convexhull("SFS 1.1"),
+ intersection("SFS 1.1"),
+ geomunion("SFS 1.1"), //is actually UNION but this conflicts with SQL UNION construct
+ difference("SFS 1.1"),
+ symdifference("SFS 1.1"),
+ filter("Min. boundingbox overlap") //Minimum Bounding Rectangle overlaps
+ ;
+
+ private final String description;
+
+ SpatialFunction(String specification) {
+ this.description = specification;
+ }
+
+}
@@ -29,6 +29,8 @@
import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.sql.*;
import java.util.HashMap;
@@ -45,6 +47,8 @@
*/
public abstract class AbstractExpectationsFactory {
+ private static final Logger LOGGER = LoggerFactory.getLogger(AbstractExpectationsFactory.class);
+
public final static int INTEGER = 1;
public final static int DOUBLE = 2;
public final static int GEOMETRY = 3;
@@ -57,7 +61,7 @@
private final DataSourceUtils dataSourceUtils;
private static final int MAX_BYTE_LEN = 1024;
- public AbstractExpectationsFactory(DataSourceUtils dataSourceUtils, SQLExpressionTemplate sqlExpressionTemplate) {
+ public AbstractExpectationsFactory(DataSourceUtils dataSourceUtils) {
this.dataSourceUtils = dataSourceUtils;
}
@@ -617,6 +621,7 @@ public Polygon getTestPolygon() {
try {
cn = createConnection();
preparedStatement = nativeSQLStatement.prepare(cn);
+ LOGGER.info("Native SQL is: " + preparedStatement.toString());
ResultSet results = preparedStatement.executeQuery();
while (results.next()) {
int id = results.getInt(1);
@@ -32,9 +32,11 @@
import org.slf4j.LoggerFactory;
import javax.sql.DataSource;
+import java.io.*;
import java.sql.*;
import java.util.HashMap;
import java.util.Map;
+import java.util.Properties;
/**
* <p>Unit testsuite-suite support class.</p>
@@ -83,6 +85,41 @@ public DataSourceUtils(String jdbcDriver, String jdbcUrl, String jdbcUser, Strin
createBasicDataSource();
}
+ /**
+ * Constructor using a properties file
+ *
+ * @param propertyFile
+ * @param template
+ */
+ public DataSourceUtils(String propertyFile, SQLExpressionTemplate template) {
+ Properties properties = readProperties(propertyFile);
+ this.jdbcUrl = properties.getProperty("jdbcUrl");
+ this.jdbcDriver = properties.getProperty("jdbcDriver");
+ this.jdbcUser = properties.getProperty("jdbcUser");
+ this.jdbcPass = properties.getProperty("jdbcPass");
+ this.sqlExpressionTemplate = template;
+ createBasicDataSource();
+ }
+
+ private Properties readProperties(String propertyFile) {
+ InputStream is = null;
+ try {
+ is = Thread.currentThread().getContextClassLoader().getResourceAsStream(propertyFile);
+ if (is == null) throw new RuntimeException(String.format("File %s not found on classpath.", propertyFile));
+ Properties properties = new Properties();
+ properties.load(is);
+ return properties;
+ } catch (IOException e) {
+ throw (new RuntimeException(e));
+ } finally {
+ if (is != null) try {
+ is.close();
+ } catch (IOException e) {
+ //nothing to do
+ }
+ }
+ }
+
private void createBasicDataSource() {
BasicDataSource bds = new BasicDataSource();
bds.setDriverClassName(jdbcDriver);
@@ -92,6 +129,16 @@ private void createBasicDataSource() {
dataSource = bds;
}
+
+ /**
+ * Closes the connections to the database.
+ *
+ * @throws SQLException
+ */
+ public void close() throws SQLException {
+ ((BasicDataSource) dataSource).close();
+ }
+
/**
* Returns a DataSource for the configured database.
*
@@ -140,7 +187,6 @@ public void deleteTestData() throws SQLException {
}
public void insertTestData(TestData testData) throws SQLException {
- deleteTestData();
Connection cn = null;
try {
cn = getDataSource().getConnection();
@@ -164,6 +210,38 @@ public void insertTestData(TestData testData) throws SQLException {
}
}
+
+ /**
+ * Parses the content of a file into an executable SQL statement.
+ *
+ * @param fileName name of a file containing SQL-statements
+ * @return
+ * @throws IOException
+ */
+ public String parseSqlIn(String fileName) throws IOException {
+ InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
+ if (is == null) {
+ throw new RuntimeException("File " + fileName + " not found on Classpath.");
+ }
+ try {
+ BufferedReader reader = new BufferedReader(
+ new InputStreamReader(is));
+
+ StringWriter sw = new StringWriter();
+ BufferedWriter writer = new BufferedWriter(sw);
+
+ for (int c = reader.read(); c != -1; c = reader.read()) {
+ writer.write(c);
+ }
+ writer.flush();
+ return sw.toString();
+ } finally {
+ if (is != null) {
+ is.close();
+ }
+ }
+ }
+
/**
* Executes a SQL statement.
* <p/>
@@ -191,6 +269,13 @@ public void executeStatement(String sql) throws SQLException {
}
}
+ /**
+ * Operations to fully initialize the
+ */
+ public void afterCreateSchema() {
+
+ }
+
/**
* Return the geometries of the testsuite-suite objects as raw (i.e. undecoded) objects from the database.
*
@@ -0,0 +1,45 @@
+package org.hibernatespatial.test;
+
+import org.hibernate.cfg.Configuration;
+import org.hibernate.testing.junit.functional.FunctionalTestCase;
+
+
+/**
+ * @author Karel Maesen, Geovise BVBA
+ * creation-date: Sep 30, 2010
+ */
+public abstract class TestSupport {
+
+ protected Configuration configuration;
+
+ public DataSourceUtils createDataSourceUtil(Configuration configuration) {
+ this.configuration = configuration;
+ return new DataSourceUtils(driver(), url(), user(), passwd(), getSQLExpressionTemplate());
+ }
+
+ public GeometryEquality createGeometryEquality() {
+ return new GeometryEquality();
+ }
+
+ public abstract TestData createTestData(FunctionalTestCase testcase);
+
+ public abstract AbstractExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils);
+
+ public abstract SQLExpressionTemplate getSQLExpressionTemplate();
+
+ protected String driver() {
+ return configuration.getProperty("hibernate.connection.driver_class");
+ }
+
+ protected String url() {
+ return configuration.getProperty("hibernate.connection.url");
+ }
+
+ protected String user() {
+ return configuration.getProperty("hibernate.connection.username");
+ }
+
+ protected String passwd() {
+ return configuration.getProperty("hibernate.connection.password");
+ }
+}
@@ -1,21 +0,0 @@
-package org.hibernatespatial.test;
-
-import org.hibernate.cfg.Configuration;
-import org.hibernate.testing.junit.functional.FunctionalTestCase;
-
-
-/**
- * @author Karel Maesen, Geovise BVBA
- * creation-date: Sep 30, 2010
- */
-public interface TestSupportFactory {
-
- public DataSourceUtils createDataSourceUtil(Configuration configuration);
-
- public TestData createTestData(FunctionalTestCase testcase);
-
-
- public GeometryEquality createGeometryEquality();
-
- public AbstractExpectationsFactory createExpectationsFactory(DataSourceUtils dataSourceUtils);
-}

0 comments on commit d381400

Please sign in to comment.