Skip to content

Miles to go ... - Arun Gupta
Syndicate content
Arun Gupta's Weblog
Updated: 1 hour 20 min ago

Java EE 6 pulled crowd at Austin JUG

Thu, 02/02/2012 - 19:16



I delivered a NetBeans-driven Java EE 6 session to about 80+ attendees at the Austin JUG yesterday. The session built a typical three-tier Web application using the new/updated technologies in the Java EE 6 platform. I was told this is one of the largest attendance seen at the JUG in recent months. Java EE 6 is indeed a crowd puller ;-)

Rob Ratcliff, the JUG leader, started with a great overview of "Whats new in Java" covering recent JDK update releases, Java FX 2.1 Developer Preview for Mac and Linux, Java EE 6 and WebLogic 12c, NetBeans 7.1 and other stuff. His complete slides are available here. I was fortunate to speak at the JUG because an informal survey of the attendees showed that nobody attends (or plan to attend) a conference in the coming months.

During my session, the highly interactive attendees learned about NetBeans wizard-driven Java EE 6 application development. Here are some of the features that were demonstrated in the talk:
  • Improvements in Java Persistence API
  • "web.xml"-free and annotation-driven Servlets
  • Simplified packaging of EJBs in a WAR file, no-interface and single file definition of EJB
  • Session preservation across redeploys
  • Facelets (XHTML/CSS) as templating language for JavaServer Faes to achieve true MVC
  • Integration of Bean Validation with JPA and JSF
  • Typesafe dependency injection and Producer/Observer of events using CDI
  • RESTful resources using JAX-RS

The application was built using NetBeans and deployed on GlassFish. This same application can be easily deployed on WebLogic 12c as well since it is full Java EE 6-compliant as well now. The complete instructions for NetBeans/GlassFish are available here and same instructions for NetBeans/WebLogic will be made available shortly as well.

The session ran almost 45 minutes beyond the scheduled time with most of the attendees staying late and asking questions. The feedback from the attendees was very positive. One of them was even starting a new project using NetBeans + Java EE 6 + GlassFish next week so this talk was directly relevant. Also found another attendee using GlassFish for development and WebLogic for deployment for their Java EE 6 application. Rob used GlassFish for an internal US Military project and has been deployed for more than 2 years with nearly zero maintenance.

Check out some pictures from the JUG visit ...






A tweet like the one below definitely make the quick trip worth it ...



The formal JUG session was followed by a beer-a-thon (lemonade-a-thon for me ;-) at BJs.

Some interesting facts about Austin ...
  • Michael Dell (chairman and CEO of Dell) lives in Austin, Dell worldwide headquarters are in Austin.
  • Lance Armstrong is from Austin.
  • Sandra Bullock, Matthew McConaughey, and Brad Pitt has homes in Austin.
  • Whole Foods chain started and headquartered in Austin. I was lucky enough to squeeze time out for a lunch with a colleague at one of their stores in this less-than-24-hour visit to Austin.
  • Keep Austin Weird
Download the NetBeans/GlassFish instructions and let us know how you are using Java EE 6.

Next stop is Reykjavik (Iceland), Stockholm (Sweden) and Umeå (Sweden), more on that later ...


Categories: Companies

Java EE 6 samples in the SDK

Tue, 01/31/2012 - 15:00

GlassFish can be downloaded in different forms and shape. Here are some of the main websites that provide a pre-packaged bundle:
And then all the deveoper JARs are checked in to Maven and of course you can check out and build the workspace. GlassFish Server Open Source Edition is used for bundling with NetBeans, Eclipse, and JDK. The diagram below shows the main difference between the open source and the commercial edition. The GlassFish For Business blog explains the benefits for commercial edition over open source and this particular blog highlights the difference between the two.

The diagram below highlights the difference between Oracle GlassFish Server and Java EE 6 SDK from the packaging perspective.



The Java EE 6 SDK provides API docs, tutorial and even has a JDK co-bundle. One of the hidden nuggets of the SDK is a comprehensive list of the Java EE 6 samples. The complete list is inlined here:


