You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2012/02/19 23:32:13 UTC

svn commit: r1291077 [2/4] - in /openejb/trunk/openejb/examples: bean-validation-design-by-contract/ bean-validation-design-by-contract/src/main/java/org/superbiz/designbycontract/ bean-validation-design-by-contract/src/test/java/ cdi-interceptors/ cdi...

Modified: openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestrictAndLog.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestrictAndLog.java?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestrictAndLog.java (original)
+++ openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestrictAndLog.java Sun Feb 19 22:32:10 2012
@@ -1,38 +1,38 @@
-/**
- * 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.superbiz.cdi.bookshow.interceptorbinding;
-
-import javax.interceptor.InterceptorBinding;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-/**
- *This InterceptorBinding inherits from @Log and @TimeRestricted Interceptor-Bindings.
- */
-@Inherited
-@InterceptorBinding
-@Target({TYPE, METHOD})
-@Retention(RUNTIME)
-@Log
-@TimeRestricted
-public @interface TimeRestrictAndLog {
-}
+/**
+ * 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.superbiz.cdi.bookshow.interceptorbinding;
+
+import javax.interceptor.InterceptorBinding;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ *This InterceptorBinding inherits from @Log and @TimeRestricted Interceptor-Bindings.
+ */
+@Inherited
+@InterceptorBinding
+@Target({TYPE, METHOD})
+@Retention(RUNTIME)
+@Log
+@TimeRestricted
+public @interface TimeRestrictAndLog {
+}

Modified: openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestricted.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestricted.java?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestricted.java (original)
+++ openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptorbinding/TimeRestricted.java Sun Feb 19 22:32:10 2012
@@ -1,31 +1,31 @@
-/**
- * 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.superbiz.cdi.bookshow.interceptorbinding;
-
-import javax.interceptor.InterceptorBinding;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-@InterceptorBinding
-@Target({TYPE, METHOD})
-@Retention(RUNTIME)
-public @interface TimeRestricted {
-}
+/**
+ * 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.superbiz.cdi.bookshow.interceptorbinding;
+
+import javax.interceptor.InterceptorBinding;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@InterceptorBinding
+@Target({TYPE, METHOD})
+@Retention(RUNTIME)
+public @interface TimeRestricted {
+}

Modified: openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowLoggingInterceptor.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowLoggingInterceptor.java?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowLoggingInterceptor.java (original)
+++ openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowLoggingInterceptor.java Sun Feb 19 22:32:10 2012
@@ -1,57 +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.
- */
-/**
- * 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.superbiz.cdi.bookshow.interceptors;
-
-import org.superbiz.cdi.bookshow.interceptorbinding.Log;
-import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker;
-
-import javax.interceptor.AroundInvoke;
-import javax.interceptor.Interceptor;
-import javax.interceptor.InvocationContext;
-import java.io.Serializable;
-import java.util.logging.Logger;
-
-@Interceptor
-@Log
-public class BookForAShowLoggingInterceptor implements Serializable {
-    private static final long serialVersionUID = 8139854519874743530L;
-    private Logger logger = Logger.getLogger("BookForAShowApplicationLogger");
-
-    @AroundInvoke
-    public Object logMethodEntry(InvocationContext ctx) throws Exception {
-        logger.info("Before entering method:" + ctx.getMethod().getName());
-        InterceptionOrderTracker.getMethodsInterceptedList().add(ctx.getMethod().getName());
-        InterceptionOrderTracker.getInterceptedByList().add(this.getClass().getSimpleName());
-        return ctx.proceed();
-    }
-}
+/**
+ * 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.
+ */
+/**
+ * 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.superbiz.cdi.bookshow.interceptors;
+
+import org.superbiz.cdi.bookshow.interceptorbinding.Log;
+import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+import java.io.Serializable;
+import java.util.logging.Logger;
+
+@Interceptor
+@Log
+public class BookForAShowLoggingInterceptor implements Serializable {
+    private static final long serialVersionUID = 8139854519874743530L;
+    private Logger logger = Logger.getLogger("BookForAShowApplicationLogger");
+
+    @AroundInvoke
+    public Object logMethodEntry(InvocationContext ctx) throws Exception {
+        logger.info("Before entering method:" + ctx.getMethod().getName());
+        InterceptionOrderTracker.getMethodsInterceptedList().add(ctx.getMethod().getName());
+        InterceptionOrderTracker.getInterceptedByList().add(this.getClass().getSimpleName());
+        return ctx.proceed();
+    }
+}

Modified: openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/TimeBasedRestrictingInterceptor.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/TimeBasedRestrictingInterceptor.java?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/TimeBasedRestrictingInterceptor.java (original)
+++ openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/interceptors/TimeBasedRestrictingInterceptor.java Sun Feb 19 22:32:10 2012
@@ -1,50 +1,50 @@
-/**
- * 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.superbiz.cdi.bookshow.interceptors;
-
-import org.superbiz.cdi.AccessDeniedException;
-import org.superbiz.cdi.bookshow.interceptorbinding.TimeRestricted;
-import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker;
-
-import javax.interceptor.AroundInvoke;
-import javax.interceptor.Interceptor;
-import javax.interceptor.InvocationContext;
-import java.io.Serializable;
-
-@Interceptor
-@TimeRestricted
-public class TimeBasedRestrictingInterceptor implements Serializable {
-    private static final long serialVersionUID = 8139854519874743530L;
-
-    @AroundInvoke
-    public Object restrictAccessBasedOnTime(InvocationContext ctx) throws Exception {
-        InterceptionOrderTracker.getMethodsInterceptedList().add(ctx.getMethod().getName());
-        InterceptionOrderTracker.getInterceptedByList().add(this.getClass().getSimpleName());
-        if (!isWorkingHours()) {
-            throw new AccessDeniedException("You are not allowed to access the method at this time");
-        }
-        return ctx.proceed();
-    }
-
-    private boolean isWorkingHours() {
-        /*
-         * int hourOfDay = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); if (hourOfDay >= 9 && hourOfDay <= 21) {
-         * return true; } else { return false; }
-         */
-        return true; // Let's assume
-    }
-}
+/**
+ * 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.superbiz.cdi.bookshow.interceptors;
+
+import org.superbiz.cdi.AccessDeniedException;
+import org.superbiz.cdi.bookshow.interceptorbinding.TimeRestricted;
+import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+import java.io.Serializable;
+
+@Interceptor
+@TimeRestricted
+public class TimeBasedRestrictingInterceptor implements Serializable {
+    private static final long serialVersionUID = 8139854519874743530L;
+
+    @AroundInvoke
+    public Object restrictAccessBasedOnTime(InvocationContext ctx) throws Exception {
+        InterceptionOrderTracker.getMethodsInterceptedList().add(ctx.getMethod().getName());
+        InterceptionOrderTracker.getInterceptedByList().add(this.getClass().getSimpleName());
+        if (!isWorkingHours()) {
+            throw new AccessDeniedException("You are not allowed to access the method at this time");
+        }
+        return ctx.proceed();
+    }
+
+    private boolean isWorkingHours() {
+        /*
+         * int hourOfDay = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); if (hourOfDay >= 9 && hourOfDay <= 21) {
+         * return true; } else { return false; }
+         */
+        return true; // Let's assume
+    }
+}

