background image

Coding the PubQuery Session Bean

<< Using JAXR Clients in Java EE Applications | Starting the Application Server >>
<< Using JAXR Clients in Java EE Applications | Starting the Application Server >>
C
ODING THE
A
PPLICATION
C
LIENT
: M
Y
A
PP
C
LIENT
.
JAVA
207
Coding the Application Client:
MyAppClient.java
The application client class,
src/MyAppClient.java
, accesses the
PubQuery
enterprise bean's remote interface. The program calls the bean's two business
methods,
executePublish
and
executeQuery
.
Coding the PubQuery Session Bean
The
PubQuery
bean is a stateless session bean that has two business methods.
The bean uses remote interfaces rather than local interfaces because it is
accessed from the application client.
The remote interface,
src/PubQueryRemote.java
, declares two business meth-
ods:
executePublish
and
executeQuery
. The bean class,
src/PubQuery-
Bean.java
, implements the
executePublish
and
executeQuery
methods and
their helper methods
getName
,
getDescription
, and
getKey
. These methods are
very similar to the methods of the same name in the simple examples
JAXR-
Query.java
and
JAXRPublish.java
. The
executePublish
method uses infor-
mation in the file
PubQueryBeanExample.properties
to create an organization
named The Coffee Enterprise Bean Break. The
executeQuery
method uses the
organization name, specified in the application client code, to locate this organi-
zation.
The bean class injects a
ConnectionFactory
resource. It implements a
@Post-
Construct
method named
makeConnection
, which uses the
ConnectionFac-
tory
to create the
Connection
. Finally, a
@PreDestroy
method named
endConnection
closes the
Connection
.
Editing the Properties File
Before you compile the application, edit the
PubQueryBeanExamples.proper-
ties
file in the same way you edited the
JAXRExamples.properties
file to run
the simple examples. Feel free to change any of the organization data in the file.