incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r1383909 - in /incubator/isis/trunk/framework: core/testsupport/src/main/java/org/apache/isis/core/testsupport/files/ runtimes/dflt/objectstores/sql/sql-impl/ runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/df...
Date Wed, 12 Sep 2012 12:25:32 GMT
Author: kevin
Date: Wed Sep 12 12:25:31 2012
New Revision: 1383909

URL: http://svn.apache.org/viewvc?rev=1383909&view=rev
Log:
ISIS-268: DateTime and TimeStamp tests now pass. resetPersistenceStoreDirectlyIfRequired correctly
deletes files for HSQL and Polymorphism tests.

Modified:
    incubator/isis/trunk/framework/core/testsupport/src/main/java/org/apache/isis/core/testsupport/files/Files.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/sqlos-testing.properties
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateTimeMapper.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcTimestampMapper.java

Modified: incubator/isis/trunk/framework/core/testsupport/src/main/java/org/apache/isis/core/testsupport/files/Files.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/core/testsupport/src/main/java/org/apache/isis/core/testsupport/files/Files.java?rev=1383909&r1=1383908&r2=1383909&view=diff
==============================================================================
--- incubator/isis/trunk/framework/core/testsupport/src/main/java/org/apache/isis/core/testsupport/files/Files.java
(original)
+++ incubator/isis/trunk/framework/core/testsupport/src/main/java/org/apache/isis/core/testsupport/files/Files.java
Wed Sep 12 12:25:31 2012
@@ -23,20 +23,30 @@ import java.io.FileFilter;
 import java.io.FilenameFilter;
 
 public final class Files {
-    
-    Files(){}
 
-    
-    ///////////////////////////////////////////////////////
+    Files() {
+    }
+
+    // /////////////////////////////////////////////////////
     // delete files
-    ///////////////////////////////////////////////////////
-    
-    
+    // /////////////////////////////////////////////////////
+
     public enum Recursion {
-        DO_RECURSE,
-        DONT_RECURSE
+        DO_RECURSE, DONT_RECURSE
+    }
+
+    /**
+     * 
+     * @param directoryName
+     *            directory to start deleting from
+     * @param filePrefix
+     *            file name prefix (no wild cards)
+     * @param recursion
+     */
+    public static void deleteFilesWithPrefix(final String directoryName, final String filePrefix,
Recursion recursion) {
+        deleteFiles(directoryName, filterFileNamePrefix(filePrefix), recursion);
     }
-    
+
     public static void deleteFiles(final String directoryName, final String fileExtension,
Recursion recursion) {
         deleteFiles(directoryName, filterFileNameExtension(fileExtension), recursion);
     }
@@ -63,36 +73,36 @@ public final class Files {
     interface Deleter {
         void deleteFile(File f);
     }
-    
+
     static void deleteFiles(final File directory, final FilenameFilter filter, Recursion
recursion, Deleter deleter) {
         for (final File file : directory.listFiles(filter)) {
             deleter.deleteFile(file);
         }
-        
-        if(recursion == Recursion.DO_RECURSE) {
-            for (final File subdir: directory.listFiles(filterDirectory())) {
+
+        if (recursion == Recursion.DO_RECURSE) {
+            for (final File subdir : directory.listFiles(filterDirectory())) {
                 deleteFiles(subdir, filter, recursion, deleter);
             }
         }
     }
 
-    
-    ///////////////////////////////////////////////////////
+    // /////////////////////////////////////////////////////
     // filters
-    ///////////////////////////////////////////////////////
+    // /////////////////////////////////////////////////////
 
     public static FilenameFilter and(final FilenameFilter... filters) {
-        return new FilenameFilter(){
+        return new FilenameFilter() {
 
             @Override
             public boolean accept(File dir, String name) {
-                for(FilenameFilter filter: filters) {
-                    if(!filter.accept(dir, name)) {
+                for (FilenameFilter filter : filters) {
+                    if (!filter.accept(dir, name)) {
                         return false;
                     }
                 }
                 return true;
-            }};
+            }
+        };
     }
 
     public static FilenameFilter filterFileNameExtension(final String fileExtension) {
@@ -105,6 +115,16 @@ public final class Files {
         };
     }
 
+    public static FilenameFilter filterFileNamePrefix(final String filePrefix) {
+        return new FilenameFilter() {
+
+            @Override
+            public boolean accept(final File arg0, final String arg1) {
+                return arg1.startsWith(filePrefix);
+            }
+        };
+    }
+
     public static FileFilter filterDirectory() {
         return new FileFilter() {
             @Override

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/sqlos-testing.properties
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/sqlos-testing.properties?rev=1383909&r1=1383908&r2=1383909&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/sqlos-testing.properties
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/sqlos-testing.properties
Wed Sep 12 12:25:31 2012
@@ -36,8 +36,6 @@ isis.persistor.sql.jdbc.user=sa
 isis.persistor.sql.jdbc.password=
 
 
-
-
 ## log4j
 # apache's log4j is used to provide system logging.
 ##
@@ -48,3 +46,14 @@ log4j.appender.Console=org.apache.log4j.
 log4j.appender.Console.target=System.out
 log4j.appender.Console.layout=org.apache.log4j.PatternLayout
 log4j.appender.Console.layout.ConversionPattern=%-5r [%-20c{1}] %-5p  %m  -- %l%n
+
+
+log4j.rootCategory=DEBUG, File
+# The file appender
+log4j.appender.File=org.apache.log4j.RollingFileAppender
+log4j.appender.File.file=isis.log
+log4j.appender.File.append=false
+#log4j.appender.File.maxFileSize=500KB
+#log4j.appender.File.maxBackupIndex=1
+log4j.appender.File.layout=org.apache.log4j.PatternLayout
+log4j.appender.File.layout.ConversionPattern=%d [%-20c{1} %-10t %-5p]  %m%n

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateTimeMapper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateTimeMapper.java?rev=1383909&r1=1383908&r2=1383909&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateTimeMapper.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcDateTimeMapper.java
Wed Sep 12 12:25:31 2012
@@ -19,15 +19,16 @@
 
 package org.apache.isis.runtimes.dflt.objectstores.sql.jdbc;
 
+import org.apache.isis.applib.PersistFailedException;
 import org.apache.isis.applib.value.DateTime;
 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.ObjectSpecification;
 import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
 import org.apache.isis.runtimes.dflt.objectstores.sql.AbstractFieldMappingFactory;
 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.mapping.FieldMapping;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
 
 public class JdbcDateTimeMapper extends AbstractJdbcFieldMapping {
 
@@ -55,18 +56,17 @@ public class JdbcDateTimeMapper extends 
 
     @Override
     public ObjectAdapter setFromDBColumn(final Results results, final String columnName,
final ObjectAssociation field) {
-        final String encodedValue = results.getString(columnName);
-        if (encodedValue == null) {
-            return null;
+
+        ObjectAdapter restoredValue;
+        final Class<?> correspondingClass = field.getSpecification().getCorrespondingClass();
+        if (correspondingClass == DateTime.class) {
+            final java.sql.Timestamp o = (java.sql.Timestamp) results.getObject(columnName);
+            final DateTime timeValue = new DateTime(o.getTime());
+            restoredValue = IsisContext.getPersistenceSession().getAdapterManager().adapterFor(timeValue);
+        } else {
+            throw new PersistFailedException("Unhandled time type: " + correspondingClass.getCanonicalName());
         }
-        // convert date to yyyymmddhhmm
-        final String year = encodedValue.substring(0, 4);
-        final String month = encodedValue.substring(5, 7);
-        final String day = encodedValue.substring(8, 10);
-        final String hour = encodedValue.substring(11, 13);
-        final String minute = encodedValue.substring(14, 16);
-        final String valueString = year + month + day + "T" + hour + minute + "00000";
-        return field.getSpecification().getFacet(EncodableFacet.class).fromEncodedString(valueString);
+        return restoredValue;
     }
 
     @Override

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcTimestampMapper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcTimestampMapper.java?rev=1383909&r1=1383908&r2=1383909&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcTimestampMapper.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcTimestampMapper.java
Wed Sep 12 12:25:31 2012
@@ -19,15 +19,16 @@
 
 package org.apache.isis.runtimes.dflt.objectstores.sql.jdbc;
 
+import org.apache.isis.applib.PersistFailedException;
 import org.apache.isis.applib.value.TimeStamp;
 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.ObjectSpecification;
 import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
 import org.apache.isis.runtimes.dflt.objectstores.sql.AbstractFieldMappingFactory;
 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.mapping.FieldMapping;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
 
 public class JdbcTimestampMapper extends AbstractJdbcFieldMapping {
 
@@ -56,33 +57,17 @@ public class JdbcTimestampMapper extends
 
     @Override
     public ObjectAdapter setFromDBColumn(final Results results, final String columnName,
final ObjectAssociation field) {
-        final String encodedValue = results.getString(columnName);
-        if (encodedValue == null) {
-            return null;
-        }
-        // convert date to yyyymmddhhmm
-        final String year = encodedValue.substring(0, 4);
-        final String month = encodedValue.substring(5, 7);
-        final String day = encodedValue.substring(8, 10);
-        final String hour = encodedValue.substring(11, 13);
-        final String minute = encodedValue.substring(14, 16);
-        final String second = encodedValue.substring(17, 19);
-        final int length = encodedValue.length();
-        String millisecond;
-        if (length > 20) {
-            millisecond = encodedValue.substring(20, length);
+
+        ObjectAdapter restoredValue;
+        final Class<?> correspondingClass = field.getSpecification().getCorrespondingClass();
+        if (correspondingClass == TimeStamp.class) {
+            final java.sql.Timestamp o = (java.sql.Timestamp) results.getObject(columnName);
+            final TimeStamp timeValue = new TimeStamp(o.getTime());
+            restoredValue = IsisContext.getPersistenceSession().getAdapterManager().adapterFor(timeValue);
         } else {
-            millisecond = "";
-        }
-        if (length < 21) {
-            millisecond = millisecond + "000";
-        } else if (length < 22) {
-            millisecond = millisecond + "00";
-        } else if (length < 23) {
-            millisecond = millisecond + "0";
+            throw new PersistFailedException("Unhandled time type: " + correspondingClass.getCanonicalName());
         }
-        final String valueString = year + month + day + "T" + hour + minute + second + millisecond;
-        return field.getSpecification().getFacet(EncodableFacet.class).fromEncodedString(valueString);
+        return restoredValue;
     }
 
     @Override



Mime
View raw message