Modified: openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/tracker/InterceptionOrderTracker.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/tracker/InterceptionOrderTracker.java?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/tracker/InterceptionOrderTracker.java (original)
+++ openejb/trunk/openejb/examples/cdi-interceptors/src/main/java/org/superbiz/cdi/bookshow/tracker/InterceptionOrderTracker.java Sun Feb 19 22:32:10 2012
@@ -1,48 +1,48 @@
-/**
- * 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.superbiz.cdi.bookshow.tracker;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * A helper class for the test. 
- * Keeps track of methods intercepted during one testXXX run
- * Keeps track of interceptors applied during one textXXX run
- */
-public class InterceptionOrderTracker {
-    /*
-     * Contains method names that were intercepted by the interceptors
-     */
-    private static List<String> methodsInterceptedList = new ArrayList<String>();
-    /*
-     * Contains the name of the interceptor class that intercepted a method
-     */
-    private static List<String> interceptedByList = new ArrayList<String>();
-
-    public static List<String> getInterceptedByList() {
-        return interceptedByList;
-    }
-
-    public static void setInterceptedByList(List<String> interceptedByList) {
-        InterceptionOrderTracker.interceptedByList = interceptedByList;
-    }
-
-    public static List<String> getMethodsInterceptedList() {
-        return methodsInterceptedList;
-    }
-}
+/**
+ * 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.superbiz.cdi.bookshow.tracker;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A helper class for the test. 
+ * Keeps track of methods intercepted during one testXXX run
+ * Keeps track of interceptors applied during one textXXX run
+ */
+public class InterceptionOrderTracker {
+    /*
+     * Contains method names that were intercepted by the interceptors
+     */
+    private static List<String> methodsInterceptedList = new ArrayList<String>();
+    /*
+     * Contains the name of the interceptor class that intercepted a method
+     */
+    private static List<String> interceptedByList = new ArrayList<String>();
+
+    public static List<String> getInterceptedByList() {
+        return interceptedByList;
+    }
+
+    public static void setInterceptedByList(List<String> interceptedByList) {
+        InterceptionOrderTracker.interceptedByList = interceptedByList;
+    }
+
+    public static List<String> getMethodsInterceptedList() {
+        return methodsInterceptedList;
+    }
+}

Modified: openejb/trunk/openejb/examples/cdi-interceptors/src/main/resources/META-INF/beans.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-interceptors/src/main/resources/META-INF/beans.xml?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/cdi-interceptors/src/main/resources/META-INF/beans.xml (original)
+++ openejb/trunk/openejb/examples/cdi-interceptors/src/main/resources/META-INF/beans.xml Sun Feb 19 22:32:10 2012
@@ -1,33 +1,33 @@
-<!--
-
-    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.
--->
-<beans>
-  <!-- By default, a bean archive has no enabled interceptors bound via interceptor 
-    bindings. An interceptor must be explicitly enabled by listing its class 
-    under the element of the beans.xml file of the bean archive. The order of 
-    the interceptor declarations determines the interceptor ordering. Interceptors 
-    which occur earlier in the list are called first. If the same class is listed 
-    twice under the interceptors element, the container automatically detects 
-    the problem and treats it as a deployment problem. -->
-
-  <interceptors>
-    <class>org.superbiz.cdi.bookshow.interceptors.BookForAShowLoggingInterceptor
-    </class>
-    <class>org.superbiz.cdi.bookshow.interceptors.TimeBasedRestrictingInterceptor
-    </class>
-  </interceptors>
-</beans>
+<!--
+
+    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.
+-->
+<beans>
+  <!-- By default, a bean archive has no enabled interceptors bound via interceptor 
+    bindings. An interceptor must be explicitly enabled by listing its class 
+    under the element of the beans.xml file of the bean archive. The order of 
+    the interceptor declarations determines the interceptor ordering. Interceptors 
+    which occur earlier in the list are called first. If the same class is listed 
+    twice under the interceptors element, the container automatically detects 
+    the problem and treats it as a deployment problem. -->
+
+  <interceptors>
+    <class>org.superbiz.cdi.bookshow.interceptors.BookForAShowLoggingInterceptor
+    </class>
+    <class>org.superbiz.cdi.bookshow.interceptors.TimeBasedRestrictingInterceptor
+    </class>
+  </interceptors>
+</beans>

Modified: openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOldStyleInterceptorBindingTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOldStyleInterceptorBindingTest.java?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOldStyleInterceptorBindingTest.java (original)
+++ openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOldStyleInterceptorBindingTest.java Sun Feb 19 22:32:10 2012
@@ -1,57 +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.superbiz.cdi.bookshow.interceptors;
-
-import junit.framework.TestCase;
-import org.superbiz.cdi.bookshow.beans.BookForAShowOldStyleInterceptorBinding;
-import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker;
-
-import javax.ejb.EJB;
-import javax.ejb.embeddable.EJBContainer;
-
-public class BookForAShowOldStyleInterceptorBindingTest extends TestCase {
-    @EJB
-    private BookForAShowOldStyleInterceptorBinding bookForAShowBean;
-    EJBContainer ejbContainer;
-
-    /**
-     * Bootstrap the Embedded EJB Container
-     *
-     * @throws Exception
-     */
-    protected void setUp() throws Exception {
-        ejbContainer = EJBContainer.createEJBContainer();
-        ejbContainer.getContext().bind("inject", this);
-    }
-
-    /**
-     * Test basic interception
-     */
-    public void testMethodShouldBeIntercepted() {
-        // action
-        bookForAShowBean.getMoviesList();
-        // verify
-        assertTrue(InterceptionOrderTracker.getMethodsInterceptedList().contains("getMoviesList"));
-    }
-
-    protected void tearDown() {
-        // clear the lists after each test
-        InterceptionOrderTracker.getInterceptedByList().clear();
-        InterceptionOrderTracker.getMethodsInterceptedList().clear();
-        ejbContainer.close();
-    }
-}
+/**
+ * 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.superbiz.cdi.bookshow.interceptors;
+
+import junit.framework.TestCase;
+import org.superbiz.cdi.bookshow.beans.BookForAShowOldStyleInterceptorBinding;
+import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker;
+
+import javax.ejb.EJB;
+import javax.ejb.embeddable.EJBContainer;
+
+public class BookForAShowOldStyleInterceptorBindingTest extends TestCase {
+    @EJB
+    private BookForAShowOldStyleInterceptorBinding bookForAShowBean;
+    EJBContainer ejbContainer;
+
+    /**
+     * Bootstrap the Embedded EJB Container
+     *
+     * @throws Exception
+     */
+    protected void setUp() throws Exception {
+        ejbContainer = EJBContainer.createEJBContainer();
+        ejbContainer.getContext().bind("inject", this);
+    }
+
+    /**
+     * Test basic interception
+     */
+    public void testMethodShouldBeIntercepted() {
+        // action
+        bookForAShowBean.getMoviesList();
+        // verify
+        assertTrue(InterceptionOrderTracker.getMethodsInterceptedList().contains("getMoviesList"));
+    }
+
+    protected void tearDown() {
+        // clear the lists after each test
+        InterceptionOrderTracker.getInterceptedByList().clear();
+        InterceptionOrderTracker.getMethodsInterceptedList().clear();
+        ejbContainer.close();
+    }
+}