Sample Application Description Enterprise Java Beans EJB 3.1 WAR-based Application An EJB application that shows the use of WAR-based packaging , the no-interface Local view, Singleton session beans, and startup/shutdown callbacks. EJB 3.1 Embeddable API A very simple EJB Stateless Session Bean with a no-interface view and a POJO Entity that demonstrates EJB 3.1 Embeddable API usage. EJB 3.1 Automatic Timer An EJB Stateless Session Bean with a Remote business interface and a POJO Entity that demonstrates EJB 3.1 automatic timer feature. Servlet 3.0 Servlet 3.0 Annotations Application A Servlet 3.0 application using annotations for servlet, filter, and content listener. Servlet 3.0 Asynchronous Application A Servlet 3.0 application using asychronous API. Servlet 3.0 Dynamic Registration of Servlets and Filters Application A Servlet 3.0 application that features the dynamic registration of Servlets and Filters from a ServletContextListener. Servlet 3.0 Multipart Application A Servlet 3.0 application that demonstrates multipart (a.k.a. file upload) support. Servlet 3.0 Absolute Ordering Web Fragments Sample A Servlet 3.0 application that demonstrates web fragments with absolute ordering. Access JAR-Bundled JSP Resource Sample An application that demonstrates how dynamic and static resources bundled inside the META-INF/resources directory of a JAR file inside the application's WEB-INF/lib directory may be accessed in the same way as if they had been placed in the application's document root. Servlet 3.0 ServletContainerInitializer Sample An application that demonstrates how the ServletContainerInitializer feature can be used by libraries to register interest in certain types of applications and take whatever action as the library sees fit. Programmatic Configuration of HTTP Session Cookies Sample An application that demonstrates the new programmatic configuration support for session cookies available with Servlet 3.0. Web Services Hello JAXWS Application An that application demonstrates how JAXWS 2.2 can generate artifacts dynamically and no use of wsgen is required when bundling and packing the artifacts. EJB 3.1 Singleton Web Services Application An application that demonstrates a singleton EJB web service. It shows how easy it is to annotate a web service with @Singleton and develop clients for it. Hello-WebServiceRef Application A JAX-WS Web Services sample that demonstrates the injecton of Web Service Client by the container through the use of @WebServiceRef and configuring WebService features like MTOM, addressing on such injected resource. Java API for RESTful Web Services Message Board Application An application that demonstrates the possibility to use no-interface EJB session beans as RESTful resource classes deployed as a servlet. Managed Beans Application An application that demonstrates the possibility to annotate REST resource class with ManagedBean annotation, thus REST resource can be Managed Bean as well. JSF 2.0 Basic AJAX Application A series of simple programs intended to illustrate some of the new Ajax features that are contained in JSF 2.0.  Ajax Basic Composite Component Application A series of simple programs intended to illustrate some of the new Composite Component features that are contained in JSF 2.0. Ajax Complete Application A series of simple programs intended to illustrate some of the new Ajax features that are contained in JSF 2.0. Contexts & Dependency Injection (CDI)

JSF 2.0 Weld Application

An application that demonstrates the use of CDI with JSF 2.0.

Weld Servlet Application

An application that illustrates the injection of Weld into a servlet. CDI Interceptors Application An application that illustrates CDI Interceptors to intercept and log method calls. CDI Events Application An application that illustrates CDI events using producer and consumer EJBs. Security Programmatic Login Application A web application that demonstrates the programmatic security (login/logout) feature in Servlets 3.0. HTTP Method Omissions Application A web application that demonstrates the use of http-method-omission feature of Servlet 3.0  to restrict the set of supported HTTP methods to just GET and POST. Java EE Connector Architecture 1.6 MailConnector Resource Adapter Sample Application An application using the mail-connector resource-adapter to retrieve e-mails. Demonstrates how to use new annotations introduced in Java EE Connector Architecture 1.6 specification. The mail connector resource adapter is completely built by specifying annotations. No deployment descriptor is used. Java Persistence API 2.0 JPA Pessimistic Locking Application An application that demonstrates the use of locking with Java Persistence APIs. JPA Advanced Mapping Sample

An application that demonstrates the use of Derived Identities and Maps.

JPA Criteria Query Sample An application that demonstrates the use of Criteria Queries. Container Features Custom Valve Application An application that demonstrates the custom valve facilities available in GlassFish v3. mod_jk Sample A sample that demonstrates running GlassFish v3 with Apache httpd. Session Persistence clusterjsp Simple JSP web application to demonstrate session persistence.

The Java EE 6 SDK can be downloaded from oracle.com/javaee. I recently added two CDI samples and will continue to add more. Let us know if you'd like to contribute your Java EE 6 samples here.

And if you find any samples broken then send us feedback or file bugs (use "sample_app" category).


Categories: Companies

