You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@tomee.apache.org by bu...@apache.org on 2012/03/06 10:11:21 UTC
svn commit: r807559 - in /websites/staging/openejb/trunk: cgi-bin/ content/
content/examples-trunk/ content/examples-trunk/spring-data-proxy/
content/examples-trunk/spring-data-proxy/src/
content/examples-trunk/spring-data-proxy/src/main/ content/examp...
Author: buildbot
Date: Tue Mar 6 09:11:20 2012
New Revision: 807559
Log:
Staging update by buildbot for openejb
Added:
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/pom.xml (with props)
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/java/
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/java/org/
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/java/org/superbiz/
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/java/org/superbiz/dynamic/
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/java/org/superbiz/dynamic/SpringDataProxy.java
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/java/org/superbiz/dynamic/User.java
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/java/org/superbiz/dynamic/UserSpringDataDao.java
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/resources/
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/resources/META-INF/
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/resources/META-INF/persistence.xml (with props)
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/test/
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/test/java/
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/test/java/org/
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/test/java/org/superbiz/
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/test/java/org/superbiz/dynamic/
websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/test/java/org/superbiz/dynamic/DynamicUserDaoTest.java
Modified:
websites/staging/openejb/trunk/cgi-bin/ (props changed)
websites/staging/openejb/trunk/content/ (props changed)
websites/staging/openejb/trunk/content/examples-trunk/pom.xml
Propchange: websites/staging/openejb/trunk/cgi-bin/
------------------------------------------------------------------------------
cms:source-revision = 1297390
Propchange: websites/staging/openejb/trunk/content/
------------------------------------------------------------------------------
cms:source-revision = 1297390
Modified: websites/staging/openejb/trunk/content/examples-trunk/pom.xml
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/pom.xml (original)
+++ websites/staging/openejb/trunk/content/examples-trunk/pom.xml Tue Mar 6 09:11:20 2012
@@ -17,7 +17,7 @@
limitations under the License.
-->
<!--test 2-->
-<!-- $Rev: 1290934 $ $Date: 2012-02-19 03:34:45 +0000 (Sun, 19 Feb 2012) $ -->
+<!-- $Rev: 1297390 $ $Date: 2012-03-06 09:10:59 +0000 (Tue, 06 Mar 2012) $ -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
@@ -86,6 +86,7 @@
<module>simple-stateless-with-descriptor</module>
<module>simple-webservice</module>
<module>spring-integration</module>
+ <module>spring-data-proxy</module>
<module>telephone-stateful</module>
<module>testcase-injection</module>
<module>testing-security-2</module>
Added: websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/pom.xml
==============================================================================
Binary file - no diff available.
Propchange: websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/pom.xml
------------------------------------------------------------------------------
svn:mime-type = application/xml
Added: websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/java/org/superbiz/dynamic/SpringDataProxy.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/java/org/superbiz/dynamic/SpringDataProxy.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/java/org/superbiz/dynamic/SpringDataProxy.java Tue Mar 6 09:11:20 2012
@@ -0,0 +1,31 @@
+package org.superbiz.dynamic;
+
+import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
+import org.springframework.data.repository.Repository;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class SpringDataProxy implements InvocationHandler {
+ @PersistenceContext
+ private EntityManager em;
+
+ private Class<Repository<?, ?>> implementingInterfaceClass; // implicitly for this kind of proxy
+
+ private final AtomicReference<Repository<?, ?>> repository = new AtomicReference<Repository<?, ?>>();
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if (repository.get() == null) {
+ synchronized (this) {
+ if (repository.get() == null) {
+ repository.set(new JpaRepositoryFactory(em).getRepository(implementingInterfaceClass));
+ }
+ }
+ }
+ return method.invoke(repository.get(), args);
+ }
+}
Added: websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/java/org/superbiz/dynamic/User.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/java/org/superbiz/dynamic/User.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/java/org/superbiz/dynamic/User.java Tue Mar 6 09:11:20 2012
@@ -0,0 +1,54 @@
+/*
+ * 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.dynamic;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+@Entity
+public class User {
+ @Id
+ @GeneratedValue
+ private long id;
+ private String name;
+ private int age;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+}
Added: websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/java/org/superbiz/dynamic/UserSpringDataDao.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/java/org/superbiz/dynamic/UserSpringDataDao.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/java/org/superbiz/dynamic/UserSpringDataDao.java Tue Mar 6 09:11:20 2012
@@ -0,0 +1,32 @@
+/*
+ * 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.dynamic;
+
+
+import org.apache.openejb.api.Proxy;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.repository.query.Param;
+
+import javax.ejb.Stateless;
+import javax.persistence.PersistenceContext;
+
+@Stateless
+@Proxy(SpringDataProxy.class)
+@PersistenceContext(name = "dynamic")
+public interface UserSpringDataDao extends JpaRepository<User, Long> {
+ User findByName(@Param("name") final String name);
+}
Added: websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/resources/META-INF/persistence.xml
==============================================================================
Binary file - no diff available.
Propchange: websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/main/resources/META-INF/persistence.xml
------------------------------------------------------------------------------
svn:mime-type = application/xml
Added: websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/test/java/org/superbiz/dynamic/DynamicUserDaoTest.java
==============================================================================
--- websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/test/java/org/superbiz/dynamic/DynamicUserDaoTest.java (added)
+++ websites/staging/openejb/trunk/content/examples-trunk/spring-data-proxy/src/test/java/org/superbiz/dynamic/DynamicUserDaoTest.java Tue Mar 6 09:11:20 2012
@@ -0,0 +1,92 @@
+/*
+ * 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.dynamic;
+
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.ejb.embeddable.EJBContainer;
+import javax.inject.Inject;
+import javax.naming.NamingException;
+import java.util.Collection;
+import java.util.Properties;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+
+public class DynamicUserDaoTest {
+ private static EJBContainer container;
+ private static boolean initialized = false;
+
+ @Inject
+ private UserSpringDataDao dao;
+
+ @Test
+ public void findAll() {
+ Collection<User> users = dao.findAll();
+ assertEquals(10, users.size());
+ }
+
+ @Test
+ public void findByName() {
+ User user = dao.findByName("bar-1");
+ assertNotNull(user);
+ assertEquals("bar-1", user.getName());
+ }
+
+ @BeforeClass
+ public static void start() throws Exception {
+ final Properties p = new Properties();
+
+ p.setProperty("openejb.deployments.classpath.include", "spring-data-proxy");
+ p.setProperty("openejb.exclude-include.order", "exclude-include");
+
+ p.setProperty("jdbc/DynamicUserDaoTest", "new://Resource?type=DataSource");
+ p.setProperty("jdbc/DynamicUserDaoTest", "new://Resource?type=DataSource");
+ p.setProperty("jdbc/DynamicUserDaoTest.JdbcDriver", "org.hsqldb.jdbcDriver");
+ p.setProperty("jdbc/DynamicUserDaoTest.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
+ p.setProperty("jdbc/DynamicUserDaoTest.UserName", "sa");
+ p.setProperty("jdbc/DynamicUserDaoTest.Password", "");
+
+ container = EJBContainer.createEJBContainer(p);
+ }
+
+ @Before
+ public void injectAndInit() throws NamingException {
+ container.getContext().bind("inject", this);
+ if (!initialized) {
+ for (int i = 0; i < 10; i++) {
+ final User u = new User();
+ u.setAge(i % 4);
+ if (i % 3 == 0) {
+ u.setName("foo");
+ } else {
+ u.setName("bar-" + i);
+ }
+ dao.save(u);
+ }
+ initialized = true;
+ }
+ }
+
+ @AfterClass
+ public static void close() {
+ container.close();
+ }
+}