incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r1081434 - in /incubator/isis/trunk/runtimes/dflt/objectstores/sql: impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/ tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/ tests-served/
Date Mon, 14 Mar 2011 16:03:22 GMT
Author: kevin
Date: Mon Mar 14 16:03:22 2011
New Revision: 1081434

URL: http://svn.apache.org/viewvc?rev=1081434&view=rev
Log:
Attempts to address potential time zone issues. Maybe this'll fix the Hudson build issue!

Modified:
    incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateMapper.java
    incubator/isis/trunk/runtimes/dflt/objectstores/sql/tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestCommon.java
    incubator/isis/trunk/runtimes/dflt/objectstores/sql/tests-served/pom.xml

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateMapper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateMapper.java?rev=1081434&r1=1081433&r2=1081434&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateMapper.java
(original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateMapper.java
Mon Mar 14 16:03:22 2011
@@ -21,13 +21,19 @@
 package org.apache.isis.runtimes.dflt.objectstores.sql.jdbc;
 
 import org.apache.isis.applib.value.Date;
+import org.apache.isis.core.commons.exceptions.IsisApplicationException;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
 import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
 import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
 import org.apache.isis.runtimes.dflt.objectstores.sql.mapping.FieldMapping;
 import org.apache.isis.runtimes.dflt.objectstores.sql.mapping.FieldMappingFactory;
 
-
+/**
+ * Handles reading and writing java.sql.Date and org.apache.isis.applib.value.Date values
to and from the data store.
+ * 
+ *
+ * @version $Rev$ $Date$
+ */
 public class JdbcDateMapper extends AbstractJdbcFieldMapping {
     
     public static class Factory implements FieldMappingFactory {
@@ -42,28 +48,31 @@ public class JdbcDateMapper extends Abst
 
     @Override
     protected Object preparedStatementObject(ObjectAdapter value){
-        java.sql.Date date; 
-        if (value.getObject() instanceof java.sql.Date){
-            date = (java.sql.Date) value.getObject();
-        }else {// if (value instanceof Date){
+        Object o = value.getObject();
+        if (o instanceof java.sql.Date){
+            return (java.sql.Date) value.getObject();
+        }else  if (o instanceof Date){
             Date asDate = (Date) value.getObject();
-            date = new java.sql.Date(asDate.dateValue().getTime());
+            return  new java.sql.Date(asDate.dateValue().getTime());
+        } else {
+            throw new IsisApplicationException("Unimplemented JdbcDateMapper instance type:
"+value.getClass().toString());
         }
-        return date;
     }
     
-
+    @Override
     public ObjectAdapter setFromDBColumn(final String encodedValue, final ObjectAssociation
field) {
-        String valueString;
+        
+        String valueString, year, month, day;
         if (encodedValue.length() > 9) {
             // convert date to yyyymmdd
-            String year = encodedValue.substring(0, 4);
-            String month = encodedValue.substring(5, 7);
-            String day = encodedValue.substring(8, 10);
+            year = encodedValue.substring(0, 4);
+            month = encodedValue.substring(5, 7);
+            day = encodedValue.substring(8, 10);
             valueString = year + month + day;
         } else {
             valueString = encodedValue;
         }
+        // Caution: ValueSemanticsProviderAbstractTemporal explicitly sets the timezone to
UTC
         return field.getSpecification().getFacet(EncodableFacet.class).fromEncodedString(valueString);
     }
 

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/sql/tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestCommon.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/sql/tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestCommon.java?rev=1081434&r1=1081433&r2=1081434&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/sql/tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestCommon.java
(original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/sql/tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestCommon.java
Mon Mar 14 16:03:22 2011
@@ -28,16 +28,13 @@ import java.io.IOException;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Calendar;
 import java.util.List;
 import java.util.Properties;
+import java.util.TimeZone;
 
 import junit.framework.TestCase;
 
-import org.apache.isis.runtimes.dflt.objectstores.sql.singleton.SqlIntegrationTestSingleton;
-import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.SqlDataClassFactory;
-import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.SimpleClass;
-import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.SimpleClassTwo;
-import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.SqlDataClass;
 import org.apache.isis.applib.value.Color;
 import org.apache.isis.applib.value.Date;
 import org.apache.isis.applib.value.DateTime;
@@ -47,6 +44,11 @@ import org.apache.isis.applib.value.Perc
 import org.apache.isis.applib.value.Time;
 import org.apache.isis.applib.value.TimeStamp;
 import org.apache.isis.core.commons.config.IsisConfigurationBuilderFileSystem;
+import org.apache.isis.runtimes.dflt.objectstores.sql.singleton.SqlIntegrationTestSingleton;
+import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.SqlDataClassFactory;
+import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.SimpleClass;
+import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.SimpleClassTwo;
+import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.SqlDataClass;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 
@@ -64,21 +66,41 @@ import org.apache.log4j.Logger;
  * 
  */
 public abstract class SqlIntegrationTestCommon extends TestCase {
-	// Helper values
-	@SuppressWarnings("deprecation")
-	private static final java.sql.Date sqlDate = new java.sql.Date(
-			java.sql.Date.UTC(110, 03, 10, 0, 0, 0));
+    private static final Logger LOG = Logger.getLogger(SqlIntegrationTestCommon.class);
+    
+    
+    private static final TimeZone UTC_TIME_ZONE;
+    // Helper values
+    private static final java.sql.Date sqlDate;// = java.sql.Date.valueOf("2010-03-05");
+    
+    static {
+        TimeZone timeZone = TimeZone.getTimeZone("Etc/UTC");
+        if (timeZone == null) {
+            timeZone = TimeZone.getTimeZone("UTC");
+        }
+        UTC_TIME_ZONE = timeZone;
+        
+        final Calendar cal = Calendar.getInstance();
+        cal.setTimeZone(UTC_TIME_ZONE);
+        cal.set(2011, 4-1, 8, 0, 0, 0);
+        cal.set(Calendar.MILLISECOND, 0);
+        
+        sqlDate = new java.sql.Date(cal.getTimeInMillis());
+    }
+	
 	private static final Date applibDate = new Date(2010, 3, 5);
-	// private static final Money money = new Money(99.99, "GBP");
-	private static final DateTime dateTime = new DateTime(2010, 3, 5, 22, 23);
+	private static final DateTime dateTime = new DateTime(2010, 3, 5, 1, 23);
 	private static final TimeStamp timeStamp = new TimeStamp(
 			dateTime.longValue());
 	private static final Time time = new Time(14, 56);
+	
 	private static final Color color = Color.BLACK;
 	private static final Image image = new Image(new int[][] { { 1, 2, 3 },
 			{ 4, 5, 6 }, { 7, 8, 9 } });
 	private static final Password password = new Password("password");
 	private static final Percentage percentage = new Percentage(42);
+    // private static final Money money = new Money(99.99, "GBP");
+	
 	// Collection mapper tests
 	private static final List<String> stringList1 = Arrays.asList("Baking",
 			"Bakery", "Canned", "Dairy");
@@ -303,10 +325,20 @@ public abstract class SqlIntegrationTest
 	 */
 	public void testDate() {
 		SqlDataClass sqlDataClass = SqlIntegrationTestSingleton.getPerson();
-		Logger.getRootLogger().log(Level.INFO, sqlDataClass.getDate());
-		assertTrue(applibDate.toString() + " is not equal to "
-				+ sqlDataClass.getDate().toString(),
-				applibDate.isEqualTo(sqlDataClass.getDate()));
+		
+        LOG.log(Level.INFO, "Test: testDate()");
+        
+        LOG.log(Level.INFO, "sqlDataClass.getDate() as String: "+sqlDataClass.getDate());
+        LOG.log(Level.INFO, "applibDate.dateValue() as String: "+applibDate);
+        
+        LOG.log(Level.INFO, "sqlDataClass.getDate().getTime() as Long: "+sqlDataClass.getDate().dateValue().getTime());
+        LOG.log(Level.INFO, "applibDate.dateValue() as Long: "+applibDate.dateValue().getTime());
+        
+        if (!applibDate.isEqualTo(sqlDataClass.getDate())){
+            fail(applibDate.toString() + " is not equal to "
+                + sqlDataClass.getDate().toString());
+        }
+		
 	}
 
 	/**
@@ -316,12 +348,46 @@ public abstract class SqlIntegrationTest
 	 */
 	public void testSqlDate() {
 		SqlDataClass sqlDataClass = SqlIntegrationTestSingleton.getPerson();
-		Logger.getRootLogger().log(Level.INFO, sqlDataClass.getSqlDate());
-		assertTrue("SQL date " + sqlDate.toString() + " is not equal to "
-				+ sqlDataClass.getSqlDate().toString(),
-				sqlDate.compareTo(sqlDataClass.getSqlDate()) == 0);
+		
+		LOG.log(Level.INFO, "Test: testSqlDate()");
+		LOG.log(Level.INFO, "sqlDataClass.getSqlDate() as String:"+sqlDataClass.getSqlDate());
+        LOG.log(Level.INFO, "sqlDate.toString() as String:"+sqlDate);
+		
+        LOG.log(Level.INFO, "sqlDataClass.getSqlDate().getTime() as Long:"+sqlDataClass.getSqlDate().getTime());
+		LOG.log(Level.INFO, "sqlDate.getTime() as Long:"+sqlDate.getTime());
+        
+        if (sqlDate.compareTo(sqlDataClass.getSqlDate()) != 0){
+            fail("SQL date " + sqlDate.toString() + " is not equal to "
+                + sqlDataClass.getSqlDate().toString());
+        }
+		
 	}
 
+    public void testDateTimezoneIssue() {
+        /*
+         * At the moment, applib Date and java.sql.Date are restored from ValueSemanticsProviderAbstractTemporal
with
+         * an explicit hourly offset that comes from the timezone. I.e. in South Africa,
with TZ +2h00, they have an
+         * implicit time of 02h00 (2AM). This can potentially seriously screw up GMT-X dates,
which, I suspect, will
+         * actually be set to the dat BEFORE.
+         * 
+         * This test is a simple test to confirm that date/time before and after checks work
as expected.   
+         *  
+         */
+        SqlDataClass sqlDataClass = SqlIntegrationTestSingleton.getPerson();
+        
+        DateTime dateTime = sqlDataClass.getDateTime(); // new DateTime(2010, 3, 5, 1, 23);
+        Date date = sqlDataClass.getDate(); // new Date(2010, 3, 5);
+        java.sql.Date sqlDate = sqlDataClass.getSqlDate(); // "2010-03-05"
+
+        /**/
+        //assertTrue("dateTime's value ("+dateTime.dateValue()+
+        //    ") should be after java.sql.date's ("+ date +")", dateTime.dateValue().after(sqlDate));
+
+        //assertTrue("dateTime's value ("+dateTime.dateValue()+
+        //    ") should be after date's ("+ date +")", dateTime.dateValue().after(date.dateValue()));
+        /**/
+    }
+	
 	/**
 	 * Test {@link Money} type.
 	 */
@@ -338,9 +404,19 @@ public abstract class SqlIntegrationTest
 	 */
 	public void testDateTime() {
 		SqlDataClass sqlDataClass = SqlIntegrationTestSingleton.getPerson();
-		assertTrue("DateTime " + dateTime.toString() + " is not equal to "
-				+ sqlDataClass.getDateTime().toString(),
-				dateTime.equals(sqlDataClass.getDateTime()));
+		
+		
+        LOG.log(Level.INFO, "Test: testDateTime()");
+        LOG.log(Level.INFO, "sqlDataClass.getDateTime() as String:"+sqlDataClass.getDateTime());
+        LOG.log(Level.INFO, "dateTime.toString() as String:"+dateTime);
+        
+        LOG.log(Level.INFO, "sqlDataClass.getDateTime().getTime() as Long:"+sqlDataClass.getDateTime().longValue());
+        LOG.log(Level.INFO, "dateTime.getTime() as Long:"+dateTime.longValue());
+		
+        if (!dateTime.equals(sqlDataClass.getDateTime())){
+            fail("DateTime " + dateTime.toString() + " is not equal to "
+                + sqlDataClass.getDateTime().toString());
+        }
 	}
 
 	/**

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/sql/tests-served/pom.xml
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/runtimes/dflt/objectstores/sql/tests-served/pom.xml?rev=1081434&r1=1081433&r2=1081434&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/sql/tests-served/pom.xml (original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/sql/tests-served/pom.xml Mon Mar 14 16:03:22
2011
@@ -72,12 +72,6 @@ Just add your server implementation to o
                 <artifactId>sql-tests-common</artifactId>
 				<version>${project.version}</version>
             </dependency>
-            <dependency>
-                <groupId>${project.groupId}</groupId>
-                <artifactId>sql-tests-common</artifactId>
-                <version>${project.version}</version>
-                <scope>test</scope>
-            </dependency>
 
             <!-- Required to support the XML cross-test -->
 			<!--



Mime
View raw message