Plus with OEPE you can develop Coherence applications in Eclipse and it has Coherence editors for all the Coherence configuration files.
In this blogpost we will test these tools and features in a demo application which uses the HR Oracle demo schema, JPA and expose these entities as Coherence REST Services.
We start by downloading OEPE Eclipse runtime bundle with WebLogic 12.1.2, Coherence and ADF http://www.oracle.com/technetwork/developer-tools/eclipse/downloads/index.html
Start OEPE and define a new workspace.
Create an Oracle Coherence Application
Provide a project name and make sure you define a target runtime. Plus enable Add project to EAR.
Use the default Coherence options.
The Coherence application will also add a dynamic Web project.
JPA Project
For this demo I will use JPA so we can use these entities in Coherence.
Also target this to WebLogic 12.1.2 and add this project to the already existing EAR project.
Define an connection to the database this will also add a persistence unit to the JPA project.
Next choose JPA entities from tables, where I select the Departments and Employees tables for this demo
Change the JPA mapping relations between the Department and Employee entities and add for REST the XML annotations.
Like @XmlRootElement(name="Department") and @XmlTransient on the getters to break the loop of loading the Department and Employee objects.
Coherence Project
We can use the OEPE Coherence Editors or go directly to the source tab.
First we change coherence-cache-config.xml file where we will define the Department and Employee cache and connect this to EclipseLink.
HrJPA is the name of the Persistence Unit ( Resource Local )
Create a new file called coherence-rest-config.xml, this contains our REST entity definitions where we add some coherence named queries and enable the direct query option.
<key-class>java.lang.Integer</key-class> must match with the primary Java Data type of the entity
The last file we need to change is the pof-config.xml and add <include>coherence-rest-pof-config.xml</include> to the user-type-list
Also upload the coherence-rest.jar to the lib folder of the CoherenceJPA project.
Web project
Last step is to enable the Web project for Coherence REST. We need to enable the Oracle Coherence Facet on this Web Project.
Remove all the Coherence files located in the src folder, we don't need this.
Add the following Coherence REST Servlet.
Also we need to add the following Jersey and Jackson jars files to the WEB-INF lib folder. ( Located in the module folder of the oracle_common )
Also create your own servlet, so we can fill the Department and Employee Coherence cache ( else the cache will be empty )
In the Eclipse Servers tab we need to add an WebLogic Domain with a Managed Coherence Server ( maybe use right click to select an WebLogic target other than the default AdminServer.
For we Coherence REST we need to change the default EclipseLink JAXB provider.
-Dcom.sun.xml.ws.spi.db.BindingContextFactory=com.sun.xml.ws.db.glassfish.JAXBRIContextFactory
-Djavax.xml.bind.JAXBContext=com.sun.xml.bind.v2.ContextFactory
Publish the EAR from OEPE which also contains the Grid Archive (GAR) to the Coherence Managed Server
Finally we can test the Rest service
Start by invoking the servlet http://wls12:7201/CoherenceJPAWeb/CoherenceServlet
Next we can use a Rest Client to test all the Rest operations.
Get all the department entries
http://wls12:7201/CoherenceJPAWeb/rest/Department
Get Deparment 100
http://wls12:7201/CoherenceJPAWeb/rest/Department/100
Add a new Department
Delete a department
Direct query ( enabled in the coherence rest config xml )
http://wls12:7201/CoherenceJPAWeb/rest/Department?q=departmentName='Finance'
Location1700 Named query also defined in the coherence rest config xml
Location Named query with a integer parameter
Here you can download or look at the github demo project.
Hi, i have to implement something similar to what you shared in this post just i have a problem...i cannot know the resource's value-class of all the cached objects. Is it possible to use Coherence REST application to query the cache if i don't know the cached resources details?
ReplyDelete