Using DataDirect XQuery™ and XQJ with EJB

The XQJ interface is designed to provide Java developers with an easy way to access XQuery functionality from virtually any environment, and to resemble the structure of the well known JDBC interface. DataDirect XQuery™ integrates smoothly in virtually any J2EE environment.

This Java example in particular (click here to open the Java code) shows how you can leverage DataDirect XQuery™ and XQJ to create a Message Driven Bean. The example references a 181 ACORD XML update request used in Updating a Relational Database, but it can be easily be modified/parameterized to execute other examples described in XQuery Operation Examples for an ACORD Insurance Application.

DataDirect XQuery™ is able to plug into the JDBC pooling mechanism supported by most application servers. The core of the required Java code, shown here, is quite simple:

  public void onMessage(Message message) {
    Connection jdbc_c = null;
    try {
      Context initContext = new InitialContext();
      Context envContext = (Context)initContext.lookup("java:/comp/env");
      DataSource jdbc_ds = (DataSource)envContext.lookup("jdbc/DDXQExample");
      jdbc_c = jdbc_ds.getConnection();
      
      XQConnection xqj_c = XQueryConnection.getXQConnection(jdbc_c);
      XQPreparedExpression xqj_p = xqj_c.prepareExpression(Acord181EJB.queryBaseDir + Acord181EJB.inputQuery);
      
      if (message instanceof TextMessage) {
        // Get the XML request from the message
        String text = ((TextMessage)message).getText();
        
        // Bind the request
        xqj_p.bindDocument(new QName("request"), new InputSource(new StringReader(text)));

        // Execute; no need to handle the response, as the XQuery is
        // performing update operations

        xqj_p.executeQuery();
      }
    }

    …

What's Next?

Go to Comparing Solutions Using DataDirect XQuery™ versus SQL and XML DOM to learn about the efficiencies possible with DataDirect XQuery™.

DataDirect XQuery FAQ

This informative DataDirect XQuery® FAQ answers frequently-asked questions about DataDirect XQuery® , including questions about performance, scalability, use-cases, resources, and more.

If you're more of a hands-on learner, then download a free copy and start exploring DataDirect XQuery® today!

New Case Study

Gevity produces sales proposals in real time using DataDirect XQuery® . See how Gevity uses DataDirect XQuery® to combine Web service data from SalesForce.com with relational data in Oracle in a pricing engine for HR management.