Author: dblevins
Date: Thu Jun 24 23:32:13 2010
New Revision: 957749
URL: http://svn.apache.org/viewvc?rev=957749&view=rev
Log:
More internal refactoring/cleanup. Created a MethodContext object to hold
metadata scoped at the bean method
Changed return type of LockType instead of a byte constant
Added:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/MethodContext.java
(with props)
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodConcurrencyBuilder.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BeanContext.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonContainer.java
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodConcurrencyBuilder.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodConcurrencyBuilder.java?rev=957749&r1=957748&r2=957749&view=diff
==============================================================================
---
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodConcurrencyBuilder.java
(original)
+++
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/MethodConcurrencyBuilder.java
Thu Jun 24 23:32:13 2010
@@ -22,6 +22,7 @@ import org.apache.openejb.DeploymentInfo
import org.apache.openejb.OpenEJBException;
import org.apache.openejb.core.CoreDeploymentInfo;
+import javax.ejb.LockType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -63,7 +64,8 @@ public class MethodConcurrencyBuilder {
MethodConcurrencyInfo value = (MethodConcurrencyInfo)
entry.getValue();
// logger.info(entry.getKey().toString() +" "+
value.transAttribute);
- deploymentInfo.setMethodConcurrencyAttribute(entry.getKey(),
value.concurrencyAttribute);
+ String s = value.concurrencyAttribute.toUpperCase();
+ deploymentInfo.setMethodConcurrencyAttribute(entry.getKey(),
LockType.valueOf(s));
}
}
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BeanContext.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BeanContext.java?rev=957749&r1=957748&r2=957749&view=diff
==============================================================================
---
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BeanContext.java
(original)
+++
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BeanContext.java
Thu Jun 24 23:32:13 2010
@@ -49,4 +49,5 @@ public class BeanContext extends Deploym
public ModuleContext getModuleContext() {
return moduleContext;
}
+
}
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java?rev=957749&r1=957748&r2=957749&view=diff
==============================================================================
---
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java
(original)
+++
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/CoreDeploymentInfo.java
Thu Jun 24 23:32:13 2010
@@ -36,6 +36,7 @@ import javax.ejb.EJBObject;
import javax.ejb.MessageDrivenBean;
import javax.ejb.TimedObject;
import javax.ejb.Timer;
+import javax.ejb.LockType;
import javax.naming.Context;
import javax.persistence.EntityManagerFactory;
@@ -100,37 +101,37 @@ public class CoreDeploymentInfo implemen
private EJBLocalHome ejbLocalHomeRef;
private String destinationId;
+ private String jarPath;
+
private String ejbName;
- private String moduleId;
private String runAs;
private final BeanContext context;
private Method createMethod = null;
- private final Map<Method, Method> postCreateMethodMap = new
HashMap<Method, Method>();
private final BeanType componentType;
+ private final Map<Method, Method> postCreateMethodMap = new
HashMap<Method, Method>();
private final Map<Method, Collection<String>> methodPermissions = new
HashMap<Method, Collection<String>>();
- private final Map<Method, Byte> methodConcurrencyAttributes = new
HashMap<Method, Byte>();
-
private final Map<Method, TransactionType> methodTransactionType = new
HashMap<Method, TransactionType>();
+ private final Map<Method, Method> methodMap = new HashMap<Method,
Method>();
+ private final Map<Method, MethodContext> methodContextMap = new
HashMap<Method, MethodContext>();
+
+ private Index<EntityManagerFactory,Map> extendedEntityManagerFactories;
+
private TransactionPolicyFactory transactionPolicyFactory;
private final List<MethodSchedule> methodSchedules = new
ArrayList<MethodSchedule>();
- private final Map<Method, List<InterceptorData>> methodInterceptors = new
HashMap<Method, List<InterceptorData>>();
private final List<InterceptorData> callbackInterceptors = new
ArrayList<InterceptorData>();
private final Set<InterceptorData> instanceScopedInterceptors = new
HashSet<InterceptorData>();
-
private final List<InterceptorInstance> systemInterceptors = new
ArrayList<InterceptorInstance>();
- private final Map<Method, Method> methodMap = new HashMap<Method,
Method>();
private final Map<String, String> securityRoleReferenceMap = new
HashMap<String, String>();
- private String jarPath;
private final Map<String, String> activationProperties = new
HashMap<String, String>();
private final List<Injection> injections = new ArrayList<Injection>();
- private Index<EntityManagerFactory,Map> extendedEntityManagerFactories;
private final Map<Class, InterfaceType> interfaces = new HashMap<Class,
InterfaceType>();
private final Map<Class, ExceptionType> exceptions = new HashMap<Class,
ExceptionType>();
+
private boolean loadOnStartup;
private boolean localbean;
private Duration accessTimeout;
@@ -358,23 +359,16 @@ public class CoreDeploymentInfo implemen
this.container = container;
}
+ /**
+ * TODO: Move to BeanContext
+ */
public BeanType getComponentType() {
return componentType;
}
- public byte getConcurrencyAttribute(Method method) {
- Byte byteWrapper = methodConcurrencyAttributes.get(method);
-
- if (byteWrapper == null){
- Method beanMethod = getMatchingBeanMethod(method);
- byteWrapper = methodConcurrencyAttributes.get(beanMethod);
- }
-
- if (byteWrapper == null) {
- return WRITE_LOCK;
- } else {
- return byteWrapper;
- }
+ public LockType getConcurrencyAttribute(Method beanMethod) {
+ LockType attribute =
getMethodContext(beanMethod).getMethodConcurrencyAttribute();
+ return (attribute == null)?LockType.WRITE: attribute;
}
public TransactionType getTransactionType(Method method) {
@@ -418,6 +412,9 @@ public class CoreDeploymentInfo implemen
this.transactionPolicyFactory = transactionPolicyFactory;
}
+ /**
+ * TODO: Remove unused
+ */
public Collection<String> getAuthorizedRoles(Method method) {
Collection<String> roleSet = methodPermissions.get(method);
if (roleSet == null) {
@@ -426,6 +423,9 @@ public class CoreDeploymentInfo implemen
return roleSet;
}
+ /**
+ * TODO: Remove unused
+ */
public String [] getAuthorizedRoles(String action) {
return null;
}
@@ -607,6 +607,9 @@ public class CoreDeploymentInfo implemen
return (method == null) ? interfaceMethod : method;
}
+ /**
+ * TODO: Remove unused
+ */
public void appendMethodPermissions(Method m, List<String> roleNames) {
Collection<String> hs = methodPermissions.get(m);
if (hs == null) {
@@ -618,6 +621,9 @@ public class CoreDeploymentInfo implemen
}
}
+ /**
+ * TODO: Remove unused
+ */
public String getSecurityRole(String securityRoleReference) {
return securityRoleReferenceMap.get(securityRoleReference);
}
@@ -626,17 +632,23 @@ public class CoreDeploymentInfo implemen
securityRoleReferenceMap.put(securityRoleReference, linkedRoleName);
}
- public void setMethodConcurrencyAttribute(Method method, String
concurrencyAttribute) {
- if ("Read".equals(concurrencyAttribute)){
- this.methodConcurrencyAttributes.put(method, READ_LOCK);
- } else if ("Write".equals(concurrencyAttribute)){
- this.methodConcurrencyAttributes.put(method, WRITE_LOCK);
- } else {
- throw new IllegalArgumentException("Unsupported
MethodConcurrencyAttribute '"+concurrencyAttribute+"'");
- }
+ public MethodContext getMethodContext(Method method) {
+ MethodContext methodContext = methodContextMap.get(method);
+ if (methodContext == null) {
+ methodContext = new MethodContext(context, method);
+ methodContextMap.put(method, methodContext);
+ }
+ return methodContext;
+ }
+
+ public void setMethodConcurrencyAttribute(Method method, LockType
concurrencyAttribute) {
+
getMethodContext(method).setMethodConcurrencyAttribute(concurrencyAttribute);
}
+ /**
+ * TODO: Move to MethodContext
+ */
public void setMethodTransactionAttribute(Method method, String
transAttribute) throws OpenEJBException {
TransactionType transactionType;
if (transAttribute.equalsIgnoreCase("Supports")) {
@@ -680,22 +692,37 @@ public class CoreDeploymentInfo implemen
methodTransactionType.put(method, transactionType);
}
+ /**
+ * TODO: Remove, not used
+ */
public List<Method> getAroundInvoke() {
return aroundInvoke;
}
+ /**
+ * TODO: Remove, not used
+ */
public List<Method> getPostConstruct() {
return postConstruct;
}
+ /**
+ * TODO: Remove, not used
+ */
public List<Method> getPreDestroy() {
return preDestroy;
}
+ /**
+ * TODO: Remove, not used
+ */
public List<Method> getPostActivate() {
return postActivate;
}
+ /**
+ * TODO: Remove, not used
+ */
public List<Method> getPrePassivate() {
return prePassivate;
}
@@ -704,35 +731,59 @@ public class CoreDeploymentInfo implemen
return removeMethods;
}
+ /**
+ * TODO: Remove, not used
+ */
public List<Method> getAfterBegin() {
return afterBegin;
}
+ /**
+ * TODO: Remove, not used
+ */
public List<Method> getBeforeCompletion() {
return beforeCompletion;
}
+ /**
+ * TODO: Remove, not used
+ */
public List<Method> getAfterCompletion() {
return afterCompletion;
}
+ /**
+ * TODO: Move to MethodContext
+ */
private final Map<Method, Boolean> removeExceptionPolicy = new
HashMap<Method,Boolean>();
+ /**
+ * TODO: Move to MethodContext
+ */
public void setRetainIfExeption(Method removeMethod, boolean retain){
if (getRemoveMethods().contains(removeMethod)){
removeExceptionPolicy.put(removeMethod, retain);
}
}
+ /**
+ * TODO: Move to MethodContext
+ */
public boolean retainIfExeption(Method removeMethod){
Boolean retain = removeExceptionPolicy.get(removeMethod);
return retain != null && retain;
}
+ /**
+ * TODO: Move to MethodContext
+ */
public List<MethodSchedule> getMethodSchedules() {
return methodSchedules;
}
+ /**
+ * TODO: Move to MethodContext
+ */
public void setMethodSchedules(List<MethodSchedule> schedules) {
methodSchedules.addAll(schedules);
}
@@ -773,13 +824,10 @@ public class CoreDeploymentInfo implemen
}
public List<InterceptorData> getMethodInterceptors(Method method) {
-
- List<InterceptorData> interceptors = methodInterceptors.get(method);
-
- return addSystemInterceptorDatas(interceptors);
+ return
addSystemInterceptorDatas(getMethodContext(method).getInterceptors());
}
- private List<InterceptorData>
addSystemInterceptorDatas(List<InterceptorData> interceptors) {
+ public List<InterceptorData>
addSystemInterceptorDatas(List<InterceptorData> interceptors) {
if (interceptors == null) interceptors = Collections.EMPTY_LIST;
if (systemInterceptors.size() <= 0) return interceptors;
@@ -798,7 +846,7 @@ public class CoreDeploymentInfo implemen
}
public void setMethodInterceptors(Method method, List<InterceptorData>
interceptors) {
- methodInterceptors.put(method, interceptors);
+ getMethodContext(method).getInterceptors().addAll(interceptors);
this.instanceScopedInterceptors.addAll(interceptors);
}
@@ -1020,6 +1068,9 @@ public class CoreDeploymentInfo implemen
this.primaryKeyField = primaryKeyField;
}
+ /**
+ * TODO: Remove, not used
+ */
public String [] getCmrFields() {
return cmrFields;
}
@@ -1040,6 +1091,9 @@ public class CoreDeploymentInfo implemen
queryMethodMap.put(queryMethod, queryString);
}
+ /**
+ * TODO: Remove, not used
+ */
public String getQuery(Method queryMethod) {
return queryMethodMap.get(queryMethod);
}
@@ -1072,6 +1126,9 @@ public class CoreDeploymentInfo implemen
this.jarPath = jarPath;
}
+ /**
+ * TODO: Remove, not used
+ */
public String getJarPath() {
return jarPath;
}
@@ -1108,10 +1165,6 @@ public class CoreDeploymentInfo implemen
this.ejbName = ejbName;
}
- public void setModuleId(String moduleId) {
- this.moduleId = moduleId;
- }
-
public void setRunAs(String runAs) {
this.runAs = runAs;
}
Added:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/MethodContext.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/MethodContext.java?rev=957749&view=auto
==============================================================================
---
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/MethodContext.java
(added)
+++
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/MethodContext.java
Thu Jun 24 23:32:13 2010
@@ -0,0 +1,107 @@
+/**
+ * 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.openejb.core;
+
+import org.apache.openejb.core.interceptor.InterceptorData;
+import org.apache.openejb.core.transaction.TransactionType;
+import org.apache.openejb.core.timer.ScheduleData;
+import org.apache.openejb.util.Duration;
+
+import javax.ejb.LockType;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MethodContext {
+ private final BeanContext beanContext;
+ private final Method beanMethod;
+ private final List<ScheduleData> schedules = new ArrayList<ScheduleData>();
+ private final List<InterceptorData> methodInterceptors = new
ArrayList<InterceptorData>();
+ private LockType methodConcurrencyAttribute;
+ private TransactionType transactionType;
+ private Duration accessTimeout;
+
+ /**
+ * Only initialized if this method represents metadata
+ * associated with a specific interface view and not the
+ * bean method itself.
+ */
+ private MethodContext beanMethodContext;
+
+ public MethodContext(BeanContext beanContext, Method beanMethod) {
+ this.beanContext = beanContext;
+ this.beanMethod = beanMethod;
+ }
+
+ public Duration getAccessTimeout() {
+ return accessTimeout;
+ }
+
+ public void setAccessTimeout(Duration accessTimeout) {
+ this.accessTimeout = accessTimeout;
+ }
+
+ public BeanContext getBeanContext() {
+ return beanContext;
+ }
+
+ public Method getBeanMethod() {
+ return beanMethod;
+ }
+
+ public List<InterceptorData> getInterceptors() {
+ return methodInterceptors;
+ }
+
+ public LockType getMethodConcurrencyAttribute() {
+ return methodConcurrencyAttribute;
+ }
+
+ public void setMethodConcurrencyAttribute(LockType
methodConcurrencyAttribute) {
+ this.methodConcurrencyAttribute = methodConcurrencyAttribute;
+ }
+
+ public TransactionType getTransactionType() {
+ return transactionType;
+ }
+
+ public void setTransactionType(TransactionType transactionType) {
+ this.transactionType = transactionType;
+ }
+
+
+ public static class InterfaceMethodContext {
+ private final MethodContext beanMethod;
+ private TransactionType transactionType;
+
+ public InterfaceMethodContext(MethodContext beanMethod) {
+ this.beanMethod = beanMethod;
+ }
+
+ public void setTransactionType(TransactionType transactionType) {
+ this.transactionType = transactionType;
+ }
+
+ public TransactionType getTransactionType() {
+ return transactionType != null ? transactionType :
beanMethod.getTransactionType();
+ }
+ }
+}
Propchange:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/MethodContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonContainer.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonContainer.java?rev=957749&r1=957748&r2=957749&view=diff
==============================================================================
---
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonContainer.java
(original)
+++
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonContainer.java
Thu Jun 24 23:32:13 2010
@@ -42,6 +42,7 @@ import javax.ejb.EJBHome;
import javax.ejb.EJBLocalHome;
import javax.ejb.EJBLocalObject;
import javax.ejb.EJBObject;
+import javax.ejb.LockType;
import javax.interceptor.AroundInvoke;
import org.apache.openejb.ContainerType;
@@ -244,7 +245,7 @@ public class SingletonContainer implemen
protected Object _invoke(Method callMethod, Method runMethod, Object[]
args, Instance instance, ThreadContext callContext, InterfaceType callType)
throws OpenEJBException {
CoreDeploymentInfo deploymentInfo = callContext.getDeploymentInfo();
- boolean read = deploymentInfo.getConcurrencyAttribute(runMethod) ==
DeploymentInfo.READ_LOCK;
+ boolean read = deploymentInfo.getConcurrencyAttribute(runMethod) ==
javax.ejb.LockType.READ;
final Lock lock = aquireLock(read, instance);