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 2011/02/28 12:17:20 UTC
svn commit: r1075294 - in /cayenne/main/trunk: docs/doc/src/main/resources/
framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/
Author: aadamchik
Date: Mon Feb 28 11:17:19 2011
New Revision: 1075294
URL: http://svn.apache.org/viewvc?rev=1075294&view=rev
Log:
CAY-1546 cayenne-lifecycle: UuidBatchFault concurrency issues
Added:
cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/UuidBatchSourceItem.java
Modified:
cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/UuidBatchFault.java
cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/UuidRelationshipBatchFaultingStrategy.java
Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=1075294&r1=1075293&r2=1075294&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Mon Feb 28 11:17:19 2011
@@ -16,6 +16,10 @@ Changes/New Features Since 3.1M2:
CAY-1544 Remove jdk1.6 module from Cayenne sources
CAY-1545 cayenne-lifecycle Referenceable handler refactoring
+Bug Fixes Since 3.1M2:
+
+CAY-1546 cayenne-lifecycle: UuidBatchFault concurrency issues
+
----------------------------------
Release: 3.1 M2
Date:
Modified: cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/UuidBatchFault.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/UuidBatchFault.java?rev=1075294&r1=1075293&r2=1075294&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/UuidBatchFault.java (original)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/UuidBatchFault.java Mon Feb 28 11:17:19 2011
@@ -18,7 +18,6 @@
****************************************************************/
package org.apache.cayenne.lifecycle.relationship;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -48,18 +47,10 @@ class UuidBatchFault {
private Collection<String> uuids;
private volatile Map<String, Object> resolved;
- UuidBatchFault(ObjectContext context) {
+ UuidBatchFault(ObjectContext context, List<UuidBatchSourceItem> batchHolder) {
this.context = context;
}
- void addUuid(String uuid) {
- if (uuids == null) {
- uuids = new ArrayList<String>();
- }
-
- uuids.add(uuid);
- }
-
Map<String, Object> getObjects() {
if (resolved == null) {
Added: cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/UuidBatchSourceItem.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/UuidBatchSourceItem.java?rev=1075294&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/UuidBatchSourceItem.java (added)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/UuidBatchSourceItem.java Mon Feb 28 11:17:19 2011
@@ -0,0 +1,46 @@
+/*****************************************************************
+ * 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.lifecycle.relationship;
+
+import org.apache.cayenne.DataObject;
+
+final class UuidBatchSourceItem {
+
+ private final DataObject object;
+ private final String uuid;
+ private final String uuidRelationship;
+
+ UuidBatchSourceItem(DataObject object, String uuid, String uuidRelationship) {
+ this.object = object;
+ this.uuid = uuid;
+ this.uuidRelationship = uuidRelationship;
+ }
+
+ DataObject getObject() {
+ return object;
+ }
+
+ String getUuidRelationship() {
+ return uuidRelationship;
+ }
+
+ String getUuid() {
+ return uuid;
+ }
+}
Modified: cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/UuidRelationshipBatchFaultingStrategy.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/UuidRelationshipBatchFaultingStrategy.java?rev=1075294&r1=1075293&r2=1075294&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/UuidRelationshipBatchFaultingStrategy.java (original)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/UuidRelationshipBatchFaultingStrategy.java Mon Feb 28 11:17:19 2011
@@ -18,6 +18,9 @@
****************************************************************/
package org.apache.cayenne.lifecycle.relationship;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.cayenne.DataObject;
/**
@@ -29,21 +32,14 @@ import org.apache.cayenne.DataObject;
public class UuidRelationshipBatchFaultingStrategy implements
UuidRelationshipFaultingStrategy {
- private ThreadLocal<UuidBatchFault> batchFaultHolder;
+ private ThreadLocal<List<UuidBatchSourceItem>> batchSources;
public UuidRelationshipBatchFaultingStrategy() {
- this.batchFaultHolder = new ThreadLocal<UuidBatchFault>();
+ this.batchSources = new ThreadLocal<List<UuidBatchSourceItem>>();
}
public void afterObjectLoaded(DataObject object) {
- UuidBatchFault batchFault = batchFaultHolder.get();
-
- if (batchFault == null) {
- batchFault = new UuidBatchFault(object.getObjectContext());
- batchFaultHolder.set(batchFault);
- }
-
String uuidProperty = uuidPropertyName(object);
String uuidRelationship = uuidRelationshipName(uuidProperty);
String uuid = (String) object.readProperty(uuidProperty);
@@ -51,15 +47,34 @@ public class UuidRelationshipBatchFaulti
object.writePropertyDirectly(uuidRelationship, null);
}
else {
- batchFault.addUuid(uuid);
- object.writePropertyDirectly(
- uuidRelationship,
- new UuidFault(batchFault, uuid));
+ List<UuidBatchSourceItem> sources = batchSources.get();
+
+ if (sources == null) {
+ sources = new ArrayList<UuidBatchSourceItem>();
+ batchSources.set(sources);
+ }
+
+ sources.add(new UuidBatchSourceItem(object, uuid, uuidRelationship));
}
}
public void afterQuery() {
- batchFaultHolder.set(null);
+
+ List<UuidBatchSourceItem> sources = batchSources.get();
+ if (sources != null) {
+ batchSources.set(null);
+
+ UuidBatchFault batchFault = new UuidBatchFault(sources
+ .get(0)
+ .getObject()
+ .getObjectContext(), sources);
+
+ for (UuidBatchSourceItem source : sources) {
+ source.getObject().writePropertyDirectly(
+ source.getUuidRelationship(),
+ new UuidFault(batchFault, source.getUuid()));
+ }
+ }
}
String uuidRelationshipName(String uuidPropertyName) {
@@ -71,10 +86,9 @@ public class UuidRelationshipBatchFaulti
UuidRelationship annotation = object.getClass().getAnnotation(
UuidRelationship.class);
- // TODO: look it up in the superclasses??
if (annotation == null) {
throw new IllegalArgumentException(
- "Object class is not annotated with 'MixinRelationship': "
+ "Object class is not annotated with @UuidRelationship: "
+ object.getClass().getName());
}
@@ -83,4 +97,5 @@ public class UuidRelationshipBatchFaulti
return annotation.value();
}
+
}