Modified: openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOneInterceptorAppliedTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOneInterceptorAppliedTest.java?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOneInterceptorAppliedTest.java (original)
+++ openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowOneInterceptorAppliedTest.java Sun Feb 19 22:32:10 2012
@@ -1,57 +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.superbiz.cdi.bookshow.interceptors;
-
-import junit.framework.TestCase;
-import org.superbiz.cdi.bookshow.beans.BookForAShowOneInterceptorApplied;
-import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker;
-
-import javax.ejb.EJB;
-import javax.ejb.embeddable.EJBContainer;
-
-public class BookForAShowOneInterceptorAppliedTest extends TestCase {
-    @EJB
-    private BookForAShowOneInterceptorApplied bookForAShowBean;
-    EJBContainer ejbContainer;
-
-    /**
-     * Bootstrap the Embedded EJB Container
-     *
-     * @throws Exception
-     */
-    protected void setUp() throws Exception {
-        ejbContainer = EJBContainer.createEJBContainer();
-        ejbContainer.getContext().bind("inject", this);
-    }
-
-    /**
-     * Test basic interception
-     */
-    public void testMethodShouldBeIntercepted() {
-        // action
-        bookForAShowBean.getMoviesList();
-        // verify
-        assertTrue(InterceptionOrderTracker.getMethodsInterceptedList().contains("getMoviesList"));
-    }
-
-    protected void tearDown() {
-        // clear the list after each test
-        InterceptionOrderTracker.getInterceptedByList().clear();
-        InterceptionOrderTracker.getMethodsInterceptedList().clear();
-        ejbContainer.close();
-    }
-}
+/**
+ * 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.superbiz.cdi.bookshow.interceptors;
+
+import junit.framework.TestCase;
+import org.superbiz.cdi.bookshow.beans.BookForAShowOneInterceptorApplied;
+import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker;
+
+import javax.ejb.EJB;
+import javax.ejb.embeddable.EJBContainer;
+
+public class BookForAShowOneInterceptorAppliedTest extends TestCase {
+    @EJB
+    private BookForAShowOneInterceptorApplied bookForAShowBean;
+    EJBContainer ejbContainer;
+
+    /**
+     * Bootstrap the Embedded EJB Container
+     *
+     * @throws Exception
+     */
+    protected void setUp() throws Exception {
+        ejbContainer = EJBContainer.createEJBContainer();
+        ejbContainer.getContext().bind("inject", this);
+    }
+
+    /**
+     * Test basic interception
+     */
+    public void testMethodShouldBeIntercepted() {
+        // action
+        bookForAShowBean.getMoviesList();
+        // verify
+        assertTrue(InterceptionOrderTracker.getMethodsInterceptedList().contains("getMoviesList"));
+    }
+
+    protected void tearDown() {
+        // clear the list after each test
+        InterceptionOrderTracker.getInterceptedByList().clear();
+        InterceptionOrderTracker.getMethodsInterceptedList().clear();
+        ejbContainer.close();
+    }
+}

Modified: openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowTwoInterceptorsAppiledTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowTwoInterceptorsAppiledTest.java?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowTwoInterceptorsAppiledTest.java (original)
+++ openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookForAShowTwoInterceptorsAppiledTest.java Sun Feb 19 22:32:10 2012
@@ -1,69 +1,69 @@
-/**
- * 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.superbiz.cdi.bookshow.interceptors;
-
-import junit.framework.TestCase;
-import org.superbiz.cdi.bookshow.beans.BookForAShowTwoInterceptorsApplied;
-import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker;
-
-import javax.ejb.EJB;
-import javax.ejb.embeddable.EJBContainer;
-import java.util.List;
-
-public class BookForAShowTwoInterceptorsAppiledTest extends TestCase {
-    @EJB
-    private BookForAShowTwoInterceptorsApplied bookForAShowBean;
-    EJBContainer ejbContainer;
-
-    /**
-     * Bootstrap the Embedded EJB Container
-     *
-     * @throws Exception
-     */
-    protected void setUp() throws Exception {
-        ejbContainer = EJBContainer.createEJBContainer();
-        ejbContainer.getContext().bind("inject", this);
-    }
-
-    /**
-     * Interceptors should be applied in order as defined in beans.xml
-     */
-    public void testInterceptorsShouldBeAppliedInOrder() {
-        // action
-        bookForAShowBean.getDiscountedPrice(100);
-        // verify
-        List<String> interceptedByList = InterceptionOrderTracker.getInterceptedByList();
-        int indexOfLogger = interceptedByList.indexOf("BookForAShowLoggingInterceptor");
-        int indexOfTimeBasedRestrictor = interceptedByList.indexOf("TimeBasedRestrictingInterceptor");
-        assertTrue(indexOfLogger < indexOfTimeBasedRestrictor);
-    }
-
-    public void testTwoInterceptorsWereInvoked() {
-        // action
-        bookForAShowBean.getDiscountedPrice(100);
-        // verify
-        List<String> interceptedByList = InterceptionOrderTracker.getInterceptedByList();
-        assertTrue(interceptedByList.contains("BookForAShowLoggingInterceptor") && interceptedByList.contains("TimeBasedRestrictingInterceptor"));
-    }
-
-    protected void tearDown() {
-        // clear the lists after each test
-        InterceptionOrderTracker.getInterceptedByList().clear();
-        InterceptionOrderTracker.getMethodsInterceptedList().clear();
-        ejbContainer.close();
-    }
-}
+/**
+ * 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.superbiz.cdi.bookshow.interceptors;
+
+import junit.framework.TestCase;
+import org.superbiz.cdi.bookshow.beans.BookForAShowTwoInterceptorsApplied;
+import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker;
+
+import javax.ejb.EJB;
+import javax.ejb.embeddable.EJBContainer;
+import java.util.List;
+
+public class BookForAShowTwoInterceptorsAppiledTest extends TestCase {
+    @EJB
+    private BookForAShowTwoInterceptorsApplied bookForAShowBean;
+    EJBContainer ejbContainer;
+
+    /**
+     * Bootstrap the Embedded EJB Container
+     *
+     * @throws Exception
+     */
+    protected void setUp() throws Exception {
+        ejbContainer = EJBContainer.createEJBContainer();
+        ejbContainer.getContext().bind("inject", this);
+    }
+
+    /**
+     * Interceptors should be applied in order as defined in beans.xml
+     */
+    public void testInterceptorsShouldBeAppliedInOrder() {
+        // action
+        bookForAShowBean.getDiscountedPrice(100);
+        // verify
+        List<String> interceptedByList = InterceptionOrderTracker.getInterceptedByList();
+        int indexOfLogger = interceptedByList.indexOf("BookForAShowLoggingInterceptor");
+        int indexOfTimeBasedRestrictor = interceptedByList.indexOf("TimeBasedRestrictingInterceptor");
+        assertTrue(indexOfLogger < indexOfTimeBasedRestrictor);
+    }
+
+    public void testTwoInterceptorsWereInvoked() {
+        // action
+        bookForAShowBean.getDiscountedPrice(100);
+        // verify
+        List<String> interceptedByList = InterceptionOrderTracker.getInterceptedByList();
+        assertTrue(interceptedByList.contains("BookForAShowLoggingInterceptor") && interceptedByList.contains("TimeBasedRestrictingInterceptor"));
+    }
+
+    protected void tearDown() {
+        // clear the lists after each test
+        InterceptionOrderTracker.getInterceptedByList().clear();
+        InterceptionOrderTracker.getMethodsInterceptedList().clear();
+        ejbContainer.close();
+    }
+}

