Monday Sep 16, 2013

Therap Services at OpenWorld: Highlights Support for Individuals with Developmental Disabilities

Therap Services, LLC. is a web-based service organization that provides an integrated solution for documentation, reporting and communication needs of agencies providing support to people with developmental disabilities. It offers an easy and efficient alternative to the immense amount of paper work that is done manually by the care providers. Therap’s software suite is relevant to all the different kinds of service organizations that support and care for people with intellectual and developmental disabilities. Therap is used in over 1,000 agencies, in small agencies serving as few as one individual to multi-state providers serving thousands of individuals. The modules can be categorized under Individual Support, Staff Support and Billing and Attendance Support. Therap uses Oracle Database and had been using JBoss as the application server for their mission critical application.  As Therap has grown, they have experienced several performance issues with JBoss – specifically problems with JBoss Messaging.  As Therap continues to expand their business, they felt the need for a more robust solution for their core business application.  Additionally, Therap needed a more advanced monitoring solution for both internal and external transactions on multiple layers:  application, database, application server. They chose Oracle WebLogic Server for three main reasons:  1) Extremely high confidence level in the Oracle Product Management team expertise, 2) Access to a better support system with product integration and best practices, and 3) Oracle’s proven reliability history.  Come join Therap Services CTO Masum at OpenWorld to hear about how Therap leverages Oracle WebLogic Server with Oracle Enterprise Manager to really take their applications to the next level. In addition, while at OpenWorld don’t miss other Cloud Application Foundation Innovators. You can join the session whether you are an OpenWorld attendee or not.

Thursday Mar 25, 2010

Recent improvements in Console Performance

[Read More]

Thursday Jan 14, 2010

EJB3: Mapping of One-to-One relationships when primary key in the source table is also a foreign key for the target entity

This blog entry will explain how to define the EJB3 object relational mappings for entities that have a 1-1 association when the primary key of the relationship's owner side is also the foreign key for the owned entity.

Consider the following diagram.

supplier-schema.JPG

The Supplier entity has a 1-1 relationship with the SupplierStatistics entity. A Supplier is identified by the ID key uniquely which is also the primary key of the SUPPLIER table. Each Supplier has an associated set of Statistics like the number of orders placed, accepted and delivered on time by a given Supplier. These statistics are persisted in the SUPPLIER_STATISTICS table. The records in the SUPPLIER and SUPPLIER_STATISTICS table are joined by the ID of the supplier. The ID column in the SUPPLIER table is also a foreign key which references the SUPPLIER_ID column in the SUPPLIER_STATISTICS table.

 

The EJB3 entity classes for the above relationship are given below.

 

package com.tutorial.entity;

 

import java.io.Serializable;

import javax.persistence.*;

 

/**

 * The persistent class for the SUPPLIER database table.

 *

 */

@Entity

public class Supplier implements Serializable {

  private static final long serialVersionUID = 1L;

 

  @Id

  @GeneratedValue(strategy=GenerationType.AUTO)

  private long id;

 

  private String name;

 

  //uni-directional one-to-one association to SupplierStatistic

  @OneToOne(cascade={CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.REFRESH})

  @JoinColumn(name="ID", insertable=false, updatable=false)

  private SupplierStatistic supplierStatistic;

 

  public Supplier() {

      supplierStatistic = new SupplierStatistic();

  }

 

  public long getId() {

    return this.id;

  }

 

  public void setId(long id) {

    this.id = id;

  }

 

  public String getName() {

    return this.name;

  }

 

  public void setName(String name) {

    this.name = name;

  }

 

  public SupplierStatistic getSupplierStatistic() {

    return this.supplierStatistic;

  }

 

  @PrePersist

  public void initializeSupplierStatistic() {

    this.supplierStatistic.setSupplierId(id);

  }

     

}

 

package com.tutorial.entity;

 

import java.io.Serializable;

import javax.persistence.*;

import java.math.BigDecimal;

 

/**

 * The persistent class for the SUPPLIER_STATISTICS database table.

 */

@Entity

@Table(name="SUPPLIER_STATISTICS")

public class SupplierStatistic implements Serializable {

  private static final long serialVersionUID = 1L;

 

  @Id

  @GeneratedValue(strategy=GenerationType.AUTO)

  @Column(name="SUPPLIER_ID")

  private long supplierId;

 

  @Column(name="ORDERS_ACCEPTED")

  private BigDecimal ordersAccepted;

 

