You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2012/07/17 11:13:08 UTC

svn commit: r1362421 - in /incubator/isis/trunk/framework: runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/ runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/reso...

Author: danhaywood
Date: Tue Jul 17 09:13:07 2012
New Revision: 1362421

URL: http://svn.apache.org/viewvc?rev=1362421&view=rev
Log:
ISIS-14: adding support for persisting applib.Date class

Added:
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateConverter.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateMapping.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/resources/META-INF/
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/resources/META-INF/MANIFEST.MF
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/resources/plugin.xml
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateConverterTest.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateMappingTest.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/scalar/Persistence_persist_applibValuedEntity.java
Modified:
    incubator/isis/trunk/framework/tck/tck-dom/src/main/java/org/apache/isis/tck/dom/scalars/ApplibValuedEntity.java
    incubator/isis/trunk/framework/tck/tck-dom/src/main/java/org/apache/isis/tck/dom/scalars/AutoAssignedEntity.java

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateConverter.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateConverter.java?rev=1362421&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateConverter.java (added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateConverter.java Tue Jul 17 09:13:07 2012
@@ -0,0 +1,33 @@
+package org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.applibtypes;
+
+import org.datanucleus.store.types.ObjectLongConverter;
+
+import org.apache.isis.applib.value.Date;
+
+public class IsisDateConverter implements ObjectLongConverter<Date>{
+
+    private static final long serialVersionUID = 1L;
+
+    public IsisDateConverter() {
+        
+    }
+    
+    @Override
+    public Long toLong(Date object) {
+        if(object == null) {
+            return null;
+        }
+
+        Date d = (Date)object;
+        return d.getMillisSinceEpoch();
+    }
+
+    @Override
+    public Date toObject(Long value) {
+        if(value == null) {
+            return null;
+        }
+        return new Date(value);
+    }
+
+}

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateMapping.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateMapping.java?rev=1362421&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateMapping.java (added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateMapping.java Tue Jul 17 09:13:07 2012
@@ -0,0 +1,30 @@
+package org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.applibtypes;
+
+import org.datanucleus.store.mapped.mapping.ObjectAsLongMapping;
+
+import org.apache.isis.applib.value.Date;
+
+public class IsisDateMapping extends ObjectAsLongMapping {
+
+    private final IsisDateConverter dateConverter = new IsisDateConverter();
+    
+    public IsisDateMapping() {
+        
+    }
+    
+    @Override
+    public Class<?> getJavaType() {
+        return org.apache.isis.applib.value.Date.class;
+    }
+
+    @Override
+    protected Long objectToLong(Object object) {
+        return dateConverter.toLong((Date) object);
+    }
+
+    @Override
+    protected Object longToObject(Long datastoreValue) {
+        return dateConverter.toObject(datastoreValue);
+    }
+
+}

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/resources/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/resources/META-INF/MANIFEST.MF?rev=1362421&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/resources/META-INF/MANIFEST.MF (added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/resources/META-INF/MANIFEST.MF Tue Jul 17 09:13:07 2012
@@ -0,0 +1,6 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: objectstores-jdo-datanucleus
+Bundle-SymbolicName: org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus
+Bundle-Version: 1.0.0
+Bundle-Vendor: Apache Software Foundation
\ No newline at end of file

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/resources/plugin.xml
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/resources/plugin.xml?rev=1362421&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/resources/plugin.xml (added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/main/resources/plugin.xml Tue Jul 17 09:13:07 2012
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<plugin>
+
+    <extension point="org.datanucleus.java_type">
+        <java-type 
+        	name="org.apache.isis.applib.value.Date" 
+        	persistent="true" 
+        	dfg="true" 
+        	embedded="true"
+            long-converter="org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.applibtypes.IsisDateConverter"/>
+    </extension>
+
+    <extension point="org.datanucleus.store_mapping">
+        <mapping 
+        	java-type="org.apache.isis.applib.value.Date" 
+        	mapping-class="org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.applibtypes.IsisDateMapping"/>
+    </extension>
+</plugin>
\ No newline at end of file

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateConverterTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateConverterTest.java?rev=1362421&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateConverterTest.java (added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateConverterTest.java Tue Jul 17 09:13:07 2012
@@ -0,0 +1,41 @@
+package org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.applibtypes;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.applib.value.Date;
+
+public class IsisDateConverterTest {
+
+    private IsisDateConverter converter;
+
+    @Before
+    public void setUp() throws Exception {
+        converter = new IsisDateConverter();
+    }
+    
+    @Test
+    public void roundTrip() {
+        Date date = new Date();
+        final Long value = converter.toLong(date);
+        Date date2 = (Date) converter.toObject(value);
+        
+        // necessary to use dateValue() because the Isis date (rather poorly) does not
+        // override equals() / hashCode()
+        assertThat(date.dateValue(), is(equalTo(date2.dateValue())));
+    }
+
+    @Test
+    public void toLong_whenNull() {
+        assertNull(converter.toLong(null));
+    }
+
+    @Test
+    public void toObject_whenNull() {
+        assertNull(converter.toObject(null));
+    }
+
+}

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateMappingTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateMappingTest.java?rev=1362421&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateMappingTest.java (added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/applibtypes/IsisDateMappingTest.java Tue Jul 17 09:13:07 2012
@@ -0,0 +1,31 @@
+package org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.applibtypes;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.applib.value.Date;
+
+public class IsisDateMappingTest {
+
+    private IsisDateMapping dateMapping;
+
+    @Before
+    public void setUp() throws Exception {
+        dateMapping = new IsisDateMapping();
+    }
+    
+    @Test
+    public void roundTrip() {
+        Date date = new Date();
+        final Long datastoreValue = dateMapping.objectToLong(date);
+        Date date2 = (Date) dateMapping.longToObject(datastoreValue);
+        
+        // necessary to use dateValue() because the Isis date (rather poorly) does not
+        // override equals() / hashCode()
+        assertThat(date.dateValue(), is(equalTo(date2.dateValue())));
+    }
+
+}

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/scalar/Persistence_persist_applibValuedEntity.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/scalar/Persistence_persist_applibValuedEntity.java?rev=1362421&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/scalar/Persistence_persist_applibValuedEntity.java (added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/jdo/jdo-datanucleus/src/test/java/org/apache/isis/runtimes/dflt/objectstores/jdo/datanucleus/scalar/Persistence_persist_applibValuedEntity.java Tue Jul 17 09:13:07 2012
@@ -0,0 +1,90 @@
+/*
+ *  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.jdo.datanucleus.scalar;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import java.awt.Image;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Timestamp;
+import java.util.List;
+
+import org.joda.time.LocalDate;
+import org.joda.time.LocalDateTime;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.applib.value.Date;
+import org.apache.isis.runtimes.dflt.objectstores.jdo.datanucleus.Utils;
+import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
+import org.apache.isis.tck.dom.scalars.ApplibValuedEntity;
+import org.apache.isis.tck.dom.scalars.ApplibValuedEntityRepository;
+import org.apache.isis.tck.dom.scalars.JdkValuedEntity;
+import org.apache.isis.tck.dom.scalars.JdkValuedEntityRepository;
+import org.apache.isis.tck.dom.scalars.MyEnum;
+
+public class Persistence_persist_applibValuedEntity {
+
+    private ApplibValuedEntityRepository repo = new ApplibValuedEntityRepository();
+    
+    @Rule
+    public IsisSystemWithFixtures iswf = Utils.systemBuilder()
+        .with(Utils.listenerToDeleteFrom("APPLIBVALUEDENTITY"))
+        .withServices(repo)
+        .build();
+
+    @Test
+    public void persistTwo() throws Exception {
+        iswf.beginTran();
+        repo.newEntity().setStringProperty("1");
+        repo.newEntity().setStringProperty("2");
+        iswf.commitTran();
+
+        iswf.bounceSystem();
+        
+        iswf.beginTran();
+        List<ApplibValuedEntity> list = repo.list();
+        assertThat(list.size(), is(2));
+        iswf.commitTran();
+    }
+
+    @Test
+    public void persistAllValues() throws Exception {
+        iswf.beginTran();
+        
+        ApplibValuedEntity entity = repo.newEntity();
+        entity.setStringProperty("1");
+
+        Date date = new Date();
+        entity.setDateProperty(date);
+        
+        iswf.commitTran();
+
+        iswf.bounceSystem();
+        
+        iswf.beginTran();
+        ApplibValuedEntity entityRetrieved = repo.list().get(0);
+        assertThat(entityRetrieved.getDateProperty().dateValue(), is(date.dateValue()));
+        
+        iswf.commitTran();
+    }
+}

Modified: incubator/isis/trunk/framework/tck/tck-dom/src/main/java/org/apache/isis/tck/dom/scalars/ApplibValuedEntity.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/tck/tck-dom/src/main/java/org/apache/isis/tck/dom/scalars/ApplibValuedEntity.java?rev=1362421&r1=1362420&r2=1362421&view=diff
==============================================================================
--- incubator/isis/trunk/framework/tck/tck-dom/src/main/java/org/apache/isis/tck/dom/scalars/ApplibValuedEntity.java (original)
+++ incubator/isis/trunk/framework/tck/tck-dom/src/main/java/org/apache/isis/tck/dom/scalars/ApplibValuedEntity.java Tue Jul 17 09:13:07 2012
@@ -23,6 +23,7 @@ import org.apache.isis.applib.AbstractDo
 import org.apache.isis.applib.annotation.MemberOrder;
 import org.apache.isis.applib.annotation.ObjectType;
 import org.apache.isis.applib.annotation.Optional;
+import org.apache.isis.applib.annotation.Title;
 import org.apache.isis.applib.value.Color;
 import org.apache.isis.applib.value.Date;
 import org.apache.isis.applib.value.DateTime;
@@ -33,25 +34,38 @@ import org.apache.isis.applib.value.Perc
 import org.apache.isis.applib.value.Time;
 import org.apache.isis.applib.value.TimeStamp;
 
+@javax.jdo.annotations.PersistenceCapable
+@javax.jdo.annotations.Discriminator("APLV")
+@javax.jdo.annotations.Query(
+        name="jdkv_findByStringProperty", language="JDOQL",  
+        value="SELECT FROM org.apache.isis.tck.dom.scalars.ApplibValuedEntity WHERE stringProperty == :i")
+@javax.persistence.Entity                    
+@javax.persistence.DiscriminatorValue("APLV")
 @ObjectType("APLV")
 public class ApplibValuedEntity extends AbstractDomainObject {
 
-    // {{ ColorProperty
-    private Color colorProperty;
+    
+    // {{ StringProperty (also title, pk)
+    @javax.jdo.annotations.PrimaryKey
+    private String stringProperty;
 
+    @Title
     @Optional
     @MemberOrder(sequence = "1")
-    public Color getColorProperty() {
-        return colorProperty;
+    public String getStringProperty() {
+        return stringProperty;
     }
 
-    public void setColorProperty(final Color colorProperty) {
-        this.colorProperty = colorProperty;
+    public void setStringProperty(final String description) {
+        this.stringProperty = description;
     }
 
     // }}
 
+    
+    
     // {{ DateProperty
+    @javax.jdo.annotations.Persistent
     private Date dateProperty;
 
     @Optional
@@ -66,7 +80,24 @@ public class ApplibValuedEntity extends 
 
     // }}
 
+    // {{ ColorProperty
+    @javax.jdo.annotations.NotPersistent
+    private Color colorProperty;
+
+    @Optional
+    @MemberOrder(sequence = "1")
+    public Color getColorProperty() {
+        return colorProperty;
+    }
+
+    public void setColorProperty(final Color colorProperty) {
+        this.colorProperty = colorProperty;
+    }
+
+    // }}
+
     // {{ DateTimeProperty
+    @javax.jdo.annotations.NotPersistent
     private DateTime dateTimeProperty;
 
     @Optional
@@ -82,6 +113,7 @@ public class ApplibValuedEntity extends 
     // }}
 
     // {{ ImageProperty
+    @javax.jdo.annotations.NotPersistent
     private Image imageProperty;
 
     @Optional
@@ -97,6 +129,7 @@ public class ApplibValuedEntity extends 
     // }}
 
     // {{ MoneyProperty
+    @javax.jdo.annotations.NotPersistent
     private Money moneyProperty;
 
     @Optional
@@ -112,6 +145,7 @@ public class ApplibValuedEntity extends 
     // }}
 
     // {{ PasswordProperty
+    @javax.jdo.annotations.NotPersistent
     private Password passwordProperty;
 
     @Optional
@@ -127,6 +161,7 @@ public class ApplibValuedEntity extends 
     // }}
 
     // {{ PercentageProperty
+    @javax.jdo.annotations.NotPersistent
     private Percentage percentageProperty;
 
     @Optional
@@ -142,6 +177,7 @@ public class ApplibValuedEntity extends 
     // }}
 
     // {{ TimeProperty
+    @javax.jdo.annotations.NotPersistent
     private Time timeProperty;
 
     @Optional
@@ -157,6 +193,7 @@ public class ApplibValuedEntity extends 
     // }}
 
     // {{ TimeStampProperty
+    @javax.jdo.annotations.NotPersistent
     private TimeStamp timeStampProperty;
 
     @Optional

Modified: incubator/isis/trunk/framework/tck/tck-dom/src/main/java/org/apache/isis/tck/dom/scalars/AutoAssignedEntity.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/tck/tck-dom/src/main/java/org/apache/isis/tck/dom/scalars/AutoAssignedEntity.java?rev=1362421&r1=1362420&r2=1362421&view=diff
==============================================================================
--- incubator/isis/trunk/framework/tck/tck-dom/src/main/java/org/apache/isis/tck/dom/scalars/AutoAssignedEntity.java (original)
+++ incubator/isis/trunk/framework/tck/tck-dom/src/main/java/org/apache/isis/tck/dom/scalars/AutoAssignedEntity.java Tue Jul 17 09:13:07 2012
@@ -35,23 +35,8 @@ import org.apache.isis.applib.annotation
 @ObjectType("AUAS")
 public class AutoAssignedEntity extends AbstractDomainObject {
 
-//    // {{ Id (Integer, also used in title)
-//    @javax.jdo.annotations.PrimaryKey
-//    private Integer id;
-//
-//    @Title(sequence="1", append=": ")
-//    @javax.persistence.Id
-//    public Integer getId() {
-//        return id;
-//    }
-//
-//    public void setId(final Integer id) {
-//        this.id = id;
-//    }
-//    // }}
-
     
-    // {{ StringProperty (also used in title)
+    // {{ StringProperty (used in title)
     private String stringProperty;
 
     @Title(sequence="2")