Java EE 6 Hands-on lab at Austin JUG Tomorrow

Mon, 01/30/2012 - 19:15

Want to learn how Java EE 6 drastically reduces the amount of code to be written and still improves your productivity for build a Web application ?

Simple, ease-of-use, extensible, light-weight are some of the terms very commonly associated with Java EE 6. In a two hour interactive session at Austin JUG tomorrow, learn how NetBeans, GlassFish, and MySQL provide a killer threesome for building your enterprise and Web applications.

When ?   Jan 31, 2012, 6:30 - 9pm
Where ?   Li'l Tex Auditorium, Commons Building (#137), University of Texas J. J. Pickle Research Campus

Be there at 6:30pm for the pizza as the session will start promptly at 7pm. And I'd like to share all the goodness with you.

And let me know if you'll be interested in running together on Wednesday morning.


Categories: Companies

JavaOne Tokyo, Moscow, and India 2012 - Save the Date

Wed, 01/25/2012 - 20:18
JavaOne Tokyo (Japan)
Date: April 4-5, 2012
Location: Academy Hills, 49F, Roppongi Tokyo
Website: Japanese, English

JavaOne Moscow (Russia)
Date: April 17-18, 2012
Location: Crocus Expo, International Exhibition Center
Website: TBD

JavaOne Hyderabad (India)
Date: May 3-4, 2012
Location: Hyderabad International Convention Center
Website: TBD

In the meanwhile, you can watch keynotes and interviews from JavaOne San Francisco, download PDFs of technical sessions or watch select sessions and birds-of-feather sessions on parleys.com.

And JavaOne San Francisco 2012 is scheduled for Sep 30 - Oct 4, 2012. Register now before March 30th for a $600 savings.


Categories: Companies

JPA 2.1 Early Draft Explained - Java EE 7 making progress

Mon, 01/23/2012 - 19:29
Java Persistence API 2.1 Early Draft has been available for about a month now. JPA2 was one of the first JSRs to be filed as part of Java EE 7. Several other specifications in Java EE 7 have released early drafts as well (JavaServer Faces 2.0, JAX-RS 2.0, CDI 1.1, more coming as well) and I'll cover them in later blogs.

