Title: Goals
1EJB Session Beans
2Goals
- Be able to deploy business logic to the EJB tier
- hosted by the container
- resource management
- threading
- security
- transactions
- accessed by other local business logic and local
web tier - accessed by remote clients
3Objectives
- Rationale
- Stateless Session Bean
- Stateful Session Bean
- Example Session Bean
- Interface Design Issues
- Lazy Load
- Pure POJOs
- DTO Classes
4Overview
- Entity Beans
- model business data in system
- Session Beans
- model interactions between other beans
- taskflow
5Associated Design Patterns
- Session Façade
- Remote Facade/Data Transfer Objects
- Value Object Assembler
6Session Façade
- Context
- multi-tiered application
- non-trivial business logic and data
- Problem
- potential tight coupling between clients and
complex business objects - too many method invocations between clients and
business objects - business methods exposed for misuse by clients
7Example Workflow Task
8Session Façade
- Forces
- hide complex interactions behind a simple client
interface - reduce the number of business objects exposed to
the client across the network - hide implementation, interactions, and
dependencies of business components - Solution
- Use a Session Bean to encapsulate the
interactions required with the business objects
9Session Beans Eliminate Workflow Complexity in
Client
10Session Façade Participants
11Session Facade
- Consequences
- Simplifies complex systems
- May appear to be a no value pass-thru in simple
systems - should involve more that one business object per
facade - should have more than one façade per system
- Decouples the business objects from being aware
of one another - Improves perceived network performance
- Centralizes security and transactions
12Remote Facade
- Context
- Adding a remote interface to a fine-grain object
model - Problem
- Object-Oriented programming promotes small
methods - allowing for control and substitution of behavior
- increases understanding
- increases number of method calls
- Fine grain methods and frequent method calls do
not scale across remote interfaces - Course-grain methods can improve performance and
add scale, but obscure the simplicity of the
object model
13Local Objects and Methods
14Remote Facade
- Forces
- core service layer (business logic and its
business objects) contains fine grain methods and
objects - a significant number of fine-grain remote calls
will not work - Solution
- add a Remote Facade
- a course-grain facade over a service layer
- contains no business logic it calls it
- translates course-grain methods and objects into
fine-grain method calls and objects to/from
service layer - bulk accessors wrap fine-grain access methods
- service layer does not have a remote interface
- fine grain business objects used might not be
Serializable
15Remote Facade Encapsulates Local Objects
16Remote Facade Encapsulates Local Logic
17DTO Pattern
- Context
- Business Objects represent too much information
or behavior to transfer to remote client - Problem
- Client may get information they don't need
- Client may get information they can't handle
- Client may get information they are not autorized
to use - Client may get too much information/behavior to
be useful (e.g., entire database serialized to
client) - Forces
- Some clients are local and can share object
references with business logic - Handling specifics of remote clients outside of
core scope of business logic
18DTO/Remote Facade Solution
- Layer a Remote Facade over Business Logic
- Remote Facade constructs Data Transfer Objects
(DTOs) from Business Objects that are appropriate
for remote client view - Remote Facade uses DTOs to construct or locate
Business Objects to communicate with Business
Logic
19DTO Pattern Roles
- Data Transfer Object
- represent a subset of the state of the
application at a point in time - not dependent on Business Objects or server-side
technologies - doing so would require sending Business Objects
to client - XML and Web services provide the ultimate
isolation in DTO implementation - Remote Facade
- uses Business Logic to perform core business
logic - layered on to of Business Logic to translate
between Business Objects and DTOs - Business Logic
- continues to perform core duties as described in
DAO Pattern
20DTO Pattern Consequences
- Clients only get what they need
- Clients only get what they understand
- Clients only get what they are authorized to use
- Remote and Local interfaces to services are
different - makes it harder to provide location transparency
- Lightweight Business Objects can be used as DTOs
- Remote Facade must make sure they are pruned of
excess related items before transferring to
client - Remote Facade must make sure they are cleaned
of DAO persistence classes before transferring to
client
21Use Cases and Session Beans
- Session Bean per Use Case too fine grain
- CreateAccountEJB
- DepositEJB
- WithdrawEJB
- TransferEJB
- Group cohesive Use Cases into a larger-grain
Session Bean - TellerEJB
- createAccount(), deposit(), withdraw(), transfer()
22Use of Session versus Entity Beans
- Session Beans
- implementation of a task
- interaction between other beans
- direct database access
- bulk operations
- examples
- TaxDistrict.calcTax(double cost)
- Teller.transfer(long fromAccount, long toAccount,
double amount) - Registrar.listStudents(String course)
23Use of Session versus Entity Beans (cont.)
- Entity Beans
- represent shared data in the database
- provide a type-safe, complete view of shared
information - interacts with data generally at the individual
object/row level - examples
- Account, Student
- Account.setOwner(String taxId),
Account.getOwner() - Account.withdraw(double amount),
Account.deposit(double amount)
24Stateless/Stateful Session Beans
- Stateless
- maintains no conversational state
- each method is ignorant of what went before it
and what will happen after it - maintains implementation state
- sharable between separate client invocations
- a set of procedures or batch commands that take
in a set of parameters and return a result
25Stateless/Stateful Session Beans
- Stateful
- maintains conversational state
- object can cache values between calls
- ex. iterator
- idle timeout period or client command ends
lifetime - maintains implementation state
- not sharable between separate clients/objects
- all resources are allocated to perform the work
of one Stateful Session bean instance. That
instance is tied to the state of the client - able to react to transaction states
- ex. Publish error message on transaction rollback
26Stateful Session Bean Example (Iteration)
27Stateless/Stateful
- Stateless
- can contain cached implementations
- JDBC DataSources
- JMS Publishers
- cached EAI state
- all non-visible to calling client
- Stateful
- may contain all of the above and add client
conversational state
28Stateless/Stateful
- Stateless
- Cheapest to implement, deploy, scale
- Stateful
- should only be used within the scope of a single
HttpRequest - should not be used at HttpSession Scope
- multiple threads would access same instance
29Stateless Session Bean Lifecycle
30Stateful Session Bean Lifecycle
31Example Core Implementation
- ejbsessionBankImpl/target/classes
- -- META-INF
- -- orm.xml
- -- persistence.xml
- -- ejava
- -- examples
- -- ejbsessionbank
- -- bl
- -- BankException.class
- -- Teller.class
- -- blimpl
- -- TellerImpl.class
- -- bo
- -- Account.class
- -- Ledger.class
- -- Owner.class
- -- dao
- -- AccountDAO.class
- -- DAOException.class
32Example Session Bean Business Interface
- package ejava.examples.ejbsessionbank.bl
- import java.util.List
- import ejava.examples.ejbsessionbank.bo.Account
- import ejava.examples.ejbsessionbank.bo.Ledger
- public interface Teller
- Account createAccount(String accNum) throws
BankException - Account getAccount(String acctNum) throws
BankException - Account closeAccount(String acctNum) throws
BankException - void updateAccount(Account account) throws
BankException - ListltAccountgt getOverdrawnAccounts(int index,
int count) - throws BankException
- ListltAccountgt getAccounts(int index, int
count) - throws BankException
- Ledger getLedger() throws BankException
33Example EJB
- ejbsessionBankEJB/target/classes
- -- META-INF
- -- ejb-jar.xml
- -- jboss.xml
- -- persistence.xml
- -- ejava
- -- examples
- -- ejbsessionbank
- -- ejb
- -- TellerEJB.class
- -- TellerLocal.class
- -- TellerRemote.class
34Example Session Bean Local and Remote Interfaces
- package ejava.examples.ejbsessionbank.ejb
- import ejava.examples.ejbsessionbank.bl.Teller
- _at_javax.ejb.Local
- public interface TellerLocal extends Teller
-
- package ejava.examples.ejbsessionbank.ejb
- import ejava.examples.ejbsessionbank.bl.Teller
- _at_javax.ejb.Remote
- public interface TellerRemote extends Teller
-
Warning although business interfaces can be
used for both local and remote interfaces, this
only works for simple data models more later
35Example Session Bean Bean Class
- package ejava.examples.ejbsessionbank.ejb
- import java.util.List
- import javax.annotation.
- import javax.ejb.
- import javax.persistence.
- import org.apache.commons.logging.
- import ejava.examples.ejbsessionbank.bl.
- import ejava.examples.ejbsessionbank.bo.
- import ejava.examples.ejbsessionbank.da.
- import ejava.examples.ejbsessionbank.jpa.JPAUtil
- _at_Stateless
- public class TellerEJB implements TellerLocal,
TellerRemote - Log log LogFactory.getLog(TellerEJB.class)
36Example Session Bean Bean Class
- protected EntityManager em
- protected Teller teller
-
- _at_Resource
- protected SessionContext ctx
-
- _at_Resource(name"daoClass")
- protected String daoClassName
- _at_PersistenceContext(unitName"ejbsessionbank")
- public void setEm(EntityManager em)
- log.debug("container setting entity
manager" em) - this.em em
-
37Example Session Bean Bean Class
- _at_PostConstruct
- public void init()
- log.debug("init(), daoClass"
daoClassName) - teller new TellerImpl()
- try
- AccountDAO dao (AccountDAO)Thread.curren
tThread() //just a partial example of resolving -
.getContextClassLoader() //a property supplied -
.loadClass(daoClassName) //by the container -
.newInstance() - ((JPAAccountDAO)dao).setEntityManager(em)
- ((TellerImpl)teller).setAcctDAO(dao)
- OwnerDAO ownerDAO new JPAOwnerDAO()
- ((JPAOwnerDAO)ownerDAO).setEntityManager(e
m) - ((TellerImpl)teller).setOwnerDAO(ownerDAO)
- catch (Exception ex)
- log.fatal("error loading dao class"
daoClassName, ex) - throw new EJBException("error loading dao
class" - daoClassName ", " ex)
-
38Example Session Bean Bean Class
- public Account createAccount(String
accountNumber) throws BankException - try
- return teller.createAccount(accountNumber)
-
- catch (AccountDAOException ex)
- ctx.setRollbackOnly()
- log.fatal("internal error creating
account", ex) - throw new BankException("internal error
creating account" ex) -
-
39Example Session Bean ejb-jar.xml
- lt?xml version"1.0"?gt
- ltejb-jar
- xmlns"http//java.sun.com/xml/ns/javaee"
- xmlnsxsi"http//www.w3.org/2001/XMLSchema-in
stance" - xsischemaLocation"http//java.sun.com/xml/ns
/javaee http//java.sun.com/xml/ns/javaee/ejb-jar_
3_0.xsd" - version"3.0"gt
- ltenterprise-beansgt
- ltsessiongt
- ltejb-namegtTellerEJBlt/ejb-namegt
- ltenv-entrygt
- ltenv-entry-namegtdaoClasslt/env-entr
y-namegt - ltenv-entry-typegtjava.lang.Stringlt/
env-entry-typegt - ltenv-entry-valuegtejava.examples.ej
bsessionbank.jpa.JPAAccountDAO - lt/env-entry-valuegt
- lt/env-entrygt
- lt/sessiongt
- lt/enterprise-beansgt
40Example Session Bean jboss.xml
- lt?xml version"1.0" encoding"UTF-8"?gt
- ltjboss xmlns"http//java.sun.com/xml/ns/javaee"
- xmlnsxsi"http//www.w3.org/2001/XMLSchema-in
stance" - xsischemaLocation"http//www.jboss.org/j2ee/
schema http//www.jboss.org/j2ee/schema/jboss_5_0.
xsd" - version"5.0"gt
- ltenterprise-beansgt
- ltsessiongt
- ltejb-namegtTellerEJBlt/ejb-namegt
- ltjndi-namegtejava/examples/ejbsessionba
nk/TellerEJB/remotelt/jndi-namegt - ltlocal-jndi-namegt
ejava/examples/ejbsessionbank/TellerEJB/local
lt/local-jndi-namegt - lt/sessiongt
- lt/enterprise-beansgt
- lt/jbossgt
41Example Session Bean persistence.xml
- lt?xml version"1.0" encoding"UTF-8"?gt
- ltpersistence xmlns"http//java.sun.com/xml/ns/per
sistence" - xmlnsxsi"http//www.w3.org/2001/XMLSchema-in
stance" - xsischemaLocation"http//java.sun.com/xml/ns
/persistence http//java.sun.com/xml/ns/persistenc
e/persistence_1_0.xsd" version"1.0"gt - ltpersistence-unit name"ejbsessionbank"gt
- ltprovidergtorg.hibernate.ejb.HibernatePersi
stencelt/providergt - ltjta-data-sourcegtjava/ejavaDSlt/jta-data-s
ourcegt - ltpropertiesgt
- ltproperty name"hibernate.dialect"
- value"org.hibernate.dialect.HSQLD
ialect"/gt - ltproperty name"hibernate.show_sql"
value"false"/gt - lt/propertiesgt
- lt/persistence-unitgt
- lt/persistencegt
42Example RMI Test
- ejbsessionBankTest/target/test-classes/
- -- ejava
- -- examples
- -- ejbsessionbank
- -- ejbclient
- -- TellerOwnerRemoteTest.class
- -- TellerRemoteTest.class
- -- jndi.properties
- -- log4j.xml
43Example RMI Test
- jndi.properties
- java.naming.factory.initialorg.jnp.interfaces.Nam
ingContextFactory - java.naming.provider.urljnp//localhost1099
- java.naming.factory.url.pkgsorg.jboss.namingorg.
jnp.interfaces - JBoss JNDI Tree
- http//localhost8080/jmx-console
- serviceJNDIView
- list()
- - ejava (class org.jnp.interfaces.NamingContex
t) - - examples (class org.jnp.interfaces.Namin
gContext) - - ejbsessionbank (class
org.jnp.interfaces.NamingContext) - - TellerEJB (class
org.jnp.interfaces.NamingContext) - - local (proxy Proxy174
implements interface ejava.examples.ejbsessionbank
.ejb.TellerLocal,...) - - remote (proxy Proxy173
implements interface ejava.examples.ejbsessionbank
.ejb.TellerRemote,...)
44Example Session Bean Client Junit Testcase
- public class TellerRemoteTest extends TestCase
- String jndiName System.getProperty("jndi.name")
//TellerEJB/remote - InitialContext jndi
- Teller teller
- public void setUp() throws Exception
- jndi new InitialContext()
- teller (TellerRemote)jndi.lookup(jndiNam
e) -
-
- public void testCreateAccount() throws
Exception - log.info(" testCreateAccount ")
- Account accountnull
-
- log.debug("creating account, teller"
teller) - account teller.createAccount("1234")
- log.debug("account created" account)
-
-
JNDI Properties being supplied through
jndi.properties file -or- through a
Properties object
45Lazy Load Issues
- EJB
- public ListltOwnergt getOwners(int index, int
count) - return teller.getOwners(index, count)
- RMI Test
- ListltOwnergt owners teller.getOwners(0,
100) - assertEquals("unexpected number of
owners", 2, owners.size()) -
- for(Owner o owners)
- for (Account a o.getAccounts())
//LINE 87 - ...
-
-
- Error
- org.hibernate.LazyInitializationException failed
to lazily initialize a collection of role
ejava.examples.ejbsessionbank.bo.Owner.accounts,
no session or session was closed - ... org.hibernate.collection.AbstractPersistentCol
lection.read(AbstractPersistentCollection.java86)
- at org.hibernate.collection.PersistentBag.
iterator(PersistentBag.java249)
46Lazy Load Correction
- EJB Remote
- _at_Remote
- public interface TellerRemote extends Teller
- ListltOwnergt getOwnersLoaded(int index, int
count) throws BankException -
- EJB
- public ListltOwnergt getOwnersLoaded(int index,
int count) - throws BankException
- ListltOwnergt owners getOwners(index,
count) - for(Owner owner owners)
- for (Account account
owner.getAccounts()) - account.getBalance() //call a
method to get loaded -
-
- return owners
-
-
47Non-POJO Class Issues
- EJB
- public ListltOwnergt getOwnersLoaded(int index, int
count) - throws BankException
- ListltOwnergt owners getOwners(index,
count) - for(Owner owner owners)
- for (Account account
owner.getAccounts()) - account.getBalance() //call a
method to get loaded -
-
- return owners
-
- RMI Test
- ListltOwnergt owners teller.getOwnersLoade
d(0, 100) - for(Owner o owners)
- for (Account a o.getAccounts())
- log.info("account" a)
-
- log.debug("addresses"
o.getAccounts().getClass().getName())
48Non-POJO Class Correction
- EJB
- public ListltOwnergt getOwnersPOJO(int index,
int count) ... - ListltOwnergt ownersPOJO new
ArrayListltOwnergt() - for(Owner owner getOwners(index,
count)) - Owner ownerPOJO new
Owner(owner.getId()) - ownerPOJO.setFirstName(owner.getFirstN
ame()) - ownerPOJO.setLastName(owner.getLastNam
e()) - ownerPOJO.setSsn(owner.getSsn())
- for (Account account
owner.getAccounts()) - Account accountPOJO new
Account(account.getId()) - accountPOJO.setAccountNumber(accou
nt.getAccountNumber()) - accountPOJO.deposit(account.getBal
ance()) - ownerPOJO.getAccounts().add(accoun
tPOJO) -
- ownersPOJO.add(ownerPOJO)
-
- return ownersPOJO
-
-
49BO Complexity Class Issues
- Business Object
- public class Owner implements Serializable
- private long id
- private String firstName
- private String lastName
- private String ssn
- private CollectionltAccountgt accounts new
ArrayListltAccountgt() - ...
50BO Complexity Correction
- DTO Class
- public class OwnerDTO implements Serializable
- private static final long serialVersionUID
1L - private long id
- private String firstName
- private String lastName
- private int accounts
- ...
- EJB
- public ListltOwnerDTOgt getOwnersDTO(int index,
int count) - throws BankException
- ListltOwnerDTOgt ownersDTO new
ArrayListltOwnerDTOgt() - for(Owner owner getOwners(index,
count)) - OwnerDTO ownerDTO new
OwnerDTO(owner.getId()) - ownerDTO.setFirstName(owner.getFirstNa
me()) - ownerDTO.setLastName(owner.getLastName
()) - ownerDTO.setAccounts(owner.getAccounts
().size()) - ownersDTO.add(ownerDTO)
51 52Parent Project
- -- ejbsessionBankBLImpl
- -- ejbsessionBankEAR
- -- ejbsessionBankEJB
- -- ejbsessionBankTest
- -- pom.xml
53Parent Project
- lt?xml version"1.0" encoding"UTF-8"?gt
- ltprojectgt
- ltmodelVersiongt4.0.0lt/modelVersiongt
- ltgroupIdgtejava.javaee.ejblt/groupIdgt
- ltartifactIdgtejbsessionBanklt/artifactIdgt
- ltpackaginggtpomlt/packaginggt
- ltnamegtSession Beanlt/namegt
- ltversiongt1.0.2008.2-SNAPSHOTlt/versiongt
- ltmodulesgt
- ltmodulegtejbsessionBankImpllt/modulegt
- ltmodulegtejbsessionBankEJBlt/modulegt
- ltmodulegtejbsessionBankEARlt/modulegt
- lt/modulesgt
- ltprofilesgt
- ltprofilegt
- ltidgtfunctional-testslt/idgt
- ltactivationgt
- ltpropertygt
54EJB Project
- ejbsessionBankEJB/
- -- pom.xml
- -- src
- -- main
- -- java
- -- ejava
- -- examples
- -- ejbsessionbank
- -- ejb
- -- TellerEJB.java
- -- TellerLocal.java
- -- TellerRemote.java
- -- resources
- -- META-INF
- -- ejb-jar.xml
- -- jboss.xml
- -- persistence.xml
55EJB Project
- ltprojectgt
- ltparentgt
- ltartifactIdgtejbsessionBanklt/artifactIdgt
- ltgroupIdgtejava.javaee.ejblt/groupIdgt
- ltversiongt1.0.2008.2-SNAPSHOTlt/versiongt
- lt/parentgt
- ltmodelVersiongt4.0.0lt/modelVersiongt
- ltgroupIdgtejava.javaee.ejblt/groupIdgt
- ltartifactIdgtejbsessionBankEJBlt/artifactIdgt
- ltpackaginggtejblt/packaginggt
- ltnamegtSession Bank EJBlt/namegt
- lt!-- this repositories holds many of the
javaee5 jar files --gt - ltrepositoriesgt
- ltrepositorygt
- ltidgtjboss-repolt/idgt
- ltnamegtJBoss Maven Repositorylt/namegt
- lturlgthttp//repository.jboss.org/maven
2lt/urlgt
56EJB Project (cont.)
- ltdependenciesgt
- lt!-- core dependencies --gt
- ltdependencygt
- ltgroupIdgtjavax.annotationlt/groupIdgt
- ltartifactIdgtjsr250-apilt/artifactIdgt
- ltversiongt1.0lt/versiongt
- ltscopegtprovidedlt/scopegt
- lt/dependencygt
- ltdependencygt
- ltgroupIdgtjavax.persistencelt/groupIdgt
- ltartifactIdgtpersistence-apilt/artifactIdgt
- ltversiongt1.0lt/versiongt
- ltscopegtprovidedlt/scopegt
- lt/dependencygt
- ltdependencygt
- ltgroupIdgtjavax.ejblt/groupIdgt
- ltartifactIdgtejb-apilt/artifactIdgt
- ltversiongt3.0lt/versiongt
- ltscopegtprovidedlt/scopegt
57EJB Project (cont.)
- ...
- ltdependencygt
- ltgroupIdgtpom.groupIdlt/groupIdgt
- ltartifactIdgtejbsessionBankImpllt/artifact
Idgt - ltversiongtpom.versionlt/versiongt
- ltscopegtcompilelt/scopegt
- lt/dependencygt
- lt!-- test dependencies --gt
- ltdependencygt
- ltgroupIdgtjunitlt/groupIdgt
- ltartifactIdgtjunitlt/artifactIdgt
- ltversiongt3.8.1lt/versiongt
- ltscopegttestlt/scopegt
- lt/dependencygt
- ltdependencygt
- ltgroupIdgtlog4jlt/groupIdgt
- ltartifactIdgtlog4jlt/artifactIdgt
- ltversiongt1.2.13lt/versiongt
58EJB Project (cont.)
- ltbuildgt
- lt!--tell the resource plugin to perform
filtering on resources - to fill in dialect, etc. --gt
- ltresourcesgt
- ltresourcegt
- ltdirectorygtsrc/main/resourceslt/dir
ectorygt - ltfilteringgttruelt/filteringgt
- lt/resourcegt
- lt/resourcesgt
- ltpluginsgt
- lt!-- make sure we are building
java5 --gt - ltplugingt
- ltgroupIdgtorg.apache.maven.pluginslt
/groupIdgt - ltartifactIdgtmaven-compiler-pluginlt
/artifactIdgt - ltconfigurationgt
- ltsourcegt1.5lt/sourcegt
- lttargetgt1.5lt/targetgt
- lt/configurationgt
59EJB Project (cont.)
- ...
- lt!-- tell the EJB plugin we are using
EJB3 and configure client-jar --gt - ltplugingt
- ltgroupIdgtorg.apache.maven.pluginslt
/groupIdgt - ltartifactIdgtmaven-ejb-pluginlt/arti
factIdgt - ltversiongt2.1lt/versiongt
- ltconfigurationgt
- ltejbVersiongt3.0lt/ejbVersiongt
- ltarchivegt
- ltmanifestgt
- ltaddClasspathgttruelt/ad
dClasspathgt - lt/manifestgt
- lt/archivegt
- ltgenerateClientgttruelt/generate
Clientgt - ltclientExcludesgt
- ltclientExcludegtMETA-INF/
/lt/clientExcludegt - ltclientExcludegt/ejb/EJB
.classlt/clientExcludegt - lt/clientExcludesgt
- lt/configurationgt
60EJB Project (cont.)
- ltprofilesgt
- ltprofilegt lt!-- defines our
persistence.xml dialect --gt - ltidgthsqllt/idgt
- ltactivationgt
- ltpropertygt lt!-- use this property
to name another db --gt - ltnamegtjdbcdblt/namegt
- ltvaluegthsqllt/valuegt
- lt/propertygt
- lt/activationgt
- ltpropertiesgt
- lthibernate.dialectgt
- org.hibernate.dialect.HSQLDi
alect - lt/hibernate.dialectgt
- lt/propertiesgt
- lt/profilegt
- lt/profilesgt
- lt/projectgt
61EJB Project persistence.xml
- lt?xml version"1.0" encoding"UTF-8"?gt
- ltpersistence xmlns"http//java.sun.com/xml/ns/per
sistence" - xmlnsxsi"http//www.w3.org/2001/XMLSchema-in
stance" - xsischemaLocation"http//java.sun.com/xml/ns
/persistence http//java.sun.com/xml/ns/persistenc
e/persistence_1_0.xsd" version"1.0"gt - ltpersistence-unit name"ejbsessionbank"gt
- ltprovidergtorg.hibernate.ejb.HibernatePersi
stencelt/providergt - ltjta-data-sourcegtjava/ejavaDSlt/jta-data-s
ourcegt - ltpropertiesgt
- ltproperty name"hibernate.dialect"
- value"hibernate.dialect"/gt
- ltproperty name"hibernate.show_sql"
value"false"/gt - lt/propertiesgt
- lt/persistence-unitgt
- After filtering
- ltproperty name"hibernate.dialect"
- value"org.hibernate.dialect.HSQLD
ialect"/gt
62EAR Project
- ejbsessionBankEAR/
- -- pom.xml
- pom.xml
- ltprojectgt
- ltparentgt
- ltartifactIdgtejbsessionBanklt/artifactIdgt
- ltgroupIdgtejava.javaee.ejblt/groupIdgt
- ltversiongt1.0.2008.2-SNAPSHOTlt/versiongt
- lt/parentgt
- ltmodelVersiongt4.0.0lt/modelVersiongt
- ltgroupIdgtejava.javaee.ejblt/groupIdgt
- ltartifactIdgtejbsessionBankEARlt/artifactIdgt
- ltpackaginggtearlt/packaginggt
- ltnamegtSession Bank EARlt/namegt
- ...
63EAR Project (cont.)
- ltdependenciesgt
- ltdependencygt
- ltgroupIdgtpom.groupIdlt/groupIdgt
- ltartifactIdgtejbsessionBankEJBlt/artifac
tIdgt - ltversiongtpom.versionlt/versiongt
- lttypegtejblt/typegt
- ltexclusionsgt
- ltexclusiongt
- ltgroupIdgtcommons-logginglt/grou
pIdgt - ltartifactIdgtcommons-logginglt/a
rtifactIdgt - lt/exclusiongt
- lt/exclusionsgt
- lt/dependencygt
- lt/dependenciesgt
- ltbuildgt
- ltpluginsgt
- ltplugingt
- ltgroupIdgtorg.apache.maven.pluginslt
/groupIdgt
64EAR Project (cont.)
- Use cargo plugin to undeploy built and deployed
EARs - ltprofilegt
- ltidgtundeploylt/idgt
- ltactivationgt
- ltpropertygt
- ltnamegtundeploylt/namegt
- ltvaluegttruelt/valuegt
- lt/propertygt
- lt/activationgt
- ltbuildgt
- ltpluginsgt
- ltplugingt
- ltgroupIdgtorg.codehaus.cargolt/groupIdgt
- ltartifactIdgtcargo-maven2-pluginlt/artif
actIdgt - ltconfigurationgt
- ltcontainergt
- ltcontainerIdgtjboss4xlt/containe
rIdgt - lttypegtremotelt/typegt
- lt/containergt
65EAR Project (cont.)
- ltexecutiongt
- ltidgtundeploy-earlt/idgt
- ltphasegtpre-cleanlt/phasegt
- ltgoalsgt
- ltgoalgtundeploylt/goalgt
- lt/goalsgt
- ltconfigurationgt
- ltconfigurationgt
- lttypegtruntimelt/typegt
- ltpropertiesgt
- ltcargo.remote.username
gtjboss.userlt/cargo.remote.usernamegt - ltcargo.remote.password
gtjboss.passwordlt/cargo.remote.passwordgt - lt/propertiesgt
- lt/configurationgt
- ltdeployergt
- lttypegtremotelt/typegt
- ltdeployablesgt
- ltdeployablegt
-
ltgroupIdgtpom.groupIdlt/groupIdgt
66RMI Test Project
- ejbsessionBankTest/
- -- pom.xml
- -- src
- -- main
- -- test
- -- java
- -- ejava
- -- examples
- -- ejbsessionbank
- -- ejbclient
- --
TellerOwnerRemoteTest.java - --
TellerRemoteTest.java - -- resources
- -- jndi.properties
- -- log4j.xml
- pom.xml
- ltprojectgt
- ltparentgt
67RMI Test Project (cont.)
- ltdependenciesgt
- lt!-- core dependencies --gt
- ltdependencygt
- ltgroupIdgtcommons-logginglt/groupIdgt
- ltartifactIdgtcommons-logginglt/artifactI
dgt - ltversiongt1.0.4lt/versiongt
- ltscopegtcompilelt/scopegt
- lt/dependencygt
- lt!-- component to test within
deployment--gt - ltdependencygt
- ltgroupIdgtpom.groupIdlt/groupIdgt
- ltartifactIdgtejbsessionBankEJBlt/artifac
tIdgt - ltversiongtpom.versionlt/versiongt
- lttypegtejb-clientlt/typegt
- ltscopegtcompilelt/scopegt
- lt/dependencygt
- ltdependencygt
- ltgroupIdgtpom.groupIdlt/groupIdgt
68RMI Test Project (cont.)
- ...
- lt!-- package being deployed must be a
dependency --gt - ltdependencygt
- ltgroupIdgtpom.groupIdlt/groupIdgt
- ltartifactIdgtejbsessionBankEARlt/artifac
tIdgt - ltversiongtpom.versionlt/versiongt
- lttypegtearlt/typegt
- lt/dependencygt
- lt!-- test dependencies --gt
- ltdependencygt
- ltgroupIdgtjunitlt/groupIdgt
- ltartifactIdgtjunitlt/artifactIdgt
- ltversiongt3.8.1lt/versiongt
- ltscopegttestlt/scopegt
- lt/dependencygt
- ltdependencygt
- ltgroupIdgtlog4jlt/groupIdgt
- ltartifactIdgtlog4jlt/artifactIdgt
69RMI Test Project (cont.)
- ltpluginsgt
- ltplugingt
- ltgroupIdgtorg.apache.maven.pluginslt
/groupIdgt - ltartifactIdgtmaven-compiler-pluginlt
/artifactIdgt - ltconfigurationgt
- ltsourcegt1.5lt/sourcegt
- lttargetgt1.5lt/targetgt
- lt/configurationgt
- lt/plugingt
- ltplugingt
- ltgroupIdgtorg.apache.maven.pluginslt
/groupIdgt - ltartifactIdgtmaven-surefire-pluginlt
/artifactIdgt - ltconfigurationgt
- ltargLinegtsurefire.argLinelt/
argLinegt - ltsystemPropertiesgt
- ltpropertygt
- ltnamegtjndi.namelt/namegt
- ltvaluegt
70RMI Test Project (cont.)
- ltprofilegt
- ltidgtjbosslt/idgt
- ltactivationgt
- ltpropertygt lt!-- activate this unless
-Dserver present --gt - ltnamegt!serverlt/namegt
- lt/propertygt
- lt/activationgt
- ltpropertiesgt
- ltjava.naming.factory.initialgtorg.jnp.int
erfaces.NamingContextFactory - lt/java.naming.factory.initialgt
- ltjava.naming.provider.urlgtjnp//localhos
t1099 - lt/java.naming.provider.urlgt
- ltjava.naming.factory.url.pkgsgtorg.jboss.
namingorg.jnp.interfaces - lt/java.naming.factory.url.pkgsgt
- lt/propertiesgt
71RMI Test Project (cont.)
- ltdependenciesgt
- ltdependencygt
- ltgroupIdgtorg.jbosslt/groupIdgt
- ltartifactIdgtjbossall-clientlt/artifactI
dgt - ltversiongt4.2.3-GAlt/versiongt
- ltscopegtsystemlt/scopegt
- ltsystemPathgtjboss.home/client/jboss
all-client.jarlt/systemPathgt - lt/dependencygt
- ltdependencygt
- ltgroupIdgtorg.jbosslt/groupIdgt
- ltartifactIdgtjboss-ejb3-clientlt/artifac
tIdgt - ltversiongt4.2.3-GAlt/versiongt
- ltscopegtsystemlt/scopegt
- ltsystemPathgtjboss.home/client/jboss
-ejb3-client.jarlt/systemPathgt - lt/dependencygt
- ltdependencygt
- ltgroupIdgtorg.jbosslt/groupIdgt
- ltartifactIdgtjboss-aop-jdk50-clientlt/ar
tifactIdgt - ltversiongt4.2.3-GAlt/versiongt
72RMI Test Project (cont.)
- Use cargo plugin to deploy dependency EAR file
prior to running tests - ltbuildgt
- ltpluginsgt
- ltplugingt
- ltgroupIdgtorg.codehaus.cargolt/groupIdgt
- ltartifactIdgtcargo-maven2-pluginlt/artif
actIdgt - ltconfigurationgt
- ltcontainergt
- ltcontainerIdgtjboss4xlt/containe
rIdgt - lttypegtremotelt/typegt
- lt/containergt
- lt/configurationgt
- ltexecutionsgt
- ...
- lt/executionsgt
- lt/plugingt
- lt/pluginsgt
- lt/buildgt
73RMI Test Project (cont.)
- ltexecutiongt
- ltidgtdeploy-componentlt/idgt
- lt!-- jump into a phase before
surefire runs tests --gt - ltphasegttest-compilelt/phasegt
- ltgoalsgt
- ltgoalgtundeploylt/goalgt
- ltgoalgtdeploylt/goalgt
- lt/goalsgt
- ltconfigurationgt
- ltconfigurationgt
- lttypegtruntimelt/typegt
- ltpropertiesgt
- ltcargo.remote.username
gtjboss.userlt/cargo.remote.usernamegt - ltcargo.remote.password
gtjboss.passwordlt/cargo.remote.passwordgt - lt/propertiesgt
- lt/configurationgt
- ltdeployergt
- lttypegtremotelt/typegt
- ltdeployablesgt
74Summary
- Integrates Bean activity (task script)
- Server-side code for client
- Stateless and Stateful
- Server-side cache for client
- Stateful
- POJO with minor amount of class metadata
75References
- Enterprise JavaBeans 3.0, 5th Edition Burke
Monsen-Haefel ISBN 0-596-00978-X O'Reilly - Mobile Design Patterns and Architectures,
http//www.titu.jyu.fi/modpa/ (MODPA) - Remote Facade
- http//www.titu.jyu.fi/modpa/Patterns/pattern-Remo
teFacade.html - Patterns of Enterprise Archecture, Chapter 15
Remote Facade Martin Fowler - http//www.theserverside.com/tt/articles/content/F
owlerPatterns/Fowler_ch15.pdf