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/07/03 23:16:59 UTC
svn commit: r418853 - in
/incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src:
cayenne/java/org/objectstyle/cayenne/map/ tests/java/org/objectstyle/art/
tests/java/org/objectstyle/art/auto/
tests/java/org/objectstyle/cayenne/property/ te...
Author: aadamchik
Date: Mon Jul 3 14:16:59 2006
New Revision: 418853
URL: http://svn.apache.org/viewvc?rev=418853&view=rev
Log:
CAY-582 (copying the fix to the 3.0 branch)
Added:
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/MixedPersistenceStrategy.java
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/MixedPersistenceStrategy2.java
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/auto/_MixedPersistenceStrategy.java
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/auto/_MixedPersistenceStrategy2.java
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/property/MixedPersistenceStrategyTst.java
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/resources/dml/property.MixedPersistenceStrategyTst.xml
Modified:
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/map/EntityDescriptor.java
incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/resources/testmap.map.xml
Modified: incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/map/EntityDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/map/EntityDescriptor.java?rev=418853&r1=418852&r2=418853&view=diff
==============================================================================
--- incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/map/EntityDescriptor.java (original)
+++ incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/map/EntityDescriptor.java Mon Jul 3 14:16:59 2006
@@ -289,19 +289,19 @@
}
/*
- * Creates an accessor for the property. First tries FieldAccessor and then
- * DataObjectAccessor.
+ * Creates an accessor for the property.
*/
PropertyAccessor makeAccessor(String propertyName, Class propertyType)
throws PropertyAccessException {
+
+ if (dataObject) {
+ return new DataObjectAccessor(propertyName);
+ }
+
try {
return new FieldAccessor(objectClass, propertyName, propertyType);
}
catch (Throwable th) {
-
- if (dataObject) {
- return new DataObjectAccessor(propertyName);
- }
throw new PropertyAccessException("Can't create accessor for property '"
+ propertyName
Added: incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/MixedPersistenceStrategy.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/MixedPersistenceStrategy.java?rev=418853&view=auto
==============================================================================
--- incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/MixedPersistenceStrategy.java (added)
+++ incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/MixedPersistenceStrategy.java Mon Jul 3 14:16:59 2006
@@ -0,0 +1,17 @@
+package org.objectstyle.art;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.objectstyle.art.auto._MixedPersistenceStrategy;
+
+public class MixedPersistenceStrategy extends _MixedPersistenceStrategy {
+
+ // a private variable that intentionally mirrors the name of the persistent property
+ // to create a "conflict"
+ private List details = new ArrayList();
+
+ public List getIvarDetails() {
+ return details;
+ }
+}
Added: incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/MixedPersistenceStrategy2.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/MixedPersistenceStrategy2.java?rev=418853&view=auto
==============================================================================
--- incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/MixedPersistenceStrategy2.java (added)
+++ incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/MixedPersistenceStrategy2.java Mon Jul 3 14:16:59 2006
@@ -0,0 +1,10 @@
+package org.objectstyle.art;
+
+import org.objectstyle.art.auto._MixedPersistenceStrategy2;
+
+public class MixedPersistenceStrategy2 extends _MixedPersistenceStrategy2 {
+
+}
+
+
+
Added: incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/auto/_MixedPersistenceStrategy.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/auto/_MixedPersistenceStrategy.java?rev=418853&view=auto
==============================================================================
--- incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/auto/_MixedPersistenceStrategy.java (added)
+++ incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/auto/_MixedPersistenceStrategy.java Mon Jul 3 14:16:59 2006
@@ -0,0 +1,45 @@
+package org.objectstyle.art.auto;
+
+import java.util.List;
+
+/** Class _MixedPersistenceStrategy was generated by Cayenne.
+ * It is probably a good idea to avoid changing this class manually,
+ * since it may be overwritten next time code is regenerated.
+ * If you need to make any customizations, please use subclass.
+ */
+public class _MixedPersistenceStrategy extends org.objectstyle.cayenne.CayenneDataObject {
+
+ public static final String DESCRIPTION_PROPERTY = "description";
+ public static final String NAME_PROPERTY = "name";
+ public static final String DETAILS_PROPERTY = "details";
+
+ public static final String ID_PK_COLUMN = "ID";
+
+ public void setDescription(String description) {
+ writeProperty("description", description);
+ }
+ public String getDescription() {
+ return (String)readProperty("description");
+ }
+
+
+ public void setName(String name) {
+ writeProperty("name", name);
+ }
+ public String getName() {
+ return (String)readProperty("name");
+ }
+
+
+ public void addToDetails(org.objectstyle.art.MixedPersistenceStrategy2 obj) {
+ addToManyTarget("details", obj, true);
+ }
+ public void removeFromDetails(org.objectstyle.art.MixedPersistenceStrategy2 obj) {
+ removeToManyTarget("details", obj, true);
+ }
+ public List getDetails() {
+ return (List)readProperty("details");
+ }
+
+
+}
Added: incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/auto/_MixedPersistenceStrategy2.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/auto/_MixedPersistenceStrategy2.java?rev=418853&view=auto
==============================================================================
--- incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/auto/_MixedPersistenceStrategy2.java (added)
+++ incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/art/auto/_MixedPersistenceStrategy2.java Mon Jul 3 14:16:59 2006
@@ -0,0 +1,32 @@
+package org.objectstyle.art.auto;
+
+/** Class _MixedPersistenceStrategy2 was generated by Cayenne.
+ * It is probably a good idea to avoid changing this class manually,
+ * since it may be overwritten next time code is regenerated.
+ * If you need to make any customizations, please use subclass.
+ */
+public class _MixedPersistenceStrategy2 extends org.objectstyle.cayenne.CayenneDataObject {
+
+ public static final String NAME_PROPERTY = "name";
+ public static final String MASTER_PROPERTY = "master";
+
+ public static final String ID_PK_COLUMN = "ID";
+
+ public void setName(String name) {
+ writeProperty("name", name);
+ }
+ public String getName() {
+ return (String)readProperty("name");
+ }
+
+
+ public void setMaster(org.objectstyle.art.MixedPersistenceStrategy master) {
+ setToOneTarget("master", master, true);
+ }
+
+ public org.objectstyle.art.MixedPersistenceStrategy getMaster() {
+ return (org.objectstyle.art.MixedPersistenceStrategy)readProperty("master");
+ }
+
+
+}
Added: incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/property/MixedPersistenceStrategyTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/property/MixedPersistenceStrategyTst.java?rev=418853&view=auto
==============================================================================
--- incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/property/MixedPersistenceStrategyTst.java (added)
+++ incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/property/MixedPersistenceStrategyTst.java Mon Jul 3 14:16:59 2006
@@ -0,0 +1,104 @@
+/* ====================================================================
+ *
+ * The ObjectStyle Group Software License, version 1.1
+ * ObjectStyle Group - http://objectstyle.org/
+ *
+ * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors
+ * of the software. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any,
+ * must include the following acknowlegement:
+ * "This product includes software developed by independent contributors
+ * and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
+ * or promote products derived from this software without prior written
+ * permission. For written permission, email
+ * "andrus at objectstyle dot org".
+ *
+ * 5. Products derived from this software may not be called "ObjectStyle"
+ * or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
+ * names without prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals and hosted on ObjectStyle Group web site. For more
+ * information on the ObjectStyle Group, please see
+ * <http://objectstyle.org/>.
+ */
+package org.objectstyle.cayenne.property;
+
+import org.objectstyle.art.MixedPersistenceStrategy;
+import org.objectstyle.art.MixedPersistenceStrategy2;
+import org.objectstyle.cayenne.DataObjectUtils;
+import org.objectstyle.cayenne.ValueHolder;
+import org.objectstyle.cayenne.access.DataContext;
+import org.objectstyle.cayenne.unit.CayenneTestCase;
+
+/**
+ * Tests conflicts between field and map-based persistence.
+ *
+ * @author Andrus Adamchik
+ */
+public class MixedPersistenceStrategyTst extends CayenneTestCase {
+
+ public void testConflictingField1() throws Exception {
+ deleteTestData();
+ createTestData("testConflictingField");
+
+ DataContext c = createDataContext();
+ MixedPersistenceStrategy object = (MixedPersistenceStrategy) DataObjectUtils
+ .objectForPK(c, MixedPersistenceStrategy.class, 1);
+
+ assertEquals(2, object.getDetails().size());
+ assertTrue(object.getDetails() instanceof ValueHolder);
+ }
+
+ /**
+ * This test case reproduces CAY-582 bug.
+ */
+ public void testConflictingField2() throws Exception {
+ deleteTestData();
+ createTestData("testConflictingField");
+
+ DataContext c = createDataContext();
+ MixedPersistenceStrategy2 detail1 = (MixedPersistenceStrategy2) DataObjectUtils
+ .objectForPK(c, MixedPersistenceStrategy2.class, 1);
+
+ MixedPersistenceStrategy2 detail2 = (MixedPersistenceStrategy2) DataObjectUtils
+ .objectForPK(c, MixedPersistenceStrategy2.class, 2);
+
+ // resolve master (this is where CAY-582 exception happens)
+ assertEquals("n1", detail1.getMaster().getName());
+
+ assertEquals(2, detail2.getMaster().getDetails().size());
+ assertTrue(detail2.getMaster().getDetails() instanceof ValueHolder);
+ }
+}
Added: incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/resources/dml/property.MixedPersistenceStrategyTst.xml
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/resources/dml/property.MixedPersistenceStrategyTst.xml?rev=418853&view=auto
==============================================================================
--- incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/resources/dml/property.MixedPersistenceStrategyTst.xml (added)
+++ incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/resources/dml/property.MixedPersistenceStrategyTst.xml Mon Jul 3 14:16:59 2006
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+
+<beans default-lazy-init="true">
+ <!-- ======================================= -->
+ <!-- Named Queries -->
+ <!-- ======================================= -->
+
+ <bean id="M11" class="org.objectstyle.cayenne.unit.util.UpdatingSQLTemplate">
+ <constructor-arg type="java.lang.Class"><value>org.objectstyle.art.MixedPersistenceStrategy</value></constructor-arg>
+ <constructor-arg><value>
+ insert into MIXED_PERSISTENCE_STRATEGY (ID, DESCRIPTION, NAME) values (1, 'd1', 'n1')
+ </value></constructor-arg>
+ </bean>
+
+ <bean id="M21" class="org.objectstyle.cayenne.unit.util.UpdatingSQLTemplate">
+ <constructor-arg type="java.lang.Class"><value>org.objectstyle.art.MixedPersistenceStrategy2</value></constructor-arg>
+ <constructor-arg><value>
+ insert into MIXED_PERSISTENCE_STRATEGY2 (ID, MASTER_ID, NAME) values (1, 1, 'dn1')
+ </value></constructor-arg>
+ </bean>
+
+ <bean id="M22" class="org.objectstyle.cayenne.unit.util.UpdatingSQLTemplate">
+ <constructor-arg type="java.lang.Class"><value>org.objectstyle.art.MixedPersistenceStrategy2</value></constructor-arg>
+ <constructor-arg><value>
+ insert into MIXED_PERSISTENCE_STRATEGY2 (ID, MASTER_ID, NAME) values (2, 1, 'dn2')
+ </value></constructor-arg>
+ </bean>
+
+ <!-- ======================================= -->
+ <!-- Data Sets -->
+ <!-- ======================================= -->
+ <bean id="testConflictingField" class="java.util.ArrayList">
+ <constructor-arg>
+ <list>
+ <ref bean="M11"/>
+ <ref bean="M21"/>
+ <ref bean="M22"/>
+ </list>
+ </constructor-arg>
+ </bean>
+</beans>
\ No newline at end of file
Modified: incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/resources/testmap.map.xml
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/resources/testmap.map.xml?rev=418853&r1=418852&r2=418853&view=diff
==============================================================================
--- incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/resources/testmap.map.xml (original)
+++ incubator/cayenne/main/branches/PROTO-3.0/cayenne/cayenne-java/src/tests/resources/testmap.map.xml Mon Jul 3 14:16:59 2006
@@ -130,6 +130,16 @@
<db-attribute name="DESCR" type="VARCHAR" length="50"/>
<db-attribute name="PK_ATTRIBUTE" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
</db-entity>
+ <db-entity name="MIXED_PERSISTENCE_STRATEGY">
+ <db-attribute name="DESCRIPTION" type="VARCHAR" length="200"/>
+ <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+ <db-attribute name="NAME" type="VARCHAR" length="200"/>
+ </db-entity>
+ <db-entity name="MIXED_PERSISTENCE_STRATEGY2">
+ <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+ <db-attribute name="MASTER_ID" type="INTEGER"/>
+ <db-attribute name="NAME" type="VARCHAR" length="200"/>
+ </db-entity>
<db-entity name="NO_PK_TEST">
<db-attribute name="ATTRIBUTE1" type="INTEGER"/>
</db-entity>
@@ -277,6 +287,13 @@
<obj-attribute name="descr" type="java.lang.String" db-attribute-path="DESCR"/>
<obj-attribute name="pkAttribute" type="java.lang.Integer" db-attribute-path="PK_ATTRIBUTE"/>
</obj-entity>
+ <obj-entity name="MixedPersistenceStrategy" className="org.objectstyle.art.MixedPersistenceStrategy" dbEntityName="MIXED_PERSISTENCE_STRATEGY">
+ <obj-attribute name="description" type="java.lang.String" db-attribute-path="DESCRIPTION"/>
+ <obj-attribute name="name" type="java.lang.String" db-attribute-path="NAME"/>
+ </obj-entity>
+ <obj-entity name="MixedPersistenceStrategy2" className="org.objectstyle.art.MixedPersistenceStrategy2" dbEntityName="MIXED_PERSISTENCE_STRATEGY2">
+ <obj-attribute name="name" type="java.lang.String" db-attribute-path="NAME"/>
+ </obj-entity>
<obj-entity name="NoPkTest" className="org.objectstyle.art.NoPkTest" dbEntityName="NO_PK_TEST">
<obj-attribute name="attribute1" type="java.lang.Integer" db-attribute-path="ATTRIBUTE1"/>
</obj-entity>
@@ -398,6 +415,12 @@
<db-relationship name="meaningfulPKDepArray" source="MEANINGFUL_PK_TEST1" target="MEANINGFUL_PK_DEP" toMany="true">
<db-attribute-pair source="PK_ATTRIBUTE" target="MASTER_PK"/>
</db-relationship>
+ <db-relationship name="details" source="MIXED_PERSISTENCE_STRATEGY" target="MIXED_PERSISTENCE_STRATEGY2" toMany="true">
+ <db-attribute-pair source="ID" target="MASTER_ID"/>
+ </db-relationship>
+ <db-relationship name="master" source="MIXED_PERSISTENCE_STRATEGY2" target="MIXED_PERSISTENCE_STRATEGY" toMany="false">
+ <db-attribute-pair source="MASTER_ID" target="ID"/>
+ </db-relationship>
<db-relationship name="toArtist" source="PAINTING" target="ARTIST" toMany="false">
<db-attribute-pair source="ARTIST_ID" target="ARTIST_ID"/>
</db-relationship>
@@ -441,6 +464,8 @@
<obj-relationship name="toDep" source="GeneratedColumnTest" target="GeneratedColumnDep" db-relationship-path="toDep"/>
<obj-relationship name="toMeaningfulPK" source="MeaningfulPKDep" target="MeaningfulPKTest1" db-relationship-path="toMeaningfulPK"/>
<obj-relationship name="meaningfulPKDepArray" source="MeaningfulPKTest1" target="MeaningfulPKDep" db-relationship-path="meaningfulPKDepArray"/>
+ <obj-relationship name="details" source="MixedPersistenceStrategy" target="MixedPersistenceStrategy2" db-relationship-path="details"/>
+ <obj-relationship name="master" source="MixedPersistenceStrategy2" target="MixedPersistenceStrategy" db-relationship-path="master"/>
<obj-relationship name="toArtist" source="Painting" target="Artist" deleteRule="Nullify" db-relationship-path="toArtist"/>
<obj-relationship name="toGallery" source="Painting" target="Gallery" deleteRule="Nullify" db-relationship-path="toGallery"/>
<obj-relationship name="toPaintingInfo" source="Painting" target="PaintingInfo" deleteRule="Cascade" db-relationship-path="toPaintingInfo"/>