Tuesday Jan 31, 2012

Java EE 6 samples in the SDK


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).

Monday Jan 30, 2012

Java EE 6 Hands-on lab at Austin JUG Tomorrow


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.

Wednesday Jan 25, 2012

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

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.

Monday Jan 23, 2012

JPA 2.1 Early Draft Explained - Java EE 7 making progress

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!


Tuesday Jan 03, 2012

Java EE 6 using WebLogic 12c, NetBeans, and MySQL (Screencast #39)




Oracle WebLogic Server 12c is now available and comes with a zip installer.

This video shows how to develop and deploy a Java EE 6 application on WebLogic 12c using NetBeans. It builds a simple application using Java Persistence API 2.0, Enterprise JavaBeans 3.1, Servlets 3.0, Java API for RESTful Web Services 1.1, Java Server Faces 2.0, and Contexts & Dependency Injection 1.0. The video also explains how to configure MySQL database in NetBeans and use it for accessing the database tables in the Java EE 6 applications.

Enjoy!



You can also check out the sample code built in this application from here.

What kind of Java EE 6 applications are you deploying on WebLogic ?

What else would you like to see on this blog relating to Java EE 6 and WebLogic ?

Follow the complete series here.

About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

Search

Archives
« January 2012 »
SunMonTueWedThuFriSat
1
2
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
24
26
27
28
29
    
       
Today