facade pattern usage with jdbc-resource on glassfish
For this project:
NetBeansProjects/EntAppWeb/
├── build.xml
├── EntAppWeb-ejb
│ ├── build.xml
│ ├── nbproject
│ │ ├── ant-deploy.xml
│ │ ├── build-impl.xml
│ │ ├── genfiles.properties
│ │ ├── private
│ │ │ ├── private.properties
│ │ │ └── private.xml
│ │ ├── project.properties
│ │ └── project.xml
│ └── src
│ └── conf
│ └── MANIFEST.MF
├── EntAppWeb-war
│ ├── build.xml
│ ├── nbproject
│ │ ├── ant-deploy.xml
│ │ ├── build-impl.xml
│ │ ├── genfiles.properties
│ │ ├── private
│ │ │ ├── private.properties
│ │ │ └── private.xml
│ │ ├── project.properties
│ │ └── project.xml
│ ├── setup
│ │ └── glassfish-resources.xml
│ ├── src
│ │ ├── conf
│ │ │ ├── MANIFEST.MF
│ │ │ └── persistence.xml
│ │ └── java
│ │ └── dur
│ │ ├── beans
│ │ │ ├── NextClient.java
│ │ │ └── NextClientLocal.java
│ │ └── jpa
│ │ ├── AbstractFacade.java
│ │ ├── ClientFacade.java
│ │ ├── ClientFacadeLocal.java
│ │ ├── Client.java
│ │ └── exceptions
│ │ ├── IllegalOrphanException.java
│ │ ├── NonexistentEntityException.java
│ │ ├── PreexistingEntityException.java
│ │ └── RollbackFailureException.java
│ └── web
│ ├── eagle.xhtml
│ ├── falcon.xhtml
│ ├── index.xhtml
│ ├── menu.xhtml
│ ├── next.xhtml
│ ├── parrot.xhtml
│ ├── template.xhtml
│ └── WEB-INF
│ └── web.xml
├── LICENSE
├── nbproject
│ ├── ant-deploy.xml
│ ├── build-impl.xml
│ ├── genfiles.properties
│ ├── private
│ │ ├── private.properties
│ │ └── private.xml
│ ├── project.properties
│ └── project.xml
├── README.md
└── src
└── conf
└── MANIFEST.MF
with this backing bean:
package dur.beans;
import dur.jpa.Client;
import dur.jpa.ClientFacadeLocal;
import javax.ejb.EJB;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
@Named("nextClient")
@ApplicationScoped
public class NextClient implements NextClientLocal {
@EJB
private ClientFacadeLocal clientFacade;
private int next = 1009;
@Override
public String getNext() {
next++;
Client client = clientFacade.find(next);
return client.toString();
}
}
and this facelets template client:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
>
<h:head></h:head>
<h:body>
This and everything before will be ignored
<ui:composition template="template.xhtml">
<ui:define name="navigation">
<ui:include src="menu.xhtml"/>
</ui:define>
<ui:define name="main">
<h1>bird</h1>
<p>
next #{nextClient.next}
</p>
</ui:define>
</ui:composition>
This and everything after will be ignored
</h:body>
</html>
I want to move the dur.jpa
package to its own project and use it as a library. Currently the database connection is done from within the Enterprise Application with:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="EntAppWeb-warPU" transaction-type="JTA">
<jta-data-source>jdbc/legacy_resource</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="create"/>
</properties>
</persistence-unit>
</persistence>
I still want to use the jdbc-resource
on glassfish.
1.) Is it correct, within best practices, to use the jdbc-resource
on glassfish?
2.) How would the Java SE library utilize the jdbc-resource
on glassfish? How is the connection established?
see also:
http://stackoverflow.com/questions/5636764/why-use-facade-pattern-for-ejb-session-bean
- 369
- 3
- 16