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 2007/10/14 21:34:24 UTC
svn commit: r584591 - in
/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src:
main/java/org/apache/cayenne/reflect/
main/java/org/apache/cayenne/reflect/valueholder/
test/java/org/apache/cayenne/ test/resources/dml/
Author: aadamchik
Date: Sun Oct 14 12:34:23 2007
New Revision: 584591
URL: http://svn.apache.org/viewvc?rev=584591&view=rev
Log:
CAY-848 Support for mapping to-many as Maps and Sets and Collections
(adding ROP runtime support for maps and sets to-many)
Added:
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/IdMapKeyAccessor.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderListProperty.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderMapProperty.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderSetProperty.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderToManyProperty.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/CayenneContextMapRelationshipTest.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/CayenneContextMapRelationshipTest.xml
Removed:
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/MultiColumnIdMapKeyAccessor.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/SingleColumnIdMapKeyAccessor.java
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/IndexedListProperty.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/ListProperty.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java
cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderDescriptorFactory.java
Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/IdMapKeyAccessor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/IdMapKeyAccessor.java?rev=584591&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/IdMapKeyAccessor.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/IdMapKeyAccessor.java Sun Oct 14 12:34:23 2007
@@ -0,0 +1,66 @@
+/*****************************************************************
+ * 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.reflect;
+
+import java.util.Map;
+
+import org.apache.cayenne.ObjectId;
+import org.apache.cayenne.Persistent;
+
+/**
+ * A stateless read-only accessor of the map key value that is based on the Persistent
+ * object id. For single-column ID's the accessor returns a single value (e.g. an
+ * Integer). For multi-column ID's it returns the ObjectId.
+ *
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+public class IdMapKeyAccessor implements Accessor {
+
+ public static final Accessor SHARED_ACCESSOR = new IdMapKeyAccessor();
+
+ public String getName() {
+ return "IdMapKeyAccessor";
+ }
+
+ public Object getValue(Object object) throws PropertyException {
+ if (object instanceof Persistent) {
+ ObjectId id = ((Persistent) object).getObjectId();
+
+ if (id.isTemporary()) {
+ return id;
+ }
+
+ Map map = id.getIdSnapshot();
+ if (map.size() == 1) {
+ Map.Entry pkEntry = (Map.Entry) map.entrySet().iterator().next();
+ return pkEntry.getValue();
+ }
+
+ return id;
+ }
+ else {
+ throw new IllegalArgumentException("Object must be Persistent: " + object);
+ }
+ }
+
+ public void setValue(Object object, Object newValue) throws PropertyException {
+ throw new UnsupportedOperationException("Setting map key is not supported");
+ }
+}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/IndexedListProperty.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/IndexedListProperty.java?rev=584591&r1=584590&r2=584591&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/IndexedListProperty.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/IndexedListProperty.java Sun Oct 14 12:34:23 2007
@@ -29,6 +29,7 @@
*
* @since 1.2
* @author Andrus Adamchik
+ * @deprecated since 3.0 (no substitute exists in Cayenne)
*/
public class IndexedListProperty extends ListProperty {
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/ListProperty.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/ListProperty.java?rev=584591&r1=584590&r2=584591&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/ListProperty.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/ListProperty.java Sun Oct 14 12:34:23 2007
@@ -29,6 +29,7 @@
*
* @since 1.2
* @author Andrus Adamchik
+ * @deprecated since 3.0 replaced by non-public classes.
*/
public class ListProperty extends BaseToManyProperty {
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java?rev=584591&r1=584590&r2=584591&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java Sun Oct 14 12:34:23 2007
@@ -233,15 +233,7 @@
return new PropertyAccessor(targetDescriptor.getProperty(mapKey));
}
- // do not use 'targetDescriptor' to resolve target entity, as it leads to an
- // endless loop during the phase when descriptos are not fully initialized
- ObjEntity targetEntity = (ObjEntity) relationship.getTargetEntity();
- if (targetEntity.getDbEntity().getPrimaryKey().size() > 1) {
- return MultiColumnIdMapKeyAccessor.SHARED_ACCESSOR;
- }
- else {
- return SingleColumnIdMapKeyAccessor.SHARED_ACCESSOR;
- }
+ return IdMapKeyAccessor.SHARED_ACCESSOR;
}
/**
Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderDescriptorFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderDescriptorFactory.java?rev=584591&r1=584590&r2=584591&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderDescriptorFactory.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderDescriptorFactory.java Sun Oct 14 12:34:23 2007
@@ -19,6 +19,7 @@
package org.apache.cayenne.reflect.valueholder;
import java.util.List;
+import java.util.Map;
import org.apache.cayenne.ValueHolder;
import org.apache.cayenne.map.ObjRelationship;
@@ -26,7 +27,6 @@
import org.apache.cayenne.reflect.ClassDescriptor;
import org.apache.cayenne.reflect.ClassDescriptorFactory;
import org.apache.cayenne.reflect.ClassDescriptorMap;
-import org.apache.cayenne.reflect.ListProperty;
import org.apache.cayenne.reflect.PersistentDescriptor;
import org.apache.cayenne.reflect.PersistentDescriptorFactory;
import org.apache.cayenne.reflect.Property;
@@ -47,7 +47,16 @@
protected void createToManyCollectionProperty(
PersistentDescriptor descriptor,
ObjRelationship relationship) {
- throw new UnsupportedOperationException("Implement me");
+ ClassDescriptor targetDescriptor = descriptorMap.getDescriptor(relationship
+ .getTargetEntityName());
+ String reverseName = relationship.getReverseRelationshipName();
+
+ Accessor accessor = createAccessor(descriptor, relationship.getName(), List.class);
+ descriptor.addDeclaredProperty(new ValueHolderListProperty(
+ descriptor,
+ targetDescriptor,
+ accessor,
+ reverseName));
}
protected void createToManyListProperty(
@@ -58,7 +67,7 @@
String reverseName = relationship.getReverseRelationshipName();
Accessor accessor = createAccessor(descriptor, relationship.getName(), List.class);
- descriptor.addDeclaredProperty(new ListProperty(
+ descriptor.addDeclaredProperty(new ValueHolderListProperty(
descriptor,
targetDescriptor,
accessor,
@@ -68,13 +77,35 @@
protected void createToManyMapProperty(
PersistentDescriptor descriptor,
ObjRelationship relationship) {
- throw new UnsupportedOperationException("Implement me");
+
+ ClassDescriptor targetDescriptor = descriptorMap.getDescriptor(relationship
+ .getTargetEntityName());
+ String reverseName = relationship.getReverseRelationshipName();
+ Accessor accessor = createAccessor(descriptor, relationship.getName(), Map.class);
+ Accessor mapKeyAccessor = createMapKeyAccessor(relationship, targetDescriptor);
+ Property property = new ValueHolderMapProperty(
+ descriptor,
+ targetDescriptor,
+ accessor,
+ reverseName,
+ mapKeyAccessor);
+
+ descriptor.addDeclaredProperty(property);
}
protected void createToManySetProperty(
PersistentDescriptor descriptor,
ObjRelationship relationship) {
- throw new UnsupportedOperationException("Implement me");
+ ClassDescriptor targetDescriptor = descriptorMap.getDescriptor(relationship
+ .getTargetEntityName());
+ String reverseName = relationship.getReverseRelationshipName();
+
+ Accessor accessor = createAccessor(descriptor, relationship.getName(), List.class);
+ descriptor.addDeclaredProperty(new ValueHolderSetProperty(
+ descriptor,
+ targetDescriptor,
+ accessor,
+ reverseName));
}
protected void createToOneProperty(
Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderListProperty.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderListProperty.java?rev=584591&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderListProperty.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderListProperty.java Sun Oct 14 12:34:23 2007
@@ -0,0 +1,52 @@
+/*****************************************************************
+ * 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.reflect.valueholder;
+
+import org.apache.cayenne.Persistent;
+import org.apache.cayenne.ValueHolder;
+import org.apache.cayenne.reflect.Accessor;
+import org.apache.cayenne.reflect.ClassDescriptor;
+import org.apache.cayenne.reflect.PropertyException;
+import org.apache.cayenne.util.PersistentObjectList;
+
+/**
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+class ValueHolderListProperty extends ValueHolderToManyProperty {
+
+ ValueHolderListProperty(ClassDescriptor owner, ClassDescriptor targetDescriptor,
+ Accessor accessor, String reverseName) {
+ super(owner, targetDescriptor, accessor, reverseName);
+ }
+
+ protected ValueHolder createCollectionValueHolder(Object object)
+ throws PropertyException {
+
+ if (!(object instanceof Persistent)) {
+
+ throw new PropertyException(
+ "ValueHolders for non-persistent objects are not supported.",
+ this,
+ object);
+ }
+
+ return new PersistentObjectList((Persistent) object, getName());
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderMapProperty.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderMapProperty.java?rev=584591&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderMapProperty.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderMapProperty.java Sun Oct 14 12:34:23 2007
@@ -0,0 +1,60 @@
+/*****************************************************************
+ * 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.reflect.valueholder;
+
+import org.apache.cayenne.Persistent;
+import org.apache.cayenne.ValueHolder;
+import org.apache.cayenne.reflect.Accessor;
+import org.apache.cayenne.reflect.ClassDescriptor;
+import org.apache.cayenne.reflect.PropertyException;
+import org.apache.cayenne.reflect.ToManyMapProperty;
+import org.apache.cayenne.util.PersistentObjectMap;
+
+/**
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+class ValueHolderMapProperty extends ValueHolderToManyProperty implements
+ ToManyMapProperty {
+
+ private Accessor mapKeyAccessor;
+
+ ValueHolderMapProperty(ClassDescriptor owner, ClassDescriptor targetDescriptor,
+ Accessor accessor, String reverseName, Accessor mapKeyAccessor) {
+ super(owner, targetDescriptor, accessor, reverseName);
+ this.mapKeyAccessor = mapKeyAccessor;
+ }
+
+ protected ValueHolder createCollectionValueHolder(Object object)
+ throws PropertyException {
+ if (!(object instanceof Persistent)) {
+
+ throw new PropertyException(
+ "ValueHolders for non-persistent objects are not supported.",
+ this,
+ object);
+ }
+
+ return new PersistentObjectMap((Persistent) object, getName(), mapKeyAccessor);
+ }
+
+ public Object getMapKey(Object target) throws PropertyException {
+ return mapKeyAccessor.getValue(target);
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderSetProperty.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderSetProperty.java?rev=584591&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderSetProperty.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderSetProperty.java Sun Oct 14 12:34:23 2007
@@ -0,0 +1,52 @@
+/*****************************************************************
+ * 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.reflect.valueholder;
+
+import org.apache.cayenne.Persistent;
+import org.apache.cayenne.ValueHolder;
+import org.apache.cayenne.reflect.Accessor;
+import org.apache.cayenne.reflect.ClassDescriptor;
+import org.apache.cayenne.reflect.PropertyException;
+import org.apache.cayenne.util.PersistentObjectSet;
+
+/**
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+class ValueHolderSetProperty extends ValueHolderToManyProperty {
+
+ ValueHolderSetProperty(ClassDescriptor owner, ClassDescriptor targetDescriptor,
+ Accessor accessor, String reverseName) {
+ super(owner, targetDescriptor, accessor, reverseName);
+ }
+
+ protected ValueHolder createCollectionValueHolder(Object object)
+ throws PropertyException {
+
+ if (!(object instanceof Persistent)) {
+
+ throw new PropertyException(
+ "ValueHolders for non-persistent objects are not supported.",
+ this,
+ object);
+ }
+
+ return new PersistentObjectSet((Persistent) object, getName());
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderToManyProperty.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderToManyProperty.java?rev=584591&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderToManyProperty.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/reflect/valueholder/ValueHolderToManyProperty.java Sun Oct 14 12:34:23 2007
@@ -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.cayenne.reflect.valueholder;
+
+import org.apache.cayenne.Fault;
+import org.apache.cayenne.ValueHolder;
+import org.apache.cayenne.reflect.Accessor;
+import org.apache.cayenne.reflect.BaseToManyProperty;
+import org.apache.cayenne.reflect.ClassDescriptor;
+import org.apache.cayenne.reflect.PropertyException;
+
+/**
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+abstract class ValueHolderToManyProperty extends BaseToManyProperty {
+
+ ValueHolderToManyProperty(ClassDescriptor owner, ClassDescriptor targetDescriptor,
+ Accessor accessor, String reverseName) {
+ super(owner, targetDescriptor, accessor, reverseName);
+ }
+
+ protected abstract ValueHolder createCollectionValueHolder(Object object)
+ throws PropertyException;
+
+ public boolean isFault(Object source) {
+ Object target = accessor.getValue(source);
+ return target == null
+ || target instanceof Fault
+ || ((ValueHolder) target).isFault();
+ }
+
+ public void invalidate(Object object) {
+ ValueHolder list = (ValueHolder) readPropertyDirectly(object);
+ if (list != null) {
+ list.invalidate();
+ }
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/CayenneContextMapRelationshipTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/CayenneContextMapRelationshipTest.java?rev=584591&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/CayenneContextMapRelationshipTest.java (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/CayenneContextMapRelationshipTest.java Sun Oct 14 12:34:23 2007
@@ -0,0 +1,70 @@
+/*****************************************************************
+ * 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;
+
+import java.util.Map;
+
+import org.apache.cayenne.access.ClientServerChannel;
+import org.apache.cayenne.query.ObjectIdQuery;
+import org.apache.cayenne.remote.ClientChannel;
+import org.apache.cayenne.remote.service.LocalConnection;
+import org.apache.cayenne.testdo.mt.ClientMtMapToMany;
+import org.apache.cayenne.testdo.mt.MtMapToMany;
+import org.apache.cayenne.unit.AccessStack;
+import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.unit.CayenneResources;
+
+public class CayenneContextMapRelationshipTest extends CayenneCase {
+
+ protected AccessStack buildAccessStack() {
+ return CayenneResources.getResources().getAccessStack(MULTI_TIER_ACCESS_STACK);
+ }
+
+ private CayenneContext createClientContext() {
+ ClientServerChannel serverChannel = new ClientServerChannel(getDomain());
+ LocalConnection connection = new LocalConnection(serverChannel);
+ ClientChannel clientChannel = new ClientChannel(connection);
+ return new CayenneContext(clientChannel);
+ }
+
+ protected void setUp() throws Exception {
+ deleteTestData();
+ }
+
+ public void testReadToMany() throws Exception {
+ createTestData("prepare");
+
+ ObjectContext context = createClientContext();
+
+ ObjectId id = new ObjectId("MtMapToMany", MtMapToMany.ID_PK_COLUMN, 1);
+ ClientMtMapToMany o1 = (ClientMtMapToMany) DataObjectUtils.objectForQuery(
+ context,
+ new ObjectIdQuery(id));
+
+ Map targets = o1.getTargets();
+
+ assertTrue(((ValueHolder) targets).isFault());
+
+ assertNotNull(targets);
+ assertEquals(3, targets.size());
+ assertNotNull(targets.get(new Integer(1)));
+ assertNotNull(targets.get(new Integer(2)));
+ assertNotNull(targets.get(new Integer(3)));
+ }
+}
Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/CayenneContextMapRelationshipTest.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/CayenneContextMapRelationshipTest.xml?rev=584591&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/CayenneContextMapRelationshipTest.xml (added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/dml/CayenneContextMapRelationshipTest.xml Sun Oct 14 12:34:23 2007
@@ -0,0 +1,97 @@
+<?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">
+
+ <bean id="O1" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+ <constructor-arg type="java.lang.Class">
+ <value>org.apache.cayenne.testdo.mt.MtMapToMany</value>
+ </constructor-arg>
+ <constructor-arg>
+ <value>
+ INSERT INTO MT_MAP_TO_MANY (ID)
+ VALUES (1)
+ </value>
+ </constructor-arg>
+ </bean>
+
+ <bean id="O2" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+ <constructor-arg type="java.lang.Class">
+ <value>org.apache.cayenne.testdo.mt.MtMapToMany</value>
+ </constructor-arg>
+ <constructor-arg>
+ <value>
+ INSERT INTO MT_MAP_TO_MANY (ID)
+ VALUES (2)
+ </value>
+ </constructor-arg>
+ </bean>
+
+ <bean id="O1C1" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+ <constructor-arg type="java.lang.Class">
+ <value>org.apache.cayenne.testdo.mt.MtMapToManyTarget</value>
+ </constructor-arg>
+ <constructor-arg>
+ <value>
+ INSERT INTO MT_MAP_TO_MANY_TARGET (ID, MAP_TO_MANY_ID)
+ VALUES (1, 1)
+ </value>
+ </constructor-arg>
+ </bean>
+
+ <bean id="O1C2" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+ <constructor-arg type="java.lang.Class">
+ <value>org.apache.cayenne.testdo.mt.MtMapToManyTarget</value>
+ </constructor-arg>
+ <constructor-arg>
+ <value>
+ INSERT INTO MT_MAP_TO_MANY_TARGET (ID, MAP_TO_MANY_ID)
+ VALUES (2, 1)
+ </value>
+ </constructor-arg>
+ </bean>
+
+ <bean id="O1C3" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+ <constructor-arg type="java.lang.Class">
+ <value>org.apache.cayenne.testdo.mt.MtMapToManyTarget</value>
+ </constructor-arg>
+ <constructor-arg>
+ <value>
+ INSERT INTO MT_MAP_TO_MANY_TARGET (ID, MAP_TO_MANY_ID)
+ VALUES (3, 1)
+ </value>
+ </constructor-arg>
+ </bean>
+
+ <bean id="O2C1" class="org.apache.cayenne.unit.util.UpdatingSQLTemplate">
+ <constructor-arg type="java.lang.Class">
+ <value>org.apache.cayenne.testdo.mt.MtMapToManyTarget</value>
+ </constructor-arg>
+ <constructor-arg>
+ <value>
+ INSERT INTO MT_MAP_TO_MANY_TARGET (ID, MAP_TO_MANY_ID)
+ VALUES (4, 2)
+ </value>
+ </constructor-arg>
+ </bean>
+
+
+
+ <!-- ======================================= -->
+ <!-- Data Sets -->
+ <!-- ======================================= -->
+
+ <bean id="prepare" class="java.util.ArrayList">
+ <constructor-arg>
+ <list>
+ <ref bean="O1" />
+ <ref bean="O2" />
+ <ref bean="O1C1" />
+ <ref bean="O1C2" />
+ <ref bean="O1C3" />
+ <ref bean="O2C1" />
+ </list>
+ </constructor-arg>
+ </bean>
+
+</beans>
\ No newline at end of file