tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: TOMEE-1592 basic support of java:/ jboss like resource name + basic support of comparable for managed tasks (not yet fully wired)
Date Tue, 26 May 2015 13:35:31 GMT
Repository: tomee
Updated Branches:
  refs/heads/master cdb04c3b9 -> 5a2545310


TOMEE-1592 basic support of java:/ jboss like resource name + basic support of comparable
for managed tasks (not yet fully wired)


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/5a254531
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/5a254531
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/5a254531

Branch: refs/heads/master
Commit: 5a254531053b662e3dcdf40c95006a803d6cb3ca
Parents: cdb04c3
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Tue May 26 15:33:54 2015 +0200
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Tue May 26 15:33:54 2015 +0200

----------------------------------------------------------------------
 .../openejb/assembler/classic/Assembler.java    |  5 +-
 .../apache/openejb/cdi/OpenEJBLifecycle.java    |  2 +-
 .../openejb/config/AnnotationDeployer.java      |  2 +-
 .../org/apache/openejb/config/AutoConfig.java   | 13 +++-
 .../openejb/config/ConfigurationFactory.java    |  5 ++
 .../config/ConvertDataSourceDefinitions.java    |  1 +
 .../openejb/config/JndiEncInfoBuilder.java      |  3 +
 .../apache/openejb/config/SunConversion.java    |  2 +-
 .../apache/openejb/threads/future/CUFuture.java |  7 +-
 .../threads/future/CUScheduleFuture.java        |  2 +-
 .../impl/ManagedExecutorServiceImpl.java        |  6 +-
 .../org/apache/openejb/threads/task/CUTask.java |  7 +-
 .../jdbc/JBossLikeDataSourceInjectionTest.java  | 80 ++++++++++++++++++++
 13 files changed, 123 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/5a254531/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