  @Column(name="ORDERS_DELIVERED_ON_TIME")

  private BigDecimal ordersDeliveredOnTime;

 

  @Column(name="ORDERS_PLACED")

  private BigDecimal ordersPlaced;

 

  SupplierStatistic() {}

 

  public long getSupplierId() {

    return this.supplierId;

  }

 

  public void setSupplierId(long supplierId) {

    this.supplierId = supplierId;

  }

 

  public BigDecimal getOrdersAccepted() {

    return this.ordersAccepted;

  }

 

  public void setOrdersAccepted(BigDecimal ordersAccepted) {

    this.ordersAccepted = ordersAccepted;

  }

 

  public BigDecimal getOrdersDeliveredOnTime() {

    return this.ordersDeliveredOnTime;

  }

 

  public void setOrdersDeliveredOnTime(BigDecimal ordersDeliveredOnTime) {

    this.ordersDeliveredOnTime = ordersDeliveredOnTime;

  }

 

  public BigDecimal getOrdersPlaced() {

    return this.ordersPlaced;

  }

 

  public void setOrdersPlaced(BigDecimal ordersPlaced) {

    this.ordersPlaced = ordersPlaced;

  }

 

}

 

Notice the salient features of the entity mappings.

 

  • The relationship is defined as a One-way 1-1 mapping from the Supplier, which is the owner of the relationship to the SupplierStatistic entity.

 

      //uni-directional one-to-one association to SupplierStatistic

@OneToOne(cascade={CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.REFRESH})

@JoinColumn(name="ID", insertable=false, updatable=false)

private SupplierStatistic supplierStatistic;


The @JoinColumn annotation has the attributes insertable=false and updatable=false. This is because the ID column which is a primary key also happens to be the foreign key for the SupplierStatistic entity. Since we don't need to persist an additional column to persist the relationship which is implicitly defined by the primary key, we mark the JoinColumn as insertable and updateable = false. Otherwise you will run into errors depending upon your JPA provider.

 

With EclipseLink JPA provider available with Oracle Enterprise Pack for Eclipse (OEPE) I was getting the following error without these attributes.

 

javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.1.2.v20090612-r4475): org.eclipse.persistence.exceptions.DatabaseException

Internal Exception: java.sql.SQLSyntaxErrorException: ORA-00957: duplicate column name

 

Error Code: 957

Call: INSERT INTO SUPPLIER (ID, NAME, ID) VALUES (?, ?, ?)

      bind => [4502, SupplierName1, 4502]

 

  • The supplierStatistic entity is implicitly created when the Supplier is created. Refer to the constructor. The OneToOne relationship is marked as CascadeType.PERSIST so the SupplierStatistic entity will be persisted along with the Supplier entity.


    public Supplier() {

    supplierStatistic = new SupplierStatistic();

  }


  • What about the SUPPLIER_ID column value for the SupplierStatistic entity? It needs to be the same value as the parent Supplier's ID value. This is achieved by injecting the ID of the parent into the child before persisting them. The initialiazeSupplierStatistic method is annotated with the @PrePresist annonation.

 

     @PrePersist

     public void initializeSupplierStatistic() {

       this.supplierStatistic.setSupplierId(id);

     }

 

This ensures that the id field value that has been either auto-generated or retrieved from the sequence table (depending upon the generation strategy for the primary key) by the JPA provider is passed onto the child entity thereby defining the 1-1 association.


  • As a best practice the constructor for the SupplierStatistic class is not public, so there is no explicit way to create and persist a SupplierStatistic entity. It gets created and persisted only in the context of the parent. Correspondingly a SupplierStatistic entity is removed along with the parent Supplier, since we also have CascadeType.REMOVE on the relationship.

 

This pattern can be applied to other situations where the same primary key value is shared between the two entities, for example Customer and Contact which can share the CUSTOMER_ID has the common key.

 

Appendix

 

DDL for the SUPPLIER and SUPPLIER_STATISTICS tables for the Oracle Database 10g Express Edition

 

CREATE TABLE "SUPPLIER" 
( "ID" NUMBER NOT NULL ENABLE, 
  "NAME" VARCHAR2(4000), 
  CONSTRAINT "SUPPLIER_PK" PRIMARY KEY ("ID") ENABLE, 
  CONSTRAINT "SUPPLIER_FK" FOREIGN KEY ("ID")
  REFERENCES "SUPPLIER_STATISTICS" ("SUPPLIER_ID") ENABLE
)
 