Here are the main highlights of JPA 2.1:
  • Support for Stored Procedures: Added support for the invocation of predefined database functions and user-defined database functions to the Java Persistence query language.

    There are different variants of EntityManager.createXXXStoredProcedureQuery methods that return a StoredProcedureQuery for executing a stored procedure.  Just liked @NamedQuery, there is @NamedStoredProcedureQuery that specifies and names a stored procedure, its parameters, and its result type. This annotation can be specified on an entity or mapped superclass. The name specified in the annotation is then used in EntityManager.createNamedStoredProcedureQuery. The IN, OUT, and INOUT parameters can be set and used to retrieve values passed back from the procedure. For example:

    @Entity
    @NamedStoredProcedureQuery(name="topGiftsStoredProcedure", procedureName="Top10Gifts")
    public class Product {
     . . .
    }

    // In your client

    StoredProcedreQuery query = EntityManager.createNamedStoredProcedureQuery("topGiftsStoredProcedure");
    query.registerStoredProcedureParameter(1, String.class, ParameterMode.INOUT);
    query.setParameter(1, "top10");
    query.registerStoredProcedureParameter(2, Integer.class, ParameterMode.IN);
    query.setParameter(2, 100);
    // there are other setParameter methods for defining the temporal type of a parameter
    . . .
    query.execute();
    String response = query.getOutputParameterValue(1);

    The section 3.8.6 provide more details.
  • Bul update/delete using Criteria: Added CriteriaUpdate, CriteriaDelete, CommonAbstractQuery interfaces, refactored AbstractQuery interface.

    Here is a sample for CriteriaUpdate from section 6.5.15:

    CriteriaUpdate<Customer> q = cb.createCriteriaUpdate(Customer.class);
    Root<Customer> c = q.from(Customer.class);
    q.set(c.get(Customer_.status), "outstanding")
     .where(cb.lt(c.get(Customer_.balance), 10000));

    with the equivalent JPQL of:

    UPDATE Customer c
    SET c.status = 'outstanding'
    WHERE c.balance < 10000

    This query can then be executed as:

    @PersistenceContext EntityManager em;
    Query query = em.createQuery(q);
    query.executeUpdate();

    Here is a sample for CriteriaDelete from section 6.5.15:

    CriteriaDelete<Customer> q = cb.createCriteriaDelete(Customer.class);
    Root<Customer> c = q.from(Customer.class);
    q.where(cb.equal(c.get(Customer_.status), "inactive"),
            cb.isEmpty(c.get(Customer_.orders)));

    with the equivalent JPQL of:

    DELETE FROM Customer c
    WHERE c.status = 'inactive'
    AND c.orders IS EMPTY

    This query can then be executed in similar way as earlier:

    @PersistenceContext EntityManager em;
    Query query = em.createQuery(q);
    query.executeUpdate();

  • New reserved keywords: Added the following to Java Persistence query language reserved identifiers: FUNCTION, ON, TREAT.
    • Pre-defined and user-defined functions using FUNCTION: JPQL provide several in-built functions which may be used in the SELECT, WHERE or HAVING clause of a query such as CONCAT, SUBSTRING, TRIM, LENGTH, ABS, SQRT, and CURRENT_DATE. The section 4.6.17.3 define invocation of predefined and user-defined database functions using the FUNCTION operator. The FUNCTION is used to invoke predefined database functions or user-defined database functions. An example from the section is:

      SELECT c
      FROM Customer c
      WHERE FUNCTION(‘hasGoodCredit’, c.balance, c.creditLimit)
    • Downcasting using TREAT: TREAT is supported for downcasting within path expressions in the FROM and WHERE clauses. Use of the TREAT operator allows access to subclass-specific state. An example from section 4.4.9 is:

      SELECT b.name, b.ISBN
      FROM Order o JOIN TREAT(o.product AS Book) b

      In this example, the join is performed between Order and Product but name and ISBN are attributes of the Book class which is a subclass of the Product class. Another example is:

      SELECT e FROM Employee e
      WHERE TREAT(e AS Exempt).vacationDays > 10
      OR TREAT(e AS Contractor).hours > 100

      Here again vacationDays are attributes for Exempt employees only and hours only for Contractor.

    • Join condition using ON: The ON clause in SQL is used to specify the relationship between the tables. It is different from the WHERE clause which specifies the criteria for the rows to be picked. An example from the section 4.4.5.2 shows the JPQL as:

      SELECT s.name, COUNT(p)
      FROM Suppliers s LEFT JOIN s.products p
      ON p.status = 'inStock'
      GROUP BY s.name

      The mapped SQL for this will be:

      SELECT s.name, COUNT(p.id)
      FROM Suppliers s LEFT JOIN Products p
      ON s.id = p.supplierId AND p.status = 'inStock'
      GROUP BY s.name

      The s.id = p.supplierId condition is generated becase of the LEFT JOIN. The additional JOIN condition of p.status = 'inStock' is also added to the generated SQL because of the ON clause in the JPQL. The result of this query will include all suppliers (with possibly NULL values). This is different from the query below:

      SELECT s.name, COUNT(p)
      FROM Suppliers s LEFT JOIN s.products p
      WHERE p.status = 'inStock'
      GROUP BY s.name

      The result of this query will not include suppliers that have no products in stock.

      Additional methods are also added to Fetch, Join, CollectionJoin, SetJoin, ListJoin, and MapJoin interfaces to support the ON clause.
  • Entity listeners using CDI: Entity Listeners allow to handle cross-cutting lifecycle events in a non-persistent listener class. In JPA 2.1, entity listeners will support dependency injection through CDI. The usual lifecycle callback methods of @PrePersist, @PostPersist, @PreUpdate, and @PreRemove can be used for entities. The entity listeners can also be annotated with @PostConstruct and @PreDestroy for their own lifecycle. The section 3.5.1 provides more details on this.

    Read more details on jsr338-experts alias archive and users@jpa-spec.
  • Synchronization of persistence contexts: In JPA 2, the persistence context is synchronized with the underlying resource manager. Any updates made to the persistence context are propagated to the resource manager. JPA 2.1 introduces the concept of unsynchronized persistence contenxt. Here is how you can create a container-managed unsynchronized persistence context:

    @PersistenceContext(synchronization=SynchronizationType.UNSYNCHRONIZED) EntityManager em;

    The section 7.6.1 provide more details.
  • Several clarifications in text and javadocs

The Appendix in the specification provide a comprehensive list of changes in this version of the specification. And there are change bars through out as well allowing you to see what has changed since JPA 2.

Here are some final set of references for you:

And of course, it'll all be delivered as part of GlassFish 4.0!



Categories: Companies