Modified: openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowInterceptorBindingInheritanceTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowInterceptorBindingInheritanceTest.java?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowInterceptorBindingInheritanceTest.java (original)
+++ openejb/trunk/openejb/examples/cdi-interceptors/src/test/java/org/superbiz/cdi/bookshow/interceptors/BookShowInterceptorBindingInheritanceTest.java Sun Feb 19 22:32:10 2012
@@ -1,57 +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.superbiz.cdi.bookshow.interceptors;
-
-import junit.framework.TestCase;
-import org.superbiz.cdi.bookshow.beans.BookShowInterceptorBindingInheritanceExplored;
-import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker;
-
-import javax.ejb.EJB;
-import javax.ejb.embeddable.EJBContainer;
-import java.util.List;
-
-public class BookShowInterceptorBindingInheritanceTest extends TestCase {
-    @EJB
-    private BookShowInterceptorBindingInheritanceExplored bookForAShowBean;
-    EJBContainer ejbContainer;
-
-    /**
-     * Bootstrap the Embedded EJB Container
-     *
-     * @throws Exception
-     */
-    protected void setUp() throws Exception {
-        ejbContainer = EJBContainer.createEJBContainer();
-        ejbContainer.getContext().bind("inject", this);
-    }
-
-    public void testInterceptorBindingCanInheritFromAnotherBinding() {
-        // action
-        bookForAShowBean.getDiscountedPrice(100);
-        // verify both interceptors were invoked
-        List<String> interceptedByList = InterceptionOrderTracker.getInterceptedByList();
-        System.out.println("Intercepted by:" + interceptedByList);
-        assertTrue(interceptedByList.contains("BookForAShowLoggingInterceptor") && interceptedByList.contains("TimeBasedRestrictingInterceptor"));
-    }
-
-    protected void tearDown() {
-        // clear the list after each test
-        InterceptionOrderTracker.getInterceptedByList().clear();
-        InterceptionOrderTracker.getMethodsInterceptedList().clear();
-        ejbContainer.close();
-    }
-}
+/**
+ * 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.superbiz.cdi.bookshow.interceptors;
+
+import junit.framework.TestCase;
+import org.superbiz.cdi.bookshow.beans.BookShowInterceptorBindingInheritanceExplored;
+import org.superbiz.cdi.bookshow.tracker.InterceptionOrderTracker;
+
+import javax.ejb.EJB;
+import javax.ejb.embeddable.EJBContainer;
+import java.util.List;
+
+public class BookShowInterceptorBindingInheritanceTest extends TestCase {
+    @EJB
+    private BookShowInterceptorBindingInheritanceExplored bookForAShowBean;
+    EJBContainer ejbContainer;
+
+    /**
+     * Bootstrap the Embedded EJB Container
+     *
+     * @throws Exception
+     */
+    protected void setUp() throws Exception {
+        ejbContainer = EJBContainer.createEJBContainer();
+        ejbContainer.getContext().bind("inject", this);
+    }
+
+    public void testInterceptorBindingCanInheritFromAnotherBinding() {
+        // action
+        bookForAShowBean.getDiscountedPrice(100);
+        // verify both interceptors were invoked
+        List<String> interceptedByList = InterceptionOrderTracker.getInterceptedByList();
+        System.out.println("Intercepted by:" + interceptedByList);
+        assertTrue(interceptedByList.contains("BookForAShowLoggingInterceptor") && interceptedByList.contains("TimeBasedRestrictingInterceptor"));
+    }
+
+    protected void tearDown() {
+        // clear the list after each test
+        InterceptionOrderTracker.getInterceptedByList().clear();
+        InterceptionOrderTracker.getMethodsInterceptedList().clear();
+        ejbContainer.close();
+    }
+}