CREATE TABLE "SUPPLIER_STATISTICS" 
( "SUPPLIER_ID" NUMBER NOT NULL ENABLE, 
  "ORDERS_PLACED" NUMBER, 
  "ORDERS_ACCEPTED" NUMBER, 
  "ORDERS_DELIVERED_ON_TIME" NUMBER, 
  CONSTRAINT "SUPPLIER_STATISTICS_PK" PRIMARY KEY ("SUPPLIER_ID") ENABLE
)
[Read More]

Tuesday Dec 01, 2009

Threads Constraints in Work Managers

[Read More]

Monday Nov 09, 2009

Stateful JAX-WS with Coherence*Web


We describe a stateful JAX-WS web service with high availability provided by Coherence*Web [1]. Deployed to two separate WebLogic managed servers, the web service stores its state in http session cookies. Coherence*Web distributes and synchronizes http session data between both managed servers. As a result, two endpoints with synchronized web service state provide high availability. With one endpoint down, another could continue to serve the service request with current web service state.

Note that WebLogic clustering can also provide highly available http sessions. However, we want to demonstrate Coherence*Web as an alternative to clustering for high availability. Therefore, we do not use clustering here. Instead, we use Coherence*Web.

Setting up the stateful web service with Coherence*Web involves the following steps.

  • start Coherence*Web cache server 
  • create and configure managed servers
    • deploy Coherence*Web as a shared library to the managed servers
  • create and deploy the web service
    • stores state in http session
    • instrument the web service using Coherence*Web
    • deploy the web service to both managed servers
Start Coherence*Web Cache Server

Start Coherence*Web cache server using the command below [2].

java -server -Xms512m -Xmx512m 
-cp coherence/lib/coherence.jar:coherence/lib/coherence-web-spi.war
-Dtangosol.coherence.management.remote=true
-Dtangosol.coherence.cacheconfig=WEB-INF/classes/session-cache-config.xml
-Dtangosol.coherence.session.localstorage=true
com.tangosol.net.DefaultCacheServer

Create and Configure Managed Servers

Copy coherence/lib/coherence.jar [2] to $DOMAIN_HOME/lib.

Start WebLogic AdminServer using

$DOMAIN_HOME/bin/startWebLogic.sh

Create two managed servers Server-2 at port 7012 and Server-3 at port 7013 using the admin console. Start both servers using the commands below.

$DOMAIN_HOME/bin/startManagedWebLogic.sh Server-2
$DOMAIN_HOME/bin/startManagedWebLogic.sh Server-3

Deploy coherence\lib\coherence-web-api.war [2] to the servers as a shared library. 

Create and Deploy the Web Service

Install Oracle Enterprise Pack for Eclipse (OEPE) on Eclipse Galileo [4]. In Eclipse, create a web service using the following WSDL and implementation.

<definitions
 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
 xmlns:tns="http://oracle.ws.demo/"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns="http://schemas.xmlsoap.org/wsdl/"
 targetNamespace="http://oracle.ws.demo/"
 name="StatefulWSService">
<types>
<xsd:schema>
<xsd:import namespace="http://oracle.ws.demo/"
 schemaLocation="http://localhost:7001/Stateful_WS_Coherence/StatefulWSService?xsd=1" />
</xsd:schema>
</types>
<message name="addItem">
<part name="parameters" element="tns:addItem" />
</message>
<message name="addItemResponse">
<part name="parameters" element="tns:addItemResponse" />
</message>
<portType name="StatefulWS">
<operation name="addItem">
<input message="tns:addItem" />
<output message="tns:addItemResponse" />
</operation>
</portType>
<binding name="StatefulWSPortBinding" type="tns:StatefulWS">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document" />
<operation name="addItem">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
<service name="StatefulWSService">
<port name="StatefulWSPort" binding="tns:StatefulWSPortBinding">
<soap:address
 location="http://localhost:7001/Stateful_WS_Coherence/StatefulWSService" />
</port>
</service>
</definitions>

StatefulWS.java and Item.java

