├── ch09-14-employeeregistry
├── transaction.log
└── src
│ ├── test
│ └── resources
│ │ └── arquillian.xml
│ └── main
│ ├── resources
│ └── persistence.xml
│ └── java
│ └── org
│ └── jboss
│ └── ejb3
│ └── examples
│ └── employeeregistry
│ ├── ch11
│ └── relationships
│ │ ├── PhoneType.java
│ │ └── Phone.java
│ ├── ch10
│ └── mapping
│ │ ├── EmployeeType.java
│ │ ├── EmployeeWithEmbeddedPK.java
│ │ ├── EmployeeWithMappedSuperClassId.java
│ │ └── EmployeeWithExternalCompositePK.java
│ ├── ch12
│ └── inheritance
│ │ ├── tableperclass
│ │ ├── Employee.java
│ │ └── Customer.java
│ │ ├── joined
│ │ ├── Employee.java
│ │ └── Customer.java
│ │ └── singleclass
│ │ ├── Employee.java
│ │ └── Customer.java
│ └── ch14
│ └── listener
│ └── EventTracker.java
├── .gitignore
├── ch15-secureschool
├── src
│ ├── test
│ │ └── resources
│ │ │ ├── groups.properties
│ │ │ └── users.properties
│ └── main
│ │ └── java
│ │ └── org
│ │ └── jboss
│ │ └── ejb3
│ │ └── examples
│ │ └── ch15
│ │ └── secureschool
│ │ ├── api
│ │ ├── FireDepartmentLocalBusiness.java
│ │ ├── SecureSchoolLocalBusiness.java
│ │ └── SchoolClosedException.java
│ │ └── impl
│ │ ├── Roles.java
│ │ └── FireDepartmentBean.java
└── pom.xml
├── ch06-filetransfer
└── src
│ ├── test
│ └── resources
│ │ ├── ftpusers.properties
│ │ ├── arquillian.xml
│ │ └── log4j.xml
│ └── main
│ └── java
│ └── org
│ └── jboss
│ └── ejb3
│ └── examples
│ └── ch06
│ └── filetransfer
│ ├── FileTransferLocalBusiness.java
│ ├── FileTransferException.java
│ └── FileTransferCommonBusiness.java
├── ch07-rsscache
└── src
│ ├── test
│ ├── resources
│ │ ├── jndi.properties
│ │ └── log4j.xml
│ └── java
│ │ └── org
│ │ └── jboss
│ │ └── ejb3
│ │ └── examples
│ │ └── ch07
│ │ └── rsscache
│ │ └── impl
│ │ └── rome
│ │ └── TestRssCacheBean.java
│ └── main
│ └── java
│ └── org
│ └── jboss
│ └── ejb3
│ └── examples
│ └── ch07
│ └── rsscache
│ ├── spi
│ ├── RssEntry.java
│ └── RssCacheCommonBusiness.java
│ └── impl
│ └── rome
│ └── ProtectExportUtil.java
├── ch08-statusupdate
└── src
│ ├── main
│ ├── resources
│ │ └── hornetq-jms.xml
│ └── java
│ │ └── org
│ │ └── jboss
│ │ └── ejb3
│ │ └── examples
│ │ └── ch08
│ │ └── statusupdate
│ │ ├── api
│ │ └── StatusUpdateConstants.java
│ │ └── mdb
│ │ └── LoggingStatusUpdateMdb.java
│ └── test
│ └── java
│ └── org
│ └── jboss
│ └── ejb3
│ └── examples
│ └── ch08
│ └── statusupdate
│ └── mdb
│ └── TwitterUpdateBlockingTestMdb.java
├── ch08-messagedestinationlink
└── src
│ └── main
│ ├── resources
│ ├── hornet-jms.xml
│ └── META-INF
│ │ └── ejb-jar.xml
│ └── java
│ └── org
│ └── jboss
│ └── ejb3
│ └── examples
│ └── ch08
│ └── messagedestinationlink
│ ├── api
│ └── MessageDestinationLinkConstants.java
│ └── slsb
│ └── MessageSendingBusiness.java
├── ch04-firstejb
└── src
│ ├── test
│ ├── resources
│ │ ├── arquillian.xml
│ │ └── log4j.xml
│ └── java
│ │ └── org
│ │ └── jboss
│ │ └── ejb3
│ │ └── examples
│ │ └── ch04
│ │ └── firstejb
│ │ ├── CalculatorAssertionDelegate.java
│ │ ├── CalculatorUnitTestCase.java
│ │ └── CalculatorIntegrationTestCase.java
│ └── main
│ └── java
│ └── org
│ └── jboss
│ └── ejb3
│ └── examples
│ └── ch04
│ └── firstejb
│ ├── CalculatorLocalBusiness.java
│ ├── CalculatorRemoteBusiness.java
│ ├── CalculatorRemote.java
│ ├── CalculatorLocal.java
│ ├── SimpleCalculatorBean.java
│ ├── NoInterfaceViewCalculatorBean.java
│ ├── CalculatorCommonBusiness.java
│ ├── CalculatorLocalHome.java
│ ├── CalculatorRemoteHome.java
│ ├── ManyViewCalculatorBean.java
│ └── CalculatorBeanBase.java
├── ch05-encryption
└── src
│ ├── test
│ ├── resources
│ │ ├── arquillian.xml
│ │ └── log4j.xml
│ └── java
│ │ └── org
│ │ └── jboss
│ │ └── ejb3
│ │ └── examples
│ │ └── ch05
│ │ └── encryption
│ │ └── EncryptionUnitTestCase.java
│ └── main
│ ├── resources
│ └── META-INF
│ │ └── ejb-jar.xml
│ └── java
│ └── org
│ └── jboss
│ └── ejb3
│ └── examples
│ └── ch05
│ └── encryption
│ ├── EncryptionLocalBusiness.java
│ ├── EncryptionRemoteBusiness.java
│ └── EncryptionException.java
├── ch17-transactions
└── src
│ ├── test
│ ├── resources
│ │ └── arquillian.xml
│ └── java
│ │ └── org
│ │ └── jboss
│ │ └── ejb3
│ │ └── examples
│ │ └── ch17
│ │ └── transactions
│ │ └── ejb
│ │ └── ExampleUserData.java
│ └── main
│ ├── resources
│ └── persistence.xml
│ └── java
│ └── org
│ └── jboss
│ └── ejb3
│ └── examples
│ └── ch17
│ └── transactions
│ ├── impl
│ └── BlackjackServiceConstants.java
│ ├── api
│ ├── InsufficientBalanceException.java
│ └── BlackjackGameLocalBusiness.java
│ └── entity
│ └── User.java
├── ch18-interceptors
└── src
│ ├── test
│ └── resources
│ │ └── arquillian.xml
│ └── main
│ └── java
│ └── org
│ └── jboss
│ └── ejb3
│ └── examples
│ └── ch18
│ └── tuner
│ ├── TunerLocalBusiness.java
│ ├── Channel2ClosedException.java
│ ├── Channel2AccessPolicy.java
│ ├── AuditedInvocation.java
│ └── TunerBean.java
├── testsupport
├── pom.xml
└── src
│ └── main
│ └── java
│ └── org
│ └── jboss
│ └── ejb3
│ └── examples
│ └── testsupport
│ ├── dbinit
│ └── DbInitializerLocalBusiness.java
│ ├── entity
│ ├── IdentityBase.java
│ └── AutogenIdentityBase.java
│ ├── dbquery
│ ├── EntityManagerExposingLocalBusiness.java
│ └── EntityManagerExposingBean.java
│ └── txwrap
│ ├── ForcedTestException.java
│ ├── TxWrappingLocalBusiness.java
│ ├── TaskExecutionException.java
│ └── TxWrappingBean.java
├── pom.xml
└── ch19-timer
├── pom.xml
└── src
└── main
└── java
└── org
└── jboss
└── ejb3
└── examples
└── ch19
└── timer
└── api
├── CreditCardTransactionProcessingLocalBusiness.java
└── CreditCardTransaction.java
/ch09-14-employeeregistry/transaction.log:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | target
2 | bin
3 | .classpath
4 | .project
5 | .settings
6 | */transaction.log
7 |
--------------------------------------------------------------------------------
/ch15-secureschool/src/test/resources/groups.properties:
--------------------------------------------------------------------------------
1 | # OpenEJB Roles Configuration
2 | # Format: Role=Username
3 | Administrator=admin
4 | Janitor=janitor
5 | Student=student
--------------------------------------------------------------------------------
/ch15-secureschool/src/test/resources/users.properties:
--------------------------------------------------------------------------------
1 | # OpenEJB Users Configuration
2 | # Format: Username=Password
3 | admin=adminPassword
4 | student=studentPassword
5 | janitor=janitorPassword
--------------------------------------------------------------------------------
/ch06-filetransfer/src/test/resources/ftpusers.properties:
--------------------------------------------------------------------------------
1 | # Users / Passwords file
2 | ftpserver.user.user.idletime=0
3 | ftpserver.user.user.userpassword=password
4 | ftpserver.user.user.homedirectory=/
5 | ftpserver.user.user.writepermission=true
6 | ftpserver.user.user.enableflag=true
--------------------------------------------------------------------------------
/ch07-rsscache/src/test/resources/jndi.properties:
--------------------------------------------------------------------------------
1 | # JNDI Properties for Remote interaction with JBoss Application Server Naming Service
2 | java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
3 | java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
4 | java.naming.provider.url=jnp://localhost:1099
--------------------------------------------------------------------------------
/ch08-statusupdate/src/main/resources/hornetq-jms.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/ch08-messagedestinationlink/src/main/resources/hornet-jms.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/ch04-firstejb/src/test/resources/arquillian.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | target/jboss-as-7.0.1.Final
8 |
9 |
10 | REMOTE
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/ch05-encryption/src/test/resources/arquillian.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | target/jboss-as-7.0.1.Final
8 |
9 |
10 | REMOTE
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/ch06-filetransfer/src/test/resources/arquillian.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | target/jboss-as-7.0.1.Final
8 |
9 |
10 | REMOTE
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/ch17-transactions/src/test/resources/arquillian.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | target/jboss-as-7.0.1.Final
8 |
9 |
10 | REMOTE
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/ch18-interceptors/src/test/resources/arquillian.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | target/jboss-as-7.0.1.Final
8 |
9 |
10 | REMOTE
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/ch09-14-employeeregistry/src/test/resources/arquillian.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | target/jboss-as-7.0.1.Final
8 |
9 |
10 | REMOTE
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/ch17-transactions/src/main/resources/persistence.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 | java:jboss/datasources/ExampleDS
9 |
10 |
11 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/ch09-14-employeeregistry/src/main/resources/persistence.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 | java:jboss/datasources/ExampleDS
9 |
10 |
11 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/testsupport/pom.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 | org.jboss.ejb3.examples
7 | jboss-ejb3-examples-build
8 | 1.1.0-SNAPSHOT
9 | ../build/pom.xml
10 |
11 |
12 |
13 | 4.0.0
14 |
15 |
16 | jboss-ejb3-examples-testsupport
17 | JBoss EJB 3.x Examples - Test Support
18 | Common Test Support for examples to accompany O'Reilly "Enterprise Java Beans 6th Edition"
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | javax
37 | javaee-api
38 | provided
39 | true
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 | 4.0.0
6 |
7 |
8 | org.jboss.ejb3.examples
9 | jboss-ejb3-examples-aggregator
10 | Aggregator POM for JBoss EJB3 Examples
11 | 1.1.0-SNAPSHOT
12 | Aggregator POM for JBoss EJB3 Examples
13 | pom
14 |
15 |
16 |
17 | build
18 | ch04-firstejb
19 | ch05-encryption
20 | ch06-filetransfer
21 | ch07-rsscache
22 |
23 |
28 | ch08-messagedestinationlink
29 | ch09-14-employeeregistry
30 | ch15-secureschool
31 | ch17-transactions
32 | ch18-interceptors
33 | ch19-timer
34 | testsupport
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/ch05-encryption/src/main/resources/META-INF/ejb-jar.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
13 |
14 |
15 |
19 | EncryptionEJB
20 |
21 |
22 |
23 | ciphersPassphrase
24 | java.lang.String
25 | OverriddenPassword
26 |
27 |
28 |
29 |
30 | messageDigestAlgorithm
31 | java.lang.String
32 | SHA
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/ch04-firstejb/src/main/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorLocalBusiness.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 |
23 | package org.jboss.ejb3.examples.ch04.firstejb;
24 |
25 | /**
26 | * Local business interface for the CalculatorEJB
27 | *
28 | * @author ALR
29 | */
30 | public interface CalculatorLocalBusiness extends CalculatorCommonBusiness
31 | {
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/ch04-firstejb/src/main/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorRemoteBusiness.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 |
23 | package org.jboss.ejb3.examples.ch04.firstejb;
24 |
25 | /**
26 | * Remote business interface for the CalculatorEJB
27 | *
28 | * @author ALR
29 | */
30 | public interface CalculatorRemoteBusiness extends CalculatorCommonBusiness
31 | {
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/ch05-encryption/src/main/java/org/jboss/ejb3/examples/ch05/encryption/EncryptionLocalBusiness.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch05.encryption;
23 |
24 | /**
25 | * EJB 3.x Local Business View of the EncryptionEJB
26 | *
27 | * @author ALR
28 | */
29 | public interface EncryptionLocalBusiness extends EncryptionCommonBusiness
30 | {
31 | // Contracts in hierarchy
32 | }
33 |
--------------------------------------------------------------------------------
/ch05-encryption/src/main/java/org/jboss/ejb3/examples/ch05/encryption/EncryptionRemoteBusiness.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch05.encryption;
23 |
24 | /**
25 | * EJB 3.x Remote Business View of the EncryptionEJB
26 | *
27 | * @author ALR
28 | */
29 | public interface EncryptionRemoteBusiness extends EncryptionCommonBusiness
30 | {
31 | // Contracts in hierarchy
32 | }
33 |
--------------------------------------------------------------------------------
/ch09-14-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/ch11/relationships/PhoneType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.employeeregistry.ch11.relationships;
23 |
24 | /**
25 | * Type of number associated with a {@link Phone}
26 | *
27 | * @author ALR
28 | * @version $Revision: $
29 | */
30 | public enum PhoneType {
31 | MOBILE, HOME, WORK
32 | }
33 |
--------------------------------------------------------------------------------
/ch04-firstejb/src/main/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorRemote.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 |
23 | package org.jboss.ejb3.examples.ch04.firstejb;
24 |
25 | import javax.ejb.EJBObject;
26 |
27 | /**
28 | * EJB 2.x Remote Component interface of the CalculatorEJB
29 | *
30 | * @author ALR
31 | */
32 | public interface CalculatorRemote extends CalculatorCommonBusiness, EJBObject
33 | {
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/ch04-firstejb/src/main/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorLocal.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 |
23 | package org.jboss.ejb3.examples.ch04.firstejb;
24 |
25 | import javax.ejb.EJBLocalObject;
26 |
27 | /**
28 | * EJB 2.x Local Component interface of the CalculatorEJB
29 | *
30 | * @author ALR
31 | */
32 | public interface CalculatorLocal extends CalculatorCommonBusiness, EJBLocalObject
33 | {
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/ch04-firstejb/src/test/resources/log4j.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/ch05-encryption/src/test/resources/log4j.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/ch06-filetransfer/src/test/resources/log4j.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/ch07-rsscache/src/test/resources/log4j.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/ch09-14-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/ch10/mapping/EmployeeType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.employeeregistry.ch10.mapping;
23 |
24 | import javax.persistence.Enumerated;
25 |
26 | /**
27 | * Types of employees in the system. Used to show {@link Enumerated}
28 | * in the entity {@link EmployeeWithProperties}.
29 | *
30 | * @author ALR
31 | * @version $Revision: $
32 | */
33 | public enum EmployeeType {
34 | MANAGER, PEON;
35 | }
36 |
--------------------------------------------------------------------------------
/ch04-firstejb/src/main/java/org/jboss/ejb3/examples/ch04/firstejb/SimpleCalculatorBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 |
23 | package org.jboss.ejb3.examples.ch04.firstejb;
24 |
25 | import javax.ejb.Local;
26 | import javax.ejb.Stateless;
27 |
28 | /**
29 | * Bean implementation class of the CalculatorEJB which
30 | * exposes one local business view
31 | *
32 | * @author ALR
33 | */
34 | @Stateless
35 | @Local(CalculatorLocalBusiness.class)
36 | public class SimpleCalculatorBean extends CalculatorBeanBase implements CalculatorCommonBusiness
37 | {
38 | /*
39 | * Implementation supplied by common base class
40 | */
41 | }
42 |
--------------------------------------------------------------------------------
/ch04-firstejb/src/main/java/org/jboss/ejb3/examples/ch04/firstejb/NoInterfaceViewCalculatorBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 |
23 | package org.jboss.ejb3.examples.ch04.firstejb;
24 |
25 | import javax.ejb.LocalBean;
26 | import javax.ejb.Stateless;
27 |
28 | /**
29 | * Bean implementation class of the CalculatorEJB which
30 | * has a no-interface view
31 | *
32 | * @author ALR
33 | */
34 | @Stateless
35 | @LocalBean
36 | //TODO This is not yet tested as OpenEJB 3.1.2 doesn't yet support no-interface views EJBBOOK-28
37 | public class NoInterfaceViewCalculatorBean extends CalculatorBeanBase
38 | {
39 | // Implementation in base class
40 | }
41 |
--------------------------------------------------------------------------------
/ch17-transactions/src/test/java/org/jboss/ejb3/examples/ch17/transactions/ejb/ExampleUserData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch17.transactions.ejb;
23 |
24 | import java.math.BigDecimal;
25 |
26 | /**
27 | * Contains example user data to be seeded in testing
28 | *
29 | * @author ALR
30 | * @version $Revision: $
31 | */
32 | public interface ExampleUserData
33 | {
34 | /*
35 | * Test Data
36 | */
37 |
38 | long USER_ALRUBINGER_ID = 2L;
39 |
40 | String USER_ALRUBINGER_NAME = "Andrew Lee Rubinger";
41 |
42 | long ACCOUNT_ALRUBINGER_ID = 2L;
43 |
44 | BigDecimal INITIAL_ACCOUNT_BALANCE_ALR = new BigDecimal(500);
45 | }
46 |
--------------------------------------------------------------------------------
/ch04-firstejb/src/main/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorCommonBusiness.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 |
23 | package org.jboss.ejb3.examples.ch04.firstejb;
24 |
25 | /**
26 | * Contains the contract for operations common to
27 | * all business interfaces of the CalculatorEJB
28 | *
29 | * @author ALR
30 | */
31 | public interface CalculatorCommonBusiness
32 | {
33 |
34 | // ---------------------------------------------------------------------------||
35 | // Contracts -----------------------------------------------------------------||
36 | // ---------------------------------------------------------------------------||
37 |
38 | /**
39 | * Adds all arguments
40 | *
41 | * @return The sum of all arguments
42 | */
43 | int add(int... arguments);
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/ch04-firstejb/src/main/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorLocalHome.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 |
23 | package org.jboss.ejb3.examples.ch04.firstejb;
24 |
25 | import javax.ejb.CreateException;
26 | import javax.ejb.EJBLocalHome;
27 |
28 | /**
29 | * EJB 2.x Local Home of the CalculatorEJB
30 | *
31 | * @author ALR
32 | */
33 | public interface CalculatorLocalHome extends EJBLocalHome
34 | {
35 | // ---------------------------------------------------------------------------||
36 | // create Methods ----------------------------------------------------||
37 | // ---------------------------------------------------------------------------||
38 |
39 | /**
40 | * Returns a reference to a local component view of the CalculatorEJB
41 | */
42 | CalculatorLocal create() throws CreateException;
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/ch04-firstejb/src/main/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorRemoteHome.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 |
23 | package org.jboss.ejb3.examples.ch04.firstejb;
24 |
25 | import java.rmi.RemoteException;
26 |
27 | import javax.ejb.CreateException;
28 | import javax.ejb.EJBHome;
29 |
30 | /**
31 | * EJB 2.x Remote Home of the CalculatorEJB
32 | *
33 | * @author ALR
34 | */
35 | public interface CalculatorRemoteHome extends EJBHome
36 | {
37 | // ---------------------------------------------------------------------------||
38 | // create Methods ----------------------------------------------------||
39 | // ---------------------------------------------------------------------------||
40 |
41 | /**
42 | * Returns a reference to a remote component view of the CalculatorEJB
43 | */
44 | CalculatorRemote create() throws CreateException, RemoteException;
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/ch15-secureschool/src/main/java/org/jboss/ejb3/examples/ch15/secureschool/api/FireDepartmentLocalBusiness.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch15.secureschool.api;
23 |
24 | /**
25 | * Represents a fire department capable of declaring
26 | * a state of emergency. Anyone may invoke this support,
27 | * and when an alert is raised we'll close the local school.
28 | *
29 | * @author ALR
30 | * @version $Revision: $
31 | */
32 | public interface FireDepartmentLocalBusiness
33 | {
34 | // ---------------------------------------------------------------------------||
35 | // Contracts -----------------------------------------------------------------||
36 | // ---------------------------------------------------------------------------||
37 |
38 | /**
39 | * Declares a state of emergency, so we must close the local school
40 | */
41 | void declareEmergency();
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/ch08-messagedestinationlink/src/main/resources/META-INF/ejb-jar.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
12 |
13 |
14 |
18 | MessageSendingEJB
19 |
20 |
25 |
26 | queue/MessageDestinationLinkQueue
27 | javax.jms.Queue
28 | Produces
29 | OurLinkName
30 |
31 |
32 |
33 |
34 |
38 |
39 | MessageDestinationLinkMdb
40 | OurLinkName
41 |
42 |
43 |
44 |
45 |
49 |
50 |
51 | OurLinkName
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/dbinit/DbInitializerLocalBusiness.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.testsupport.dbinit;
23 |
24 | /**
25 | * Contract of an EJB which can reset and populate a database with
26 | * known data for user tests
27 | *
28 | * @author ALR
29 | * @version $Revision: $
30 | */
31 | public interface DbInitializerLocalBusiness
32 | {
33 | //-------------------------------------------------------------------------------------||
34 | // Contracts --------------------------------------------------------------------------||
35 | //-------------------------------------------------------------------------------------||
36 |
37 | /**
38 | * Clears and repopulates the database with default test data
39 | *
40 | * @throws Exception If an error occurred in refreshing with default data
41 | */
42 | void refreshWithDefaultData() throws Exception;
43 | }
44 |
--------------------------------------------------------------------------------
/ch17-transactions/src/main/java/org/jboss/ejb3/examples/ch17/transactions/impl/BlackjackServiceConstants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch17.transactions.impl;
23 |
24 | import java.math.BigDecimal;
25 |
26 | /**
27 | * Constants used by the implementation of the
28 | * {@link BlackjackGameBean}
29 | *
30 | * @author ALR
31 | * @version $Revision: $
32 | */
33 | public interface BlackjackServiceConstants
34 | {
35 | //-------------------------------------------------------------------------------------||
36 | // Constants --------------------------------------------------------------------------||
37 | //-------------------------------------------------------------------------------------||
38 |
39 | long USER_BLACKJACKGAME_ID = 1L;
40 |
41 | String USER_BLACKJACKGAME_NAME = "The Blackjack Game System";
42 |
43 | long ACCOUNT_BLACKJACKGAME_ID = 1L;
44 |
45 | BigDecimal INITIAL_ACCOUNT_BALANCE_BLACKJACKGAME = new BigDecimal(10000);
46 | }
47 |
--------------------------------------------------------------------------------
/ch04-firstejb/src/main/java/org/jboss/ejb3/examples/ch04/firstejb/ManyViewCalculatorBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 |
23 | package org.jboss.ejb3.examples.ch04.firstejb;
24 |
25 | import javax.ejb.Local;
26 | import javax.ejb.LocalBean;
27 | import javax.ejb.LocalHome;
28 | import javax.ejb.Remote;
29 | import javax.ejb.RemoteHome;
30 | import javax.ejb.Stateless;
31 |
32 | /**
33 | * Bean implementation class of the CalculatorEJB which
34 | * exposes local and remote business and component views,
35 | * as well as an EJB 3.1 no-interface view
36 | *
37 | * @author ALR
38 | */
39 | @Stateless
40 | @Local(CalculatorLocalBusiness.class)
41 | @Remote(CalculatorRemoteBusiness.class)
42 | @LocalHome(CalculatorLocalHome.class)
43 | @RemoteHome(CalculatorRemoteHome.class)
44 | @LocalBean // No-interface view
45 | public class ManyViewCalculatorBean extends CalculatorBeanBase implements CalculatorCommonBusiness
46 | {
47 | /*
48 | * Implementation supplied by common base class
49 | */
50 | }
51 |
--------------------------------------------------------------------------------
/ch07-rsscache/src/test/java/org/jboss/ejb3/examples/ch07/rsscache/impl/rome/TestRssCacheBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch07.rsscache.impl.rome;
23 |
24 | import java.net.URL;
25 |
26 | /**
27 | * Extension of the RSS Cache Bean which exposes support to
28 | * set the Feed URL for testing
29 | *
30 | * @author ALR
31 | */
32 | public class TestRssCacheBean extends RssCacheBean
33 | {
34 |
35 | //-------------------------------------------------------------------------------------||
36 | // Overridden Implementations ---------------------------------------------------------||
37 | //-------------------------------------------------------------------------------------||
38 |
39 | /* (non-Javadoc)
40 | * @see org.jboss.ejb3.examples.ch07.rsscache.impl.rome.RssCacheBean#setUrl(java.net.URL)
41 | */
42 | @Override
43 | public void setUrl(final URL url) throws IllegalArgumentException
44 | {
45 | super.setUrl(url);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/ch06-filetransfer/src/main/java/org/jboss/ejb3/examples/ch06/filetransfer/FileTransferLocalBusiness.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch06.filetransfer;
23 |
24 | import javax.ejb.Remove;
25 |
26 | /**
27 | * Local Business interface for the FileTransferEJB.
28 | * Because this will only be used in EJB environments, we define
29 | * a method to end the current session.
30 | *
31 | * @author ALR
32 | */
33 | public interface FileTransferLocalBusiness extends FileTransferCommonBusiness
34 | {
35 | // ---------------------------------------------------------------------------||
36 | // Contracts -----------------------------------------------------------------||
37 | // ---------------------------------------------------------------------------||
38 |
39 | /**
40 | * Ends the current session; will result in a SFSB @Remove call
41 | * as the bean implementation class will annotate this with
42 | * {@link Remove}
43 | */
44 | void endSession();
45 | }
46 |
--------------------------------------------------------------------------------
/ch18-interceptors/src/main/java/org/jboss/ejb3/examples/ch18/tuner/TunerLocalBusiness.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch18.tuner;
23 |
24 | import java.io.InputStream;
25 |
26 | /**
27 | * Local business interface of an EJB which
28 | * provides access to television streams
29 | *
30 | * @author ALR
31 | * @version $Revision: $
32 | */
33 | public interface TunerLocalBusiness
34 | {
35 | //-------------------------------------------------------------------------------------||
36 | // Contracts --------------------------------------------------------------------------||
37 | //-------------------------------------------------------------------------------------||
38 |
39 | /**
40 | * Obtains the stream containing viewable content
41 | * for the specified television channel. Supported channels are 1 and 2.
42 | *
43 | * @param channel
44 | * @return
45 | * @throws IllegalArgumentException If the channel is not valid
46 | */
47 | InputStream getChannel(int channel) throws IllegalArgumentException;
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/ch07-rsscache/src/main/java/org/jboss/ejb3/examples/ch07/rsscache/spi/RssEntry.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch07.rsscache.spi;
23 |
24 | import java.net.URL;
25 |
26 | /**
27 | * Defines the contract for a single RSS Entry
28 | *
29 | * @author ALR
30 | */
31 | public interface RssEntry
32 | {
33 | // ---------------------------------------------------------------------------||
34 | // Contracts -----------------------------------------------------------------||
35 | // ---------------------------------------------------------------------------||
36 |
37 | /**
38 | * Obtains the author of the entry
39 | *
40 | * @return
41 | */
42 | String getAuthor();
43 |
44 | /**
45 | * Obtains the title of the entry
46 | *
47 | * @return
48 | */
49 | String getTitle();
50 |
51 | /**
52 | * Obtains the URL linking to the entry
53 | *
54 | * @return
55 | */
56 | URL getUrl();
57 |
58 | /**
59 | * Obtains the short description of the entry
60 | *
61 | * @return
62 | */
63 | String getDescription();
64 | }
65 |
--------------------------------------------------------------------------------
/ch15-secureschool/src/main/java/org/jboss/ejb3/examples/ch15/secureschool/impl/Roles.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch15.secureschool.impl;
23 |
24 | /**
25 | * Holds the list of roles with which users of the school
26 | * may be affiliated. EJB Security is role-based, so this
27 | * is how we'll determine access.
28 | *
29 | * @author ALR
30 | * @version $Revision: $
31 | */
32 | public interface Roles
33 | {
34 | // ---------------------------------------------------------------------------||
35 | // Constants -----------------------------------------------------------------||
36 | // ---------------------------------------------------------------------------||
37 |
38 | /*
39 | * Roles of callers to the system
40 | */
41 |
42 | /**
43 | * Role denoting the user is a school administrator
44 | */
45 | String ADMIN = "Administrator";
46 |
47 | /**
48 | * Role denoting the user is a student
49 | */
50 | String STUDENT = "Student";
51 |
52 | /**
53 | * Role denoting the user is a janitor
54 | */
55 | String JANITOR = "Janitor";
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/ch07-rsscache/src/main/java/org/jboss/ejb3/examples/ch07/rsscache/spi/RssCacheCommonBusiness.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch07.rsscache.spi;
23 |
24 | import java.net.URL;
25 | import java.util.List;
26 |
27 | /**
28 | * Common business interface for beans exposing a cached view of an RSS
29 | * Feed (ie. the EJB Container)
30 | *
31 | * @author ALR
32 | */
33 | public interface RssCacheCommonBusiness
34 | {
35 | // ---------------------------------------------------------------------------||
36 | // Contracts -----------------------------------------------------------------||
37 | // ---------------------------------------------------------------------------||
38 |
39 | /**
40 | * Returns all entries in the RSS Feed represented by {@link RssCacheCommonBusiness#getUrl()}.
41 | * This list will not support mutation and is read-only.
42 | */
43 | List getEntries();
44 |
45 | /**
46 | * Returns the URL of the RSS Feed
47 | *
48 | * @return
49 | */
50 | URL getUrl();
51 |
52 | /**
53 | * Flushes the cache and refreshes the entries from the feed
54 | */
55 | void refresh();
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/ch08-messagedestinationlink/src/main/java/org/jboss/ejb3/examples/ch08/messagedestinationlink/api/MessageDestinationLinkConstants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch08.messagedestinationlink.api;
23 |
24 | /**
25 | * Contains constants used in referring to resources shared
26 | * by clients of the MessageDestinationLink EJBs.
27 | *
28 | * @author ALR
29 | * @version $Revision: $
30 | */
31 | public interface MessageDestinationLinkConstants
32 | {
33 | //-------------------------------------------------------------------------------------||
34 | // Contracts --------------------------------------------------------------------------||
35 | //-------------------------------------------------------------------------------------||
36 |
37 | /**
38 | * JNDI Name of the JMS Connection Factory
39 | */
40 | String JNDI_NAME_CONNECTION_FACTORY = "ConnectionFactory";
41 |
42 | /**
43 | * Name of the Message Destination Link Ref
44 | */
45 | String NAME_MESSAGE_DESTINATION_LINK_REF = "queue/MessageDestinationLinkQueue"; // To match XML message-destination-ref-name
46 |
47 | /**
48 | * The type of destination used by StatusUpdate MDB implementations
49 | */
50 | String TYPE_DESTINATION = "javax.jms.Queue";
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/ch08-statusupdate/src/main/java/org/jboss/ejb3/examples/ch08/statusupdate/api/StatusUpdateConstants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch08.statusupdate.api;
23 |
24 | import javax.management.ObjectName;
25 |
26 | /**
27 | * Contains constants used in referring to resources shared
28 | * by clients of the StatusUpdate MDBs.
29 | *
30 | * @author ALR
31 | */
32 | public interface StatusUpdateConstants
33 | {
34 | //-------------------------------------------------------------------------------------||
35 | // Contracts --------------------------------------------------------------------------||
36 | //-------------------------------------------------------------------------------------||
37 |
38 | /**
39 | * JNDI Name of the pub/sub Topic for status updates
40 | */
41 | String JNDI_NAME_TOPIC_STATUSUPDATE = "topic/StatusUpdate";
42 |
43 | /**
44 | * The type of destination used by StatusUpdate MDB implementations
45 | */
46 | String TYPE_DESTINATION_STATUSUPDATE = "javax.jms.Topic";
47 |
48 | /**
49 | * The JMX {@link ObjectName} which will be used as a dependency name for the Topic
50 | */
51 | String OBJECT_NAME_TOPIC_STATUSUPDATE = "jboss.messaging.destination:service=Topic,name=StatusUpdate";
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/entity/IdentityBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.testsupport.entity;
23 |
24 | import javax.persistence.Id;
25 | import javax.persistence.MappedSuperclass;
26 |
27 | /**
28 | * Base class for all entities with a manually-assigned ID
29 | *
30 | * @author ALR
31 | * @version $Revision: $
32 | */
33 | @MappedSuperclass
34 | public abstract class IdentityBase
35 | {
36 |
37 | //-------------------------------------------------------------------------------------||
38 | // Instance Members -------------------------------------------------------------------||
39 | //-------------------------------------------------------------------------------------||
40 |
41 | /**
42 | * Primary key
43 | */
44 | @Id
45 | private Long id;
46 |
47 | //-------------------------------------------------------------------------------------||
48 | // Accessors / Mutators ---------------------------------------------------------------||
49 | //-------------------------------------------------------------------------------------||
50 |
51 | /**
52 | * @return the id
53 | */
54 | public Long getId()
55 | {
56 | return id;
57 | }
58 |
59 | /**
60 | * @param id the id to set
61 | */
62 | public void setId(final Long id)
63 | {
64 | this.id = id;
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/dbquery/EntityManagerExposingLocalBusiness.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.testsupport.dbquery;
23 |
24 | import javax.ejb.TransactionAttributeType;
25 | import javax.persistence.EntityManager;
26 |
27 | /**
28 | * Contract of a test EJB which exposes generic database
29 | * operations directly via the {@link EntityManager}.
30 | * Used in validating pre- and postconditions during testing.
31 | * All methods will be executed in an existing Transaction, which
32 | * is {@link TransactionAttributeType#MANDATORY}.
33 | *
34 | * @author ALR
35 | * @version $Revision: $
36 | */
37 | public interface EntityManagerExposingLocalBusiness
38 | {
39 |
40 | //-------------------------------------------------------------------------------------||
41 | // Contracts --------------------------------------------------------------------------||
42 | //-------------------------------------------------------------------------------------||
43 |
44 | /**
45 | * Obtains a direct reference to the underlying {@link EntityManager},
46 | * which may be used directly from tests (in the context of a running
47 | * Transaction) to perform direct operations such as {@link EntityManager#persist(Object)},
48 | * {@link EntityManager#find(Class, Object)}, and {@link EntityManager#remove(Object)}.
49 | */
50 | EntityManager getEntityManager();
51 | }
52 |
--------------------------------------------------------------------------------
/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/ForcedTestException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.testsupport.txwrap;
23 |
24 | import javax.ejb.ApplicationException;
25 |
26 | /**
27 | * May be thrown manually by the test to force a transactional
28 | * rollback condition
29 | *
30 | * @author ALR
31 | * @version $Revision: $
32 | */
33 | @ApplicationException(rollback = true)
34 | public class ForcedTestException extends Exception
35 | {
36 | //-------------------------------------------------------------------------------------||
37 | // Class Members ----------------------------------------------------------------------||
38 | //-------------------------------------------------------------------------------------||
39 |
40 | /**
41 | * serialVersionUID
42 | */
43 | private static final long serialVersionUID = 1L;
44 |
45 | /**
46 | * Message to be thrown
47 | */
48 | private static final String MESSAGE = "Intentional Test Exception";
49 |
50 | //-------------------------------------------------------------------------------------||
51 | // Constructor ------------------------------------------------------------------------||
52 | //-------------------------------------------------------------------------------------||
53 |
54 | /**
55 | * Creates a new instance
56 | */
57 | public ForcedTestException()
58 | {
59 | super(MESSAGE);
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/ch17-transactions/src/main/java/org/jboss/ejb3/examples/ch17/transactions/api/InsufficientBalanceException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch17.transactions.api;
23 |
24 | import javax.ejb.ApplicationException;
25 |
26 | /**
27 | * Exception thrown when attempting to invoke an operation that requires
28 | * more funds than are currently available
29 | *
30 | * @author ALR
31 | * @version $Revision: $
32 | */
33 | @ApplicationException(rollback = true)
34 | public class InsufficientBalanceException extends Exception
35 | {
36 |
37 | //-------------------------------------------------------------------------------------||
38 | // Class Members ----------------------------------------------------------------------||
39 | //-------------------------------------------------------------------------------------||
40 |
41 | /**
42 | * serialVersionUID
43 | */
44 | private static final long serialVersionUID = 1L;
45 |
46 | //-------------------------------------------------------------------------------------||
47 | // Constructor ------------------------------------------------------------------------||
48 | //-------------------------------------------------------------------------------------||
49 |
50 | /**
51 | * Creates a new {@link InsufficientBalanceException} with the specified message
52 | */
53 | public InsufficientBalanceException(final String message)
54 | {
55 | super(message);
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/ch06-filetransfer/src/main/java/org/jboss/ejb3/examples/ch06/filetransfer/FileTransferException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch06.filetransfer;
23 |
24 | /**
25 | * Exception to indicate that a problem has occurred during
26 | * a file transfer operation.
27 | *
28 | * @author ALR
29 | */
30 | public class FileTransferException extends RuntimeException
31 | {
32 |
33 | //-------------------------------------------------------------------------------------||
34 | // Class Members ----------------------------------------------------------------------||
35 | //-------------------------------------------------------------------------------------||
36 |
37 | private static final long serialVersionUID = 1L;
38 |
39 | //-------------------------------------------------------------------------------------||
40 | // Constructor ------------------------------------------------------------------------||
41 | //-------------------------------------------------------------------------------------||
42 |
43 | public FileTransferException()
44 | {
45 | super();
46 | }
47 |
48 | public FileTransferException(final String message, final Throwable cause)
49 | {
50 | super(message, cause);
51 | }
52 |
53 | public FileTransferException(final String message)
54 | {
55 | super(message);
56 | }
57 |
58 | public FileTransferException(final Throwable cause)
59 | {
60 | super(cause);
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/ch09-14-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/ch12/inheritance/tableperclass/Employee.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.employeeregistry.ch12.inheritance.tableperclass;
23 |
24 | import javax.persistence.Entity;
25 |
26 | /**
27 | * Employee
28 | *
29 | * @author ALR
30 | * @version $Revision: $
31 | */
32 | @Entity(name = "TABLEPERCLASS_EMPLOYEE")
33 | public class Employee extends Customer
34 | {
35 | //-------------------------------------------------------------------------------------||
36 | // Instance Members -------------------------------------------------------------------||
37 | //-------------------------------------------------------------------------------------||
38 |
39 | /**
40 | * ID of the Employee
41 | */
42 | private Integer employeeId;
43 |
44 | //-------------------------------------------------------------------------------------||
45 | // Accessors / Mutators ---------------------------------------------------------------||
46 | //-------------------------------------------------------------------------------------||
47 |
48 | /**
49 | * @return the employeeId
50 | */
51 | public Integer getEmployeeId()
52 | {
53 | return employeeId;
54 | }
55 |
56 | /**
57 | * @param employeeId the employeeId to set
58 | */
59 | public void setEmployeeId(final Integer employeeId)
60 | {
61 | this.employeeId = employeeId;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/TxWrappingLocalBusiness.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.testsupport.txwrap;
23 |
24 | import java.util.concurrent.Callable;
25 |
26 | /**
27 | * Contract of an EJB which wraps arbitrary {@link Callable}
28 | * tasks inside of a new Tx.
29 | *
30 | * @author ALR
31 | * @version $Revision: $
32 | */
33 | public interface TxWrappingLocalBusiness
34 | {
35 |
36 | //-------------------------------------------------------------------------------------||
37 | // Contracts --------------------------------------------------------------------------||
38 | //-------------------------------------------------------------------------------------||
39 |
40 | /**
41 | * Wraps the specified task in a new Transaction, returning the value
42 | *
43 | * @param task
44 | * @throws IllegalArgumentException If no task is specified
45 | * @throws TaskExecutionException If an error occurred in invoking {@link Callable#call()}
46 | */
47 | T wrapInTx(Callable task) throws IllegalArgumentException, TaskExecutionException;
48 |
49 | /**
50 | * Wraps the specified tasks in a new Transaction
51 | *
52 | * @param task
53 | * @throws IllegalArgumentException If no tasks are specified
54 | * @throws TaskExecutionException If an error occurred in invoking {@link Callable#call()}
55 | */
56 | void wrapInTx(Callable>... tasks) throws IllegalArgumentException, TaskExecutionException;
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/ch09-14-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/ch12/inheritance/joined/Employee.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.employeeregistry.ch12.inheritance.joined;
23 |
24 | import javax.persistence.Entity;
25 | import javax.persistence.PrimaryKeyJoinColumn;
26 |
27 | /**
28 | * Employee
29 | *
30 | * @author ALR
31 | * @version $Revision: $
32 | */
33 | @Entity(name = "JOINED_EMPLOYEE")
34 | @PrimaryKeyJoinColumn(name = "EMP_PK")
35 | public class Employee extends Customer
36 | {
37 | //-------------------------------------------------------------------------------------||
38 | // Instance Members -------------------------------------------------------------------||
39 | //-------------------------------------------------------------------------------------||
40 |
41 | /**
42 | * ID of the Employee
43 | */
44 | private Integer employeeId;
45 |
46 | //-------------------------------------------------------------------------------------||
47 | // Accessors / Mutators ---------------------------------------------------------------||
48 | //-------------------------------------------------------------------------------------||
49 |
50 | /**
51 | * @return the employeeId
52 | */
53 | public Integer getEmployeeId()
54 | {
55 | return employeeId;
56 | }
57 |
58 | /**
59 | * @param employeeId the employeeId to set
60 | */
61 | public void setEmployeeId(final Integer employeeId)
62 | {
63 | this.employeeId = employeeId;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/ch09-14-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/ch12/inheritance/singleclass/Employee.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.employeeregistry.ch12.inheritance.singleclass;
23 |
24 | import javax.persistence.DiscriminatorValue;
25 | import javax.persistence.Entity;
26 |
27 | /**
28 | * Employee
29 | *
30 | * @author ALR
31 | * @version $Revision: $
32 | */
33 | @Entity(name = "SINGLECLASS_EMPLOYEE")
34 | @DiscriminatorValue("EMPLOYEE")
35 | public class Employee extends Customer
36 | {
37 | //-------------------------------------------------------------------------------------||
38 | // Instance Members -------------------------------------------------------------------||
39 | //-------------------------------------------------------------------------------------||
40 |
41 | /**
42 | * ID of the Employee
43 | */
44 | private Integer employeeId;
45 |
46 | //-------------------------------------------------------------------------------------||
47 | // Accessors / Mutators ---------------------------------------------------------------||
48 | //-------------------------------------------------------------------------------------||
49 |
50 | /**
51 | * @return the employeeId
52 | */
53 | public Integer getEmployeeId()
54 | {
55 | return employeeId;
56 | }
57 |
58 | /**
59 | * @param employeeId the employeeId to set
60 | */
61 | public void setEmployeeId(final Integer employeeId)
62 | {
63 | this.employeeId = employeeId;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/ch08-messagedestinationlink/src/main/java/org/jboss/ejb3/examples/ch08/messagedestinationlink/slsb/MessageSendingBusiness.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch08.messagedestinationlink.slsb;
23 |
24 | import javax.jms.TextMessage;
25 |
26 | /**
27 | * Business interface to send a message to a message
28 | * destination link (to be picked up by an MDB as configured
29 | * down the chain)
30 | *
31 | * @author ALR
32 | * @version $Revision: $
33 | */
34 | public interface MessageSendingBusiness
35 | {
36 | //-------------------------------------------------------------------------------------||
37 | // Constants --------------------------------------------------------------------------||
38 | //-------------------------------------------------------------------------------------||
39 |
40 | /**
41 | * EJB Name
42 | */
43 | String NAME_EJB = "MessageSendingEJB";
44 |
45 | /**
46 | * Location to which we'll bind in JNDI
47 | */
48 | String NAME_JNDI = NAME_EJB + "/local";
49 |
50 | //-------------------------------------------------------------------------------------||
51 | // Contracts --------------------------------------------------------------------------||
52 | //-------------------------------------------------------------------------------------||
53 |
54 | /**
55 | * Sends a {@link TextMessage} with the specified contents to the
56 | * message destination link as configured by ejb-jar.xml
57 | *
58 | * @throws IllegalArgumentException If the contents are not specified
59 | */
60 | void sendMessage(String contents) throws IllegalArgumentException;
61 | }
62 |
--------------------------------------------------------------------------------
/ch19-timer/pom.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 | org.jboss.ejb3.examples
7 | jboss-ejb3-examples-build
8 | 1.1.0-SNAPSHOT
9 | ../build/pom.xml
10 |
11 |
12 |
13 | 4.0.0
14 |
15 |
16 | jboss-ejb3-examples-ch19-timer
17 | JBoss EJB 3.x Examples - Chapter 19: EJB Timer Service
18 | Example to accompany O'Reilly "Enterprise Java Beans 6th Edition" Chapter 19
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | org.jboss.as
37 | jboss-as-spec-api
38 | pom
39 |
40 |
41 |
45 |
46 |
59 |
60 |
61 |
62 | junit
63 | junit
64 |
65 |
66 |
80 |
81 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/ch09-14-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/ch14/listener/EventTracker.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.employeeregistry.ch14.listener;
23 |
24 | /**
25 | * Tracks events fired by the {@link EntityListenerEmployee}
26 | *
27 | * @author ALR
28 | * @version $Revision: $
29 | */
30 | public class EventTracker
31 | {
32 |
33 | //-------------------------------------------------------------------------------------||
34 | // Class Members ----------------------------------------------------------------------||
35 | //-------------------------------------------------------------------------------------||
36 |
37 | /*
38 | * Flags denoting whether an event was fired
39 | */
40 |
41 | public static boolean prePersist;
42 |
43 | public static boolean postPersist;
44 |
45 | public static boolean postLoad;
46 |
47 | public static boolean preUpdate;
48 |
49 | public static boolean postUpdate;
50 |
51 | public static boolean preRemove;
52 |
53 | public static boolean postRemove;
54 |
55 | //-------------------------------------------------------------------------------------||
56 | // Functional Methods -----------------------------------------------------------------||
57 | //-------------------------------------------------------------------------------------||
58 |
59 | /**
60 | * Resets all events to false
61 | */
62 | public static void reset()
63 | {
64 | prePersist = false;
65 | postPersist = false;
66 | postLoad = false;
67 | preUpdate = false;
68 | postUpdate = false;
69 | preRemove = false;
70 | postRemove = false;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/ch05-encryption/src/main/java/org/jboss/ejb3/examples/ch05/encryption/EncryptionException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch05.encryption;
23 |
24 | import javax.ejb.ApplicationException;
25 |
26 | /**
27 | * A checked Application Exception denoting
28 | * some unexpected problem with Encryption operations
29 | *
30 | * @author ALR
31 | */
32 | @ApplicationException
33 | // Explicit annotation, though this is inferred as default because we extend Exception
34 | public class EncryptionException extends Exception
35 | {
36 |
37 | // ---------------------------------------------------------------------------||
38 | // Class Members -------------------------------------------------------------||
39 | // ---------------------------------------------------------------------------||
40 |
41 | /**
42 | * To satisfy explicit serialization hints to the JVM
43 | */
44 | private static final long serialVersionUID = 1L;
45 |
46 | // ---------------------------------------------------------------------------||
47 | // Constructors --------------------------------------------------------------||
48 | // ---------------------------------------------------------------------------||
49 |
50 | /*
51 | * All constructors will delegate to the superclass implementation
52 | */
53 |
54 | public EncryptionException()
55 | {
56 | super();
57 | }
58 |
59 | public EncryptionException(String message, Throwable cause)
60 | {
61 | super(message, cause);
62 | }
63 |
64 | public EncryptionException(String message)
65 | {
66 | super(message);
67 | }
68 |
69 | public EncryptionException(Throwable cause)
70 | {
71 | super(cause);
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/ch07-rsscache/src/main/java/org/jboss/ejb3/examples/ch07/rsscache/impl/rome/ProtectExportUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch07.rsscache.impl.rome;
23 |
24 | import java.net.MalformedURLException;
25 | import java.net.URL;
26 |
27 | /**
28 | * Package-private utilities to protect against mutable
29 | * state getting exported
30 | *
31 | * @author ALR
32 | */
33 | class ProtectExportUtil
34 | {
35 | //-------------------------------------------------------------------------------------||
36 | // Constructor ------------------------------------------------------------------------||
37 | //-------------------------------------------------------------------------------------||
38 |
39 | /**
40 | * Internal constructor; protects against instantiation
41 | */
42 | private ProtectExportUtil()
43 | {
44 | }
45 |
46 | //-------------------------------------------------------------------------------------||
47 | // Functional Methods -----------------------------------------------------------------||
48 | //-------------------------------------------------------------------------------------||
49 |
50 | /**
51 | * Returns a copy of the specified URL; used to ensure that mutable
52 | * internal state is not leaked out to clients
53 | * @param url
54 | * @return
55 | */
56 | static URL copyUrl(final URL url)
57 | {
58 | // If null, return
59 | if (url == null)
60 | {
61 | return url;
62 | }
63 |
64 | try
65 | {
66 | // Copy
67 | return new URL(url.toExternalForm());
68 | }
69 | catch (final MalformedURLException e)
70 | {
71 | throw new RuntimeException("Error in copying URL", e);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/ch18-interceptors/src/main/java/org/jboss/ejb3/examples/ch18/tuner/Channel2ClosedException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch18.tuner;
23 |
24 | import javax.ejb.ApplicationException;
25 |
26 | /**
27 | * Denotes that Channel 2 is not currently available for viewing
28 | *
29 | * @author ALR
30 | * @version $Revision: $
31 | */
32 | @ApplicationException
33 | // Denotes that this exception type should be returned to the client as-is, not wrapped
34 | public class Channel2ClosedException extends Exception
35 | {
36 |
37 | //-------------------------------------------------------------------------------------||
38 | // Class Members ----------------------------------------------------------------------||
39 | //-------------------------------------------------------------------------------------||
40 |
41 | /**
42 | * serialVersionUID
43 | */
44 | private static final long serialVersionUID = 1L;
45 |
46 | /**
47 | * The sole instance, this type has no state
48 | */
49 | public static final Channel2ClosedException INSTANCE;
50 | static
51 | {
52 | INSTANCE = new Channel2ClosedException();
53 | }
54 |
55 | /**
56 | * Message for all incoming Exceptions
57 | */
58 | private static final String MSG = "Channel 2 is not currently available for viewing";
59 |
60 | //-------------------------------------------------------------------------------------||
61 | // Constructor ------------------------------------------------------------------------||
62 | //-------------------------------------------------------------------------------------||
63 |
64 | /**
65 | * Constructs a new instance
66 | */
67 | private Channel2ClosedException()
68 | {
69 | super(MSG);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/TaskExecutionException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.testsupport.txwrap;
23 |
24 | import javax.ejb.ApplicationException;
25 | import javax.ejb.EJBException;
26 |
27 | /**
28 | * Indicates that an exception has occurred while submitting
29 | * a task to {@link TxWrappingLocalBusiness#wrapInTx(java.util.concurrent.Callable...)}.
30 | * Not wrapped in {@link EJBException} because this is an {@link ApplicationException}
31 | *
32 | * @author ALR
33 | * @version $Revision: $
34 | */
35 | @ApplicationException(rollback = true)
36 | public class TaskExecutionException extends Exception
37 | {
38 | //-------------------------------------------------------------------------------------||
39 | // Class Members ----------------------------------------------------------------------||
40 | //-------------------------------------------------------------------------------------||
41 |
42 | /**
43 | * serialVersionUID
44 | */
45 | private static final long serialVersionUID = 1L;
46 |
47 | //-------------------------------------------------------------------------------------||
48 | // Constructor ------------------------------------------------------------------------||
49 | //-------------------------------------------------------------------------------------||
50 |
51 | /**
52 | * Creates a new instance with the specified root cause
53 | */
54 | public TaskExecutionException(final Throwable cause)
55 | {
56 | super(cause);
57 | }
58 |
59 | /**
60 | * Creates a new instance with the specified message
61 | * @param message
62 | */
63 | public TaskExecutionException(String message)
64 | {
65 | super(message);
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/ch04-firstejb/src/main/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorBeanBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 |
23 | package org.jboss.ejb3.examples.ch04.firstejb;
24 |
25 | import java.util.logging.Logger;
26 |
27 | /**
28 | * Base for bean implementation classes of the CalculatorEJB,
29 | * provides business logic for required contracts
30 | *
31 | * @author ALR
32 | */
33 | public class CalculatorBeanBase implements CalculatorCommonBusiness
34 | {
35 | // ---------------------------------------------------------------------------||
36 | // Class Members -------------------------------------------------------------||
37 | // ---------------------------------------------------------------------------||
38 |
39 | /**
40 | * Logger
41 | */
42 | private static final Logger log = Logger.getLogger(CalculatorBeanBase.class.getName());
43 |
44 | // ---------------------------------------------------------------------------||
45 | // Required Implementations --------------------------------------------------||
46 | // ---------------------------------------------------------------------------||
47 |
48 | /**
49 | * {@inheritDoc}
50 | * @see org.jboss.ejb3.examples.ch04.firstejb.CalculatorCommonBusiness#add(int[])
51 | */
52 | @Override
53 | public int add(final int... arguments)
54 | {
55 | // Initialize
56 | final StringBuffer sb = new StringBuffer();
57 | sb.append("Adding arguments: ");
58 | int result = 0;
59 |
60 | // Add all arguments
61 | for (final int arg : arguments)
62 | {
63 | result += arg;
64 | sb.append(arg);
65 | sb.append(" ");
66 | }
67 |
68 | // Return
69 | log.info(sb.toString());
70 | log.info("Result: " + result);
71 | return result;
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/ch04-firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorAssertionDelegate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch04.firstejb;
23 |
24 | import java.util.logging.Logger;
25 |
26 | import junit.framework.TestCase;
27 |
28 | /**
29 | * Contains functions to assert that implementations
30 | * of {@link CalculatorCommonBusiness} are working
31 | * as expected
32 | *
33 | * @author ALR
34 | */
35 | class CalculatorAssertionDelegate
36 | {
37 | // ---------------------------------------------------------------------------||
38 | // Class Members -------------------------------------------------------------||
39 | // ---------------------------------------------------------------------------||
40 |
41 | /**
42 | * Logger
43 | */
44 | private static final Logger log = Logger.getLogger(CalculatorAssertionDelegate.class.getName());
45 |
46 | // ---------------------------------------------------------------------------||
47 | // Functional Methods --------------------------------------------------------||
48 | // ---------------------------------------------------------------------------||
49 |
50 | /**
51 | * Uses the supplied Calculator instance to test the addition
52 | * algorithm
53 | */
54 | void assertAdditionSucceeds(final CalculatorCommonBusiness calc)
55 | {
56 | // Initialize
57 | final int[] arguments = new int[]
58 | {2, 3, 5};
59 | final int expectedSum = 10;
60 |
61 | // Add
62 | final int actualSum = calc.add(arguments);
63 |
64 | // Test
65 | TestCase.assertEquals("Addition did not return the expected result", expectedSum, actualSum);
66 |
67 | // Log
68 | final StringBuffer sb = new StringBuffer();
69 | sb.append("Obtained expected result, ");
70 | sb.append(actualSum);
71 | sb.append(", from arguments: ");
72 | for (final int arg : arguments)
73 | {
74 | sb.append(arg);
75 | sb.append(" ");
76 | }
77 | log.info(sb.toString());
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/ch19-timer/src/main/java/org/jboss/ejb3/examples/ch19/timer/api/CreditCardTransactionProcessingLocalBusiness.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch19.timer.api;
23 |
24 | import java.util.Date;
25 | import java.util.List;
26 |
27 | import javax.ejb.ScheduleExpression;
28 | import javax.ejb.Timer;
29 |
30 | /**
31 | * Contract of a service capable of storing a series
32 | * of {@link CreditCardTransaction}s to be processed,
33 | * scheduling processing, and processing payment of
34 | * all pending transactions.
35 | *
36 | * @author ALR
37 | * @version $Revision: $
38 | */
39 | public interface CreditCardTransactionProcessingLocalBusiness
40 | {
41 | //-------------------------------------------------------------------------------------||
42 | // Contracts --------------------------------------------------------------------------||
43 | //-------------------------------------------------------------------------------------||
44 |
45 | /**
46 | * Returns an immutable view of all transactions
47 | * pending processing
48 | * @return
49 | */
50 | List getPendingTransactions();
51 |
52 | /**
53 | * Proceses all pending {@link CreditCardTransaction}s,
54 | * clearing them from the pending list when complete
55 | */
56 | void process();
57 |
58 | /**
59 | * Adds the specified {@link CreditCardTransaction} to be processed
60 | * @param transaction
61 | * @throws IllegalArgumentException If the transaction is null
62 | */
63 | void add(CreditCardTransaction transaction) throws IllegalArgumentException;
64 |
65 | /**
66 | * Schedules a new {@link Timer} to process pending payments
67 | * according to the supplied {@link ScheduleExpression}. Returns
68 | * the {@link Date} representing when the next job is to fire.
69 | * @param expression
70 | * @return
71 | * @throws IllegalArgumentException If the expression is null
72 | */
73 | Date scheduleProcessing(ScheduleExpression expression) throws IllegalArgumentException;
74 | }
75 |
--------------------------------------------------------------------------------
/ch18-interceptors/src/main/java/org/jboss/ejb3/examples/ch18/tuner/Channel2AccessPolicy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch18.tuner;
23 |
24 | /**
25 | * Defines the authoritative policy governing whether or not
26 | * Channel 2 should be currently accessible
27 | *
28 | * @author ALR
29 | * @version $Revision: $
30 | */
31 | public class Channel2AccessPolicy
32 | {
33 |
34 | //-------------------------------------------------------------------------------------||
35 | // Class Members ----------------------------------------------------------------------||
36 | //-------------------------------------------------------------------------------------||
37 |
38 | /**
39 | * Flag dictating whether or not Channel 2 should be shown
40 | */
41 | private static boolean channel2Permitted = false;
42 |
43 | //-------------------------------------------------------------------------------------||
44 | // Constructor ------------------------------------------------------------------------||
45 | //-------------------------------------------------------------------------------------||
46 |
47 | /**
48 | * No instantiation
49 | */
50 | private Channel2AccessPolicy()
51 | {
52 | throw new UnsupportedOperationException("No instances permitted");
53 | }
54 |
55 | //-------------------------------------------------------------------------------------||
56 | // Functional Methods -----------------------------------------------------------------||
57 | //-------------------------------------------------------------------------------------||
58 |
59 | /**
60 | * Returns whether or not requests to view Channel 2 will be honored
61 | */
62 | public static boolean isChannel2Permitted()
63 | {
64 | return channel2Permitted;
65 | }
66 |
67 | /**
68 | * Returns whether or not requests to view Channel 2 will be honored
69 | */
70 | public static void setChannel2Permitted(final boolean channel2Permitted)
71 | {
72 | Channel2AccessPolicy.channel2Permitted = channel2Permitted;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/ch06-filetransfer/src/main/java/org/jboss/ejb3/examples/ch06/filetransfer/FileTransferCommonBusiness.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch06.filetransfer;
23 |
24 | /**
25 | * Contains the contract for operations common to all
26 | * business interfaces of the FileTransferEJB.
27 | *
28 | * Includes support for switching present working directories,
29 | * printing the current working directory, and making directories.
30 | *
31 | * @author ALR
32 | */
33 | public interface FileTransferCommonBusiness
34 | {
35 | // ---------------------------------------------------------------------------||
36 | // Contracts -----------------------------------------------------------------||
37 | // ---------------------------------------------------------------------------||
38 |
39 | /**
40 | * Makes a directory of the specified name
41 | *
42 | * @throws IllegalStateException If the client connection has not been initialized
43 | */
44 | void mkdir(String directory) throws IllegalStateException;
45 |
46 | /**
47 | * Changes into the named directory
48 | *
49 | * @param directory
50 | * @throws IllegalStateException If the client connection has not been initialized
51 | */
52 | void cd(String directory) throws IllegalStateException;
53 |
54 | /**
55 | * Obtains the name of the current working directory
56 | *
57 | * @return
58 | * @throws IllegalStateException If the client connection has not been initialized
59 | */
60 | String pwd() throws IllegalStateException;
61 |
62 | /**
63 | * Denotes that the client is done using this service; flushes
64 | * any pending operations and does all appropriate cleanup. If
65 | * already disconnected, this is a no-op.
66 | */
67 | void disconnect();
68 |
69 | /**
70 | * Opens the underlying connections to the target FTP Server,
71 | * performs any other tasks required before commands may be sent
72 | * (ie. login, etc)
73 | *
74 | * @throws IllegalStateException If already initialized/connected
75 | */
76 | void connect() throws IllegalStateException;
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/ch17-transactions/src/main/java/org/jboss/ejb3/examples/ch17/transactions/api/BlackjackGameLocalBusiness.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch17.transactions.api;
23 |
24 | import java.math.BigDecimal;
25 |
26 | import org.jboss.ejb3.examples.ch17.transactions.entity.User;
27 |
28 | /**
29 | * Contract of a service capable of simulating
30 | * a single game of blackjack. The actual gameplay is not modeled,
31 | * only the inputs and outputs of a single trial.
32 | *
33 | * @author ALR
34 | * @version $Revision: $
35 | */
36 | public interface BlackjackGameLocalBusiness
37 | {
38 | //-------------------------------------------------------------------------------------||
39 | // Constants --------------------------------------------------------------------------||
40 | //-------------------------------------------------------------------------------------||
41 |
42 | /**
43 | * Name to which we'll bind in JNDI
44 | */
45 | String JNDI_NAME = "PokerGameLocal";
46 |
47 | //-------------------------------------------------------------------------------------||
48 | // Contracts --------------------------------------------------------------------------||
49 | //-------------------------------------------------------------------------------------||
50 |
51 | /**
52 | * Places a single bet, returning if the bet won or lost. If the result
53 | * is a win, the amount specified will be transferred from the Blackjack Service
54 | * account to {@link User#getAccount()}, else it will be deducted from the user account
55 | * and placed into the Blackjack Service account.
56 | *
57 | * @return Whether the bet won or lost
58 | * @param userId The ID of the user placing the bet
59 | * @param amount The amount of the bet
60 | * @throws IllegalArgumentException If either the user of the amount is not specified or
61 | * the amount is a negative number.
62 | * @throws InsufficientBalanceException If the user does not have enough in his/her account
63 | * to cover the bet
64 | */
65 | boolean bet(long userId, BigDecimal amount) throws IllegalArgumentException, InsufficientBalanceException;
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/ch18-interceptors/src/main/java/org/jboss/ejb3/examples/ch18/tuner/AuditedInvocation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch18.tuner;
23 |
24 | import java.security.Principal;
25 |
26 | import javax.interceptor.InvocationContext;
27 |
28 | /**
29 | * Data object encapsulating the auditable properties behind an invocation
30 | *
31 | * @author ALR
32 | * @version $Revision: $
33 | */
34 | public class AuditedInvocation
35 | {
36 |
37 | //-------------------------------------------------------------------------------------||
38 | // Instance Members -------------------------------------------------------------------||
39 | //-------------------------------------------------------------------------------------||
40 |
41 | /**
42 | * Invoked context
43 | */
44 | private final InvocationContext context;
45 |
46 | /**
47 | * Caller
48 | */
49 | private final Principal caller;
50 |
51 | //-------------------------------------------------------------------------------------||
52 | // Constructor ------------------------------------------------------------------------||
53 | //-------------------------------------------------------------------------------------||
54 |
55 | /**
56 | * Creates a new instance
57 | */
58 | AuditedInvocation(final InvocationContext context, final Principal caller)
59 | {
60 | // Precondition checks
61 | assert context != null : "context must be specified";
62 | assert caller != null : "caller must be specified";
63 |
64 | // Set
65 | this.context = context;
66 | this.caller = caller;
67 | }
68 |
69 | //-------------------------------------------------------------------------------------||
70 | // Functional Methods -----------------------------------------------------------------||
71 | //-------------------------------------------------------------------------------------||
72 |
73 | /**
74 | * @return the context
75 | */
76 | public InvocationContext getContext()
77 | {
78 | return context;
79 | }
80 |
81 | /**
82 | * @return the caller
83 | */
84 | public Principal getCaller()
85 | {
86 | return caller;
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/ch15-secureschool/src/main/java/org/jboss/ejb3/examples/ch15/secureschool/api/SecureSchoolLocalBusiness.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch15.secureschool.api;
23 |
24 | import org.jboss.ejb3.examples.ch15.secureschool.impl.Roles;
25 |
26 | /**
27 | * Represents a school holding doors which may be
28 | * opened by various users. Using the EJB Security model,
29 | * access to open a particular door may be blocked
30 | * to certain users.
31 | *
32 | * @author ALR
33 | * @version $Revision: $
34 | */
35 | public interface SecureSchoolLocalBusiness
36 | {
37 | // ---------------------------------------------------------------------------||
38 | // Contracts -----------------------------------------------------------------||
39 | // ---------------------------------------------------------------------------||
40 |
41 | /**
42 | * Closes the school for business. At this point the
43 | * front door will be unlocked for all.
44 | * This method may only be called by users in role
45 | * {@link Roles#ADMIN}.
46 | */
47 | void open();
48 |
49 | /**
50 | * Closes the school for business. At this point the
51 | * front door will be locked for all but users
52 | * in role {@link Roles#ADMIN}
53 | * This method may only be called by admins.
54 | */
55 | void close();
56 |
57 | /**
58 | * Opens the front door. While school is open,
59 | * any authenticated user may open the door, else
60 | * only the {@link Roles#ADMIN} may open.
61 | *
62 | * @throws SchoolClosedException If the current user
63 | * is not in {@link Roles#ADMIN} and is attempting to open
64 | * the door while {@link SecureSchoolLocalBusiness#isOpen()}
65 | * is false.
66 | */
67 | void openFrontDoor() throws SchoolClosedException;
68 |
69 | /**
70 | * Opens the service door. Users in {@link Roles#STUDENT}
71 | * role may not open this door, but {@link Roles#ADMIN}
72 | * and {@link Roles#JANITOR} may.
73 | */
74 | void openServiceDoor();
75 |
76 | /**
77 | * Returns whether or not the school is open. When closed, only
78 | * the {@link Roles#ADMIN} is allowed access to all doors. Anyone,
79 | * even unauthenticated users, may check if school is open.
80 | * @return
81 | */
82 | boolean isOpen();
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/ch15-secureschool/src/main/java/org/jboss/ejb3/examples/ch15/secureschool/api/SchoolClosedException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch15.secureschool.api;
23 |
24 | import javax.ejb.ApplicationException;
25 | import javax.ejb.EJBAccessException;
26 |
27 | import org.jboss.ejb3.examples.ch15.secureschool.impl.Roles;
28 |
29 | /**
30 | * Thrown when a user in role other than {@link Roles#ADMIN}
31 | * attempts to open the front door to school while it's closed
32 | *
33 | * @author ALR
34 | * @version $Revision: $
35 | */
36 | @ApplicationException(rollback = true)
37 | // So this isn't wrapped in EJBException
38 | public class SchoolClosedException extends EJBAccessException
39 | {
40 | //-------------------------------------------------------------------------------------||
41 | // Class Members ----------------------------------------------------------------------||
42 | //-------------------------------------------------------------------------------------||
43 |
44 | /**
45 | * serialVersionUID
46 | */
47 | private static final long serialVersionUID = 1L;
48 |
49 | //-------------------------------------------------------------------------------------||
50 | // Constructor ------------------------------------------------------------------------||
51 | //-------------------------------------------------------------------------------------||
52 |
53 | /**
54 | * Constructs a new exception
55 | */
56 | private SchoolClosedException(final String message)
57 | {
58 | super(message);
59 | }
60 |
61 | //-------------------------------------------------------------------------------------||
62 | // Factory ----------------------------------------------------------------------------||
63 | //-------------------------------------------------------------------------------------||
64 |
65 | /**
66 | * Constructs a new exception with the specified, required message
67 | * @param message
68 | * @throws IllegalArgumentException If the message is not specified
69 | */
70 | public static SchoolClosedException newInstance(final String message) throws IllegalArgumentException
71 | {
72 | // Precondition checks
73 | if (message == null)
74 | {
75 | throw new IllegalArgumentException("message must be specified");
76 | }
77 |
78 | // Return
79 | return new SchoolClosedException(message);
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/ch15-secureschool/src/main/java/org/jboss/ejb3/examples/ch15/secureschool/impl/FireDepartmentBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch15.secureschool.impl;
23 |
24 | import java.util.logging.Logger;
25 |
26 | import javax.annotation.security.PermitAll;
27 | import javax.annotation.security.RunAs;
28 | import javax.ejb.EJB;
29 | import javax.ejb.Singleton;
30 |
31 | import org.jboss.ejb3.examples.ch15.secureschool.api.FireDepartmentLocalBusiness;
32 | import org.jboss.ejb3.examples.ch15.secureschool.api.SecureSchoolLocalBusiness;
33 |
34 | /**
35 | * Bean implementation class of the fire department.
36 | * Closes the local school in case of emergency.
37 | *
38 | * @author ALR
39 | * @version $Revision: $
40 | */
41 | @Singleton
42 | @RunAs(Roles.ADMIN)
43 | @PermitAll
44 | // Implicit, but included here to show access policy
45 | public class FireDepartmentBean implements FireDepartmentLocalBusiness
46 | {
47 |
48 | //-------------------------------------------------------------------------------------||
49 | // Class Members ----------------------------------------------------------------------||
50 | //-------------------------------------------------------------------------------------||
51 |
52 | /**
53 | * Logger
54 | */
55 | private static final Logger log = Logger.getLogger(FireDepartmentBean.class.getName());
56 |
57 | //-------------------------------------------------------------------------------------||
58 | // Instance Members -------------------------------------------------------------------||
59 | //-------------------------------------------------------------------------------------||
60 |
61 | /**
62 | * School to close in case of emergency
63 | */
64 | @EJB
65 | private SecureSchoolLocalBusiness school;
66 |
67 | //-------------------------------------------------------------------------------------||
68 | // Required Implementations -----------------------------------------------------------||
69 | //-------------------------------------------------------------------------------------||
70 |
71 | /**
72 | * {@inheritDoc}
73 | * @see org.jboss.ejb3.examples.ch15.secureschool.api.FireDepartmentLocalBusiness#declareEmergency()
74 | */
75 | @Override
76 | public void declareEmergency()
77 | {
78 | log.info("Dispatching emergency support from the Fire Department, closing local school");
79 | school.close();
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/txwrap/TxWrappingBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.testsupport.txwrap;
23 |
24 | import java.util.concurrent.Callable;
25 |
26 | import javax.ejb.Local;
27 | import javax.ejb.Stateless;
28 | import javax.ejb.TransactionAttribute;
29 | import javax.ejb.TransactionAttributeType;
30 |
31 | /**
32 | * EJB which wraps a specified series of {@link Callable}
33 | * tasks within the context of a new Transaction
34 | *
35 | * @author ALR
36 | * @version $Revision: $
37 | */
38 | @Stateless
39 | @Local(TxWrappingLocalBusiness.class)
40 | @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
41 | // We always require a new Tx here, so we ensure to wrap
42 | public class TxWrappingBean implements TxWrappingLocalBusiness
43 | {
44 | //-------------------------------------------------------------------------------------||
45 | // Required Implementations -----------------------------------------------------------||
46 | //-------------------------------------------------------------------------------------||
47 |
48 | /**
49 | * {@inheritDoc}
50 | * @see org.jboss.ejb3.examples.chxx.transactions.ejb.TxWrappingLocalBusiness#wrapInTx(java.util.concurrent.Callable[])
51 | */
52 | @Override
53 | public void wrapInTx(final Callable>... tasks) throws IllegalArgumentException, TaskExecutionException
54 | {
55 | // Precondition check
56 | if (tasks == null)
57 | {
58 | throw new IllegalArgumentException("task must be specified");
59 | }
60 |
61 | // Just delegate along to the tasks in order; now it's executed inside of a Tx
62 | for (final Callable> task : tasks)
63 | {
64 | this.wrapInTx(task);
65 | }
66 | }
67 |
68 | /**
69 | * {@inheritDoc}
70 | * @see org.jboss.ejb3.examples.testsupport.txwrap.TxWrappingLocalBusiness#wrapInTx(java.util.concurrent.Callable)
71 | */
72 | @Override
73 | public T wrapInTx(final Callable task) throws IllegalArgumentException, TaskExecutionException
74 | {
75 | try
76 | {
77 | // Invoke
78 | return task.call();
79 | }
80 | // Every problem we encounter here becomes an ApplicationException
81 | // to be unwrapped later by the caller (so the container doesn't wrap
82 | // in EJBException
83 | catch (final Throwable e)
84 | {
85 | throw new TaskExecutionException(e);
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/ch15-secureschool/pom.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 | org.jboss.ejb3.examples
7 | jboss-ejb3-examples-build
8 | 1.1.0-SNAPSHOT
9 | ../build/pom.xml
10 |
11 |
12 |
13 | 4.0.0
14 |
15 |
16 | jboss-ejb3-examples-ch15-secureschool
17 | JBoss EJB 3.x Examples - Chapter 15: SecureSchool EJBs
18 | Example to accompany O'Reilly "Enterprise Java Beans 6th Edition" Chapter 15
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | org.jboss.as
38 | jboss-as-spec-api
39 | pom
40 |
41 |
42 |
43 | junit
44 | junit
45 |
46 |
47 |
48 | org.jboss.arquillian.container
49 | arquillian-openejb-embedded-3.1
50 |
51 |
52 |
53 | org.jboss.arquillian.junit
54 | arquillian-junit-container
55 |
56 |
57 |
58 | org.apache.openejb
59 | openejb-core
60 | compile
61 |
62 |
63 |
64 | javax.inject
65 | javax.inject
66 | test
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | it
77 |
78 | true
79 |
80 |
81 |
82 |
83 |
84 |
85 |
89 |
90 | maven-surefire-plugin
91 |
92 |
93 | surefire-it
94 | integration-test
95 |
96 | test
97 |
98 |
99 | false
100 | true
101 | true
102 | always
103 |
104 | **/*IntegrationTest.java
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
--------------------------------------------------------------------------------
/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/dbquery/EntityManagerExposingBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.testsupport.dbquery;
23 |
24 | import javax.ejb.Local;
25 | import javax.ejb.Stateless;
26 | import javax.ejb.TransactionAttribute;
27 | import javax.ejb.TransactionAttributeType;
28 | import javax.persistence.EntityManager;
29 | import javax.persistence.PersistenceContext;
30 |
31 | /**
32 | * Implementation of a test EJB which exposes generic database
33 | * query operations directly via the {@link EntityManager}.
34 | * Used in validating pre- and postconditions during testing.
35 | * All methods will be executed in an existing Transaction, which
36 | * is {@link TransactionAttributeType#MANDATORY}.
37 | *
38 | * @author ALR
39 | * @version $Revision: $
40 | */
41 | @Stateless
42 | @Local(EntityManagerExposingLocalBusiness.class)
43 | @TransactionAttribute(TransactionAttributeType.MANDATORY)
44 | // We make a current Tx mandatory from the caller so that the
45 | // caller is sure to get back an entity instance which is still attached. This way we can run any tests/checks
46 | // on it without fear that we'll run into Exceptions. We can use a TxWrappingBean to submit the test logic and
47 | // execute it in the context of a new Transaction. David Blevins has a writeup of this technique:
48 | // http://openejb.apache.org/3.0/testing-transactions-example.html
49 | public class EntityManagerExposingBean implements EntityManagerExposingLocalBusiness
50 | {
51 |
52 | //-------------------------------------------------------------------------------------||
53 | // Instance Members -------------------------------------------------------------------||
54 | //-------------------------------------------------------------------------------------||
55 |
56 | /**
57 | * Underlying hook to persistence
58 | */
59 | @PersistenceContext
60 | private EntityManager em;
61 |
62 | //-------------------------------------------------------------------------------------||
63 | // Required Implementations -----------------------------------------------------------||
64 | //-------------------------------------------------------------------------------------||
65 |
66 | /**
67 | * {@inheritDoc}
68 | * @see org.jboss.ejb3.examples.testsupport.dbquery.EntityManagerExposingLocalBusiness#getEntityManager()
69 | */
70 | @Override
71 | public EntityManager getEntityManager()
72 | {
73 | if (em == null)
74 | {
75 | throw new IllegalStateException(EntityManager.class.getSimpleName() + " was not injected.");
76 | }
77 | return em;
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/ch08-statusupdate/src/main/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/LoggingStatusUpdateMdb.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch08.statusupdate.mdb;
23 |
24 | import java.util.logging.Logger;
25 |
26 | import javax.ejb.ActivationConfigProperty;
27 | import javax.ejb.MessageDriven;
28 | import javax.jms.MessageListener;
29 |
30 | import org.jboss.ejb3.examples.ch08.statusupdate.api.StatusUpdate;
31 | import org.jboss.ejb3.examples.ch08.statusupdate.api.StatusUpdateConstants;
32 |
33 | /**
34 | * An MDB which, {@link MessageListener#onMessage(javax.jms.Message)}, will
35 | * log out the status update at INFO-level.
36 | *
37 | * Not explicitly tested by the examples (because we can't test for logging),
38 | * but its usage should be illustrative.
39 | *
40 | * @author ALR
41 | */
42 | @MessageDriven(activationConfig =
43 | {
44 | @ActivationConfigProperty(propertyName = "destinationType", propertyValue = StatusUpdateConstants.TYPE_DESTINATION_STATUSUPDATE),
45 | @ActivationConfigProperty(propertyName = "destination", propertyValue = StatusUpdateConstants.JNDI_NAME_TOPIC_STATUSUPDATE)})
46 | public class LoggingStatusUpdateMdb extends StatusUpdateBeanBase implements MessageListener
47 | {
48 |
49 | //-------------------------------------------------------------------------------------||
50 | // Class Members ----------------------------------------------------------------------||
51 | //-------------------------------------------------------------------------------------||
52 |
53 | /**
54 | * Logger
55 | */
56 | private static final Logger log = Logger.getLogger(LoggingStatusUpdateMdb.class.getName());
57 |
58 | //-------------------------------------------------------------------------------------||
59 | // Required Implementations -----------------------------------------------------------||
60 | //-------------------------------------------------------------------------------------||
61 |
62 | /**
63 | * Logs status out at INFO-level
64 | * @see org.jboss.ejb3.examples.ch08.statusupdate.mdb.StatusUpdateBeanBase#updateStatus(org.jboss.ejb3.examples.ch08.statusupdate.api.StatusUpdate)
65 | */
66 | @Override
67 | public void updateStatus(final StatusUpdate newStatus) throws IllegalArgumentException, Exception
68 | {
69 | // Precondition checks
70 | if (newStatus == null)
71 | {
72 | throw new IllegalArgumentException("status must be specified");
73 | }
74 |
75 | // Get info
76 | final String status = newStatus.getText();
77 |
78 | // Log
79 | log.info("New status received: \"" + status + "\"");
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/ch09-14-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/ch10/mapping/EmployeeWithEmbeddedPK.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.employeeregistry.ch10.mapping;
23 |
24 | import javax.persistence.EmbeddedId;
25 | import javax.persistence.Entity;
26 |
27 | /**
28 | * Represents an Employee in the system. The identity
29 | * (primary key) is determined by embedded properties
30 | * via the {@link EmbeddedEmployeePK}.
31 | *
32 | * @author ALR
33 | * @version $Revision: $
34 | */
35 | @Entity
36 | // Mark that we're an Entity Bean, EJB's integration point
37 | // with Java Persistence
38 | public class EmployeeWithEmbeddedPK
39 | {
40 |
41 | //-------------------------------------------------------------------------------------||
42 | // Instance Members -------------------------------------------------------------------||
43 | //-------------------------------------------------------------------------------------||
44 |
45 | /**
46 | * Primary key, composite and embedded
47 | */
48 | @EmbeddedId
49 | private EmbeddedEmployeePK id;
50 |
51 | //-------------------------------------------------------------------------------------||
52 | // Constructor ------------------------------------------------------------------------||
53 | //-------------------------------------------------------------------------------------||
54 |
55 | /**
56 | * Default constructor, required by JPA
57 | */
58 | public EmployeeWithEmbeddedPK()
59 | {
60 |
61 | }
62 |
63 | //-------------------------------------------------------------------------------------||
64 | // Accessors / Mutators ---------------------------------------------------------------||
65 | //-------------------------------------------------------------------------------------||
66 |
67 | /**
68 | * @return the id
69 | */
70 | public EmbeddedEmployeePK getId()
71 | {
72 | return id;
73 | }
74 |
75 | /**
76 | * @param id the id to set
77 | */
78 | public void setId(final EmbeddedEmployeePK id)
79 | {
80 | this.id = id;
81 | }
82 |
83 | //-------------------------------------------------------------------------------------||
84 | // Overridden Implementations ---------------------------------------------------------||
85 | //-------------------------------------------------------------------------------------||
86 |
87 | /**
88 | * {@inheritDoc}
89 | * @see java.lang.Object#toString()
90 | */
91 | @Override
92 | public String toString()
93 | {
94 | return EmployeeWithEmbeddedPK.class.getSimpleName() + " [id=" + id + "]";
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/ch17-transactions/src/main/java/org/jboss/ejb3/examples/ch17/transactions/entity/User.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch17.transactions.entity;
23 |
24 | import javax.persistence.CascadeType;
25 | import javax.persistence.Entity;
26 | import javax.persistence.OneToOne;
27 |
28 | import org.jboss.ejb3.examples.testsupport.entity.IdentityBase;
29 |
30 | /**
31 | * Entity representing a user of the poker service
32 | *
33 | * @author ALR
34 | * @version $Revision: $
35 | */
36 | @Entity
37 | public class User extends IdentityBase
38 | {
39 |
40 | //-------------------------------------------------------------------------------------||
41 | // Instance Members -------------------------------------------------------------------||
42 | //-------------------------------------------------------------------------------------||
43 |
44 | /**
45 | * Name of the user
46 | */
47 | private String name;
48 |
49 | /**
50 | * The user's poker account
51 | */
52 | @OneToOne(cascade = CascadeType.PERSIST)
53 | private Account account;
54 |
55 | //-------------------------------------------------------------------------------------||
56 | // Accessors / Mutators ---------------------------------------------------------------||
57 | //-------------------------------------------------------------------------------------||
58 |
59 | /**
60 | * @return the name
61 | */
62 | public String getName()
63 | {
64 | return name;
65 | }
66 |
67 | /**
68 | * @param name the name to set
69 | */
70 | public void setName(final String name)
71 | {
72 | this.name = name;
73 | }
74 |
75 | /**
76 | * @return the account
77 | */
78 | public Account getAccount()
79 | {
80 | return account;
81 | }
82 |
83 | /**
84 | * @param account the account to set
85 | */
86 | public void setAccount(Account account)
87 | {
88 | this.account = account;
89 | }
90 |
91 | //-------------------------------------------------------------------------------------||
92 | // Overridden Implementations ---------------------------------------------------------||
93 | //-------------------------------------------------------------------------------------||
94 |
95 | /**
96 | * {@inheritDoc}
97 | * @see java.lang.Object#toString()
98 | */
99 | @Override
100 | public String toString()
101 | {
102 | return User.class.getSimpleName() + " [id=" + this.getId() + ", name=" + name + ", account=" + account + "]";
103 | }
104 |
105 | }
106 |
--------------------------------------------------------------------------------
/ch05-encryption/src/test/java/org/jboss/ejb3/examples/ch05/encryption/EncryptionUnitTestCase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch05.encryption;
23 |
24 | import java.util.logging.Logger;
25 |
26 | import org.junit.BeforeClass;
27 | import org.junit.Test;
28 |
29 | /**
30 | * Tests to ensure that the business methods of the EncryptionEJB
31 | * are working as expected
32 | *
33 | * @author ALR
34 | */
35 | public class EncryptionUnitTestCase extends EncryptionTestCaseSupport
36 | {
37 | // ---------------------------------------------------------------------------||
38 | // Class Members -------------------------------------------------------------||
39 | // ---------------------------------------------------------------------------||
40 |
41 | /**
42 | * Logger
43 | */
44 | private static final Logger log = Logger.getLogger(EncryptionUnitTestCase.class.getName());
45 |
46 | /**
47 | * POJO Encryption Service
48 | */
49 | private static EncryptionBean encryptionService;
50 |
51 | // ---------------------------------------------------------------------------||
52 | // Lifecycle -----------------------------------------------------------------||
53 | // ---------------------------------------------------------------------------||
54 |
55 | /**
56 | * Initializes the suite, invoked once before any tests are run
57 | */
58 | @BeforeClass
59 | public static void initialize() throws Throwable
60 | {
61 | // Create the encryption service as a POJO
62 | encryptionService = new EncryptionBean();
63 | encryptionService.initialize(); // We call init manually here
64 | }
65 |
66 | // ---------------------------------------------------------------------------||
67 | // Tests ---------------------------------------------------------------------||
68 | // ---------------------------------------------------------------------------||
69 |
70 | /*
71 | * These tests will use the POJO set up in test initialization
72 | */
73 |
74 | /**
75 | * @see {@link EncryptionTestCaseSupport#assertHashing(EncryptionCommonBusiness)}
76 | */
77 | @Test
78 | public void testHashing() throws Throwable
79 | {
80 | // Log
81 | log.info("testHashing");
82 |
83 | // Test via superclass
84 | this.assertHashing(encryptionService);
85 | }
86 |
87 | /**
88 | * @see {@link EncryptionTestCaseSupport#assertEncryption(EncryptionCommonBusiness)}
89 | */
90 | @Test
91 | public void testEncryption() throws Throwable
92 | {
93 | // Log
94 | log.info("testEncryption");
95 |
96 | // Test via superclass
97 | this.assertEncryption(encryptionService);
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/ch04-firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorUnitTestCase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 |
23 | package org.jboss.ejb3.examples.ch04.firstejb;
24 |
25 | import java.util.logging.Logger;
26 |
27 | import junit.framework.TestCase;
28 |
29 | import org.junit.BeforeClass;
30 | import org.junit.Test;
31 |
32 | /**
33 | * Tests to ensure that the business methods of the CalculatorEJB
34 | * are working as expected
35 | *
36 | * @author ALR
37 | */
38 | public class CalculatorUnitTestCase
39 | {
40 | // ---------------------------------------------------------------------------||
41 | // Class Members -------------------------------------------------------------||
42 | // ---------------------------------------------------------------------------||
43 |
44 | /**
45 | * Logger
46 | */
47 | private static final Logger log = Logger.getLogger(CalculatorUnitTestCase.class.getName());
48 |
49 | /**
50 | * The POJO instance to test
51 | */
52 | private static CalculatorCommonBusiness calc;
53 |
54 | // ---------------------------------------------------------------------------||
55 | // Lifecycle Methods ---------------------------------------------------------||
56 | // ---------------------------------------------------------------------------||
57 |
58 | @BeforeClass
59 | public static void beforeClass()
60 | {
61 | // Make a POJO instance adhering to the
62 | // CalculatorCommonBusiness contract
63 | calc = new SimpleCalculatorBean();
64 | }
65 |
66 | // ---------------------------------------------------------------------------||
67 | // Tests ---------------------------------------------------------------------||
68 | // ---------------------------------------------------------------------------||
69 |
70 | /**
71 | * Ensures that the business logic behind the
72 | * CalculatorEJB adds as expected when used
73 | * as a pure POJO
74 | */
75 | @Test
76 | public void testAddition()
77 | {
78 | // Initialize
79 | final int[] arguments = new int[]
80 | {3, 7, 2};
81 | final int expectedSum = 12;
82 |
83 | // Add
84 | final int actualSum = calc.add(arguments);
85 |
86 | // Test
87 | TestCase.assertEquals("Addition did not return the expected result", expectedSum, actualSum);
88 |
89 | // Log
90 | final StringBuffer sb = new StringBuffer();
91 | sb.append("Obtained expected result, ");
92 | sb.append(actualSum);
93 | sb.append(", from arguments: ");
94 | for (final int arg : arguments)
95 | {
96 | sb.append(arg);
97 | sb.append(" ");
98 | }
99 | log.info(sb.toString());
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/ch09-14-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/ch11/relationships/Phone.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.employeeregistry.ch11.relationships;
23 |
24 | import javax.persistence.Entity;
25 | import javax.persistence.EnumType;
26 | import javax.persistence.Enumerated;
27 |
28 | import org.jboss.ejb3.examples.testsupport.entity.AutogenIdentityBase;
29 |
30 | /**
31 | * Represents a Phone number. An {@link Employee}
32 | * may have many, but the relationship is unidirectional.
33 | *
34 | * @author ALR
35 | * @version $Revision: $
36 | */
37 | @Entity
38 | // Mark that we're an Entity Bean, EJB's integration point
39 | // with Java Persistence
40 | public class Phone extends AutogenIdentityBase
41 | {
42 |
43 | //-------------------------------------------------------------------------------------||
44 | // Instance Members -------------------------------------------------------------------||
45 | //-------------------------------------------------------------------------------------||
46 |
47 | /**
48 | * Phone number
49 | */
50 | private String number;
51 |
52 | /**
53 | * Type
54 | */
55 | @Enumerated(EnumType.STRING)
56 | private PhoneType type;
57 |
58 | //-------------------------------------------------------------------------------------||
59 | // Accessors / Mutators ---------------------------------------------------------------||
60 | //-------------------------------------------------------------------------------------||
61 |
62 | /**
63 | * @return the number
64 | */
65 | public String getNumber()
66 | {
67 | return number;
68 | }
69 |
70 | /**
71 | * @param number the number to set
72 | */
73 | public void setNumber(String number)
74 | {
75 | this.number = number;
76 | }
77 |
78 | /**
79 | * @return the type
80 | */
81 | public PhoneType getType()
82 | {
83 | return type;
84 | }
85 |
86 | /**
87 | * @param type the type to set
88 | */
89 | public void setType(PhoneType type)
90 | {
91 | this.type = type;
92 | }
93 |
94 | //-------------------------------------------------------------------------------------||
95 | // Required Implementations -----------------------------------------------------------||
96 | //-------------------------------------------------------------------------------------||
97 |
98 | /**
99 | * {@inheritDoc}
100 | * @see java.lang.Object#toString()
101 | */
102 | @Override
103 | public String toString()
104 | {
105 | return Phone.class.getSimpleName() + " [number=" + number + ", type=" + type + ", getId()=" + getId() + "]";
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/ch09-14-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/ch12/inheritance/joined/Customer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.employeeregistry.ch12.inheritance.joined;
23 |
24 | import javax.persistence.Entity;
25 |
26 | /**
27 | * Represents a customer, a {@link Person}
28 | * associated with a company. Sits in the middle of an inheritance
29 | * hierarchy and is extended by employee types, who are a special type of
30 | * {@link Customer}.
31 | *
32 | * @author ALR
33 | * @version $Revision: $
34 | */
35 | @Entity(name = "JOINED_CUSTOMER")
36 | public class Customer extends Person
37 | {
38 |
39 | //-------------------------------------------------------------------------------------||
40 | // Instance Members -------------------------------------------------------------------||
41 | //-------------------------------------------------------------------------------------||
42 |
43 | /**
44 | * Street-level address
45 | */
46 | private String street;
47 |
48 | /**
49 | * City
50 | */
51 | private String city;
52 |
53 | /**
54 | * State
55 | */
56 | private String state;
57 |
58 | /**
59 | * ZIP
60 | */
61 | private String zip;
62 |
63 | //-------------------------------------------------------------------------------------||
64 | // Accessors / Mutators ---------------------------------------------------------------||
65 | //-------------------------------------------------------------------------------------||
66 | /**
67 | * @return the street
68 | */
69 | public String getStreet()
70 | {
71 | return street;
72 | }
73 |
74 | /**
75 | * @param street the street to set
76 | */
77 | public void setStreet(final String street)
78 | {
79 | this.street = street;
80 | }
81 |
82 | /**
83 | * @return the city
84 | */
85 | public String getCity()
86 | {
87 | return city;
88 | }
89 |
90 | /**
91 | * @param city the city to set
92 | */
93 | public void setCity(final String city)
94 | {
95 | this.city = city;
96 | }
97 |
98 | /**
99 | * @return the state
100 | */
101 | public String getState()
102 | {
103 | return state;
104 | }
105 |
106 | /**
107 | * @param state the state to set
108 | */
109 | public void setState(final String state)
110 | {
111 | this.state = state;
112 | }
113 |
114 | /**
115 | * @return the zip
116 | */
117 | public String getZip()
118 | {
119 | return zip;
120 | }
121 |
122 | /**
123 | * @param zip the zip to set
124 | */
125 | public void setZip(final String zip)
126 | {
127 | this.zip = zip;
128 | }
129 |
130 | }
131 |
--------------------------------------------------------------------------------
/ch09-14-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/ch12/inheritance/tableperclass/Customer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.employeeregistry.ch12.inheritance.tableperclass;
23 |
24 | import javax.persistence.Entity;
25 |
26 | /**
27 | * Represents a customer, a {@link Person}
28 | * associated with a company. Sits in the middle of an inheritance
29 | * hierarchy and is extended by employee types, who are a special type of
30 | * {@link Customer}.
31 | *
32 | * @author ALR
33 | * @version $Revision: $
34 | */
35 | @Entity(name = "TABLEPERCLASS_CUSTOMER")
36 | public class Customer extends Person
37 | {
38 |
39 | //-------------------------------------------------------------------------------------||
40 | // Instance Members -------------------------------------------------------------------||
41 | //-------------------------------------------------------------------------------------||
42 |
43 | /**
44 | * Street-level address
45 | */
46 | private String street;
47 |
48 | /**
49 | * City
50 | */
51 | private String city;
52 |
53 | /**
54 | * State
55 | */
56 | private String state;
57 |
58 | /**
59 | * ZIP
60 | */
61 | private String zip;
62 |
63 | //-------------------------------------------------------------------------------------||
64 | // Accessors / Mutators ---------------------------------------------------------------||
65 | //-------------------------------------------------------------------------------------||
66 | /**
67 | * @return the street
68 | */
69 | public String getStreet()
70 | {
71 | return street;
72 | }
73 |
74 | /**
75 | * @param street the street to set
76 | */
77 | public void setStreet(final String street)
78 | {
79 | this.street = street;
80 | }
81 |
82 | /**
83 | * @return the city
84 | */
85 | public String getCity()
86 | {
87 | return city;
88 | }
89 |
90 | /**
91 | * @param city the city to set
92 | */
93 | public void setCity(final String city)
94 | {
95 | this.city = city;
96 | }
97 |
98 | /**
99 | * @return the state
100 | */
101 | public String getState()
102 | {
103 | return state;
104 | }
105 |
106 | /**
107 | * @param state the state to set
108 | */
109 | public void setState(final String state)
110 | {
111 | this.state = state;
112 | }
113 |
114 | /**
115 | * @return the zip
116 | */
117 | public String getZip()
118 | {
119 | return zip;
120 | }
121 |
122 | /**
123 | * @param zip the zip to set
124 | */
125 | public void setZip(final String zip)
126 | {
127 | this.zip = zip;
128 | }
129 |
130 | }
131 |
--------------------------------------------------------------------------------
/testsupport/src/main/java/org/jboss/ejb3/examples/testsupport/entity/AutogenIdentityBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.testsupport.entity;
23 |
24 | import javax.persistence.GeneratedValue;
25 | import javax.persistence.Id;
26 | import javax.persistence.MappedSuperclass;
27 |
28 | /**
29 | * Base class for all entities with an autogenerated ID
30 | *
31 | * @author ALR
32 | * @version $Revision: $
33 | */
34 | @MappedSuperclass
35 | public abstract class AutogenIdentityBase
36 | {
37 |
38 | //-------------------------------------------------------------------------------------||
39 | // Instance Members -------------------------------------------------------------------||
40 | //-------------------------------------------------------------------------------------||
41 |
42 | /**
43 | * Primary key
44 | */
45 | @Id
46 | @GeneratedValue
47 | private Long id;
48 |
49 | //-------------------------------------------------------------------------------------||
50 | // Accessors / Mutators ---------------------------------------------------------------||
51 | //-------------------------------------------------------------------------------------||
52 |
53 | /**
54 | * @return the id
55 | */
56 | public Long getId()
57 | {
58 | return id;
59 | }
60 |
61 | /**
62 | * @param id the id to set
63 | */
64 | public void setId(final Long id)
65 | {
66 | this.id = id;
67 | }
68 |
69 | //-------------------------------------------------------------------------------------||
70 | // Overridden Implementations ---------------------------------------------------------||
71 | //-------------------------------------------------------------------------------------||
72 |
73 | /*
74 | * Value equality is based by ID only
75 | */
76 |
77 | /**
78 | * {@inheritDoc}
79 | * @see java.lang.Object#hashCode()
80 | */
81 | @Override
82 | public int hashCode()
83 | {
84 | final int prime = 31;
85 | int result = 1;
86 | result = prime * result + ((id == null) ? 0 : id.hashCode());
87 | return result;
88 | }
89 |
90 | /**
91 | * {@inheritDoc}
92 | * @see java.lang.Object#equals(java.lang.Object)
93 | */
94 | @Override
95 | public boolean equals(Object obj)
96 | {
97 | if (this == obj)
98 | return true;
99 | if (obj == null)
100 | return false;
101 | if (getClass() != obj.getClass())
102 | return false;
103 | AutogenIdentityBase other = (AutogenIdentityBase) obj;
104 | if (id == null)
105 | {
106 | if (other.id != null)
107 | return false;
108 | }
109 | else if (!id.equals(other.id))
110 | return false;
111 | return true;
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/ch09-14-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/ch12/inheritance/singleclass/Customer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.employeeregistry.ch12.inheritance.singleclass;
23 |
24 | import javax.persistence.DiscriminatorValue;
25 | import javax.persistence.Entity;
26 |
27 | /**
28 | * Represents a customer, a {@link Person}
29 | * associated with a company. Sits in the middle of an inheritance
30 | * hierarchy and is extended by employee types, who are a special type of
31 | * {@link Customer}.
32 | *
33 | * @author ALR
34 | * @version $Revision: $
35 | */
36 | @Entity(name = "SINGLECLASS_CUSTOMER")
37 | @DiscriminatorValue("CUSTOMER")
38 | public class Customer extends Person
39 | {
40 |
41 | //-------------------------------------------------------------------------------------||
42 | // Instance Members -------------------------------------------------------------------||
43 | //-------------------------------------------------------------------------------------||
44 |
45 | /**
46 | * Street-level address
47 | */
48 | private String street;
49 |
50 | /**
51 | * City
52 | */
53 | private String city;
54 |
55 | /**
56 | * State
57 | */
58 | private String state;
59 |
60 | /**
61 | * ZIP
62 | */
63 | private String zip;
64 |
65 | //-------------------------------------------------------------------------------------||
66 | // Accessors / Mutators ---------------------------------------------------------------||
67 | //-------------------------------------------------------------------------------------||
68 | /**
69 | * @return the street
70 | */
71 | public String getStreet()
72 | {
73 | return street;
74 | }
75 |
76 | /**
77 | * @param street the street to set
78 | */
79 | public void setStreet(final String street)
80 | {
81 | this.street = street;
82 | }
83 |
84 | /**
85 | * @return the city
86 | */
87 | public String getCity()
88 | {
89 | return city;
90 | }
91 |
92 | /**
93 | * @param city the city to set
94 | */
95 | public void setCity(final String city)
96 | {
97 | this.city = city;
98 | }
99 |
100 | /**
101 | * @return the state
102 | */
103 | public String getState()
104 | {
105 | return state;
106 | }
107 |
108 | /**
109 | * @param state the state to set
110 | */
111 | public void setState(final String state)
112 | {
113 | this.state = state;
114 | }
115 |
116 | /**
117 | * @return the zip
118 | */
119 | public String getZip()
120 | {
121 | return zip;
122 | }
123 |
124 | /**
125 | * @param zip the zip to set
126 | */
127 | public void setZip(final String zip)
128 | {
129 | this.zip = zip;
130 | }
131 |
132 | }
133 |
--------------------------------------------------------------------------------
/ch09-14-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/ch10/mapping/EmployeeWithMappedSuperClassId.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.employeeregistry.ch10.mapping;
23 |
24 | import javax.persistence.Column;
25 | import javax.persistence.Entity;
26 | import javax.persistence.Table;
27 |
28 | import org.jboss.ejb3.examples.testsupport.entity.AutogenIdentityBase;
29 | import org.jboss.ejb3.examples.testsupport.entity.IdentityBase;
30 |
31 | /**
32 | * Represents an Employee in the system. Inherits the
33 | * primary key support from {@link IdentityBase#getId()}.
34 | *
35 | * @author ALR
36 | * @version $Revision: $
37 | */
38 | @Entity
39 | // Mark that we're an Entity Bean, EJB's integration point
40 | // with Java Persistence
41 | @Table(name = "employees_with_autogen_pk")
42 | // Explicitly denote the name of the table in the DB
43 | public class EmployeeWithMappedSuperClassId extends AutogenIdentityBase
44 | {
45 |
46 | //-------------------------------------------------------------------------------------||
47 | // Instance Members -------------------------------------------------------------------||
48 | //-------------------------------------------------------------------------------------||
49 |
50 | /**
51 | * Name of the employee
52 | */
53 | // We can use @Column.name to denote the name of the column in the DB
54 | @Column(name = "employee_name")
55 | private String name;
56 |
57 | //-------------------------------------------------------------------------------------||
58 | // Constructor ------------------------------------------------------------------------||
59 | //-------------------------------------------------------------------------------------||
60 |
61 | /**
62 | * Default constructor, required by JPA
63 | */
64 | public EmployeeWithMappedSuperClassId()
65 | {
66 |
67 | }
68 |
69 | /**
70 | * Convenience constructor
71 | */
72 | public EmployeeWithMappedSuperClassId(final String name)
73 | {
74 | // Set
75 | this.name = name;
76 | }
77 |
78 | //-------------------------------------------------------------------------------------||
79 | // Accessors / Mutators ---------------------------------------------------------------||
80 | //-------------------------------------------------------------------------------------||
81 |
82 | /**
83 | * @return the name
84 | */
85 | public String getName()
86 | {
87 | return name;
88 | }
89 |
90 | /**
91 | * @param name the name to set
92 | */
93 | public void setName(final String name)
94 | {
95 | this.name = name;
96 | }
97 |
98 | /**
99 | * {@inheritDoc}
100 | * @see java.lang.Object#toString()
101 | */
102 | @Override
103 | public String toString()
104 | {
105 | return EmployeeWithMappedSuperClassId.class.getSimpleName() + " [id=" + this.getId() + ", name=" + name + "]";
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/ch19-timer/src/main/java/org/jboss/ejb3/examples/ch19/timer/api/CreditCardTransaction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch19.timer.api;
23 |
24 | import java.math.BigDecimal;
25 |
26 | /**
27 | * Value object representing a single credit card transaction.
28 | * Immutable.
29 | *
30 | * @author ALR
31 | * @version $Revision: $
32 | */
33 | public class CreditCardTransaction
34 | {
35 | //-------------------------------------------------------------------------------------||
36 | // Instance Members -------------------------------------------------------------------||
37 | //-------------------------------------------------------------------------------------||
38 |
39 | /**
40 | * The card number
41 | */
42 | private final String cardNumber;
43 |
44 | /**
45 | * The amount to be charged
46 | */
47 | private final BigDecimal amount;
48 |
49 | //-------------------------------------------------------------------------------------||
50 | // Constructor ------------------------------------------------------------------------||
51 | //-------------------------------------------------------------------------------------||
52 |
53 | /**
54 | * Creates a new instance with the specified card number and amount
55 | * @param cardNumber
56 | * @param amount
57 | * @throws IllegalArgumentException If either argument is null
58 | */
59 | public CreditCardTransaction(final String cardNumber, final BigDecimal amount) throws IllegalArgumentException
60 | {
61 | // Precondition checks
62 | if (cardNumber == null || cardNumber.length() == 0)
63 | {
64 | throw new IllegalArgumentException("card number must be specified");
65 | }
66 | if (amount == null)
67 | {
68 | throw new IllegalArgumentException("amount must be specified");
69 | }
70 |
71 | // Set
72 | this.amount = amount;
73 | this.cardNumber = cardNumber;
74 | }
75 |
76 | //-------------------------------------------------------------------------------------||
77 | // Required Implementations -----------------------------------------------------------||
78 | //-------------------------------------------------------------------------------------||
79 |
80 | /**
81 | * {@inheritDoc}
82 | * @see java.lang.Object#toString()
83 | */
84 | @Override
85 | public String toString()
86 | {
87 | return "CreditCardTransaction [amount=" + amount + ", cardNumber=" + cardNumber + "]";
88 | }
89 |
90 | //-------------------------------------------------------------------------------------||
91 | // Functional Methods -----------------------------------------------------------------||
92 | //-------------------------------------------------------------------------------------||
93 |
94 | /**
95 | * @return the cardNumber
96 | */
97 | public String getCardNumber()
98 | {
99 | return cardNumber;
100 | }
101 |
102 | /**
103 | * @return the amount
104 | */
105 | public BigDecimal getAmount()
106 | {
107 | return amount;
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/ch18-interceptors/src/main/java/org/jboss/ejb3/examples/ch18/tuner/TunerBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch18.tuner;
23 |
24 | import java.io.IOException;
25 | import java.io.InputStream;
26 | import java.util.logging.Logger;
27 |
28 | import javax.ejb.Local;
29 | import javax.ejb.Stateless;
30 | import javax.interceptor.Interceptors;
31 | import javax.interceptor.InvocationContext;
32 |
33 | /**
34 | * Simple EJB which returns references back to the client. Used to
35 | * show configuration of interceptors; here we've configured the
36 | * {@link CachingAuditor} to remember all previous
37 | * {@link InvocationContext}s made upon the EJB.
38 | *
39 | * @author ALR
40 | * @version $Revision: $
41 | */
42 | @Stateless
43 | // Class-level interceptors will be run upon requests to every method of this EJB
44 | @Interceptors(CachingAuditor.class)
45 | @Local(TunerLocalBusiness.class)
46 | public class TunerBean implements TunerLocalBusiness
47 | {
48 | //-------------------------------------------------------------------------------------||
49 | // Class Members ----------------------------------------------------------------------||
50 | //-------------------------------------------------------------------------------------||
51 |
52 | /**
53 | * Logger
54 | */
55 | private static final Logger log = Logger.getLogger(TunerBean.class.getName());
56 |
57 | //-------------------------------------------------------------------------------------||
58 | // Required Implementations -----------------------------------------------------------||
59 | //-------------------------------------------------------------------------------------||
60 |
61 | /**
62 | * {@inheritDoc}
63 | * @see org.jboss.ejb3.examples.ch18.tuner.TunerLocalBusiness#getChannel(int)
64 | */
65 | // Here we declare method-level interceptors, which will only take place on this method
66 | @Interceptors(Channel2Restrictor.class)
67 | @Override
68 | public InputStream getChannel(final int channel) throws IllegalArgumentException
69 | {
70 | // Declare the stream we'll use
71 | final InputStream stream;
72 | switch (channel)
73 | {
74 | // We want channel 1
75 | case 1 :
76 | stream = new InputStream()
77 | {
78 |
79 | @Override
80 | public int read() throws IOException
81 | {
82 | return 1;
83 | }
84 | };
85 | break;
86 | // We want channel 2
87 | case 2 :
88 | stream = new InputStream()
89 | {
90 |
91 | @Override
92 | public int read() throws IOException
93 | {
94 | return 2;
95 | }
96 | };
97 | break;
98 | // We've requested an improper channel
99 | default :
100 | throw new IllegalArgumentException("Not a valid channel: " + channel);
101 | }
102 |
103 | // Return
104 | log.info("Returning stream for Channel " + channel + ": " + stream);
105 | return stream;
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/ch04-firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorIntegrationTestCase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2009, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 |
23 | package org.jboss.ejb3.examples.ch04.firstejb;
24 |
25 | import java.net.MalformedURLException;
26 | import java.util.logging.Logger;
27 |
28 | import javax.ejb.EJB;
29 |
30 | import org.jboss.arquillian.container.test.api.Deployment;
31 | import org.jboss.arquillian.junit.Arquillian;
32 | import org.jboss.shrinkwrap.api.ShrinkWrap;
33 | import org.jboss.shrinkwrap.api.spec.JavaArchive;
34 | import org.junit.Before;
35 | import org.junit.Test;
36 | import org.junit.runner.RunWith;
37 |
38 | /**
39 | * Integration tests for the CalculatorEJB exposing one
40 | * business view
41 | *
42 | * @author ALR
43 | */
44 | @RunWith(Arquillian.class)
45 | public class CalculatorIntegrationTestCase
46 | {
47 | // ---------------------------------------------------------------------------||
48 | // Class Members -------------------------------------------------------------||
49 | // ---------------------------------------------------------------------------||
50 |
51 | /**
52 | * Logger
53 | */
54 | private static final Logger log = Logger.getLogger(CalculatorIntegrationTestCase.class.getName());
55 |
56 | /**
57 | * The EJB 3.x local business view of the CalculatorEJB
58 | */
59 | @EJB(mappedName="java:app/firstejb/SimpleCalculatorBean")
60 | private static CalculatorLocalBusiness calcLocalBusiness;
61 |
62 | /**
63 | * Delegate for ensuring that the obtained Calculators are working as expected
64 | */
65 | private static CalculatorAssertionDelegate assertionDelegate;
66 |
67 | /**
68 | * Define the deployment
69 | */
70 | @Deployment
71 | public static JavaArchive createDeployment() throws MalformedURLException
72 | {
73 | final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "firstejb.jar").addPackage(
74 | CalculatorBeanBase.class.getPackage());
75 | log.info(archive.toString(true));
76 | return archive;
77 | }
78 |
79 | // ---------------------------------------------------------------------------||
80 | // Lifecycle Methods ---------------------------------------------------------||
81 | // ---------------------------------------------------------------------------||
82 |
83 | /**
84 | * Run in container before the test
85 | */
86 | @Before
87 | public void beforeClass() throws Throwable
88 | {
89 | // Create Assertion Delegate
90 | assertionDelegate = new CalculatorAssertionDelegate();
91 | }
92 |
93 | // ---------------------------------------------------------------------------||
94 | // Tests ---------------------------------------------------------------------||
95 | // ---------------------------------------------------------------------------||
96 |
97 | /**
98 | * Ensures that the CalculatorEJB adds as expected,
99 | * using the EJB 3.x business view
100 | */
101 | @Test
102 | public void testAdditionUsingBusinessReference() throws Throwable
103 | {
104 | // Test
105 | log.info("Testing EJB via business reference...");
106 | assertionDelegate.assertAdditionSucceeds(calcLocalBusiness);
107 | }
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/ch08-statusupdate/src/test/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/TwitterUpdateBlockingTestMdb.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.ch08.statusupdate.mdb;
23 |
24 | import java.util.concurrent.CountDownLatch;
25 | import java.util.logging.Logger;
26 |
27 | import javax.ejb.ActivationConfigProperty;
28 | import javax.ejb.MessageDriven;
29 | import javax.jms.MessageListener;
30 |
31 | import org.jboss.ejb3.examples.ch08.statusupdate.api.StatusUpdate;
32 | import org.jboss.ejb3.examples.ch08.statusupdate.api.StatusUpdateConstants;
33 |
34 | /**
35 | * Extends the {@link TwitterUpdateMdb} example to add a latch to
36 | * be shared in testing only, such that tests can be sure we're done
37 | * processing before they proceed
38 | *
39 | * @author ALR
40 | */
41 | @MessageDriven(name = TwitterUpdateMdb.NAME, activationConfig =
42 | {
43 | @ActivationConfigProperty(propertyName = "destinationType", propertyValue = StatusUpdateConstants.TYPE_DESTINATION_STATUSUPDATE),
44 | @ActivationConfigProperty(propertyName = "destination", propertyValue = StatusUpdateConstants.JNDI_NAME_TOPIC_STATUSUPDATE)})
45 | public class TwitterUpdateBlockingTestMdb extends TwitterUpdateMdb implements MessageListener
46 | {
47 |
48 | //-------------------------------------------------------------------------------------||
49 | // Class Members ----------------------------------------------------------------------||
50 | //-------------------------------------------------------------------------------------||
51 |
52 | /**
53 | * Logger
54 | */
55 | private static final Logger log = Logger.getLogger(TwitterUpdateBlockingTestMdb.class.getName());
56 |
57 | /**
58 | * Shared latch, so tests can wait until the MDB is processed. In POJO
59 | * testing this is wholly unnecessary as we've got a single-threaded environment, but
60 | * when testing in an EJB Container running in the *same* JVM as the test, the test
61 | * can use this to wait until the MDB has been invoked, strengthening the integrity
62 | * of the test. It's not recommended to put this piece into a production EJB; instead
63 | * test an extension of your EJB which adds this (and only this) support.
64 | */
65 | public static CountDownLatch LATCH = new CountDownLatch(1);
66 |
67 | //-------------------------------------------------------------------------------------||
68 | // Overridden Implementations ---------------------------------------------------------||
69 | //-------------------------------------------------------------------------------------||
70 |
71 | /**
72 | * {@inheritDoc}
73 | * Additionally waits upon a shared barrier so that the test can ensure we're done before
74 | * it proceeds
75 | * @see org.jboss.ejb3.examples.ch08.statusupdate.mdb.TwitterUpdateMdb#updateStatus(org.jboss.ejb3.examples.ch08.statusupdate.api.StatusUpdate)
76 | */
77 | @Override
78 | public void updateStatus(final StatusUpdate newStatus) throws IllegalArgumentException, Exception
79 | {
80 | // Call the super implementation
81 | try
82 | {
83 | super.updateStatus(newStatus);
84 | }
85 | finally
86 | {
87 | // Count down the latch
88 | log.info("Counting down the latch...");
89 | LATCH.countDown();
90 | }
91 |
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/ch09-14-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/ch10/mapping/EmployeeWithExternalCompositePK.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JBoss, Home of Professional Open Source.
3 | * Copyright 2010, Red Hat Middleware LLC, and individual contributors
4 | * as indicated by the @author tags. See the copyright.txt file in the
5 | * distribution for a full listing of individual contributors.
6 | *
7 | * This is free software; you can redistribute it and/or modify it
8 | * under the terms of the GNU Lesser General Public License as
9 | * published by the Free Software Foundation; either version 2.1 of
10 | * the License, or (at your option) any later version.
11 | *
12 | * This software is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * Lesser General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU Lesser General Public
18 | * License along with this software; if not, write to the Free
19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 | */
22 | package org.jboss.ejb3.examples.employeeregistry.ch10.mapping;
23 |
24 | import javax.persistence.Entity;
25 | import javax.persistence.Id;
26 | import javax.persistence.IdClass;
27 |
28 | /**
29 | * Represents an Employee in the system. The identity
30 | * (primary key) is determined by composite properties
31 | * defined by {@link ExternalEmployeePK}.
32 | *
33 | * @author ALR
34 | * @version $Revision: $
35 | */
36 | @Entity
37 | // Mark that we're an Entity Bean, EJB's integration point
38 | // with Java Persistence
39 | @IdClass(ExternalEmployeePK.class)
40 | // Use a composite primary key using a custom PK class
41 | public class EmployeeWithExternalCompositePK
42 | {
43 |
44 | //-------------------------------------------------------------------------------------||
45 | // Instance Members -------------------------------------------------------------------||
46 | //-------------------------------------------------------------------------------------||
47 |
48 | /**
49 | * Last Name
50 | */
51 | @Id
52 | private String lastName;
53 |
54 | /**
55 | * Social Security Number (United States Federal ID)
56 | */
57 | @Id
58 | private Long ssn;
59 |
60 | //-------------------------------------------------------------------------------------||
61 | // Constructor ------------------------------------------------------------------------||
62 | //-------------------------------------------------------------------------------------||
63 |
64 | /**
65 | * Default constructor, required by JPA
66 | */
67 | public EmployeeWithExternalCompositePK()
68 | {
69 |
70 | }
71 |
72 | //-------------------------------------------------------------------------------------||
73 | // Accessors / Mutators ---------------------------------------------------------------||
74 | //-------------------------------------------------------------------------------------||
75 |
76 | /**
77 | * @return the lastName
78 | */
79 | public String getLastName()
80 | {
81 | return lastName;
82 | }
83 |
84 | /**
85 | * @param lastName the lastName to set
86 | */
87 | public void setLastName(final String lastName)
88 | {
89 | this.lastName = lastName;
90 | }
91 |
92 | /**
93 | * @return the ssn
94 | */
95 | public Long getSsn()
96 | {
97 | return ssn;
98 | }
99 |
100 | /**
101 | * @param ssn the ssn to set
102 | */
103 | public void setSsn(final Long ssn)
104 | {
105 | this.ssn = ssn;
106 | }
107 |
108 | //-------------------------------------------------------------------------------------||
109 | // Overridden Implementations ---------------------------------------------------------||
110 | //-------------------------------------------------------------------------------------||
111 |
112 | /**
113 | * {@inheritDoc}
114 | * @see java.lang.Object#toString()
115 | */
116 | @Override
117 | public String toString()
118 | {
119 | return EmployeeWithExternalCompositePK.class.getSimpleName() + " [lastName=" + lastName + ", ssn=" + ssn + "]";
120 | }
121 |
122 | }
123 |
--------------------------------------------------------------------------------