index b6cdaf9..e0cde14 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
@@ -1028,7 +1028,10 @@ public class Assembler extends AssemblerTool implements org.apache.openejb.spi.A
                 for (final Bean<?> bean : appContext.getWebBeansContext().getBeanManagerImpl().getBeans())
{
                     if (ResourceBean.class.isInstance(bean)) {
                         final ResourceReference reference = ResourceBean.class.cast(bean).getReference();
-                        final String jndi = reference.getJndiName().replace("java:", "");
+                        String jndi = reference.getJndiName().replace("java:", "");
+                        if (reference.getJndiName().startsWith("java:/")) {
+                            jndi = jndi.substring(1);
+                        }
                         Object lookup = bindings.get(jndi);
                         if (lookup == null && reference.getAnnotation(EJB.class)
!= null) {
                             final CdiPlugin plugin = CdiPlugin.class.cast(appContext.getWebBeansContext().getPluginLoader().getEjbPlugin());

http://git-wip-us.apache.org/repos/asf/tomee/blob/5a254531/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
b/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
index 3bfa8ad..dd25ddf 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
@@ -440,7 +440,7 @@ public class OpenEJBLifecycle implements ContainerLifecycle {
         }
         else
         {
-            logger.warning("Default JSPFactroy instance has not found. Skipping OWB JSP handling");
+            logger.debug("Default JSPFactroy instance has not found. Skipping OWB JSP handling");
         }
     }
 

http://git-wip-us.apache.org/repos/asf/tomee/blob/5a254531/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
b/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
index 00adadc..711c35a 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
@@ -4178,7 +4178,7 @@ public class AnnotationDeployer implements DynamicDeployer {
 
         private String normalize(final String refName) {
             if (refName.startsWith("java:")) {
-                return refName;
+                return refName.startsWith("/") ? refName.substring(1) : refName;
             }
             return "java:comp/env/" + refName;
         }

http://git-wip-us.apache.org/repos/asf/tomee/blob/5a254531/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
b/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
index 90883db..b634ce5 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
@@ -1056,7 +1056,7 @@ public class AutoConfig implements DynamicDeployer, JndiConstants {
     private String dataSourceLookupName(final Resource datasource) {
         final String jndi = datasource.getJndi();
         if (jndi.startsWith("java:")) {
-            return jndi;
+            return jndi.startsWith("/") ? jndi.substring(1) : jndi;
         }
         if (jndi.startsWith("comp/env/")) {
             return "java:" + jndi;
@@ -1190,6 +1190,9 @@ public class AutoConfig implements DynamicDeployer, JndiConstants {
                 if (id.startsWith("java:")) {
                     id = id.substring("java:".length());
                 }
+                if (id.startsWith("/")) {
+                    id = id.substring(1);
+                }
                 try {
                     final AppModule appModule = ejbModule.getAppModule();
                     if (appModule != null) {
@@ -1942,7 +1945,10 @@ public class AutoConfig implements DynamicDeployer, JndiConstants {
         }
 
         if (resourceId.startsWith("java:")) { // can be an absolute path
-            final String jndi = resourceId.substring("java:".length());
+            String jndi = resourceId.substring("java:".length());
+            if (jndi.startsWith("/")) {
+                jndi = jndi.substring(1);
+            }
             if (ServiceUtils.hasServiceProvider(jndi)) {
                 return jndi;
             }
@@ -2125,6 +2131,9 @@ public class AutoConfig implements DynamicDeployer, JndiConstants {
 
         if (resourceId.startsWith("java:")) {
             resourceId = resourceId.substring("java:".length());
+            if (resourceId.startsWith("/")) {
+                resourceId = resourceId.substring(1);
+            }
         }
 
         // strip off "java:comp/env"

http://git-wip-us.apache.org/repos/asf/tomee/blob/5a254531/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
b/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
index 6f6c787..5254f72 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
@@ -1227,6 +1227,11 @@ public class ConfigurationFactory implements OpenEjbConfigurationFactory
{
                 throw new OpenEJBException(messages.format("configureService.cannotInstantiateClass",
infoType.getName()), e);
             }
 
+            // some jndi adjustment
+            if (service.getId().startsWith("java:/")) {
+                service.setId(service.getId().substring("java:/".length()));
+            }
+
             info.service = provider.getService();
             info.types.addAll(provider.getTypes());
             info.description = provider.getDescription();

http://git-wip-us.apache.org/repos/asf/tomee/blob/5a254531/container/openejb-core/src/main/java/org/apache/openejb/config/ConvertDataSourceDefinitions.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/ConvertDataSourceDefinitions.java
b/container/openejb-core/src/main/java/org/apache/openejb/config/ConvertDataSourceDefinitions.java
index a1d7634..5353379 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/ConvertDataSourceDefinitions.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/ConvertDataSourceDefinitions.java
@@ -63,6 +63,7 @@ public class ConvertDataSourceDefinitions implements DynamicDeployer {
     private Resource toResource(final DataSource datasource) {
         String name = datasource.getName();
         name = name.replaceFirst("java:comp/env/", "");
+        name = name.replaceFirst("java:/", "");
         name = name.replaceFirst("java:", "");
 
         final Resource def = new Resource(name, javax.sql.DataSource.class.getName());

http://git-wip-us.apache.org/repos/asf/tomee/blob/5a254531/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java
b/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java
index 223a2d3..20bdaf0 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/JndiEncInfoBuilder.java
@@ -588,6 +588,9 @@ public class JndiEncInfoBuilder {
         } else if (name.startsWith("java:comp/")) {
             i.referenceName = name.substring(5);
             comp.add(i);
+        } else if (name.startsWith("java:/")) {
+            i.referenceName = name.substring(6);
+            comp.add(i);
         } else {
             logger.warning("config.invalid.referenceName.suffix", name);
         }

http://git-wip-us.apache.org/repos/asf/tomee/blob/5a254531/container/openejb-core/src/main/java/org/apache/openejb/config/SunConversion.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/SunConversion.java
b/container/openejb-core/src/main/java/org/apache/openejb/config/SunConversion.java
index bbf9bad..5f40caa 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/SunConversion.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/SunConversion.java
@@ -465,7 +465,7 @@ public class SunConversion implements DynamicDeployer {
         if (!refName.startsWith("java:")) {
             refName = "java:comp/env/" + refName;
         }
-        return refName;
+        return refName.startsWith("java:/") ? "java:" + refName.substring("java:/".length())
: refName;
     }
 
     public void convertModule(final WebModule webModule) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/5a254531/container/openejb-core/src/main/java/org/apache/openejb/threads/future/CUFuture.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/threads/future/CUFuture.java
b/container/openejb-core/src/main/java/org/apache/openejb/threads/future/CUFuture.java
index ecbdb95..d41ccfb 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/threads/future/CUFuture.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/threads/future/CUFuture.java
@@ -24,7 +24,7 @@ import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
-public class CUFuture<V> implements Future<V> {
+public class CUFuture<V, C> implements Future<V>, Comparable<C> {
     protected final Future<V> delegate;
     protected final ManagedTaskListenerTask listener;
 
@@ -59,4 +59,9 @@ public class CUFuture<V> implements Future<V> {
     public V get(final long timeout, final TimeUnit unit) throws InterruptedException, ExecutionException,
TimeoutException {
         return delegate.get(timeout, unit);
     }
+
+    @Override
+    public int compareTo(final C o) {
+        return Comparable.class.isInstance(delegate) ? Comparable.class.cast(delegate).compareTo(o)
: -1;
+    }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/5a254531/container/openejb-core/src/main/java/org/apache/openejb/threads/future/CUScheduleFuture.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/threads/future/CUScheduleFuture.java
b/container/openejb-core/src/main/java/org/apache/openejb/threads/future/CUScheduleFuture.java
index 7e3a2c5..027f560 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/threads/future/CUScheduleFuture.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/threads/future/CUScheduleFuture.java
@@ -22,7 +22,7 @@ import java.util.concurrent.Delayed;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 
-public class CUScheduleFuture<V> extends CUFuture<V> implements ScheduledFuture<V>
{
+public class CUScheduleFuture<V> extends CUFuture<V, Delayed> implements ScheduledFuture<V>
{
     public CUScheduleFuture(final ScheduledFuture<V> delegate, final ManagedTaskListenerTask
listener) {
         super(delegate, listener);
     }

http://git-wip-us.apache.org/repos/asf/tomee/blob/5a254531/container/openejb-core/src/main/java/org/apache/openejb/threads/impl/ManagedExecutorServiceImpl.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/threads/impl/ManagedExecutorServiceImpl.java
b/container/openejb-core/src/main/java/org/apache/openejb/threads/impl/ManagedExecutorServiceImpl.java
index 4ed4b64..e710aa8 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/threads/impl/ManagedExecutorServiceImpl.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/threads/impl/ManagedExecutorServiceImpl.java
@@ -70,7 +70,7 @@ public class ManagedExecutorServiceImpl extends AbstractExecutorService
implemen
         final CUCallable<T> wrapper = new CUCallable<T>(task);
         final Future<T> future = delegate.submit(wrapper);
         wrapper.taskSubmitted(future, this, task);
-        return new CUFuture<T>(future, wrapper);
+        return new CUFuture<>(future, wrapper);
     }
 
     @Override
@@ -78,7 +78,7 @@ public class ManagedExecutorServiceImpl extends AbstractExecutorService
implemen
         final CURunnable wrapper = new CURunnable(task);
         final Future<T> future = delegate.submit(wrapper, result);
         wrapper.taskSubmitted(future, this, task);
-        return new CUFuture<T>(future, wrapper);
+        return new CUFuture<>(future, wrapper);
     }
 
     @Override
@@ -86,7 +86,7 @@ public class ManagedExecutorServiceImpl extends AbstractExecutorService
implemen
         final CURunnable wrapper = new CURunnable(task);
         final Future<?> future = delegate.submit(wrapper);
         wrapper.taskSubmitted(future, this, task);
-        return new CUFuture<Void>(Future.class.cast(future), wrapper);
+        return new CUFuture<>(Future.class.cast(future), wrapper);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/tomee/blob/5a254531/container/openejb-core/src/main/java/org/apache/openejb/threads/task/CUTask.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/threads/task/CUTask.java
b/container/openejb-core/src/main/java/org/apache/openejb/threads/task/CUTask.java
index c920044..146b52e 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/threads/task/CUTask.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/threads/task/CUTask.java
@@ -26,7 +26,7 @@ import org.apache.openejb.spi.SecurityService;
 import javax.security.auth.login.LoginException;
 import java.util.concurrent.Callable;
 
-public abstract class CUTask<T> extends ManagedTaskListenerTask {
+public abstract class CUTask<T> extends ManagedTaskListenerTask implements Comparable<Object>
{
     private static final SecurityService SECURITY_SERVICE = SystemInstance.get().getComponent(SecurityService.class);
 
     private final Context initialContext;
@@ -179,4 +179,9 @@ public abstract class CUTask<T> extends ManagedTaskListenerTask
{
             currentContext = null;
         }
     }
+
+    @Override
+    public int compareTo(final Object o) {
+        return Comparable.class.isInstance(delegate) ? Comparable.class.cast(delegate).compareTo(o)
: -1;
+    }
 }

http://git-wip-us.apache.org/repos/asf/tomee/blob/5a254531/container/openejb-core/src/test/java/org/apache/openejb/resource/jdbc/JBossLikeDataSourceInjectionTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/resource/jdbc/JBossLikeDataSourceInjectionTest.java
b/container/openejb-core/src/test/java/org/apache/openejb/resource/jdbc/JBossLikeDataSourceInjectionTest.java
new file mode 100644
index 0000000..9707e8e
--- /dev/null
+++ b/container/openejb-core/src/test/java/org/apache/openejb/resource/jdbc/JBossLikeDataSourceInjectionTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.resource.jdbc;
+
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.testing.Classes;
+import org.apache.openejb.testing.Configuration;
+import org.apache.openejb.testing.SimpleLog;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Properties;
+import javax.annotation.Resource;
+import javax.ejb.LocalBean;
+import javax.ejb.Singleton;
+import javax.inject.Inject;
+import javax.sql.DataSource;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+@SimpleLog
+@Classes(cdi = true, value = JBossLikeDataSourceInjectionTest.IWantInjection.class)
+@RunWith(ApplicationComposer.class)
+public class JBossLikeDataSourceInjectionTest {
+    private static final String URL = "jdbc:hsqldb:mem:jbosslike";
+
+    @Inject
+    private IWantInjection persistManager;
+
+    @Configuration
+    public Properties config() {
+        final Properties p = new Properties();
+        p.put("openejb.log.async", "false");
+        p.put("noise", "new://Resource?type=DataSource"); // to potential fail auto adjusting
+        p.put("java:/jdbc/DefaultDS", "new://Resource?type=DataSource");
+        p.put("java:/jdbc/DefaultDS.JdbcDriver", "org.hsqldb.jdbcDriver");
+        p.put("java:/jdbc/DefaultDS.JdbcUrl", URL);
+        p.put("java:/jdbc/DefaultDS.UserName", "sa");
+        return p;
+    }
+
+    @LocalBean
+    @Singleton
+    public static class IWantInjection {
+        @Resource(name = "java:/jdbc/DefaultDS")
+        private DataSource ds;
+
+
+        public void check() throws SQLException {
+            assertNotNull(ds);
+            final Connection c = ds.getConnection();
+            assertEquals(URL, c.getMetaData().getURL());
+            c.close();
+            assertTrue(c.isClosed());
+        }
+    }
+
+    @Test
+    public void isClosed() throws SQLException {
+        persistManager.check();
+    }
+}


Mime
View raw message