You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2006/08/06 20:17:08 UTC
svn commit: r429167 - in /incubator/cayenne/main/trunk/core/cayenne-jpa: ./
src/main/java/org/apache/cayenne/jpa/bridge/
src/main/java/org/apache/cayenne/jpa/conf/
src/test/java/org/apache/cayenne/jpa/bridge/
src/test/java/org/apache/cayenne/jpa/conf/
Author: aadamchik
Date: Sun Aug 6 11:17:07 2006
New Revision: 429167
URL: http://svn.apache.org/viewvc?rev=429167&view=rev
Log:
all JPA tests pass
Added:
incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor1Test.java
incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/MockAnnotatedBeanVersion.java
Modified:
incubator/cayenne/main/trunk/core/cayenne-jpa/pom.xml
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/main/java/org/apache/cayenne/jpa/conf/MemberAnnotationProcessorFactory.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/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/pom.xml?rev=429167&r1=429166&r2=429167&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/pom.xml (original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/pom.xml Sun Aug 6 11:17:07 2006
@@ -73,20 +73,6 @@
</configuration>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <excludes>
- <exclude>**/EntityMapAnnotationLoaderTest.java</exclude>
- <exclude>**/EntityMapDefaultsProcessorTest.java</exclude>
- <exclude>**/EntityMapXMLLoaderTest.java</exclude>
- <exclude>**/DataMapConverterTest.java</exclude>
- <exclude>**/Test*.java</exclude>
- </excludes>
- </configuration>
- </plugin>
-
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
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?rev=429167&r1=429166&r2=429167&view=diff
==============================================================================
--- 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 Aug 6 11:17:07 2006
@@ -22,11 +22,11 @@
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
-import javax.persistence.TemporalType;
-
import org.apache.cayenne.jpa.JpaProviderException;
import org.apache.cayenne.jpa.conf.EntityMapLoaderContext;
import org.apache.cayenne.jpa.map.AccessType;
+import org.apache.cayenne.jpa.map.JpaAttribute;
+import org.apache.cayenne.jpa.map.JpaAttributes;
import org.apache.cayenne.jpa.map.JpaBasic;
import org.apache.cayenne.jpa.map.JpaColumn;
import org.apache.cayenne.jpa.map.JpaEntity;
@@ -41,6 +41,7 @@
import org.apache.cayenne.jpa.map.JpaQueryHint;
import org.apache.cayenne.jpa.map.JpaRelationship;
import org.apache.cayenne.jpa.map.JpaTable;
+import org.apache.cayenne.jpa.map.JpaVersion;
import org.apache.cayenne.map.DataMap;
import org.apache.cayenne.map.DbAttribute;
import org.apache.cayenne.map.DbEntity;
@@ -168,18 +169,44 @@
}
}
+ class JpaVersionVisitor extends JpaBasicVisitor {
+
+ @Override
+ Object createObject(ProjectPath path) {
+
+ JpaVersion version = (JpaVersion) path.getObject();
+
+ ObjEntity parentCayenneEntity = (ObjEntity) targetPath.getObject();
+
+ ObjAttribute cayenneAttribute = new ObjAttribute(version.getName());
+ cayenneAttribute.setType(getAttributeType(path, version.getName()).getName());
+ cayenneAttribute.setDbAttributeName(version.getColumn().getName());
+
+ parentCayenneEntity.addAttribute(cayenneAttribute);
+ return cayenneAttribute;
+ }
+ }
+
class JpaColumnVisitor extends BaseTreeVisitor {
@Override
public boolean onStartNode(ProjectPath path) {
JpaColumn jpaColumn = (JpaColumn) path.getObject();
- JpaBasic jpaBasic = (JpaBasic) path.getObjectParent();
+ JpaAttribute attribute = (JpaAttribute) path.getObjectParent();
DbAttribute dbAttribute = new DbAttribute(jpaColumn.getName());
- TemporalType ttype = jpaBasic.getTemporal();
+ if (attribute instanceof JpaBasic) {
+ JpaBasic basic = (JpaBasic) attribute;
+ dbAttribute.setType(attribute.getPropertyDescriptor().getJdbcType(
+ basic.getTemporal()));
+ }
+ else if (attribute instanceof JpaVersion) {
+ JpaVersion version = (JpaVersion) attribute;
+ dbAttribute.setType(attribute.getPropertyDescriptor().getJdbcType(
+ version.getTemporal()));
+ }
- dbAttribute.setType(jpaBasic.getPropertyDescriptor().getJdbcType(ttype));
dbAttribute.setMandatory(!jpaColumn.isNullable());
dbAttribute.setMaxLength(jpaColumn.getLength());
@@ -317,13 +344,15 @@
JpaManyToMany.class,
new JpaRelationshipVisitor());
attributeVisitor.addChildVisitor(JpaBasic.class, new JpaBasicVisitor());
-
- // addChildVisitor(JpaAttribute.class, attributeVisitor);
+ attributeVisitor.addChildVisitor(JpaVersion.class, new JpaVersionVisitor());
BaseTreeVisitor idVisitor = new BaseTreeVisitor();
idVisitor.addChildVisitor(JpaColumn.class, new JpaIdColumnVisitor());
- addChildVisitor(JpaId.class, idVisitor);
+ attributeVisitor.addChildVisitor(JpaId.class, idVisitor);
+
+ // TODO: andrus 8/6/2006 - handle Embedded, EmbeddedId, AttributeOverride
+ addChildVisitor(JpaAttributes.class, attributeVisitor);
addChildVisitor(JpaTable.class, new JpaTableVisitor());
addChildVisitor(JpaNamedQuery.class, new JpaNamedQueryVisitor());
}
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?rev=429167&r1=429166&r2=429167&view=diff
==============================================================================
--- 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 Aug 6 11:17:07 2006
@@ -43,6 +43,7 @@
import org.apache.cayenne.jpa.map.JpaPropertyDescriptor;
import org.apache.cayenne.jpa.map.JpaRelationship;
import org.apache.cayenne.jpa.map.JpaTable;
+import org.apache.cayenne.jpa.map.JpaVersion;
import org.apache.cayenne.project.ProjectPath;
import org.apache.cayenne.util.BaseTreeVisitor;
import org.apache.cayenne.util.HierarchicalTreeVisitor;
@@ -84,6 +85,7 @@
BaseTreeVisitor attributeVisitor = new BaseTreeVisitor();
attributeVisitor.addChildVisitor(JpaId.class, new IdVisitor());
attributeVisitor.addChildVisitor(JpaBasic.class, new BasicVisitor());
+ attributeVisitor.addChildVisitor(JpaVersion.class, new VersionVisitor());
attributeVisitor.addChildVisitor(JpaManyToOne.class, new FKVisitor());
attributeVisitor.addChildVisitor(JpaOneToOne.class, new FKVisitor());
attributeVisitor.addChildVisitor(
@@ -179,7 +181,7 @@
}
}
- final class BasicVisitor extends BaseTreeVisitor {
+ class BasicVisitor extends BaseTreeVisitor {
BasicVisitor() {
addChildVisitor(JpaColumn.class, new ColumnVisitor());
@@ -209,6 +211,32 @@
}
}
+ class VersionVisitor extends BasicVisitor {
+
+ @Override
+ public boolean onStartNode(ProjectPath path) {
+ JpaVersion jpaBasic = (JpaVersion) path.getObject();
+ if (jpaBasic.getColumn() == null) {
+ JpaColumn column = new JpaColumn(AnnotationPrototypes.getColumn());
+ column.setName(jpaBasic.getName());
+ jpaBasic.setColumn(column);
+ }
+
+ if (jpaBasic.getTemporal() == null) {
+ JpaEntity entity = (JpaEntity) path.firstInstanceOf(JpaEntity.class);
+ JpaClassDescriptor descriptor = entity.getClassDescriptor();
+ JpaPropertyDescriptor property = descriptor.getProperty(jpaBasic
+ .getName());
+
+ if (Date.class.equals(property.getType())) {
+ jpaBasic.setTemporal(TemporalType.TIMESTAMP);
+ }
+ }
+
+ return true;
+ }
+ }
+
final class ColumnVisitor extends BaseTreeVisitor {
@Override
@@ -367,14 +395,25 @@
if (relationship instanceof JpaOneToOne) {
joinColumns = ((JpaOneToOne) relationship).getJoinColumns();
mappedBy = ((JpaOneToOne) relationship).getMappedBy();
+ if (joinColumns.isEmpty() && mappedBy != null) {
+ joinColumns.add(new JpaJoinColumn(AnnotationPrototypes
+ .getJoinColumn()));
+ }
}
else if (relationship instanceof JpaOneToMany) {
joinColumns = ((JpaOneToMany) relationship).getJoinColumns();
mappedBy = ((JpaOneToMany) relationship).getMappedBy();
+ if (joinColumns.isEmpty() && mappedBy != null) {
+ joinColumns.add(new JpaJoinColumn(AnnotationPrototypes
+ .getJoinColumn()));
+ }
}
-
- if (joinColumns != null && joinColumns.isEmpty() && mappedBy != null) {
- joinColumns.add(new JpaJoinColumn(AnnotationPrototypes.getJoinColumn()));
+ else if (relationship instanceof JpaManyToOne) {
+ joinColumns = ((JpaManyToOne) relationship).getJoinColumns();
+ if (joinColumns.isEmpty()) {
+ joinColumns.add(new JpaJoinColumn(AnnotationPrototypes
+ .getJoinColumn()));
+ }
}
return true;
Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/MemberAnnotationProcessorFactory.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/MemberAnnotationProcessorFactory.java?rev=429167&r1=429166&r2=429167&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/MemberAnnotationProcessorFactory.java (original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/MemberAnnotationProcessorFactory.java Sun Aug 6 11:17:07 2006
@@ -137,7 +137,7 @@
attribute = (JpaAttribute) parent;
}
else {
- attribute = findOrCreateAttribute(element, parent);
+ attribute = findOrCreateAttribute(element, parent, context);
}
if (parent != null) {
@@ -148,7 +148,10 @@
}
}
- JpaAttribute findOrCreateAttribute(AnnotatedElement element, Object parent) {
+ JpaAttribute findOrCreateAttribute(
+ AnnotatedElement element,
+ Object parent,
+ AnnotationProcessorStack context) {
JpaBasic basic = null;
@@ -158,7 +161,11 @@
basic = managedClass.getAttributes().getBasicAttribute(name);
if (basic == null) {
basic = new JpaBasic();
- basic.setName(name);
+
+ // do push/pop as the context does some required injection
+ context.push(basic);
+ context.pop();
+
managedClass.getAttributes().getBasicAttributes().add(basic);
}
}
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?rev=429167&r1=429166&r2=429167&view=diff
==============================================================================
--- 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 Aug 6 11:17:07 2006
@@ -17,7 +17,6 @@
* under the License.
****************************************************************/
-
package org.apache.cayenne.jpa.bridge;
import junit.framework.TestCase;
@@ -52,9 +51,6 @@
assertEquals("s1", cayenneMap.getDefaultSchema());
}
- /**
- * @see org.apache.cayenne.jpa.conf.EntityMapAnnotationLoaderTest#testLoadClassMapping()
- */
public void testLoadClassMapping() throws Exception {
EntityMapLoaderContext context = new EntityMapLoaderContext(
new MockPersistenceUnitInfo());
Added: incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor1Test.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor1Test.java?rev=429167&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor1Test.java (added)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor1Test.java Sun Aug 6 11:17:07 2006
@@ -0,0 +1,48 @@
+/*****************************************************************
+ * 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.conf;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.jpa.map.JpaEntity;
+import org.apache.cayenne.jpa.map.JpaEntityMap;
+import org.apache.cayenne.jpa.map.JpaVersion;
+import org.apache.cayenne.jpa.spi.MockPersistenceUnitInfo;
+
+public class EntityMapDefaultsProcessor1Test extends TestCase {
+
+ public void testVersion() {
+
+ EntityMapLoaderContext context = new EntityMapLoaderContext(
+ new MockPersistenceUnitInfo());
+ EntityMapAnnotationLoader loader = new EntityMapAnnotationLoader(context);
+ loader.loadClassMapping(MockAnnotatedBeanVersion.class);
+
+ // apply defaults
+ new EntityMapDefaultsProcessor().applyDefaults(context);
+
+ JpaEntityMap map = context.getEntityMap();
+ JpaEntity entity = map.entityForClass(MockAnnotatedBeanVersion.class);
+ assertNotNull(entity);
+
+ JpaVersion v = entity.getAttributes().getVersionAttribute("attribute1");
+ assertNotNull(v);
+ assertNotNull(v.getColumn());
+ }
+}
Added: incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/MockAnnotatedBeanVersion.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/MockAnnotatedBeanVersion.java?rev=429167&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/MockAnnotatedBeanVersion.java (added)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/conf/MockAnnotatedBeanVersion.java Sun Aug 6 11:17:07 2006
@@ -0,0 +1,29 @@
+/*****************************************************************
+ * 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.conf;
+
+import javax.persistence.Entity;
+import javax.persistence.Version;
+
+@Entity
+public class MockAnnotatedBeanVersion {
+
+ @Version
+ protected String attribute1;
+}