incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r1090856 - in /incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql: Defaults.java SqlObjectStore.java VersionMapping.java jdbc/JdbcDateTimeMapper.java jdbc/JdbcResults.java
Date Sun, 10 Apr 2011 17:56:16 GMT
Author: kevin
Date: Sun Apr 10 17:56:15 2011
New Revision: 1090856

URL: http://svn.apache.org/viewvc?rev=1090856&view=rev
Log:
Some tidying up. Also created a ...objectstores.sql.Defaults class to hold object store default
timezone and manage java calendar in sync with this.

Added:
    incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/Defaults.java
  (with props)
Modified:
    incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlObjectStore.java
    incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/VersionMapping.java
    incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateTimeMapper.java
    incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcResults.java

Added: incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/Defaults.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/Defaults.java?rev=1090856&view=auto
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/Defaults.java
(added)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/Defaults.java
Sun Apr 10 17:56:15 2011
@@ -0,0 +1,55 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.runtimes.dflt.objectstores.sql;
+
+import java.util.Calendar;
+
+import org.joda.time.DateTimeZone;
+
+/**
+ * Provides objectstore defaults. Most significantly, maintains the object store default
TimeZone, and maintains
+ * Calendar.
+ * 
+ * 
+ * @version $Rev$ $Date$
+ */
+public class Defaults {
+    public static void initialise() {
+        setTimeZone(DateTimeZone.UTC);
+    }
+
+    private static Calendar calendar;
+
+    public static Calendar getCalendar() {
+        return calendar;
+    }
+
+    private static DateTimeZone dateTimeZone;
+
+    public static DateTimeZone getTimeZone() {
+        return dateTimeZone;
+    }
+
+    public static void setTimeZone(DateTimeZone timezone) {
+        dateTimeZone = timezone;
+        calendar = Calendar.getInstance(timezone.toTimeZone());
+    }
+
+}

Propchange: incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/Defaults.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlObjectStore.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/SqlObjectStore.java?rev=1090856&r1=1090855&r2=1090856&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlObjectStore.java
(original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlObjectStore.java
Sun Apr 10 17:56:15 2011
@@ -19,13 +19,10 @@
 
 package org.apache.isis.runtimes.dflt.objectstores.sql;
 
-import java.util.Calendar;
 import java.util.List;
-import java.util.TimeZone;
 import java.util.Vector;
 
 import org.apache.log4j.Logger;
-import org.joda.time.DateTimeZone;
 
 import org.apache.isis.core.commons.debug.DebugBuilder;
 import org.apache.isis.core.commons.debug.DebugString;
@@ -60,22 +57,6 @@ public final class SqlObjectStore implem
     private ObjectMappingLookup objectMappingLookup;
     private boolean isInitialized;
 
-    private static Calendar calendar;
-    static {
-        TimeZone UTC = TimeZone.getTimeZone("UTC");
-        calendar = Calendar.getInstance(UTC);
-    }
-
-    public static Calendar defaultCalendar() {
-        return calendar;
-    }
-
-    private static DateTimeZone dateTimeZone = DateTimeZone.UTC;
-
-    public static DateTimeZone defaultTimeZone() {
-        return dateTimeZone;
-    }
-
     @Override
     public void abortTransaction() {
     }
@@ -238,6 +219,7 @@ public final class SqlObjectStore implem
         return allInstances(spec);
     }
 
