|
From: <jef...@us...> - 2012-10-01 01:09:07
|
Revision: 1258
http://dbunit.svn.sourceforge.net/dbunit/?rev=1258&view=rev
Author: jeffjensen
Date: 2012-10-01 01:09:01 +0000 (Mon, 01 Oct 2012)
Log Message:
-----------
[3499513] Postgres Geometry Type
Modified Paths:
--------------
trunk/dbunit/src/changes/changes.xml
trunk/dbunit/src/main/java/org/dbunit/ext/postgresql/PostgresqlDataTypeFactory.java
Added Paths:
-----------
trunk/dbunit/src/main/java/org/dbunit/ext/postgresql/GeometryType.java
Modified: trunk/dbunit/src/changes/changes.xml
===================================================================
--- trunk/dbunit/src/changes/changes.xml 2012-09-30 23:45:58 UTC (rev 1257)
+++ trunk/dbunit/src/changes/changes.xml 2012-10-01 01:09:01 UTC (rev 1258)
@@ -11,6 +11,8 @@
<body>
<release version="next" date="in SCM" description="">
+ <action dev="jeffjensen" type="add" issue="3499513" due-to="MPriess">Add Postgres Geometry Type.</action>
+ <action dev="jeffjensen" type="fix" issue="" due-to="">.</action>
<action dev="jeffjensen" type="fix" issue="3542576" due-to="(unknown)">Calls to JdbcDatabaseTester getConnection return new connect.</action>
<action dev="jeffjensen" type="fix" issue="3545861" due-to="artbristol">CsvURLProducer swallows exception stack.</action>
<action dev="jeffjensen" type="fix" issue="3554287" due-to="statalex">Trim CSV file column names.</action>
Added: trunk/dbunit/src/main/java/org/dbunit/ext/postgresql/GeometryType.java
===================================================================
--- trunk/dbunit/src/main/java/org/dbunit/ext/postgresql/GeometryType.java (rev 0)
+++ trunk/dbunit/src/main/java/org/dbunit/ext/postgresql/GeometryType.java 2012-10-01 01:09:01 UTC (rev 1258)
@@ -0,0 +1,59 @@
+package org.dbunit.ext.postgresql;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.dbunit.dataset.datatype.AbstractDataType;
+import org.dbunit.dataset.datatype.TypeCastException;
+
+public class GeometryType extends AbstractDataType {
+ public GeometryType() {
+ super("geometry", Types.OTHER, String.class, false);
+ }
+
+ public Object getSqlValue(int column, ResultSet resultSet)
+ throws SQLException, TypeCastException {
+ return resultSet.getString(column);
+ }
+
+ public void setSqlValue(Object geom, int column, PreparedStatement statement)
+ throws SQLException, TypeCastException {
+ statement.setObject(column,
+ getGeometry(geom, statement.getConnection()));
+ }
+
+ public Object typeCast(Object arg0) throws TypeCastException {
+ return arg0.toString();
+ }
+
+ private Object getGeometry(Object value, Connection connection)
+ throws TypeCastException {
+ Object tempgeom = null;
+
+ try {
+ Class aPGIntervalClass = super.loadClass("org.postgis.PGgeometry",
+ connection);
+ Constructor ct = aPGIntervalClass
+ .getConstructor(new Class[] { String.class });
+
+ tempgeom = ct.newInstance(new Object[] { value });
+ } catch (ClassNotFoundException e) {
+ throw new TypeCastException(value, this, e);
+ } catch (InvocationTargetException e) {
+ throw new TypeCastException(value, this, e);
+ } catch (NoSuchMethodException e) {
+ throw new TypeCastException(value, this, e);
+ } catch (IllegalAccessException e) {
+ throw new TypeCastException(value, this, e);
+ } catch (InstantiationException e) {
+ throw new TypeCastException(value, this, e);
+ }
+
+ return tempgeom;
+ }
+}
Property changes on: trunk/dbunit/src/main/java/org/dbunit/ext/postgresql/GeometryType.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/dbunit/src/main/java/org/dbunit/ext/postgresql/PostgresqlDataTypeFactory.java
===================================================================
--- trunk/dbunit/src/main/java/org/dbunit/ext/postgresql/PostgresqlDataTypeFactory.java 2012-09-30 23:45:58 UTC (rev 1257)
+++ trunk/dbunit/src/main/java/org/dbunit/ext/postgresql/PostgresqlDataTypeFactory.java 2012-10-01 01:09:01 UTC (rev 1258)
@@ -58,6 +58,11 @@
return DATABASE_PRODUCTS;
}
+ public static Collection getDatabaseProducts()
+ {
+ return DATABASE_PRODUCTS;
+ }
+
public DataType createDataType(int sqlType, String sqlTypeName) throws DataTypeException {
logger.debug("createDataType(sqlType={}, sqlTypeName={})",
String.valueOf(sqlType), sqlTypeName);
@@ -71,6 +76,8 @@
return new IntervalType();
else if ("inet".equals(sqlTypeName))
return new InetType();
+ else if("geometry".equals(sqlTypeName))
+ return new GeometryType();
else
{
// Finally check whether the user defined a custom datatype
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|