Author: ppoddar
Date: Wed Apr 15 01:48:06 2009
New Revision: 765031
URL: http://svn.apache.org/viewvc?rev=765031&view=rev
Log:
OPENJPA-1010: Tests for Canonical Metamodel Generator from annotated source
code.
Added:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/
(with props)
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ArrayMember.java
(with props)
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/DefaultFieldAccessBase.java
(with props)
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/DefaultFieldAccessMappedSuperclass.java
(with props)
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/DefaultFieldAccessSubclass.java
(with props)
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/Embed0.java
(with props)
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/Embed1.java
(with props)
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitFieldAccess.java
(with props)
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitFieldAccessMixed.java
(with props)
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitPropertyAccess.java
(with props)
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitPropertyAccessMixed.java
(with props)
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/TestCanonicalMetamodelGeneration.java
(with props)
Removed:
openjpa/trunk/openjpa-persistence/src/main/resources/META-INF/services/javax.annotation.processing.Processor.hidden
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
openjpa/trunk/openjpa-persistence/pom.xml
openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/meta/localizer.properties
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java?rev=765031&r1=765030&r2=765031&view=diff
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
(original)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/PersistenceTestCase.java
Wed Apr 15 01:48:06 2009
@@ -47,8 +47,6 @@
import org.apache.openjpa.persistence.JPAFacadeHelper;
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
-import sun.security.action.GetLongAction;
-
/**
* Base test class providing persistence utilities.
*
Modified: openjpa/trunk/openjpa-persistence/pom.xml
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/pom.xml?rev=765031&r1=765030&r2=765031&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/pom.xml (original)
+++ openjpa/trunk/openjpa-persistence/pom.xml Wed Apr 15 01:48:06 2009
@@ -86,8 +86,8 @@
<phase>process-classes</phase>
<configuration>
<tasks>
- <echo
file="${basedir}/target/classes/META-INF/services/javax.annotation.processing.Processor"
-
message="org.apache.openjpa.persistence.meta.AnnotationProcessor6"/>
+ <!-- echo
file="${basedir}/src/main/resources/META-INF/services/javax.annotation.processing.Processor"
+
message="org.apache.openjpa.persistence.meta.AnnotationProcessor6"/ -->
</tasks>
</configuration>
<goals>
Modified:
openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java?rev=765031&r1=765030&r2=765031&view=diff
==============================================================================
---
openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
(original)
+++
openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/meta/AnnotationProcessor6.java
Wed Apr 15 01:48:06 2009
@@ -216,8 +216,6 @@
String originalSimpleClass = e.getSimpleName().toString();
String metaClass = originalClass + UNDERSCORE;
- log(_loc.get("mmg-process", originalClass).getMessage());
-
SourceCode source = new SourceCode(metaClass);
comment(source);
annotate(source, originalClass);
@@ -292,6 +290,7 @@
throws IOException {
Filer filer = processingEnv.getFiler();
JavaFileObject javaFile = filer.createSourceFile(metaClass, e);
+ log(_loc.get("mmg-process", metaClass, javaFile.toUri()).getMessage());
OutputStream out = javaFile.openOutputStream();
PrintWriter writer = new PrintWriter(out);
return writer;
Modified:
openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/meta/localizer.properties
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/meta/localizer.properties?rev=765031&r1=765030&r2=765031&view=diff
==============================================================================
---
openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/meta/localizer.properties
(original)
+++
openjpa/trunk/openjpa-persistence/src/main/resources/org/apache/openjpa/persistence/meta/localizer.properties
Wed Apr 15 01:48:06 2009
@@ -35,5 +35,5 @@
match with the expected key type "{2}"
getter-unmatched: Getter method "{0}" in "{1}" has no matching setter method.
mmg-tool-banner: Starting OpenJPA Annotation Processor for Metamodel Generation
-mmg-process: Processing source code "{0}" to generate metamodel source code
+mmg-process: Generating source code for meta-model class "{0}" at "{1}"
mmg-too-sign: Generated by OpenJPA MetaModel Generator Tool.
\ No newline at end of file
Propchange:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Apr 15 01:48:06 2009
@@ -0,0 +1,3 @@
+ArrayMember_.class
+*_.java
+*.class
Added:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ArrayMember.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ArrayMember.java?rev=765031&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ArrayMember.java
(added)
+++
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ArrayMember.java
Wed Apr 15 01:48:06 2009
@@ -0,0 +1,30 @@
+/*
+ * 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.openjpa.persistence.meta;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+
+...@entity
+public class ArrayMember {
+ @Basic
+ private Integer[] Array;
+ @Basic
+ private int[] array;
+}
Propchange:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ArrayMember.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/DefaultFieldAccessBase.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/DefaultFieldAccessBase.java?rev=765031&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/DefaultFieldAccessBase.java
(added)
+++
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/DefaultFieldAccessBase.java
Wed Apr 15 01:48:06 2009
@@ -0,0 +1,120 @@
+/*
+ * 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.openjpa.persistence.meta;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.persistence.Entity;
+import javax.persistence.ManyToMany;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+
+/**
+ * Domain classes used by meta-model testing.
+ *
+ * Uses default, field based access type.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+...@entity
+public class DefaultFieldAccessBase extends DefaultFieldAccessMappedSuperclass
{
+ private String string;
+ private int primitiveInt;
+ private Integer boxedInt;
+
+ @OneToOne
+ private ExplicitFieldAccess one2oneRelation;
+ @OneToMany
+ private Collection<ExplicitFieldAccess> collectionRelation;
+ @OneToMany
+ private List<ExplicitFieldAccess> listRelation;
+ @OneToMany
+ private Set<ExplicitFieldAccess> setRelation;
+ @ManyToMany
+ private Map<ExplicitPropertyAccess, ExplicitFieldAccess>
+ mapRelationKeyPC;
+ @ManyToMany
+ private Map<Integer, ExplicitFieldAccess> mapRelationKeyBasic;
+
+ public String getString() {
+ return string;
+ }
+ public void setString(String string) {
+ this.string = string;
+ }
+ public int getPrimitiveInt() {
+ return primitiveInt;
+ }
+ public void setPrimitiveInt(int primitiveInt) {
+ this.primitiveInt = primitiveInt;
+ }
+ public Integer getBoxedInt() {
+ return boxedInt;
+ }
+ public void setBoxedInt(Integer boxedInt) {
+ this.boxedInt = boxedInt;
+ }
+ public ExplicitFieldAccess getOne2oneRelation() {
+ return one2oneRelation;
+ }
+ public void setOne2oneRelation(ExplicitFieldAccess
+ one2oneRelation) {
+ this.one2oneRelation = one2oneRelation;
+ }
+ public Collection<ExplicitFieldAccess> getCollectionRelation() {
+ return collectionRelation;
+ }
+ public void setCollectionRelation(Collection<ExplicitFieldAccess>
+ collection) {
+ this.collectionRelation = collection;
+ }
+ public List<ExplicitFieldAccess> getListRelation() {
+ return listRelation;
+ }
+ public void setListRelation(List<ExplicitFieldAccess>
+ listRelation) {
+ this.listRelation = listRelation;
+ }
+ public Set<ExplicitFieldAccess> getSetRelation() {
+ return setRelation;
+ }
+ public void setSetRelation(Set<ExplicitFieldAccess> setRelation) {
+ this.setRelation = setRelation;
+ }
+ public Map<ExplicitPropertyAccess, ExplicitFieldAccess>
+ getMapRelationKeyPC() {
+ return mapRelationKeyPC;
+ }
+ public void setMapRelationKeyPC(Map<ExplicitPropertyAccess,
+ ExplicitFieldAccess> map) {
+ this.mapRelationKeyPC = map;
+ }
+ public Map<Integer, ExplicitFieldAccess> getMapRelationKeyBasic() {
+ return mapRelationKeyBasic;
+ }
+ public void setMapRelationKeyBasic(Map<Integer,
+ ExplicitFieldAccess> map) {
+ this.mapRelationKeyBasic = map;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/DefaultFieldAccessBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/DefaultFieldAccessMappedSuperclass.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/DefaultFieldAccessMappedSuperclass.java?rev=765031&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/DefaultFieldAccessMappedSuperclass.java
(added)
+++
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/DefaultFieldAccessMappedSuperclass.java
Wed Apr 15 01:48:06 2009
@@ -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.openjpa.persistence.meta;
+
+import javax.persistence.Id;
+import javax.persistence.MappedSuperclass;
+
+/**
+ * Domain class used by meta-model testing.
+ *
+ * Uses default field based access.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+...@mappedsuperclass
+public class DefaultFieldAccessMappedSuperclass {
+ @Id
+ private long id;
+
+ private java.util.Date createTime;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public java.util.Date getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(java.util.Date createTime) {
+ this.createTime = createTime;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/DefaultFieldAccessMappedSuperclass.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/DefaultFieldAccessSubclass.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/DefaultFieldAccessSubclass.java?rev=765031&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/DefaultFieldAccessSubclass.java
(added)
+++
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/DefaultFieldAccessSubclass.java
Wed Apr 15 01:48:06 2009
@@ -0,0 +1,58 @@
+/*
+ * 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.openjpa.persistence.meta;
+
+import java.util.Map;
+
+import javax.persistence.Entity;
+import javax.persistence.ManyToMany;
+import javax.persistence.OneToOne;
+
+/**
+ * Domain class used y meta-model testing.
+ *
+ * Uses default field based access.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+...@entity
+public class DefaultFieldAccessSubclass extends DefaultFieldAccessBase {
+ private DefaultFieldAccessBase base;
+ private Map<Embed0, ExplicitPropertyAccess> mapRelationKeyEmbedded;
+
+ @OneToOne
+ public DefaultFieldAccessBase getBase() {
+ return base;
+ }
+
+ public void setBase(DefaultFieldAccessBase base) {
+ this.base = base;
+ }
+
+ @ManyToMany
+ public Map<Embed0, ExplicitPropertyAccess> getMapRelationKeyEmbedded() {
+ return mapRelationKeyEmbedded;
+ }
+
+ public void setMapRelationKeyEmbedded(Map<Embed0,
ExplicitPropertyAccess> map) {
+ this.mapRelationKeyEmbedded = map;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/DefaultFieldAccessSubclass.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/Embed0.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/Embed0.java?rev=765031&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/Embed0.java
(added)
+++
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/Embed0.java
Wed Apr 15 01:48:06 2009
@@ -0,0 +1,54 @@
+/*
+ * 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.openjpa.persistence.meta;
+
+import javax.persistence.Access;
+import javax.persistence.AccessType;
+import javax.persistence.Embeddable;
+import javax.persistence.OneToOne;
+
+/**
+ * Domain class used by meta-model testing.
+ *
+ * Uses explicit field based access.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+...@embeddable
+...@access(AccessType.FIELD)
+public class Embed0 {
+ private long f1;
+ @OneToOne
+ private DefaultFieldAccessSubclass entity1;
+
+ public long getF1() {
+ return f1;
+ }
+ public void setF1(long f1) {
+ this.f1 = f1;
+ }
+ public DefaultFieldAccessSubclass getEntity1() {
+ return entity1;
+ }
+ public void setEntity1(DefaultFieldAccessSubclass entity1) {
+ this.entity1 = entity1;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/Embed0.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/Embed1.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/Embed1.java?rev=765031&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/Embed1.java
(added)
+++
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/Embed1.java
Wed Apr 15 01:48:06 2009
@@ -0,0 +1,57 @@
+/*
+ * 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.openjpa.persistence.meta;
+
+import javax.persistence.Access;
+import javax.persistence.AccessType;
+import javax.persistence.Embeddable;
+import javax.persistence.OneToOne;
+
+/**
+ * Domain class used by meta-model testing.
+ *
+ * Uses explicit field based access.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+...@embeddable
+...@access(AccessType.PROPERTY)
+public class Embed1 {
+ private String f1;
+ private DefaultFieldAccessBase entity0;
+
+
+ public String getF1() {
+ return f1;
+ }
+ public void setF1(String f1) {
+ this.f1 = f1;
+ }
+
+ @OneToOne
+ public DefaultFieldAccessBase getEntity0() {
+ return entity0;
+ }
+
+ public void setEntity0(DefaultFieldAccessBase entity0) {
+ this.entity0 = entity0;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/Embed1.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitFieldAccess.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitFieldAccess.java?rev=765031&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitFieldAccess.java
(added)
+++
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitFieldAccess.java
Wed Apr 15 01:48:06 2009
@@ -0,0 +1,83 @@
+/*
+ * 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.openjpa.persistence.meta;
+
+import javax.persistence.Access;
+import javax.persistence.AccessType;
+import javax.persistence.Entity;
+import javax.persistence.Transient;
+
+/**
+ * Domain class used by meta-model testing.
+ *
+ * Uses explicit, non-mixed field based access.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+...@entity
+...@access(AccessType.FIELD)
+public class ExplicitFieldAccess {
+ private long f1;
+ private int f2;
+ @Transient private short f3;
+ private DefaultFieldAccessBase f4;
+ private DefaultFieldAccessBase f5;
+ private transient DefaultFieldAccessBase f6;
+
+ public long getF1() {
+ return f1;
+ }
+ public void setF1(long f1) {
+ this.f1 = f1;
+ }
+ public int getF2() {
+ return f2;
+ }
+ public void setF2(int f2) {
+ this.f2 = f2;
+ }
+ public short getF3() {
+ return f3;
+ }
+ public void setF3(short f3) {
+ this.f3 = f3;
+ }
+ public DefaultFieldAccessBase getF4() {
+ return f4;
+ }
+ public void setF4(DefaultFieldAccessBase f4) {
+ this.f4 = f4;
+ }
+
+ public DefaultFieldAccessBase getF5() {
+ return f5;
+ }
+ public void setF5(DefaultFieldAccessBase f5) {
+ this.f5 = f5;
+ }
+
+ public DefaultFieldAccessBase getF6() {
+ return f6;
+ }
+ public void setF6(DefaultFieldAccessBase f6) {
+ this.f6 = f6;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitFieldAccess.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitFieldAccessMixed.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitFieldAccessMixed.java?rev=765031&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitFieldAccessMixed.java
(added)
+++
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitFieldAccessMixed.java
Wed Apr 15 01:48:06 2009
@@ -0,0 +1,86 @@
+/*
+ * 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.openjpa.persistence.meta;
+
+import javax.persistence.Access;
+import javax.persistence.AccessType;
+import javax.persistence.Entity;
+import javax.persistence.OneToOne;
+import javax.persistence.Transient;
+
+/**
+ * Domain class used by meta-model testing.
+ *
+ * Uses explicit field based access mixed with property access.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+...@entity
+...@access(AccessType.FIELD)
+public class ExplicitFieldAccessMixed {
+ private long f1;
+ private int f2;
+ @Transient private short f3;
+ private DefaultFieldAccessBase f4;
+ private DefaultFieldAccessBase f5;
+ private transient DefaultFieldAccessBase f6;
+
+ public long getF1() {
+ return f1;
+ }
+ public void setF1(long f1) {
+ this.f1 = f1;
+ }
+ public int getF2() {
+ return f2;
+ }
+ public void setF2(int f2) {
+ this.f2 = f2;
+ }
+ public short getF3() {
+ return f3;
+ }
+ public void setF3(short f3) {
+ this.f3 = f3;
+ }
+ public DefaultFieldAccessBase getF4() {
+ return f4;
+ }
+ public void setF4(DefaultFieldAccessBase f4) {
+ this.f4 = f4;
+ }
+
+ @Access(AccessType.PROPERTY)
+ @OneToOne
+ public DefaultFieldAccessBase getF5() {
+ return f5;
+ }
+ public void setF5(DefaultFieldAccessBase f5) {
+ this.f5 = f5;
+ }
+
+ public DefaultFieldAccessBase getF6() {
+ return f6;
+ }
+ public void setF6(DefaultFieldAccessBase f6) {
+ this.f6 = f6;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitFieldAccessMixed.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitPropertyAccess.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitPropertyAccess.java?rev=765031&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitPropertyAccess.java
(added)
+++
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitPropertyAccess.java
Wed Apr 15 01:48:06 2009
@@ -0,0 +1,86 @@
+/*
+ * 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.openjpa.persistence.meta;
+
+import javax.persistence.Access;
+import javax.persistence.AccessType;
+import javax.persistence.Entity;
+import javax.persistence.OneToOne;
+import javax.persistence.Transient;
+
+/**
+ * Domain class used by meta-model testing.
+ *
+ * Uses explicit, non-mixed, property based access.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+...@entity
+...@access(AccessType.PROPERTY)
+public class ExplicitPropertyAccess {
+ private String f1;
+ private long f2;
+ private String f3;
+ private String f4;
+ private DefaultFieldAccessBase f5;
+ private DefaultFieldAccessBase f6;
+
+ public String getF1() {
+ return f1;
+ }
+ public void setF1(String f1) {
+ this.f1 = f1;
+ }
+ @Transient
+ public long getF2() {
+ return f2;
+ }
+ public void setF2(long f2) {
+ this.f2 = f2;
+ }
+ public String getF3() {
+ return f3;
+ }
+ public void setF3(String f3) {
+ this.f3 = f3;
+ }
+ public String getF4() {
+ return f4;
+ }
+ public void setF4(String f4) {
+ this.f4 = f4;
+ }
+ @OneToOne
+ public DefaultFieldAccessBase getF5() {
+ return f5;
+ }
+ public void setF5(DefaultFieldAccessBase f5) {
+ this.f5 = f5;
+ }
+ @OneToOne
+ public DefaultFieldAccessBase getF6() {
+ return f6;
+ }
+
+ public void setF6(DefaultFieldAccessBase f6) {
+ this.f6 = f6;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitPropertyAccess.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitPropertyAccessMixed.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitPropertyAccessMixed.java?rev=765031&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitPropertyAccessMixed.java
(added)
+++
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitPropertyAccessMixed.java
Wed Apr 15 01:48:06 2009
@@ -0,0 +1,91 @@
+/*
+ * 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.openjpa.persistence.meta;
+
+import javax.persistence.Access;
+import javax.persistence.AccessType;
+import javax.persistence.Entity;
+import javax.persistence.OneToOne;
+import javax.persistence.Transient;
+
+/**
+ * Domain class used by meta-model testing.
+ *
+ * Uses explicit property access mixed with field access.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+...@entity
+...@access(AccessType.PROPERTY)
+public class ExplicitPropertyAccessMixed {
+ private String f1;
+ private long f2;
+
+ @Access(AccessType.FIELD)
+ @OneToOne
+ private DefaultFieldAccessBase f3;
+ private int f4;
+ private short f5;
+ private DefaultFieldAccessBase f6;
+
+ public String getF1() {
+ return f1;
+ }
+ public void setF1(String f1) {
+ this.f1 = f1;
+ }
+ @Transient
+ public long getF2() {
+ return f2;
+ }
+ public void setF2(long f2) {
+ this.f2 = f2;
+ }
+
+ public DefaultFieldAccessBase getF3() {
+ return f3;
+ }
+ public void setF3(DefaultFieldAccessBase f3) {
+ this.f3 = f3;
+ }
+
+ public int getF4() {
+ return f4;
+ }
+ public void setF4(int f4) {
+ this.f4 = f4;
+ }
+
+ public short getF5() {
+ return f5;
+ }
+ public void setF5(short f5) {
+ this.f5 = f5;
+ }
+
+ @OneToOne
+ public DefaultFieldAccessBase getF6() {
+ return f6;
+ }
+ public void setF6(DefaultFieldAccessBase f6) {
+ this.f6 = f6;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/ExplicitPropertyAccessMixed.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/TestCanonicalMetamodelGeneration.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/TestCanonicalMetamodelGeneration.java?rev=765031&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/TestCanonicalMetamodelGeneration.java
(added)
+++
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/TestCanonicalMetamodelGeneration.java
Wed Apr 15 01:48:06 2009
@@ -0,0 +1,267 @@
+package org.apache.openjpa.persistence.meta;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.annotation.processing.Processor;
+import javax.tools.JavaCompiler;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.StandardLocation;
+import javax.tools.ToolProvider;
+import javax.tools.JavaCompiler.CompilationTask;
+
+import org.apache.openjpa.lib.util.Files;
+import org.apache.openjpa.lib.util.TemporaryClassLoader;
+
+/**
+ * Tests generation of canonical meta-model classes.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class TestCanonicalMetamodelGeneration extends junit.framework.TestCase
{
+ public static final char DOT = '.';
+ public static final char SLASH = '/';
+ public static final String UNDERSCORE = "_";
+ public static final String BLANK = "";
+ public static final String PACKAGE =
"org.apache.openjpa.persistence.meta.";
+ public static final String[] DOMAIN_CLASSES = {
+ PACKAGE + "DefaultFieldAccessMappedSuperclass",
+ PACKAGE + "DefaultFieldAccessBase",
+ PACKAGE + "DefaultFieldAccessSubclass",
+ PACKAGE + "Embed0",
+ PACKAGE + "Embed1",
+ PACKAGE + "ExplicitFieldAccessMixed",
+ PACKAGE + "ExplicitPropertyAccessMixed",
+ PACKAGE + "ExplicitFieldAccess",
+ PACKAGE + "ExplicitPropertyAccess",
+ PACKAGE + "ArrayMember"
+ };
+ public static String ADDITIONAL_CLASSPATH;
+ private static boolean isMaven;
+ private static boolean compiled;
+
+ public void setUp() throws Exception {
+ if (!compiled) {
+ String currentDir = System.getProperty("user.dir");
+ isMaven = currentDir.endsWith("openjpa-persistence");
+ String srcPath = isMaven ? BLANK :
"openjpa-persistence";
+ ADDITIONAL_CLASSPATH = currentDir + File.separator +
+ srcPath + File.separator +
+ "src.test.java".replace(DOT, File.separatorChar);
+ System.err.println("Additional Path = " +
ADDITIONAL_CLASSPATH);
+ addClasspath(ADDITIONAL_CLASSPATH);
+ deleteByteCode(false, DOMAIN_CLASSES);
+ deleteByteCode(true, DOMAIN_CLASSES);
+ deleteSourceCode(true, DOMAIN_CLASSES);
+
+ compile(findSourceCode(false, DOMAIN_CLASSES));
+ compiled = true;
+ }
+ }
+
+ File findFile(String clsName, String extension) {
+ String filePath = ADDITIONAL_CLASSPATH + File.separator +
+ clsName.replace(DOT, File.separatorChar) + extension ;
+ File file = Files.getFile(filePath, null);
+ assertTrue(filePath + " does not exist", file.exists());
+ return file;
+ }
+
+ File findSourceCode(String clsName) {
+ return findFile(clsName, ".java");
+ }
+
+ File findByteCode(String clsName) {
+ return findFile(clsName, ".class");
+ }
+
+ File[] findSourceCode(boolean canonical, String...classNames) {
+ File[] files = new File[classNames.length];
+ for (int i = 0; i < classNames.length; i++) {
+ files[i] = findSourceCode(classNames[i]
+ + (canonical ? UNDERSCORE : BLANK));
+ }
+ return files;
+ }
+
+ File[] findByteCode(boolean canonical, String...classNames) {
+ File[] files = new File[classNames.length];
+ for (int i = 0; i < classNames.length; i++) {
+ files[i] = findByteCode(classNames[i]
+ + (canonical ? UNDERSCORE : BLANK));
+ }
+ return files;
+ }
+
+ /**
+ * Deletes the *.java of the given class names.
+ */
+ void deleteSourceCode(boolean canonical, String...classNames) {
+ for (String clsName : classNames) {
+ try {
+ findSourceCode(clsName + (canonical ?
UNDERSCORE : BLANK))
+ .delete();
+ } catch (Throwable t) {
+
+ }
+ }
+ }
+ /**
+ * Deletes the *.class of the given class names.
+ */
+ void deleteByteCode(boolean canonical, String...classNames) {
+ for (String clsName : classNames) {
+ try {
+ findByteCode(clsName + (canonical ? UNDERSCORE
: BLANK)).delete();
+ } catch (Throwable t) {
+
+ }
+ }
+ }
+
+ public void testCanonicalModelIsGenerated() {
+ findSourceCode(true, DOMAIN_CLASSES);
+ findByteCode(true, DOMAIN_CLASSES);
+ }
+
+ public void testExplicitFieldAccessMixed() {
+ Class<?> model = loadCanonicalClassFor(PACKAGE +
"ExplicitFieldAccessMixed");
+ assertField(model, "f1", "f2", "f4", "f5");
+ }
+
+ public void testExplicitFieldAccess() {
+ Class<?> model = loadCanonicalClassFor(PACKAGE +
"ExplicitFieldAccess");
+ assertField(model, "f1", "f2", "f4", "f5");
+ }
+
+ public void testExplicitPropertyAccessMixed() {
+ Class<?> model = loadCanonicalClassFor(PACKAGE +
"ExplicitPropertyAccessMixed");
+ assertField(model, "f1", "f3", "f4", "f5", "f6");
+ }
+
+ public void testExplicitPropertyAccess() {
+ Class<?> model = loadCanonicalClassFor(PACKAGE +
"ExplicitPropertyAccess");
+ assertField(model, "f1", "f3", "f4", "f5", "f6");
+ }
+
+ public void testArrayMembers() {
+ Class<?> model = loadCanonicalClassFor(PACKAGE + "ArrayMember");
+ assertField(model, "Array", "array");
+ }
+
+ /**
+ * Compiles the given *.java files with an annotation processor.
+ */
+ void compile(File...files) {
+ List<File> classpaths = getClasspath(isMaven
+ ? "surefire.test.class.path" : "java.class.path");
+ List<File> classOutput = Collections.singletonList
+ (new File(ADDITIONAL_CLASSPATH));
+
+ List<? extends Processor> processors = Arrays.asList(new
Processor[]{
+ new AnnotationProcessor6()});
+
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ StandardJavaFileManager mgr = compiler.getStandardFileManager(null,
+ null, null);
+ try {
+ mgr.setLocation(StandardLocation.CLASS_PATH,
classpaths);
+ mgr.setLocation(StandardLocation.CLASS_OUTPUT,
classOutput);
+ mgr.setLocation(StandardLocation.SOURCE_OUTPUT,
classOutput);
+ print("Javac Compiler Source output= ",
mgr.getLocation(StandardLocation.SOURCE_OUTPUT));
+ print("Javac Compiler Class output = ",
mgr.getLocation(StandardLocation.CLASS_OUTPUT));
+ print("Javac Compiler Classpath = ",
mgr.getLocation(StandardLocation.CLASS_PATH));
+ } catch (IOException e) {
+ fail();
+ }
+ List<String> options = Arrays.asList(new String[]{"-Alog"});
+ CompilationTask task = compiler.getTask(null, // writer
+ mgr,
+ null, // listener,
+ options, // options
+ null, // classes
+ mgr.getJavaFileObjects(files));
+ task.setProcessors(processors);
+ task.call();
+ }
+
+ void addClasspath(String newPath) {
+ String sysprop = isMaven ? "surefire.test.class.path" :
"java.class.path";
+ String currentPath = System.getProperty(sysprop);
+ System.setProperty(sysprop, currentPath + File.pathSeparator +
newPath);
+ }
+
+ List<File> getClasspath(String sysprop) {
+ List<File> result = new ArrayList<File>();
+ String[] paths =
System.getProperty(sysprop).split(File.pathSeparator);
+ for (String path : paths) {
+ result.add(new File(path));
+ }
+ return result;
+ }
+
+ Class<?> loadCanonicalClassFor(String clsName) {
+ try {
+ GeneratedClassLoader loader = new GeneratedClassLoader(
+ this.getClass().getClassLoader());
+ return loader.loadClass(clsName + UNDERSCORE);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Failed to load canonical class for " + clsName);
+ }
+ return null;
+ }
+
+ /**
+ * Assert the given class has the given fields and no other field.
+ */
+ void assertField(Class<?> cls, String... fieldNames) {
+ for (String f : fieldNames) {
+ try {
+ cls.getField(f);
+ } catch (NoSuchFieldException e) {
+ fail(f + " not found in " + cls);
+ }
+ }
+ assertEquals("Actual members : " + Arrays.toString(cls.getFields()) +
+ " expected " + Arrays.toString(fieldNames),
+ fieldNames.length, cls.getFields().length);
+ }
+
+ void print(String header, Iterable<? extends File> location) {
+ Iterator<? extends File> files = location.iterator();
+ System.err.println(header + files.next().getAbsolutePath());
+ while (files.hasNext())
+ System.err.println("\t" +
files.next().getAbsolutePath());
+
+ }
+
+
+ public class GeneratedClassLoader extends TemporaryClassLoader {
+ public GeneratedClassLoader(ClassLoader loader) {
+ super(loader);
+ }
+
+ @Override
+ public InputStream getResourceAsStream(String clsName) {
+ String path = ADDITIONAL_CLASSPATH + File.separator +
+ clsName.replace(SLASH, File.separatorChar);
+ try {
+ return new FileInputStream(Files.getFile(path,
null));
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ fail(clsName + " loacation " + path + " not
loadable");
+ }
+ return null;
+ }
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence/src/test/java/org/apache/openjpa/persistence/meta/TestCanonicalMetamodelGeneration.java
------------------------------------------------------------------------------
svn:eol-style = native