cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r442017 - in /incubator/cayenne/main/trunk/core/cayenne-jpa/src: main/java/org/apache/cayenne/jpa/bridge/ main/java/org/apache/cayenne/jpa/conf/ test/java/org/apache/cayenne/jpa/bridge/ test/java/org/apache/cayenne/jpa/entity/
Date Sun, 10 Sep 2006 22:32:14 GMT
Author: aadamchik
Date: Sun Sep 10 15:32:14 2006
New Revision: 442017

URL: http://svn.apache.org/viewvc?view=rev&rev=442017
Log:
fixing id column mapping
fixing Basic optional flag processing

Added:
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/MockBasicEntity.java
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/MockIdColumnEntity.java
Modified:
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapConverterTest.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java?view=diff&rev=442017&r1=442016&r2=442017
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
Sun Sep 10 15:32:14 2006
@@ -263,7 +263,8 @@
 
             if (jpaColumn.getTable() == null) {
                 recordConflict(path, "No table defined for JpaColumn '"
-                        + jpaColumn.getName());
+                        + jpaColumn.getName()
+                        + "'");
                 return false;
             }
 
@@ -272,7 +273,8 @@
 
             if (entity == null) {
                 recordConflict(path, "Invalid table definition for JpaColumn: "
-                        + jpaColumn.getTable());
+                        + jpaColumn.getTable()
+                        + "'");
                 return false;
             }
 

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java?view=diff&rev=442017&r1=442016&r2=442017
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java
Sun Sep 10 15:32:14 2006
@@ -196,6 +196,7 @@
             if (jpaBasic.getColumn() == null) {
                 JpaColumn column = new JpaColumn(AnnotationPrototypes.getColumn());
                 column.setName(jpaBasic.getName());
+                column.setNullable(jpaBasic.isOptional());
                 jpaBasic.setColumn(column);
             }
 
@@ -325,6 +326,10 @@
     }
 
     final class IdVisitor extends BaseTreeVisitor {
+
+        IdVisitor() {
+            addChildVisitor(JpaColumn.class, new ColumnVisitor());
+        }
 
         @Override
         public boolean onStartNode(ProjectPath path) {

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapConverterTest.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapConverterTest.java?view=diff&rev=442017&r1=442016&r2=442017
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapConverterTest.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/bridge/DataMapConverterTest.java
Sun Sep 10 15:32:14 2006
@@ -27,6 +27,8 @@
 import org.apache.cayenne.jpa.conf.EntityMapAnnotationLoader;
 import org.apache.cayenne.jpa.conf.EntityMapDefaultsProcessor;
 import org.apache.cayenne.jpa.conf.EntityMapLoaderContext;
+import org.apache.cayenne.jpa.entity.MockBasicEntity;
+import org.apache.cayenne.jpa.entity.MockIdColumnEntity;
 import org.apache.cayenne.jpa.entity.MockTypesEntity;
 import org.apache.cayenne.jpa.entity.cayenne.MockCayenneEntity1;
 import org.apache.cayenne.jpa.entity.cayenne.MockCayenneEntity2;
@@ -146,5 +148,63 @@
         DbAttribute byteArrayColumn = (DbAttribute) typesTable.getAttribute("byteArray");
         assertNotNull(byteArrayColumn);
         assertEquals(Types.BINARY, byteArrayColumn.getType());
+    }
+
+    public void testColumnOverrides() {
+        EntityMapLoaderContext context = new EntityMapLoaderContext(
+                new MockPersistenceUnitInfo());
+        EntityMapAnnotationLoader loader = new EntityMapAnnotationLoader(context);
+
+        loader.loadClassMapping(MockIdColumnEntity.class);
+
+        // apply defaults before conversion
+        new EntityMapDefaultsProcessor().applyDefaults(context);
+
+        assertFalse("Found conflicts: " + context.getConflicts(), context
+                .getConflicts()
+                .hasFailures());
+
+        DataMap dataMap = new DataMapConverter().toDataMap("n1", context);
+        assertFalse("Found DataMap conflicts: " + context.getConflicts(), context
+                .getConflicts()
+                .hasFailures());
+
+        DbEntity table = dataMap.getDbEntity("MockIdColumnEntity");
+        assertNotNull(table);
+
+        DbAttribute pk = (DbAttribute) table.getAttribute("pk_column");
+        assertNotNull(pk);
+        assertTrue(pk.isPrimaryKey());
+    }
+
+    public void testBasicOptionality() {
+        EntityMapLoaderContext context = new EntityMapLoaderContext(
+                new MockPersistenceUnitInfo());
+        EntityMapAnnotationLoader loader = new EntityMapAnnotationLoader(context);
+
+        loader.loadClassMapping(MockBasicEntity.class);
+
+        // apply defaults before conversion
+        new EntityMapDefaultsProcessor().applyDefaults(context);
+
+        assertFalse("Found conflicts: " + context.getConflicts(), context
+                .getConflicts()
+                .hasFailures());
+
+        DataMap dataMap = new DataMapConverter().toDataMap("n1", context);
+        assertFalse("Found DataMap conflicts: " + context.getConflicts(), context
+                .getConflicts()
+                .hasFailures());
+
+        DbEntity table = dataMap.getDbEntity("MockBasicEntity");
+        assertNotNull(table);
+
+        DbAttribute optional = (DbAttribute) table.getAttribute("optionalBasic");
+        assertNotNull(optional);
+        assertFalse(optional.isMandatory());
+        
+        DbAttribute required = (DbAttribute) table.getAttribute("requiredBasic");
+        assertNotNull(required);
+        assertTrue(required.isMandatory());
     }
 }

Added: incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/MockBasicEntity.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/MockBasicEntity.java?view=auto&rev=442017
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/MockBasicEntity.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/MockBasicEntity.java
Sun Sep 10 15:32:14 2006
@@ -0,0 +1,36 @@
+/*****************************************************************
+ *   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.cayenne.jpa.entity;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+@Entity
+public class MockBasicEntity {
+
+    @Id
+    protected int id;
+
+    @Basic(optional = false)
+    protected String requiredBasic;
+
+    @Basic(optional = true)
+    protected String optionalBasic;
+}

Added: incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/MockIdColumnEntity.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/MockIdColumnEntity.java?view=auto&rev=442017
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/MockIdColumnEntity.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/entity/MockIdColumnEntity.java
Sun Sep 10 15:32:14 2006
@@ -0,0 +1,31 @@
+/*****************************************************************
+ *   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.cayenne.jpa.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+@Entity
+public class MockIdColumnEntity {
+
+    @Id
+    @Column(name = "pk_column")
+    protected int id;
+}



Mime
View raw message