package demo.ws.oracle;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.*;
import javax.xml.ws.handler.MessageContext;
import javax.jws.*;
import javax.annotation.Resource;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*
@WebService
public class StatefulWS {
@Resource
WebServiceContext ctx;
@WebMethod()
public int addItem(String name) {
HttpServletRequest req = (HttpServletRequest)
ctx.getMessageContext().get(MessageContext.SERVLET_REQUEST);
HttpSession session = req.getSession(true);
if (session == null)
throw new WebServiceException("No HTTP Session found");
System.out.println("httpsession: id="+session.getId());

//Get the cart object from the HttpSession
List<Item> cart = (List<Item>)session.getAttribute("myCart");
if (cart == null)
{ cart = new ArrayList(); }
// Add the item to the cart
cart.add(new Item(name));
// Save the updated cart in the HTTPSession
session.setAttribute("myCart", cart);
// return the number of items in the stateful cart
return cart.size();
}
}
package demo.ws.oracle;
public class Item implements java.io.Serializable {
public String name;public Item(String name){
this.name = name;
}
}

Add coherence-web-api library into weblogic.xml [2].

<weblogic-web-app
 xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app
 http://xmlns.oracle.com/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd"
>
<weblogic-version>10.3.1</weblogic-version>
<context-root>Stateful_WS_Coherence</context-root>
<library-ref>
<library-name>coherence-web-spi</library-name>
<specification-version>1.0.0.0</specification-version>
<implementation-version>1.0.0.0</implementation-version>
<exact-match>false</exact-match>
</library-ref>
</weblogic-web-app>

Deploy the web service to both managed servers.

Test 

Run the test.

package demo.ws;
import demo.ws.oracle.*;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;

public class StatefulWSClient {
public static void main(String[] args) throws Exception {
StatefulWSService service =
new
StatefulWSService(Thread.currentThread().getContextClassLoader()
.getResource("META-INF/wsdls/StatefulWSService.wsdl")
 , new QName("http://oracle.ws.demo/", "StatefulWSService"));
StatefulWS port = service.getStatefulWSPort();

((BindingProvider)port).getRequestContext()
.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);

((BindingProvider)port).getRequestContext()
.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://stacd15.us.oracle.com:7012/Stateful_WS_Coherence/StatefulWSService");

System.out.println("calling " +
((BindingProvider)port).getRequestContext()
.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY));
for (int j=0; j<5; j++) {
try {
int response = port.addItem("abc");
System.out.println("Got " + response);
Thread.currentThread().sleep(3000);
} catch (Exception ex) {}
}

((BindingProvider)port).getRequestContext()
.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://stacd15.us.oracle.com:7013/Stateful_WS_Coherence/StatefulWSService");
System.out.println("calling " +
((BindingProvider)port).getRequestContext()
.get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY));
for (int j=0; j<5; j++) {
try {
int response = port.addItem("abc");
System.out.println("Got " + response);
Thread.currentThread().sleep(3000);
} catch (Exception ex) {}
}
}
}

The test invokes the web service five times for each endpoint.  The output shows that the returned count increases, indicating synchronized web service state across both endpoints.

calling http://stacd15.us.oracle.com:7012/Stateful_WS_Coherence/StatefulWSService
Got 1
Got 2
Got 3
Got 4
Got 5
calling http://stacd15.us.oracle.com:7013/Stateful_WS_Coherence/StatefulWSService
Got 6
Got 7
Got 8
Got 9
Got 10

Both managed servers output the same http session id's.

httpsession: id=tS1DNs2XTJZuQNhNfsl4fvpuj0Qd2ZnmTmHFKtKlUX4EytukR9V0!-280396885!1257829391923
httpsession: id=tS1DNs2XTJZuQNhNfsl4fvpuj0Qd2ZnmTmHFKtKlUX4EytukR9V0!-280396885!1257829391923
httpsession: id=tS1DNs2XTJZuQNhNfs14fvpuj0Qd2ZnmTmHFKtKlUX4EytukR9V0!-280396885!1257829391923
httpsession: id=tS1DNs2XTJZuQNhNfsl4fvpuj0Qd2ZnmTmHFKtKlUX4EytukR9V0!-280396885!1257829391923

Reference
  1. Coherence*Web and WebLogic Server
  2. Installing Coherence*Web on the WebLogic Server 10.3
  3. Stateful JAX-WS
  4. Oracle Enterprise Pack for Eclipse
 [Read More]

Monday Oct 12, 2009

Are My Servers Running?

[Read More]

Monday Sep 14, 2009

Migrating OC4J 10.1.3 Stateful Web Services to WebLogic

[Read More]

Thursday Sep 10, 2009

Application Client Upgrades from OC4J to WLS

[Read More]

Thursday Aug 20, 2009

Starting WLS through nodemanager details

[Read More]
About

The official blog for Oracle WebLogic Server fans and followers!

Stay Connected

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
5
6
7
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today