Modified: openejb/trunk/openejb/examples/dynamic-datasource-routing/README.md
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/dynamic-datasource-routing/README.md?rev=1291077&r1=1291076&r2=1291077&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/dynamic-datasource-routing/README.md (original)
+++ openejb/trunk/openejb/examples/dynamic-datasource-routing/README.md Sun Feb 19 22:32:10 2012
@@ -1,407 +1,407 @@
-Title: Dynamic Datasource Routing
-
-The TomEE dynamic datasource api aims to allow to use multiple data sources as one from an application point of view.
-
-It can be useful for technical reasons (load balancing for example) or more generally
-functionnal reasons (filtering, aggregation, enriching...). However please note you can choose
-only one datasource by transaction. It means the goal of this feature is not to switch more than
-once of datasource in a transaction. The following code will not work:
-
-    @Stateless
-    public class MyEJB {
-        @Resource private MyRouter router;
-        @PersistenceContext private EntityManager em;
-
-        public void workWithDataSources() {
-            router.setDataSource("ds1");
-            em.persist(new MyEntity());
-
-            router.setDataSource("ds2"); // same transaction -> this invocation doesn't work
-            em.persist(new MyEntity());
-        }
-    }
-
-In this example the implementation simply use a datasource from its name and needs to be set before using any JPA
-operation in the transaction (to keep the logic simple in the example).
-
-# The implementation of the Router
-
-Our router has two configuration parameters:
-* a list of jndi names representing datasources to use
-* a default datasource to use
-
-## Router implementation
-
-The interface Router (`org.apache.openejb.resource.jdbc.Router`) has only one method to implement, `public DataSource getDataSource()`
-
-Our `DeterminedRouter` implementation uses a ThreadLocal to manage the currently used datasource. Keep in mind JPA used more than once the getDatasource() method
-for one operation. To change the datasource in one transaction is dangerous and should be avoid.
-
-    package org.superbiz.dynamicdatasourcerouting;
-
-    import org.apache.openejb.resource.jdbc.AbstractRouter;
-
-    import javax.naming.NamingException;
-    import javax.sql.DataSource;
-    import java.util.Map;
-    import java.util.concurrent.ConcurrentHashMap;
-
-    /**
-     * @author Romain Manni-Bucau
-     */
-    public class DeterminedRouter extends AbstractRouter {
-        private String dataSourceNames;
-        private String defaultDataSourceName;
-        private Map<String, DataSource> dataSources = null;
-        private ThreadLocal<DataSource> currentDataSource = new ThreadLocal<DataSource>();
-
-        /**
-         * @param datasourceList datasource resource name, separator is a space
-         */
-        public void setDataSourceNames(String datasourceList) {
-            dataSourceNames = datasourceList;
-        }
-
-        /**
-         * lookup datasource in openejb resources
-         */
-        private void init() {
-            dataSources = new ConcurrentHashMap<String, DataSource>();
-            for (String ds : dataSourceNames.split(" ")) {
-                try {
-                    Object o = getOpenEJBResource(ds);
-                    if (o instanceof DataSource) {
-                        dataSources.put(ds, DataSource.class.cast(o));
-                    }
-                } catch (NamingException e) {
-                    // ignored
-                }
-            }
-        }
-
-        /**
-         * @return the user selected data source if it is set
-         *         or the default one
-         *  @throws IllegalArgumentException if the data source is not found
-         */
-        @Override
-        public DataSource getDataSource() {
-            // lazy init of routed datasources
-            if (dataSources == null) {
-                init();
-            }
-
-            // if no datasource is selected use the default one
-            if (currentDataSource.get() == null) {
-                if (dataSources.containsKey(defaultDataSourceName)) {
-                    return dataSources.get(defaultDataSourceName);
-
-                } else {
-                    throw new IllegalArgumentException("you have to specify at least one datasource");
-                }
-            }
-
-            // the developper set the datasource to use
-            return currentDataSource.get();
-        }
-
-        /**
-         *
-         * @param datasourceName data source name
-         */
-        public void setDataSource(String datasourceName) {
-            if (dataSources == null) {
-                init();
-            }
-            if (!dataSources.containsKey(datasourceName)) {
-                throw new IllegalArgumentException("data source called " + datasourceName + " can't be found.");
-            }
-            DataSource ds = dataSources.get(datasourceName);
-            currentDataSource.set(ds);
-        }
-
-        /**
-         * reset the data source
-         */
-        public void clear() {
-            currentDataSource.remove();
-        }
-
-        public void setDefaultDataSourceName(String name) {
-            this.defaultDataSourceName = name;
-        }
-    }
-
-## Declaring the implementation
-
-To be able to use your router as a resource you need to provide a service configuration. It is done in a file
-you can find in META-INF/org.router/ and called service-jar.xml
-(for your implementation you can of course change the package name).
-
-It contains the following code:
-
-    <ServiceJar>
-      <ServiceProvider id="DeterminedRouter" <!-- the name you want to use -->
-          service="Resource"
-          type="org.apache.openejb.resource.jdbc.Router"
-          class-name="org.superbiz.dynamicdatasourcerouting.DeterminedRouter"> <!-- implementation class -->
-
-        # the parameters
-
-        DataSourceNames
-        DefaultDataSourceName
-      </ServiceProvider>
-    </ServiceJar>
-
-
-# Using the Router
-
-Here we have a `RoutedPersister` stateless bean which uses our `DeterminedRouter`
-
-    package org.superbiz.dynamicdatasourcerouting;
-
-    import javax.annotation.Resource;
-    import javax.ejb.Stateless;
-    import javax.persistence.EntityManager;
-    import javax.persistence.PersistenceContext;
-
-    /**
-     * @author Romain Manni-Bucau
-     */
-    @Stateless
-    public class RoutedPersister {
-        @PersistenceContext(unitName = "router")
-        private EntityManager em;
-
-        @Resource(name = "My Router", type = DeterminedRouter.class)
-        private DeterminedRouter router;
-
-        public void persist(int id, String name, String ds) {
-            router.setDataSource(ds);
-            em.persist(new Person(id, name));
-        }
-    }
-
-# The test
-
-In test mode and using property style configuration the foolowing configuration is used:
-
-    public class DynamicDataSourceTest {
-        @Test
-        public void route() throws Exception {
-            String[] databases = new String[]{"database1", "database2", "database3"};
-
-            Properties properties = new Properties();
-            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
-
-            // resources
-            // datasources
-            for (int i = 1; i <= databases.length; i++) {
-                String dbName = databases[i - 1];
-                properties.setProperty(dbName, "new://Resource?type=DataSource");
-                dbName += ".";
-                properties.setProperty(dbName + "JdbcDriver", "org.hsqldb.jdbcDriver");
-                properties.setProperty(dbName + "JdbcUrl", "jdbc:hsqldb:mem:db" + i);
-                properties.setProperty(dbName + "UserName", "sa");
-                properties.setProperty(dbName + "Password", "");
-                properties.setProperty(dbName + "JtaManaged", "true");
-            }
-
-            // router
-            properties.setProperty("My Router", "new://Resource?provider=org.router:DeterminedRouter&type=" + DeterminedRouter.class.getName());
-            properties.setProperty("My Router.DatasourceNames", "database1 database2 database3");
-            properties.setProperty("My Router.DefaultDataSourceName", "database1");
-
-            // routed datasource
-            properties.setProperty("Routed Datasource", "new://Resource?provider=RoutedDataSource&type=" + Router.class.getName());
-            properties.setProperty("Routed Datasource.Router", "My Router");
-
-            Context ctx = EJBContainer.createEJBContainer(properties).getContext();
-            RoutedPersister ejb = (RoutedPersister) ctx.lookup("java:global/dynamic-datasource-routing/RoutedPersister");
-            for (int i = 0; i < 18; i++) {
-                // persisting a person on database db -> kind of manual round robin
-                String name = "record " + i;
-                String db = databases[i % 3];
-                ejb.persist(i, name, db);
-            }
-
-            // assert database records number using jdbc
-            for (int i = 1; i <= databases.length; i++) {
-                Connection connection = DriverManager.getConnection("jdbc:hsqldb:mem:db" + i, "sa", "");
-                Statement st = connection.createStatement();
-                ResultSet rs = st.executeQuery("select count(*) from PERSON");
-                rs.next();
-                assertEquals(6, rs.getInt(1));
-                st.close();
-                connection.close();
-            }
-
-            ctx.close();
-        }
-    }
-
-# Configuration via openejb.xml
-
-The testcase above uses properties for configuration.  The identical way to do it via the `conf/openejb.xml` is as follows:
-
-    <!-- Router and datasource -->
-    <Resource id="My Router" type="org.apache.openejb.router.test.DynamicDataSourceTest$DeterminedRouter" provider="org.routertest:DeterminedRouter">
-        DatasourceNames = database1 database2 database3
-        DefaultDataSourceName = database1
-    </Resource>
-    <Resource id="Routed Datasource" type="org.apache.openejb.resource.jdbc.Router" provider="RoutedDataSource">
-        Router = My Router
-    </Resource>
-
-    <!-- real datasources -->
-    <Resource id="database1" type="DataSource">
-        JdbcDriver = org.hsqldb.jdbcDriver
-        JdbcUrl = jdbc:hsqldb:mem:db1
-        UserName = sa
-        Password
-        JtaManaged = true
-    </Resource>
-    <Resource id="database2" type="DataSource">
-        JdbcDriver = org.hsqldb.jdbcDriver
-        JdbcUrl = jdbc:hsqldb:mem:db2
-        UserName = sa
-        Password
-        JtaManaged = true
-    </Resource>
-    <Resource id="database3" type="DataSource">
-        JdbcDriver = org.hsqldb.jdbcDriver
-        JdbcUrl = jdbc:hsqldb:mem:db3
-        UserName = sa
-        Password
-        JtaManaged = true
-    </Resource>
-
-
-
-
-## Some hack for OpenJPA
-
-Using more than one datasource behind one EntityManager means the databases are already created. If it is not the case,
-the JPA provider has to create the datasource at boot time.
-
-Hibernate do it so if you declare your databases it will work. However with OpenJPA
-(the default JPA provider for OpenEJB), the creation is lazy and it happens only once so when you'll switch of database
-it will no more work.
-
-Of course OpenEJB provides @Singleton and @Startup features of Java EE 6 and we can do a bean just making a simple find,
-even on none existing entities, just to force the database creation:
-
-    @Startup
-    @Singleton
-    public class BoostrapUtility {
-        // inject all real databases
-
-        @PersistenceContext(unitName = "db1")
-        private EntityManager em1;
-
-        @PersistenceContext(unitName = "db2")
-        private EntityManager em2;
-
-        @PersistenceContext(unitName = "db3")
-        private EntityManager em3;
-
-        // force database creation
-
-        @PostConstruct
-        @TransactionAttribute(TransactionAttributeType.SUPPORTS)
-        public void initDatabase() {
-            em1.find(Person.class, 0);
-            em2.find(Person.class, 0);
-            em3.find(Person.class, 0);
-        }
-    }
-
-## Using the routed datasource
-
-Now you configured the way you want to route your JPA operation, you registered the resources and you initialized
-your databases you can use it and see how it is simple:
-
-    @Stateless
-    public class RoutedPersister {
-        // injection of the "proxied" datasource
-        @PersistenceContext(unitName = "router")
-        private EntityManager em;
-
-        // injection of the router you need it to configured the database
-        @Resource(name = "My Router", type = DeterminedRouter.class)
-        private DeterminedRouter router;
-
-        public void persist(int id, String name, String ds) {
-            router.setDataSource(ds); // configuring the database for the current transaction
-            em.persist(new Person(id, name)); // will use ds database automatically
-        }
-    }
-
-# Running
-
-
-    -------------------------------------------------------
-     T E S T S
-    -------------------------------------------------------
-    Running org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest
-    Apache OpenEJB 4.0.0-beta-1    build: 20111002-04:06
-    http://openejb.apache.org/
-    INFO - openejb.home = /Users/dblevins/examples/dynamic-datasource-routing
-    INFO - openejb.base = /Users/dblevins/examples/dynamic-datasource-routing
-    INFO - Using 'javax.ejb.embeddable.EJBContainer=true'
-    INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
-    INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
-    INFO - Configuring Service(id=My Router, type=Resource, provider-id=DeterminedRouter)
-    INFO - Configuring Service(id=database3, type=Resource, provider-id=Default JDBC Database)
-    INFO - Configuring Service(id=database2, type=Resource, provider-id=Default JDBC Database)
-    INFO - Configuring Service(id=Routed Datasource, type=Resource, provider-id=RoutedDataSource)
-    INFO - Configuring Service(id=database1, type=Resource, provider-id=Default JDBC Database)
-    INFO - Found EjbModule in classpath: /Users/dblevins/examples/dynamic-datasource-routing/target/classes
-    INFO - Beginning load: /Users/dblevins/examples/dynamic-datasource-routing/target/classes
-    INFO - Configuring enterprise application: /Users/dblevins/examples/dynamic-datasource-routing
-    WARN - Method 'lookup' is not available for 'javax.annotation.Resource'. Probably using an older Runtime.
-    INFO - Configuring Service(id=Default Singleton Container, type=Container, provider-id=Default Singleton Container)
-    INFO - Auto-creating a container for bean BoostrapUtility: Container(type=SINGLETON, id=Default Singleton Container)
-    INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container)
-    INFO - Auto-creating a container for bean RoutedPersister: Container(type=STATELESS, id=Default Stateless Container)
-    INFO - Auto-linking resource-ref 'java:comp/env/My Router' in bean RoutedPersister to Resource(id=My Router)
-    INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
-    INFO - Auto-creating a container for bean org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest: Container(type=MANAGED, id=Default Managed Container)
-    INFO - Configuring PersistenceUnit(name=router)
-    INFO - Configuring PersistenceUnit(name=db1)
-    INFO - Auto-creating a Resource with id 'database1NonJta' of type 'DataSource for 'db1'.
-    INFO - Configuring Service(id=database1NonJta, type=Resource, provider-id=database1)
-    INFO - Adjusting PersistenceUnit db1 <non-jta-data-source> to Resource ID 'database1NonJta' from 'null'
-    INFO - Configuring PersistenceUnit(name=db2)
-    INFO - Auto-creating a Resource with id 'database2NonJta' of type 'DataSource for 'db2'.
-    INFO - Configuring Service(id=database2NonJta, type=Resource, provider-id=database2)
-    INFO - Adjusting PersistenceUnit db2 <non-jta-data-source> to Resource ID 'database2NonJta' from 'null'
-    INFO - Configuring PersistenceUnit(name=db3)
-    INFO - Auto-creating a Resource with id 'database3NonJta' of type 'DataSource for 'db3'.
-    INFO - Configuring Service(id=database3NonJta, type=Resource, provider-id=database3)
-    INFO - Adjusting PersistenceUnit db3 <non-jta-data-source> to Resource ID 'database3NonJta' from 'null'
-    INFO - Enterprise application "/Users/dblevins/examples/dynamic-datasource-routing" loaded.
-    INFO - Assembling app: /Users/dblevins/examples/dynamic-datasource-routing
-    INFO - PersistenceUnit(name=router, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 504ms
-    INFO - PersistenceUnit(name=db1, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 11ms
-    INFO - PersistenceUnit(name=db2, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 7ms
-    INFO - PersistenceUnit(name=db3, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 6ms
-    INFO - Jndi(name="java:global/dynamic-datasource-routing/BoostrapUtility!org.superbiz.dynamicdatasourcerouting.BoostrapUtility")
-    INFO - Jndi(name="java:global/dynamic-datasource-routing/BoostrapUtility")
-    INFO - Jndi(name="java:global/dynamic-datasource-routing/RoutedPersister!org.superbiz.dynamicdatasourcerouting.RoutedPersister")
-    INFO - Jndi(name="java:global/dynamic-datasource-routing/RoutedPersister")
-    INFO - Jndi(name="java:global/EjbModule1519652738/org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest!org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest")
-    INFO - Jndi(name="java:global/EjbModule1519652738/org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest")
-    INFO - Created Ejb(deployment-id=RoutedPersister, ejb-name=RoutedPersister, container=Default Stateless Container)
-    INFO - Created Ejb(deployment-id=org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest, ejb-name=org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest, container=Default Managed Container)
-    INFO - Created Ejb(deployment-id=BoostrapUtility, ejb-name=BoostrapUtility, container=Default Singleton Container)
-    INFO - Started Ejb(deployment-id=RoutedPersister, ejb-name=RoutedPersister, container=Default Stateless Container)
-    INFO - Started Ejb(deployment-id=org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest, ejb-name=org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest, container=Default Managed Container)
-    INFO - Started Ejb(deployment-id=BoostrapUtility, ejb-name=BoostrapUtility, container=Default Singleton Container)
-    INFO - Deployed Application(path=/Users/dblevins/examples/dynamic-datasource-routing)
-    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.504 sec
-
-    Results :
-
-    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
-
+Title: Dynamic Datasource Routing
+
+The TomEE dynamic datasource api aims to allow to use multiple data sources as one from an application point of view.
+
+It can be useful for technical reasons (load balancing for example) or more generally
+functionnal reasons (filtering, aggregation, enriching...). However please note you can choose
+only one datasource by transaction. It means the goal of this feature is not to switch more than
+once of datasource in a transaction. The following code will not work:
+
+    @Stateless
+    public class MyEJB {
+        @Resource private MyRouter router;
+        @PersistenceContext private EntityManager em;
+
+        public void workWithDataSources() {
+            router.setDataSource("ds1");
+            em.persist(new MyEntity());
+
+            router.setDataSource("ds2"); // same transaction -> this invocation doesn't work
+            em.persist(new MyEntity());
+        }
+    }
+
+In this example the implementation simply use a datasource from its name and needs to be set before using any JPA
+operation in the transaction (to keep the logic simple in the example).
+
+# The implementation of the Router
+
+Our router has two configuration parameters:
+* a list of jndi names representing datasources to use
+* a default datasource to use
+
+## Router implementation
+
+The interface Router (`org.apache.openejb.resource.jdbc.Router`) has only one method to implement, `public DataSource getDataSource()`
+
+Our `DeterminedRouter` implementation uses a ThreadLocal to manage the currently used datasource. Keep in mind JPA used more than once the getDatasource() method
+for one operation. To change the datasource in one transaction is dangerous and should be avoid.
+
+    package org.superbiz.dynamicdatasourcerouting;
+
+    import org.apache.openejb.resource.jdbc.AbstractRouter;
+
+    import javax.naming.NamingException;
+    import javax.sql.DataSource;
+    import java.util.Map;
+    import java.util.concurrent.ConcurrentHashMap;
+
+    /**
+     * @author Romain Manni-Bucau
+     */
+    public class DeterminedRouter extends AbstractRouter {
+        private String dataSourceNames;
+        private String defaultDataSourceName;
+        private Map<String, DataSource> dataSources = null;
+        private ThreadLocal<DataSource> currentDataSource = new ThreadLocal<DataSource>();
+
+        /**
+         * @param datasourceList datasource resource name, separator is a space
+         */
+        public void setDataSourceNames(String datasourceList) {
+            dataSourceNames = datasourceList;
+        }
+
+        /**
+         * lookup datasource in openejb resources
+         */
+        private void init() {
+            dataSources = new ConcurrentHashMap<String, DataSource>();
+            for (String ds : dataSourceNames.split(" ")) {
+                try {
+                    Object o = getOpenEJBResource(ds);
+                    if (o instanceof DataSource) {
+                        dataSources.put(ds, DataSource.class.cast(o));
+                    }
+                } catch (NamingException e) {
+                    // ignored
+                }
+            }
+        }
+
+        /**
+         * @return the user selected data source if it is set
+         *         or the default one
+         *  @throws IllegalArgumentException if the data source is not found
+         */
+        @Override
+        public DataSource getDataSource() {
+            // lazy init of routed datasources
+            if (dataSources == null) {
+                init();
+            }
+
+            // if no datasource is selected use the default one
+            if (currentDataSource.get() == null) {
+                if (dataSources.containsKey(defaultDataSourceName)) {
+                    return dataSources.get(defaultDataSourceName);
+
+                } else {
+                    throw new IllegalArgumentException("you have to specify at least one datasource");
+                }
+            }
+
+            // the developper set the datasource to use
+            return currentDataSource.get();
+        }
+
+        /**
+         *
+         * @param datasourceName data source name
+         */
+        public void setDataSource(String datasourceName) {
+            if (dataSources == null) {
+                init();
+            }
+            if (!dataSources.containsKey(datasourceName)) {
+                throw new IllegalArgumentException("data source called " + datasourceName + " can't be found.");
+            }
+            DataSource ds = dataSources.get(datasourceName);
+            currentDataSource.set(ds);
+        }
+
+        /**
+         * reset the data source
+         */
+        public void clear() {
+            currentDataSource.remove();
+        }
+
+        public void setDefaultDataSourceName(String name) {
+            this.defaultDataSourceName = name;
+        }
+    }
+
+## Declaring the implementation
+
+To be able to use your router as a resource you need to provide a service configuration. It is done in a file
+you can find in META-INF/org.router/ and called service-jar.xml
+(for your implementation you can of course change the package name).
+
+It contains the following code:
+
+    <ServiceJar>
+      <ServiceProvider id="DeterminedRouter" <!-- the name you want to use -->
+          service="Resource"
+          type="org.apache.openejb.resource.jdbc.Router"
+          class-name="org.superbiz.dynamicdatasourcerouting.DeterminedRouter"> <!-- implementation class -->
+
+        # the parameters
+
+        DataSourceNames
+        DefaultDataSourceName
+      </ServiceProvider>
+    </ServiceJar>
+
+
+# Using the Router
+
+Here we have a `RoutedPersister` stateless bean which uses our `DeterminedRouter`
+
+    package org.superbiz.dynamicdatasourcerouting;
+
+    import javax.annotation.Resource;
+    import javax.ejb.Stateless;
+    import javax.persistence.EntityManager;
+    import javax.persistence.PersistenceContext;
+
+    /**
+     * @author Romain Manni-Bucau
+     */
+    @Stateless
+    public class RoutedPersister {
+        @PersistenceContext(unitName = "router")
+        private EntityManager em;
+
+        @Resource(name = "My Router", type = DeterminedRouter.class)
+        private DeterminedRouter router;
+
+        public void persist(int id, String name, String ds) {
+            router.setDataSource(ds);
+            em.persist(new Person(id, name));
+        }
+    }
+
+# The test
+
+In test mode and using property style configuration the foolowing configuration is used:
+
+    public class DynamicDataSourceTest {
+        @Test
+        public void route() throws Exception {
+            String[] databases = new String[]{"database1", "database2", "database3"};
+
+            Properties properties = new Properties();
+            properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
+
+            // resources
+            // datasources
+            for (int i = 1; i <= databases.length; i++) {
+                String dbName = databases[i - 1];
+                properties.setProperty(dbName, "new://Resource?type=DataSource");
+                dbName += ".";
+                properties.setProperty(dbName + "JdbcDriver", "org.hsqldb.jdbcDriver");
+                properties.setProperty(dbName + "JdbcUrl", "jdbc:hsqldb:mem:db" + i);
+                properties.setProperty(dbName + "UserName", "sa");
+                properties.setProperty(dbName + "Password", "");
+                properties.setProperty(dbName + "JtaManaged", "true");
+            }
+
+            // router
+            properties.setProperty("My Router", "new://Resource?provider=org.router:DeterminedRouter&type=" + DeterminedRouter.class.getName());
+            properties.setProperty("My Router.DatasourceNames", "database1 database2 database3");
+            properties.setProperty("My Router.DefaultDataSourceName", "database1");
+
+            // routed datasource
+            properties.setProperty("Routed Datasource", "new://Resource?provider=RoutedDataSource&type=" + Router.class.getName());
+            properties.setProperty("Routed Datasource.Router", "My Router");
+
+            Context ctx = EJBContainer.createEJBContainer(properties).getContext();
+            RoutedPersister ejb = (RoutedPersister) ctx.lookup("java:global/dynamic-datasource-routing/RoutedPersister");
+            for (int i = 0; i < 18; i++) {
+                // persisting a person on database db -> kind of manual round robin
+                String name = "record " + i;
+                String db = databases[i % 3];
+                ejb.persist(i, name, db);
+            }
+
+            // assert database records number using jdbc
+            for (int i = 1; i <= databases.length; i++) {
+                Connection connection = DriverManager.getConnection("jdbc:hsqldb:mem:db" + i, "sa", "");
+                Statement st = connection.createStatement();
+                ResultSet rs = st.executeQuery("select count(*) from PERSON");
+                rs.next();
+                assertEquals(6, rs.getInt(1));
+                st.close();
+                connection.close();
+            }
+
+            ctx.close();
+        }
+    }
+
+# Configuration via openejb.xml
+
+The testcase above uses properties for configuration.  The identical way to do it via the `conf/openejb.xml` is as follows:
+
+    <!-- Router and datasource -->
+    <Resource id="My Router" type="org.apache.openejb.router.test.DynamicDataSourceTest$DeterminedRouter" provider="org.routertest:DeterminedRouter">
+        DatasourceNames = database1 database2 database3
+        DefaultDataSourceName = database1
+    </Resource>
+    <Resource id="Routed Datasource" type="org.apache.openejb.resource.jdbc.Router" provider="RoutedDataSource">
+        Router = My Router
+    </Resource>
+
+    <!-- real datasources -->
+    <Resource id="database1" type="DataSource">
+        JdbcDriver = org.hsqldb.jdbcDriver
+        JdbcUrl = jdbc:hsqldb:mem:db1
+        UserName = sa
+        Password
+        JtaManaged = true
+    </Resource>
+    <Resource id="database2" type="DataSource">
+        JdbcDriver = org.hsqldb.jdbcDriver
+        JdbcUrl = jdbc:hsqldb:mem:db2
+        UserName = sa
+        Password
+        JtaManaged = true
+    </Resource>
+    <Resource id="database3" type="DataSource">
+        JdbcDriver = org.hsqldb.jdbcDriver
+        JdbcUrl = jdbc:hsqldb:mem:db3
+        UserName = sa
+        Password
+        JtaManaged = true
+    </Resource>
+
+
+
+
+## Some hack for OpenJPA
+
+Using more than one datasource behind one EntityManager means the databases are already created. If it is not the case,
+the JPA provider has to create the datasource at boot time.
+
+Hibernate do it so if you declare your databases it will work. However with OpenJPA
+(the default JPA provider for OpenEJB), the creation is lazy and it happens only once so when you'll switch of database
+it will no more work.
+
+Of course OpenEJB provides @Singleton and @Startup features of Java EE 6 and we can do a bean just making a simple find,
+even on none existing entities, just to force the database creation:
+
+    @Startup
+    @Singleton
+    public class BoostrapUtility {
+        // inject all real databases
+
+        @PersistenceContext(unitName = "db1")
+        private EntityManager em1;
+
+        @PersistenceContext(unitName = "db2")
+        private EntityManager em2;
+
+        @PersistenceContext(unitName = "db3")
+        private EntityManager em3;
+
+        // force database creation
+
+        @PostConstruct
+        @TransactionAttribute(TransactionAttributeType.SUPPORTS)
+        public void initDatabase() {
+            em1.find(Person.class, 0);
+            em2.find(Person.class, 0);
+            em3.find(Person.class, 0);
+        }
+    }
+
+## Using the routed datasource
+
+Now you configured the way you want to route your JPA operation, you registered the resources and you initialized
+your databases you can use it and see how it is simple:
+
+    @Stateless
+    public class RoutedPersister {
+        // injection of the "proxied" datasource
+        @PersistenceContext(unitName = "router")
+        private EntityManager em;
+
+        // injection of the router you need it to configured the database
+        @Resource(name = "My Router", type = DeterminedRouter.class)
+        private DeterminedRouter router;
+
+        public void persist(int id, String name, String ds) {
+            router.setDataSource(ds); // configuring the database for the current transaction
+            em.persist(new Person(id, name)); // will use ds database automatically
+        }
+    }
+
+# Running
+
+
+    -------------------------------------------------------
+     T E S T S
+    -------------------------------------------------------
+    Running org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest
+    Apache OpenEJB 4.0.0-beta-1    build: 20111002-04:06
+    http://openejb.apache.org/
+    INFO - openejb.home = /Users/dblevins/examples/dynamic-datasource-routing
+    INFO - openejb.base = /Users/dblevins/examples/dynamic-datasource-routing
+    INFO - Using 'javax.ejb.embeddable.EJBContainer=true'
+    INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service)
+    INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager)
+    INFO - Configuring Service(id=My Router, type=Resource, provider-id=DeterminedRouter)
+    INFO - Configuring Service(id=database3, type=Resource, provider-id=Default JDBC Database)
+    INFO - Configuring Service(id=database2, type=Resource, provider-id=Default JDBC Database)
+    INFO - Configuring Service(id=Routed Datasource, type=Resource, provider-id=RoutedDataSource)
+    INFO - Configuring Service(id=database1, type=Resource, provider-id=Default JDBC Database)
+    INFO - Found EjbModule in classpath: /Users/dblevins/examples/dynamic-datasource-routing/target/classes
+    INFO - Beginning load: /Users/dblevins/examples/dynamic-datasource-routing/target/classes
+    INFO - Configuring enterprise application: /Users/dblevins/examples/dynamic-datasource-routing
+    WARN - Method 'lookup' is not available for 'javax.annotation.Resource'. Probably using an older Runtime.
+    INFO - Configuring Service(id=Default Singleton Container, type=Container, provider-id=Default Singleton Container)
+    INFO - Auto-creating a container for bean BoostrapUtility: Container(type=SINGLETON, id=Default Singleton Container)
+    INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container)
+    INFO - Auto-creating a container for bean RoutedPersister: Container(type=STATELESS, id=Default Stateless Container)
+    INFO - Auto-linking resource-ref 'java:comp/env/My Router' in bean RoutedPersister to Resource(id=My Router)
+    INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
+    INFO - Auto-creating a container for bean org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest: Container(type=MANAGED, id=Default Managed Container)
+    INFO - Configuring PersistenceUnit(name=router)
+    INFO - Configuring PersistenceUnit(name=db1)
+    INFO - Auto-creating a Resource with id 'database1NonJta' of type 'DataSource for 'db1'.
+    INFO - Configuring Service(id=database1NonJta, type=Resource, provider-id=database1)
+    INFO - Adjusting PersistenceUnit db1 <non-jta-data-source> to Resource ID 'database1NonJta' from 'null'
+    INFO - Configuring PersistenceUnit(name=db2)
+    INFO - Auto-creating a Resource with id 'database2NonJta' of type 'DataSource for 'db2'.
+    INFO - Configuring Service(id=database2NonJta, type=Resource, provider-id=database2)
+    INFO - Adjusting PersistenceUnit db2 <non-jta-data-source> to Resource ID 'database2NonJta' from 'null'
+    INFO - Configuring PersistenceUnit(name=db3)
+    INFO - Auto-creating a Resource with id 'database3NonJta' of type 'DataSource for 'db3'.
+    INFO - Configuring Service(id=database3NonJta, type=Resource, provider-id=database3)
+    INFO - Adjusting PersistenceUnit db3 <non-jta-data-source> to Resource ID 'database3NonJta' from 'null'
+    INFO - Enterprise application "/Users/dblevins/examples/dynamic-datasource-routing" loaded.
+    INFO - Assembling app: /Users/dblevins/examples/dynamic-datasource-routing
+    INFO - PersistenceUnit(name=router, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 504ms
+    INFO - PersistenceUnit(name=db1, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 11ms
+    INFO - PersistenceUnit(name=db2, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 7ms
+    INFO - PersistenceUnit(name=db3, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 6ms
+    INFO - Jndi(name="java:global/dynamic-datasource-routing/BoostrapUtility!org.superbiz.dynamicdatasourcerouting.BoostrapUtility")
+    INFO - Jndi(name="java:global/dynamic-datasource-routing/BoostrapUtility")
+    INFO - Jndi(name="java:global/dynamic-datasource-routing/RoutedPersister!org.superbiz.dynamicdatasourcerouting.RoutedPersister")
+    INFO - Jndi(name="java:global/dynamic-datasource-routing/RoutedPersister")
+    INFO - Jndi(name="java:global/EjbModule1519652738/org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest!org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest")
+    INFO - Jndi(name="java:global/EjbModule1519652738/org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest")
+    INFO - Created Ejb(deployment-id=RoutedPersister, ejb-name=RoutedPersister, container=Default Stateless Container)
+    INFO - Created Ejb(deployment-id=org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest, ejb-name=org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest, container=Default Managed Container)
+    INFO - Created Ejb(deployment-id=BoostrapUtility, ejb-name=BoostrapUtility, container=Default Singleton Container)
+    INFO - Started Ejb(deployment-id=RoutedPersister, ejb-name=RoutedPersister, container=Default Stateless Container)
+    INFO - Started Ejb(deployment-id=org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest, ejb-name=org.superbiz.dynamicdatasourcerouting.DynamicDataSourceTest, container=Default Managed Container)
+    INFO - Started Ejb(deployment-id=BoostrapUtility, ejb-name=BoostrapUtility, container=Default Singleton Container)
+    INFO - Deployed Application(path=/Users/dblevins/examples/dynamic-datasource-routing)
+    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.504 sec
+
+    Results :
+
+    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+