http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/container/openejb-jpa-integration/src/main/java/org/apache/openejb/jpa/integration/eclipselink/OpenEJBServerPlatform.java ---------------------------------------------------------------------- diff --git a/container/openejb-jpa-integration/src/main/java/org/apache/openejb/jpa/integration/eclipselink/OpenEJBServerPlatform.java b/container/openejb-jpa-integration/src/main/java/org/apache/openejb/jpa/integration/eclipselink/OpenEJBServerPlatform.java index 8d091b6..eabbae2 100644 --- a/container/openejb-jpa-integration/src/main/java/org/apache/openejb/jpa/integration/eclipselink/OpenEJBServerPlatform.java +++ b/container/openejb-jpa-integration/src/main/java/org/apache/openejb/jpa/integration/eclipselink/OpenEJBServerPlatform.java @@ -1,56 +1,56 @@ -/* - * 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.jpa.integration.eclipselink; - -import org.eclipse.persistence.platform.server.JMXServerPlatformBase; -import org.eclipse.persistence.sessions.DatabaseSession; -import org.eclipse.persistence.transaction.JTATransactionController; - -import javax.management.MBeanServer; -import javax.transaction.TransactionManager; - -public class OpenEJBServerPlatform extends JMXServerPlatformBase { - public OpenEJBServerPlatform(final DatabaseSession newDatabaseSession) { - super(newDatabaseSession); - try { - mBeanServer = MBeanServer.class.cast( - OpenEJBServerPlatform.class.getClassLoader().loadClass("org.apache.openejb.monitoring.LocalMBeanServer") - .getMethod("get").invoke(null)); - } catch (final Exception e) { - // no-op - } - } - - @Override - public boolean isRuntimeServicesEnabledDefault() { - return "true".equalsIgnoreCase(System.getProperty("openejb.eclipselink.jmx", "true")); - } - - @Override - public Class getExternalTransactionControllerClass() { - return OpenEJBJTATransactionController.class; - } - - public static class OpenEJBJTATransactionController extends JTATransactionController { - @Override - protected TransactionManager acquireTransactionManager() throws Exception { - return TransactionManager.class.cast( - OpenEJBJTATransactionController.class.getClassLoader().loadClass("org.apache.openejb.OpenEJB") - .getDeclaredMethod("getTransactionManager").invoke(null)); - } - } -} +/* + * 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.jpa.integration.eclipselink; + +import org.eclipse.persistence.platform.server.JMXServerPlatformBase; +import org.eclipse.persistence.sessions.DatabaseSession; +import org.eclipse.persistence.transaction.JTATransactionController; + +import javax.management.MBeanServer; +import javax.transaction.TransactionManager; + +public class OpenEJBServerPlatform extends JMXServerPlatformBase { + public OpenEJBServerPlatform(final DatabaseSession newDatabaseSession) { + super(newDatabaseSession); + try { + mBeanServer = MBeanServer.class.cast( + OpenEJBServerPlatform.class.getClassLoader().loadClass("org.apache.openejb.monitoring.LocalMBeanServer") + .getMethod("get").invoke(null)); + } catch (final Exception e) { + // no-op + } + } + + @Override + public boolean isRuntimeServicesEnabledDefault() { + return "true".equalsIgnoreCase(System.getProperty("openejb.eclipselink.jmx", "true")); + } + + @Override + public Class getExternalTransactionControllerClass() { + return OpenEJBJTATransactionController.class; + } + + public static class OpenEJBJTATransactionController extends JTATransactionController { + @Override + protected TransactionManager acquireTransactionManager() throws Exception { + return TransactionManager.class.cast( + OpenEJBJTATransactionController.class.getClassLoader().loadClass("org.apache.openejb.OpenEJB") + .getDeclaredMethod("getTransactionManager").invoke(null)); + } + } +}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/doap_tomee.rdf ---------------------------------------------------------------------- diff --git a/doap_tomee.rdf b/doap_tomee.rdf index ce0ca8b..506246b 100644 --- a/doap_tomee.rdf +++ b/doap_tomee.rdf @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="UTF-8"?> +<?xml version="1.0" encoding="UTF-8"?> <!-- ====================================================================== --> <!-- ===================== - DO NOT EDIT THIS FILE! - ===================== --> @@ -11,7 +11,7 @@ <!-- --> <!-- ====================================================================== --> -<rdf:RDF xml:lang="en" xmlns="http://usefulinc.com/ns/doap#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:asfext="http://projects.apache.org/ns/asfext#"> +<rdf:RDF xml:lang="en" xmlns="http://usefulinc.com/ns/doap#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:asfext="http://projects.apache.org/ns/asfext#"> <Project rdf:about="http://tomee.apache.org/tomee"> <!-- ====================================================================== --> @@ -27,7 +27,7 @@ <description xml:lang="en">Apache TomEE Web Profile delivers Servlets, JSP, JSF, JTA, JPA, CDI, Bean Validation and EJB Lite. Apache TomEE Plus has all the features of TomEE with the addition of JAX-RS (RESTfull Services), JAX-WS (Web Services), JMS (Java Message Service) and JCA (the Java Connector Architecture). The - additional functionality is delivered via Apache CXF, Apache ActiveMQ and the Geronimo Connector library</description> + additional functionality is delivered via Apache CXF, Apache ActiveMQ and the Geronimo Connector library</description> <shortdesc xml:lang="en">Apache TomEE is an all-Apache Java EE 6 Web Profile stack for Apache Tomcat</shortdesc> <!-- ====================================================================== --> @@ -76,20 +76,20 @@ <!-- Anonymous Source Repository. --> <!-- ====================================================================== --> - <repository> - <Repository> - <location rdf:resource="http://svn.apache.org/viewvc/tomee/tomee/trunk/"/> - </Repository> + <repository> + <Repository> + <location rdf:resource="http://svn.apache.org/viewvc/tomee/tomee/trunk/"/> + </Repository> </repository> <!-- ====================================================================== --> <!-- Developer Source Repository. --> <!-- ====================================================================== --> - <repository> - <Repository> - <location rdf:resource="https://svn.apache.org/repos/asf/tomee/tomee/trunk"/> - </Repository> + <repository> + <Repository> + <location rdf:resource="https://svn.apache.org/repos/asf/tomee/tomee/trunk"/> + </Repository> </repository> <!-- ====================================================================== --> @@ -113,42 +113,42 @@ <!-- ====================================================================== --> <!-- Project releases. --> <!-- ====================================================================== --> - - <release> - <Version> - <name>Apache TomEE</name> - <revision>1.7.0</revision> - <file-release>http://repo.maven.apache.org/maven2/org/apache/openejb/tomee/1.7.0/tomee-1.7.0.pom</file-release> - </Version> - </release> - <release> - <Version> - <name>Apache OpenEJB</name> - <revision>4.7.0</revision> - <file-release>http://central.maven.org/maven2/org/apache/openejb/openejb/4.7.0/openejb-4.7.0.pom</file-release> - </Version> + + <release> + <Version> + <name>Apache TomEE</name> + <revision>1.7.0</revision> + <file-release>http://repo.maven.apache.org/maven2/org/apache/openejb/tomee/1.7.0/tomee-1.7.0.pom</file-release> + </Version> + </release> + <release> + <Version> + <name>Apache OpenEJB</name> + <revision>4.7.0</revision> + <file-release>http://central.maven.org/maven2/org/apache/openejb/openejb/4.7.0/openejb-4.7.0.pom</file-release> + </Version> </release> <!-- ====================================================================== --> <!-- ASF extension. --> <!-- ====================================================================== --> - <asfext:pmc rdf:resource="http://tomee.apache.org"/> - <asfext:name>Apache TomEE</asfext:name> - <foaf:homepage rdf:resource="http://tomee.apache.org"/> - <asfext:charter>Apache TomEE provides an all-Apache Java EE 6 Web Profile stack for Apache Tomcat</asfext:charter> - <asfext:chair> - <foaf:Person> - <foaf:name>David Blevins</foaf:name> - </foaf:Person> - </asfext:chair> - <asfext:implements> - <asfext:Standard> - <asfext:title>Java EE 6 Web Profile</asfext:title> - <asfext:body>Java Community Process</asfext:body> - <asfext:id>JSR 316</asfext:id> - <asfext:url>https://jcp.org/en/jsr/detail?id=316</asfext:url> - </asfext:Standard> - </asfext:implements> - </Project> + <asfext:pmc rdf:resource="http://tomee.apache.org"/> + <asfext:name>Apache TomEE</asfext:name> + <foaf:homepage rdf:resource="http://tomee.apache.org"/> + <asfext:charter>Apache TomEE provides an all-Apache Java EE 6 Web Profile stack for Apache Tomcat</asfext:charter> + <asfext:chair> + <foaf:Person> + <foaf:name>David Blevins</foaf:name> + </foaf:Person> + </asfext:chair> + <asfext:implements> + <asfext:Standard> + <asfext:title>Java EE 6 Web Profile</asfext:title> + <asfext:body>Java Community Process</asfext:body> + <asfext:id>JSR 316</asfext:id> + <asfext:url>https://jcp.org/en/jsr/detail?id=316</asfext:url> + </asfext:Standard> + </asfext:implements> + </Project> </rdf:RDF> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/BusyBee.java ---------------------------------------------------------------------- diff --git a/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/BusyBee.java b/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/BusyBee.java index 420bcc3..6cb0316 100644 --- a/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/BusyBee.java +++ b/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/BusyBee.java @@ -1,66 +1,66 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.accesstimeout; - -import org.superbiz.accesstimeout.api.AwaitBriefly; -import org.superbiz.accesstimeout.api.AwaitForever; -import org.superbiz.accesstimeout.api.AwaitNever; - -import javax.ejb.Asynchronous; -import javax.ejb.Lock; -import javax.ejb.Singleton; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Future; - -import static javax.ejb.LockType.WRITE; - -/** - * @version $Revision$ $Date$ - */ -@Singleton -@Lock(WRITE) -public class BusyBee { - - @Asynchronous - public Future stayBusy(CountDownLatch ready) { - ready.countDown(); - - try { - new CountDownLatch(1).await(); - } catch (InterruptedException e) { - Thread.interrupted(); - } - - return null; - } - - @AwaitNever - public void doItNow() { - // do something - } - - @AwaitBriefly - public void doItSoon() { - // do something - } - - @AwaitForever - public void justDoIt() { - // do something - } - -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.accesstimeout; + +import org.superbiz.accesstimeout.api.AwaitBriefly; +import org.superbiz.accesstimeout.api.AwaitForever; +import org.superbiz.accesstimeout.api.AwaitNever; + +import javax.ejb.Asynchronous; +import javax.ejb.Lock; +import javax.ejb.Singleton; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Future; + +import static javax.ejb.LockType.WRITE; + +/** + * @version $Revision$ $Date$ + */ +@Singleton +@Lock(WRITE) +public class BusyBee { + + @Asynchronous + public Future stayBusy(CountDownLatch ready) { + ready.countDown(); + + try { + new CountDownLatch(1).await(); + } catch (InterruptedException e) { + Thread.interrupted(); + } + + return null; + } + + @AwaitNever + public void doItNow() { + // do something + } + + @AwaitBriefly + public void doItSoon() { + // do something + } + + @AwaitForever + public void justDoIt() { + // do something + } + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/api/AwaitBriefly.java ---------------------------------------------------------------------- diff --git a/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/api/AwaitBriefly.java b/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/api/AwaitBriefly.java index f42494a..7132780 100644 --- a/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/api/AwaitBriefly.java +++ b/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/api/AwaitBriefly.java @@ -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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.accesstimeout.api; - -import javax.ejb.AccessTimeout; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.util.concurrent.TimeUnit; - -@Metatype -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) - -@AccessTimeout(value = 5, unit = TimeUnit.SECONDS) -public @interface AwaitBriefly { - +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.accesstimeout.api; + +import javax.ejb.AccessTimeout; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.concurrent.TimeUnit; + +@Metatype +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) + +@AccessTimeout(value = 5, unit = TimeUnit.SECONDS) +public @interface AwaitBriefly { + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/api/AwaitForever.java ---------------------------------------------------------------------- diff --git a/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/api/AwaitForever.java b/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/api/AwaitForever.java index f40d43c..e0f1243 100644 --- a/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/api/AwaitForever.java +++ b/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/api/AwaitForever.java @@ -1,32 +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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.accesstimeout.api; - -import javax.ejb.AccessTimeout; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Metatype -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) - -@AccessTimeout(-1) -public @interface AwaitForever { - -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.accesstimeout.api; + +import javax.ejb.AccessTimeout; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Metatype +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) + +@AccessTimeout(-1) +public @interface AwaitForever { + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/api/AwaitNever.java ---------------------------------------------------------------------- diff --git a/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/api/AwaitNever.java b/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/api/AwaitNever.java index d3ad371..80c60af 100644 --- a/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/api/AwaitNever.java +++ b/examples/access-timeout-meta/src/main/java/org/superbiz/accesstimeout/api/AwaitNever.java @@ -1,32 +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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.accesstimeout.api; - -import javax.ejb.AccessTimeout; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Metatype -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) - -@AccessTimeout(1) -public @interface AwaitNever { - +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.accesstimeout.api; + +import javax.ejb.AccessTimeout; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Metatype +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) + +@AccessTimeout(1) +public @interface AwaitNever { + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/access-timeout-meta/src/test/java/org/superbiz/accesstimeout/BusyBeeTest.java ---------------------------------------------------------------------- diff --git a/examples/access-timeout-meta/src/test/java/org/superbiz/accesstimeout/BusyBeeTest.java b/examples/access-timeout-meta/src/test/java/org/superbiz/accesstimeout/BusyBeeTest.java index 7d0e498..0d786cf 100644 --- a/examples/access-timeout-meta/src/test/java/org/superbiz/accesstimeout/BusyBeeTest.java +++ b/examples/access-timeout-meta/src/test/java/org/superbiz/accesstimeout/BusyBeeTest.java @@ -1,82 +1,82 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.accesstimeout; - -import junit.framework.TestCase; - -import javax.ejb.embeddable.EJBContainer; -import javax.naming.Context; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -/** - * @version $Revision$ $Date$ - */ -public class BusyBeeTest extends TestCase { - - public void test() throws Exception { - - final Context context = EJBContainer.createEJBContainer().getContext(); - - final CountDownLatch ready = new CountDownLatch(1); - - final BusyBee busyBee = (BusyBee) context.lookup("java:global/access-timeout-meta/BusyBee"); - - // This asynchronous method will never exit - busyBee.stayBusy(ready); - - // Are you working yet little bee? - ready.await(); - - // OK, Bee is busy - - { // Timeout Immediately - final long start = System.nanoTime(); - - try { - busyBee.doItNow(); - - fail("The bee should be busy"); - } catch (Exception e) { - // the bee is still too busy as expected - } - - assertEquals(0, seconds(start)); - } - - { // Timeout in 5 seconds - final long start = System.nanoTime(); - - try { - busyBee.doItSoon(); - - fail("The bee should be busy"); - } catch (Exception e) { - // the bee is still too busy as expected - } - - assertEquals(5, seconds(start)); - } - - // This will wait forever, give it a try if you have that long - //busyBee.justDoIt(); - } - - private long seconds(long start) { - return TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - start); - } -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.accesstimeout; + +import junit.framework.TestCase; + +import javax.ejb.embeddable.EJBContainer; +import javax.naming.Context; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/** + * @version $Revision$ $Date$ + */ +public class BusyBeeTest extends TestCase { + + public void test() throws Exception { + + final Context context = EJBContainer.createEJBContainer().getContext(); + + final CountDownLatch ready = new CountDownLatch(1); + + final BusyBee busyBee = (BusyBee) context.lookup("java:global/access-timeout-meta/BusyBee"); + + // This asynchronous method will never exit + busyBee.stayBusy(ready); + + // Are you working yet little bee? + ready.await(); + + // OK, Bee is busy + + { // Timeout Immediately + final long start = System.nanoTime(); + + try { + busyBee.doItNow(); + + fail("The bee should be busy"); + } catch (Exception e) { + // the bee is still too busy as expected + } + + assertEquals(0, seconds(start)); + } + + { // Timeout in 5 seconds + final long start = System.nanoTime(); + + try { + busyBee.doItSoon(); + + fail("The bee should be busy"); + } catch (Exception e) { + // the bee is still too busy as expected + } + + assertEquals(5, seconds(start)); + } + + // This will wait forever, give it a try if you have that long + //busyBee.justDoIt(); + } + + private long seconds(long start) { + return TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - start); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/access-timeout/src/main/java/org/superbiz/accesstimeout/BusyBee.java ---------------------------------------------------------------------- diff --git a/examples/access-timeout/src/main/java/org/superbiz/accesstimeout/BusyBee.java b/examples/access-timeout/src/main/java/org/superbiz/accesstimeout/BusyBee.java index e9c00f1..920b3a5 100644 --- a/examples/access-timeout/src/main/java/org/superbiz/accesstimeout/BusyBee.java +++ b/examples/access-timeout/src/main/java/org/superbiz/accesstimeout/BusyBee.java @@ -1,64 +1,64 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.accesstimeout; - -import javax.ejb.AccessTimeout; -import javax.ejb.Asynchronous; -import javax.ejb.Lock; -import javax.ejb.Singleton; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -import static javax.ejb.LockType.WRITE; - -/** - * @version $Revision$ $Date$ - */ -@Singleton -@Lock(WRITE) -public class BusyBee { - - @Asynchronous - public Future stayBusy(CountDownLatch ready) { - ready.countDown(); - - try { - new CountDownLatch(1).await(); - } catch (InterruptedException e) { - Thread.interrupted(); - } - - return null; - } - - @AccessTimeout(0) - public void doItNow() { - // do something - } - - @AccessTimeout(value = 5, unit = TimeUnit.SECONDS) - public void doItSoon() { - // do something - } - - @AccessTimeout(-1) - public void justDoIt() { - // do something - } - -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.accesstimeout; + +import javax.ejb.AccessTimeout; +import javax.ejb.Asynchronous; +import javax.ejb.Lock; +import javax.ejb.Singleton; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +import static javax.ejb.LockType.WRITE; + +/** + * @version $Revision$ $Date$ + */ +@Singleton +@Lock(WRITE) +public class BusyBee { + + @Asynchronous + public Future stayBusy(CountDownLatch ready) { + ready.countDown(); + + try { + new CountDownLatch(1).await(); + } catch (InterruptedException e) { + Thread.interrupted(); + } + + return null; + } + + @AccessTimeout(0) + public void doItNow() { + // do something + } + + @AccessTimeout(value = 5, unit = TimeUnit.SECONDS) + public void doItSoon() { + // do something + } + + @AccessTimeout(-1) + public void justDoIt() { + // do something + } + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/access-timeout/src/test/java/org/superbiz/accesstimeout/BusyBeeTest.java ---------------------------------------------------------------------- diff --git a/examples/access-timeout/src/test/java/org/superbiz/accesstimeout/BusyBeeTest.java b/examples/access-timeout/src/test/java/org/superbiz/accesstimeout/BusyBeeTest.java index 2201b6f..61d7bad 100644 --- a/examples/access-timeout/src/test/java/org/superbiz/accesstimeout/BusyBeeTest.java +++ b/examples/access-timeout/src/test/java/org/superbiz/accesstimeout/BusyBeeTest.java @@ -1,82 +1,82 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.accesstimeout; - -import junit.framework.TestCase; - -import javax.ejb.embeddable.EJBContainer; -import javax.naming.Context; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -/** - * @version $Revision$ $Date$ - */ -public class BusyBeeTest extends TestCase { - - public void test() throws Exception { - - final Context context = EJBContainer.createEJBContainer().getContext(); - - final CountDownLatch ready = new CountDownLatch(1); - - final BusyBee busyBee = (BusyBee) context.lookup("java:global/access-timeout/BusyBee"); - - // This asynchronous method will never exit - busyBee.stayBusy(ready); - - // Are you working yet little bee? - ready.await(); - - // OK, Bee is busy - - { // Timeout Immediately - final long start = System.nanoTime(); - - try { - busyBee.doItNow(); - - fail("The bee should be busy"); - } catch (Exception e) { - // the bee is still too busy as expected - } - - assertEquals(0, seconds(start)); - } - - { // Timeout in 5 seconds - final long start = System.nanoTime(); - - try { - busyBee.doItSoon(); - - fail("The bee should be busy"); - } catch (Exception e) { - // the bee is still too busy as expected - } - - assertEquals(5, seconds(start)); - } - - // This will wait forever, give it a try if you have that long - //busyBee.justDoIt(); - } - - private long seconds(long start) { - return TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - start); - } -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.accesstimeout; + +import junit.framework.TestCase; + +import javax.ejb.embeddable.EJBContainer; +import javax.naming.Context; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/** + * @version $Revision$ $Date$ + */ +public class BusyBeeTest extends TestCase { + + public void test() throws Exception { + + final Context context = EJBContainer.createEJBContainer().getContext(); + + final CountDownLatch ready = new CountDownLatch(1); + + final BusyBee busyBee = (BusyBee) context.lookup("java:global/access-timeout/BusyBee"); + + // This asynchronous method will never exit + busyBee.stayBusy(ready); + + // Are you working yet little bee? + ready.await(); + + // OK, Bee is busy + + { // Timeout Immediately + final long start = System.nanoTime(); + + try { + busyBee.doItNow(); + + fail("The bee should be busy"); + } catch (Exception e) { + // the bee is still too busy as expected + } + + assertEquals(0, seconds(start)); + } + + { // Timeout in 5 seconds + final long start = System.nanoTime(); + + try { + busyBee.doItSoon(); + + fail("The bee should be busy"); + } catch (Exception e) { + // the bee is still too busy as expected + } + + assertEquals(5, seconds(start)); + } + + // This will wait forever, give it a try if you have that long + //busyBee.justDoIt(); + } + + private long seconds(long start) { + return TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - start); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movie.java ---------------------------------------------------------------------- diff --git a/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movie.java b/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movie.java index bcc375a..106978f 100644 --- a/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movie.java +++ b/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movie.java @@ -1,61 +1,61 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.altdd; - -import javax.persistence.Entity; - -@Entity -public class Movie { - - private String director; - private String title; - private int year; - - public Movie() { - } - - public Movie(String director, String title, int year) { - this.director = director; - this.title = title; - this.year = year; - } - - public String getDirector() { - return director; - } - - public void setDirector(String director) { - this.director = director; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public int getYear() { - return year; - } - - public void setYear(int year) { - this.year = year; - } - -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.altdd; + +import javax.persistence.Entity; + +@Entity +public class Movie { + + private String director; + private String title; + private int year; + + public Movie() { + } + + public Movie(String director, String title, int year) { + this.director = director; + this.title = title; + this.year = year; + } + + public String getDirector() { + return director; + } + + public void setDirector(String director) { + this.director = director; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movies.java ---------------------------------------------------------------------- diff --git a/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movies.java b/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movies.java index 61e72ad..9317194 100644 --- a/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movies.java +++ b/examples/alternate-descriptors/src/main/java/org/superbiz/altdd/Movies.java @@ -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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.altdd; - -import javax.ejb.Stateful; -import javax.ejb.TransactionAttribute; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.PersistenceContextType; -import javax.persistence.Query; -import java.util.List; - -import static javax.ejb.TransactionAttributeType.MANDATORY; - -//START SNIPPET: code -@Stateful -@TransactionAttribute(MANDATORY) -public class Movies { - - @PersistenceContext(unitName = "movie-unit", type = PersistenceContextType.TRANSACTION) - private EntityManager entityManager; - - public void addMovie(Movie movie) throws Exception { - entityManager.persist(movie); - } - - public void deleteMovie(Movie movie) throws Exception { - entityManager.remove(movie); - } - - public List<Movie> getMovies() throws Exception { - Query query = entityManager.createQuery("SELECT m from Movie as m"); - return query.getResultList(); - } -} -//END SNIPPET: code +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.altdd; + +import javax.ejb.Stateful; +import javax.ejb.TransactionAttribute; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.PersistenceContextType; +import javax.persistence.Query; +import java.util.List; + +import static javax.ejb.TransactionAttributeType.MANDATORY; + +//START SNIPPET: code +@Stateful +@TransactionAttribute(MANDATORY) +public class Movies { + + @PersistenceContext(unitName = "movie-unit", type = PersistenceContextType.TRANSACTION) + private EntityManager entityManager; + + public void addMovie(Movie movie) throws Exception { + entityManager.persist(movie); + } + + public void deleteMovie(Movie movie) throws Exception { + entityManager.remove(movie); + } + + public List<Movie> getMovies() throws Exception { + Query query = entityManager.createQuery("SELECT m from Movie as m"); + return query.getResultList(); + } +} +//END SNIPPET: code http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/alternate-descriptors/src/test/java/org/superbiz/altdd/MoviesTest.java ---------------------------------------------------------------------- diff --git a/examples/alternate-descriptors/src/test/java/org/superbiz/altdd/MoviesTest.java b/examples/alternate-descriptors/src/test/java/org/superbiz/altdd/MoviesTest.java index 29a94e5..fbf0460 100644 --- a/examples/alternate-descriptors/src/test/java/org/superbiz/altdd/MoviesTest.java +++ b/examples/alternate-descriptors/src/test/java/org/superbiz/altdd/MoviesTest.java @@ -1,99 +1,99 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.altdd; - -import junit.framework.TestCase; - -import javax.annotation.Resource; -import javax.ejb.EJB; -import javax.ejb.SessionContext; -import javax.ejb.embeddable.EJBContainer; -import javax.interceptor.AroundInvoke; -import javax.interceptor.InvocationContext; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.transaction.RollbackException; -import javax.transaction.UserTransaction; -import java.util.List; -import java.util.Properties; - -//START SNIPPET: code -public class MoviesTest extends TestCase { - - @EJB - private Movies movies; - - @Resource - private UserTransaction userTransaction; - - @PersistenceContext - private EntityManager entityManager; - - public void setUp() throws Exception { - Properties p = new Properties(); - p.put("movieDatabase", "new://Resource?type=DataSource"); - p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver"); - p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); - - p.put("openejb.altdd.prefix", "test"); - - EJBContainer.createEJBContainer(p).getContext().bind("inject", this); - } - - public void test() throws Exception { - - userTransaction.begin(); - - try { - entityManager.persist(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992)); - entityManager.persist(new Movie("Joel Coen", "Fargo", 1996)); - entityManager.persist(new Movie("Joel Coen", "The Big Lebowski", 1998)); - - List<Movie> list = movies.getMovies(); - assertEquals("List.size()", 3, list.size()); - - for (Movie movie : list) { - movies.deleteMovie(movie); - } - - assertEquals("Movies.getMovies()", 0, movies.getMovies().size()); - - } finally { - try { - userTransaction.commit(); - fail("Transaction should have been rolled back"); - } catch (RollbackException e) { - // Good, we don't want to clean up the db - } - } - } - - public static class Interceptor { - - @Resource - private SessionContext sessionContext; - - @AroundInvoke - public Object invoke(InvocationContext context) throws Exception { - - sessionContext.setRollbackOnly(); - - return context.proceed(); - } - } -} -//END SNIPPET: code +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.altdd; + +import junit.framework.TestCase; + +import javax.annotation.Resource; +import javax.ejb.EJB; +import javax.ejb.SessionContext; +import javax.ejb.embeddable.EJBContainer; +import javax.interceptor.AroundInvoke; +import javax.interceptor.InvocationContext; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.transaction.RollbackException; +import javax.transaction.UserTransaction; +import java.util.List; +import java.util.Properties; + +//START SNIPPET: code +public class MoviesTest extends TestCase { + + @EJB + private Movies movies; + + @Resource + private UserTransaction userTransaction; + + @PersistenceContext + private EntityManager entityManager; + + public void setUp() throws Exception { + Properties p = new Properties(); + p.put("movieDatabase", "new://Resource?type=DataSource"); + p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver"); + p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); + + p.put("openejb.altdd.prefix", "test"); + + EJBContainer.createEJBContainer(p).getContext().bind("inject", this); + } + + public void test() throws Exception { + + userTransaction.begin(); + + try { + entityManager.persist(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992)); + entityManager.persist(new Movie("Joel Coen", "Fargo", 1996)); + entityManager.persist(new Movie("Joel Coen", "The Big Lebowski", 1998)); + + List<Movie> list = movies.getMovies(); + assertEquals("List.size()", 3, list.size()); + + for (Movie movie : list) { + movies.deleteMovie(movie); + } + + assertEquals("Movies.getMovies()", 0, movies.getMovies().size()); + + } finally { + try { + userTransaction.commit(); + fail("Transaction should have been rolled back"); + } catch (RollbackException e) { + // Good, we don't want to clean up the db + } + } + } + + public static class Interceptor { + + @Resource + private SessionContext sessionContext; + + @AroundInvoke + public Object invoke(InvocationContext context) throws Exception { + + sessionContext.setRollbackOnly(); + + return context.proceed(); + } + } +} +//END SNIPPET: code http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/applet/src/main/java/org/superbiz/applet/Calculator.java ---------------------------------------------------------------------- diff --git a/examples/applet/src/main/java/org/superbiz/applet/Calculator.java b/examples/applet/src/main/java/org/superbiz/applet/Calculator.java index bb34178..7362de0 100644 --- a/examples/applet/src/main/java/org/superbiz/applet/Calculator.java +++ b/examples/applet/src/main/java/org/superbiz/applet/Calculator.java @@ -1,25 +1,25 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.applet; - -import javax.ejb.Remote; - -@Remote -public interface Calculator { - - public double add(double x, double y); -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.applet; + +import javax.ejb.Remote; + +@Remote +public interface Calculator { + + public double add(double x, double y); +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/applet/src/main/java/org/superbiz/applet/CalculatorApplet.java ---------------------------------------------------------------------- diff --git a/examples/applet/src/main/java/org/superbiz/applet/CalculatorApplet.java b/examples/applet/src/main/java/org/superbiz/applet/CalculatorApplet.java index eb16e25..52703ad 100644 --- a/examples/applet/src/main/java/org/superbiz/applet/CalculatorApplet.java +++ b/examples/applet/src/main/java/org/superbiz/applet/CalculatorApplet.java @@ -1,100 +1,100 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.applet; - -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import javax.rmi.PortableRemoteObject; -import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.Properties; - -public class CalculatorApplet extends JApplet { - - JTextArea area; - - JTextField field1; - JTextField field2; - JLabel label1; - JLabel label2; - JButton button; - JLabel label3; - Context ctx; - - public void init() { - try { - SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - createUI(); - } - }); - } catch (Exception e) { - System.err.println("createGUI didn't successfully complete"); - } - - } - - private void createUI() { - field1 = new JTextField(); - field2 = new JTextField(); - label1 = new JLabel("Enter first number"); - label2 = new JLabel("Enter second number"); - label3 = new JLabel("RESULT="); - button = new JButton("Add"); - - setLayout(new GridLayout(3, 2)); - add(label1); - add(field1); - add(label2); - add(field2); - add(button); - add(label3); - Properties props = new Properties(); - props.put(Context.INITIAL_CONTEXT_FACTORY, - "org.apache.openejb.client.RemoteInitialContextFactory"); - props.put(Context.PROVIDER_URL, "http://127.0.0.1:8080/applet/ejb"); - try { - ctx = new InitialContext(props); - } catch (NamingException e) { - throw new RuntimeException(e); - } - button.addActionListener(new ActionListener() { - - public void actionPerformed(ActionEvent e) { - - try { - final Object ref = ctx.lookup("CalculatorImplRemote"); - Calculator calc = (Calculator) PortableRemoteObject.narrow( - ref, Calculator.class); - String text1 = field1.getText(); - String text2 = field2.getText(); - int num1 = Integer.parseInt(text1); - int num2 = Integer.parseInt(text2); - double result = calc.add(num1, num2); - label3.setText("RESULT=" + result); - } catch (NamingException ex) { - throw new RuntimeException(ex); - } - - } - }); - - } -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.applet; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.rmi.PortableRemoteObject; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Properties; + +public class CalculatorApplet extends JApplet { + + JTextArea area; + + JTextField field1; + JTextField field2; + JLabel label1; + JLabel label2; + JButton button; + JLabel label3; + Context ctx; + + public void init() { + try { + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + createUI(); + } + }); + } catch (Exception e) { + System.err.println("createGUI didn't successfully complete"); + } + + } + + private void createUI() { + field1 = new JTextField(); + field2 = new JTextField(); + label1 = new JLabel("Enter first number"); + label2 = new JLabel("Enter second number"); + label3 = new JLabel("RESULT="); + button = new JButton("Add"); + + setLayout(new GridLayout(3, 2)); + add(label1); + add(field1); + add(label2); + add(field2); + add(button); + add(label3); + Properties props = new Properties(); + props.put(Context.INITIAL_CONTEXT_FACTORY, + "org.apache.openejb.client.RemoteInitialContextFactory"); + props.put(Context.PROVIDER_URL, "http://127.0.0.1:8080/applet/ejb"); + try { + ctx = new InitialContext(props); + } catch (NamingException e) { + throw new RuntimeException(e); + } + button.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + + try { + final Object ref = ctx.lookup("CalculatorImplRemote"); + Calculator calc = (Calculator) PortableRemoteObject.narrow( + ref, Calculator.class); + String text1 = field1.getText(); + String text2 = field2.getText(); + int num1 = Integer.parseInt(text1); + int num2 = Integer.parseInt(text2); + double result = calc.add(num1, num2); + label3.setText("RESULT=" + result); + } catch (NamingException ex) { + throw new RuntimeException(ex); + } + + } + }); + + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/applet/src/main/java/org/superbiz/applet/CalculatorImpl.java ---------------------------------------------------------------------- diff --git a/examples/applet/src/main/java/org/superbiz/applet/CalculatorImpl.java b/examples/applet/src/main/java/org/superbiz/applet/CalculatorImpl.java index 6fccc92..ef0c074 100644 --- a/examples/applet/src/main/java/org/superbiz/applet/CalculatorImpl.java +++ b/examples/applet/src/main/java/org/superbiz/applet/CalculatorImpl.java @@ -1,28 +1,28 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.applet; - -import javax.ejb.Stateless; - -@Stateless -public class CalculatorImpl implements Calculator { - - public double add(double x, double y) { - return x + y; - } - -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.applet; + +import javax.ejb.Stateless; + +@Stateless +public class CalculatorImpl implements Calculator { + + public double add(double x, double y) { + return x + y; + } + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/applet/src/test/java/org/superbiz/JNDILookupTest.java ---------------------------------------------------------------------- diff --git a/examples/applet/src/test/java/org/superbiz/JNDILookupTest.java b/examples/applet/src/test/java/org/superbiz/JNDILookupTest.java index 1663148..45bf18e 100644 --- a/examples/applet/src/test/java/org/superbiz/JNDILookupTest.java +++ b/examples/applet/src/test/java/org/superbiz/JNDILookupTest.java @@ -1,46 +1,46 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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; - -import org.junit.Assert; -import org.junit.Test; -import org.superbiz.applet.Calculator; - -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.rmi.PortableRemoteObject; -import java.util.Properties; - -public class JNDILookupTest { - - @Test - public void test() { - Properties props = new Properties(); - props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory"); - props.put(Context.PROVIDER_URL, "http://127.0.0.1:8080/tomee/ejb"); - try { - Context ctx = new InitialContext(props); - System.out.println("Found context " + ctx); - final Object ref = ctx.lookup("CalculatorImplRemote"); - Calculator calc = (Calculator) PortableRemoteObject.narrow(ref, Calculator.class); - double result = calc.add(10, 30); - Assert.assertEquals(40, result, 0.5); - } catch (Exception e) { - e.printStackTrace(); - } - } -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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; + +import org.junit.Assert; +import org.junit.Test; +import org.superbiz.applet.Calculator; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.rmi.PortableRemoteObject; +import java.util.Properties; + +public class JNDILookupTest { + + @Test + public void test() { + Properties props = new Properties(); + props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory"); + props.put(Context.PROVIDER_URL, "http://127.0.0.1:8080/tomee/ejb"); + try { + Context ctx = new InitialContext(props); + System.out.println("Found context " + ctx); + final Object ref = ctx.lookup("CalculatorImplRemote"); + Calculator calc = (Calculator) PortableRemoteObject.narrow(ref, Calculator.class); + double result = calc.add(10, 30); + Assert.assertEquals(40, result, 0.5); + } catch (Exception e) { + e.printStackTrace(); + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/application-composer/src/main/java/org/superbiz/composed/Movie.java ---------------------------------------------------------------------- diff --git a/examples/application-composer/src/main/java/org/superbiz/composed/Movie.java b/examples/application-composer/src/main/java/org/superbiz/composed/Movie.java index 88d71df..143f2ab 100644 --- a/examples/application-composer/src/main/java/org/superbiz/composed/Movie.java +++ b/examples/application-composer/src/main/java/org/superbiz/composed/Movie.java @@ -1,61 +1,61 @@ -/** - * 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.composed; - -import javax.persistence.Entity; - -@Entity -public class Movie { - - private String director; - private String title; - private int year; - - public Movie() { - } - - public Movie(String director, String title, int year) { - this.director = director; - this.title = title; - this.year = year; - } - - public String getDirector() { - return director; - } - - public void setDirector(String director) { - this.director = director; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public int getYear() { - return year; - } - - public void setYear(int year) { - this.year = year; - } - -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.composed; + +import javax.persistence.Entity; + +@Entity +public class Movie { + + private String director; + private String title; + private int year; + + public Movie() { + } + + public Movie(String director, String title, int year) { + this.director = director; + this.title = title; + this.year = year; + } + + public String getDirector() { + return director; + } + + public void setDirector(String director) { + this.director = director; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/application-composer/src/main/java/org/superbiz/composed/Movies.java ---------------------------------------------------------------------- diff --git a/examples/application-composer/src/main/java/org/superbiz/composed/Movies.java b/examples/application-composer/src/main/java/org/superbiz/composed/Movies.java index 36b2343..417280e 100644 --- a/examples/application-composer/src/main/java/org/superbiz/composed/Movies.java +++ b/examples/application-composer/src/main/java/org/superbiz/composed/Movies.java @@ -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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.composed; - -import java.util.List; - -/** - * @version $Revision: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ - */ -public interface Movies { - - void addMovie(Movie movie) throws Exception; - - void deleteMovie(Movie movie) throws Exception; - - List<Movie> getMovies() throws Exception; -} +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.composed; + +import java.util.List; + +/** + * @version $Revision: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $ + */ +public interface Movies { + + void addMovie(Movie movie) throws Exception; + + void deleteMovie(Movie movie) throws Exception; + + List<Movie> getMovies() throws Exception; +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/application-composer/src/main/java/org/superbiz/composed/MoviesImpl.java ---------------------------------------------------------------------- diff --git a/examples/application-composer/src/main/java/org/superbiz/composed/MoviesImpl.java b/examples/application-composer/src/main/java/org/superbiz/composed/MoviesImpl.java index 933d53e..b99f2e5 100644 --- a/examples/application-composer/src/main/java/org/superbiz/composed/MoviesImpl.java +++ b/examples/application-composer/src/main/java/org/superbiz/composed/MoviesImpl.java @@ -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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.composed; - -import javax.ejb.Stateful; -import javax.ejb.TransactionAttribute; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.PersistenceContextType; -import javax.persistence.Query; -import java.util.List; - -import static javax.ejb.TransactionAttributeType.MANDATORY; - -//START SNIPPET: code -@Stateful(name = "Movies") -@TransactionAttribute(MANDATORY) -public class MoviesImpl implements Movies { - - @PersistenceContext(unitName = "movie-unit", type = PersistenceContextType.TRANSACTION) - private EntityManager entityManager; - - public void addMovie(Movie movie) throws Exception { - entityManager.persist(movie); - } - - public void deleteMovie(Movie movie) throws Exception { - entityManager.remove(movie); - } - - public List<Movie> getMovies() throws Exception { - Query query = entityManager.createQuery("SELECT m from Movie as m"); - return query.getResultList(); - } -} -//END SNIPPET: code +/** + * 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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.composed; + +import javax.ejb.Stateful; +import javax.ejb.TransactionAttribute; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.PersistenceContextType; +import javax.persistence.Query; +import java.util.List; + +import static javax.ejb.TransactionAttributeType.MANDATORY; + +//START SNIPPET: code +@Stateful(name = "Movies") +@TransactionAttribute(MANDATORY) +public class MoviesImpl implements Movies { + + @PersistenceContext(unitName = "movie-unit", type = PersistenceContextType.TRANSACTION) + private EntityManager entityManager; + + public void addMovie(Movie movie) throws Exception { + entityManager.persist(movie); + } + + public void deleteMovie(Movie movie) throws Exception { + entityManager.remove(movie); + } + + public List<Movie> getMovies() throws Exception { + Query query = entityManager.createQuery("SELECT m from Movie as m"); + return query.getResultList(); + } +} +//END SNIPPET: code