+    // TODO: allInstances of should find all derived types, too.
     private ObjectAdapter[] allInstances(ObjectSpecification spec) {
         DatabaseConnector connector = connectionPool.acquire();
         ObjectMapping mapper = objectMappingLookup.getMapping(spec, connector);
@@ -323,6 +305,9 @@ public final class SqlObjectStore implem
         DatabaseConnector connector = connectionPool.acquire();
         isInitialized = connector.hasTable(Sql.tableIdentifier(TABLE_NAME));
         if (!isInitialized) {
+
+            Defaults.initialise();
+
             StringBuffer sql = new StringBuffer();
             sql.append("create table ");
             sql.append(Sql.tableIdentifier(TABLE_NAME));
@@ -403,8 +388,8 @@ public final class SqlObjectStore implem
     @Override
     public void startTransaction() {
     }
-    
-    public static String getTableName(){
+
+    public static String getTableName() {
         return TABLE_NAME;
     }
 

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/VersionMapping.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/VersionMapping.java?rev=1090856&r1=1090855&r2=1090856&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/VersionMapping.java
(original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/VersionMapping.java
Sun Apr 10 17:56:15 2011
@@ -22,9 +22,9 @@ package org.apache.isis.runtimes.dflt.ob
 import java.sql.Timestamp;
 import java.util.Date;
 
-import org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.JdbcConnector;
 import org.apache.isis.core.metamodel.adapter.version.SerialNumberVersion;
 import org.apache.isis.core.metamodel.adapter.version.Version;
+import org.apache.isis.runtimes.dflt.objectstores.sql.jdbc.JdbcConnector;
 
 public class VersionMapping {
     private String lastActivityDateColumn;
@@ -84,7 +84,7 @@ public class VersionMapping {
 
         sql.append(",");
         sql.append(lastActivityDateColumn);
-        sql.append(" "+JdbcConnector.timeStampType());
+        sql.append(" " + JdbcConnector.timeStampType());
 
         return sql.toString();
     }
@@ -97,7 +97,7 @@ public class VersionMapping {
     public Version getLock(Results rs) {
         long number = rs.getLong(versionColumn);
         String user = rs.getString(lastActivityUserColumn);
-        Date time = rs.getJavaDateTime(lastActivityDateColumn, SqlObjectStore.defaultCalendar());
+        Date time = rs.getJavaDateTime(lastActivityDateColumn, Defaults.getCalendar());
         Version version = new SerialNumberVersion(number, user, time);
         return version;
     }

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateTimeMapper.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/JdbcDateTimeMapper.java?rev=1090856&r1=1090855&r2=1090856&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateTimeMapper.java
(original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateTimeMapper.java
Sun Apr 10 17:56:15 2011
@@ -43,7 +43,7 @@ public class JdbcDateTimeMapper extends 
     @Override
     protected Object preparedStatementObject(ObjectAdapter value) {
         DateTime asDate = (DateTime) value.getObject();
-        java.sql.Timestamp dateTime = new java.sql.Timestamp(asDate.longValue());
+        java.sql.Timestamp dateTime = new java.sql.Timestamp(asDate.millisSinceEpoch());
         return dateTime;
     }
 

Modified: incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcResults.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/JdbcResults.java?rev=1090856&r1=1090855&r2=1090856&view=diff
==============================================================================
--- incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcResults.java
(original)
+++ incubator/isis/trunk/runtimes/dflt/objectstores/sql/impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcResults.java
Sun Apr 10 17:56:15 2011
@@ -17,7 +17,6 @@
  *  under the License.
  */
 
-
 package org.apache.isis.runtimes.dflt.objectstores.sql.jdbc;
 
 import java.sql.CallableStatement;
@@ -32,15 +31,15 @@ import org.joda.time.format.DateTimeForm
 
 import org.apache.isis.applib.value.Date;
 import org.apache.isis.applib.value.Time;
+import org.apache.isis.runtimes.dflt.objectstores.sql.Defaults;
 import org.apache.isis.runtimes.dflt.objectstores.sql.Results;
-import org.apache.isis.runtimes.dflt.objectstores.sql.SqlObjectStore;
 import org.apache.isis.runtimes.dflt.objectstores.sql.SqlObjectStoreException;
 
-
 public class JdbcResults implements Results {
     ResultSet set;
 
-    public JdbcResults(final CallableStatement statement) {}
+    public JdbcResults(final CallableStatement statement) {
+    }
 
     public JdbcResults(final ResultSet set) {
         this.set = set;
@@ -98,8 +97,8 @@ public class JdbcResults implements Resu
             // 2010-04-08 = 1270684800000
             // This is really painful! Java refuses to create java.util.Date in UTC!
             // It creates java.util.Dates in Local time-zone, but assumes the DB date is
UTC.
-            String string = set.getString(columnName); 
-            final DateTime utcDate = new DateTime(string, SqlObjectStore.defaultTimeZone());
+            String string = set.getString(columnName);
+            final DateTime utcDate = new DateTime(string, Defaults.getTimeZone());
             final java.sql.Date date = new java.sql.Date(utcDate.getMillis());
             return date;
         } catch (SQLException e) {
@@ -114,7 +113,7 @@ public class JdbcResults implements Resu
 
             DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm:ss");
 
-            final DateTime utcDate = formatter.withZone(SqlObjectStore.defaultTimeZone()).parseDateTime(string);
+            final DateTime utcDate = formatter.withZone(Defaults.getTimeZone()).parseDateTime(string);
             final java.sql.Time time = new java.sql.Time(utcDate.getMillis());
 
             return time;
@@ -124,7 +123,7 @@ public class JdbcResults implements Resu
     }
 
     @Override
-    public java.util.Date getJavaDateTime(String columnName, Calendar calendar){
+    public java.util.Date getJavaDateTime(String columnName, Calendar calendar) {
         try {
             return set.getDate(columnName, calendar);
         } catch (SQLException e) {
@@ -148,8 +147,8 @@ public class JdbcResults implements Resu
             // 2010-04-08 = 1270684800000
             // This is really painful! Java refuses to create java.util.Date in UTC!
             // It creates java.util.Dates in Local time-zone, but assumes the DB date is
UTC.
-            String string = set.getString(columnName); 
-            final DateTime utcDate = new DateTime(string, SqlObjectStore.defaultTimeZone());
+            String string = set.getString(columnName);
+            final DateTime utcDate = new DateTime(string, Defaults.getTimeZone());
             return new Date(utcDate);
         } catch (SQLException e) {
             throw new SqlObjectStoreException(e);
@@ -161,7 +160,7 @@ public class JdbcResults implements Resu
         try {
             String string = set.getString(columnName);
             DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm:ss");
-            final DateTimeZone defaultTimeZone = SqlObjectStore.defaultTimeZone();
+            final DateTimeZone defaultTimeZone = Defaults.getTimeZone();
             final DateTime utcDate = formatter.withZone(defaultTimeZone).parseDateTime(string);
             return new Time(utcDate);
         } catch (SQLException e) {
@@ -169,6 +168,7 @@ public class JdbcResults implements Resu
         }
     }
 
+    @Override
     public double getDouble(String columnName) {
         try {
             return set.getDouble(columnName);



Mime
View raw message