|
From: <svn...@os...> - 2012-01-19 17:27:34
|
Author: aaime
Date: 2012-01-19 09:27:22 -0800 (Thu, 19 Jan 2012)
New Revision: 38503
Added:
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDateTest.java
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDateTestSetup.java
Modified:
branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerFilterToSQL.java
Log:
[GEOT-4012] Implement date/datetime support for sql server on 2.7.x
Modified: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerFilterToSQL.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerFilterToSQL.java 2012-01-17 18:40:35 UTC (rev 38502)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/main/java/org/geotools/data/sqlserver/SQLServerFilterToSQL.java 2012-01-19 17:27:22 UTC (rev 38503)
@@ -17,6 +17,8 @@
package org.geotools.data.sqlserver;
import java.io.IOException;
+import java.sql.Date;
+import java.text.SimpleDateFormat;
import org.geotools.data.jdbc.FilterToSQL;
import org.geotools.filter.FilterCapabilities;
@@ -163,4 +165,15 @@
return extraData;
}
+
+ static SimpleDateFormat DATETIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+ @Override
+ protected void writeLiteral(Object literal) throws IOException {
+ if (literal instanceof Date) {
+ out.write("'" + DATETIME_FORMAT.format(literal) + "'");
+ } else {
+ super.writeLiteral(literal);
+ }
+ }
}
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDateTest.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDateTest.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDateTest.java 2012-01-19 17:27:22 UTC (rev 38503)
@@ -0,0 +1,29 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2011, Open Source Geospatial Foundation (OSGeo)
+ *
+ * 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;
+ * version 2.1 of the License.
+ *
+ * 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.
+ */
+package org.geotools.data.sqlserver;
+
+import org.geotools.jdbc.JDBCDateTest;
+import org.geotools.jdbc.JDBCDateTestSetup;
+
+public class SQLServerDateTest extends JDBCDateTest {
+
+ @Override
+ protected JDBCDateTestSetup createTestSetup() {
+ return new SQLServerDateTestSetup();
+ }
+
+}
\ No newline at end of file
Added: branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDateTestSetup.java
===================================================================
--- branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDateTestSetup.java (rev 0)
+++ branches/2.7.x/modules/plugin/jdbc/jdbc-sqlserver/src/test/java/org/geotools/data/sqlserver/SQLServerDateTestSetup.java 2012-01-19 17:27:22 UTC (rev 38503)
@@ -0,0 +1,52 @@
+/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2011, Open Source Geospatial Foundation (OSGeo)
+ *
+ * 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;
+ * version 2.1 of the License.
+ *
+ * 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.
+ */
+package org.geotools.data.sqlserver;
+
+import org.geotools.jdbc.JDBCDateTestSetup;
+
+public class SQLServerDateTestSetup extends JDBCDateTestSetup {
+
+ protected SQLServerDateTestSetup() {
+ super(new SQLServerTestSetup());
+ }
+
+ @Override
+ protected void createDateTable() throws Exception {
+ run( "CREATE TABLE dates (d DATE, dt DATETIME, t TIME)");
+
+ run( "INSERT INTO dates VALUES (" +
+ "CAST('2009-06-28' as DATE), " +
+ "CAST('2009-06-28 15:12:41' as DATETIME)," +
+ "CAST('15:12:41' as TIME) )");
+
+ run( "INSERT INTO dates VALUES (" +
+ "CAST('2009-01-15' as DATE), " +
+ "CAST('2009-01-15 13:10:12' as DATETIME)," +
+ "CAST('13:10:12' as TIME) )");
+
+ run( "INSERT INTO dates VALUES (" +
+ "CAST('2009-09-29' as DATE), " +
+ "CAST('2009-09-29 17:54:23' as DATETIME)," +
+ "CAST('17:54:23' as TIME) )");
+ }
+
+ @Override
+ protected void dropDateTable() throws Exception {
+ runSafe("DROP TABLE dates");
+ }
+
+}
\ No newline at end of file
|