Wednesday, May 8, 2013

EclipseLink JPA on Oracle WebLogic 12c with a JAX-RS based JSF and JQuery thin client

EclipseLink JPA on Oracle WebLogic 12c with a JAX-RS based JSF and JQuery thin client


Enable JPA Metamodel Modelgen compilation in your Eclipse project

Turn on APT in your project settings and add EclipseLink jars

An automatic rebuild will show the new _ underscore JPA canonical metamodel classes that can be used for typesafe Criteria API queries.



Parsing JSON via AJAX call from JQuery client







JAX-RS backend server

@Path("/read")
public class RestServiceImpl extends Application {
 // not supported until 2.0 https://java.net/jira/browse/JERSEY-517
 //@EJB(name="ejb/ApplicationService") // not for JAX-RS
 //@Inject
 private ApplicationServiceLocal applicationServiceLocal;
   @GET
   @Path("/json/latest/{id}")  
   //@Consumes(MediaType.TEXT_PLAIN)
   @Produces(MediaType.APPLICATION_JSON)
   public List getLatestJSON(@PathParam("id")String identifier) {    
    return getApplicationService().latest(identifier);
   }
....

@Stateless(mappedName = "applicationService")
public class ApplicationService implements ApplicationServiceLocal {
 @PersistenceContext(unitName="gps", type=PersistenceContextType.TRANSACTION)
 private EntityManager entityManager;

    public List latest(String user) {
 CriteriaBuilder cb = entityManager.getCriteriaBuilder();
     CriteriaQuery query = cb.createQuery(Record.class);
     Root target = query.from(Record.class);
     SingularAttribute anAttribute = entityManager.getMetamodel()
       .entity(Record.class).getSingularAttribute("tsStop", Long.class);
     query.orderBy(cb.desc(target.get(anAttribute)));
     query.where(
       cb.equal(target.get("userId"), user));
     TypedQuery typedQuery = entityManager.createQuery(query);
     typedQuery.setMaxResults(1);
     Record result = (Record)typedQuery.getSingleResult();
     List list = new ArrayList<>();
     list.add(result);
 return list;         
    }
...

Thursday, May 2, 2013

JPA 2 Entity Caching

JPA 2 Entity Caching


Enabling Caching
- use a named query and set the cachable hint to true (how do we cache criteria API queries?)
- set the cache mode

       <shared-cache-mode>ALL</shared-cache-mode>
       <!-- shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode--><!-- override with @Cacheable(true) -->
       <!-- shared-cache-mode>DISABLE_SELECTIVE</shared-cache-mode--><!-- override with @Cacheable(false) -->
       <!-- shared-cache-mode>NONE</shared-cache-mode--><!-- do not use -->

Use the default
<property name="javax.persistence.cache.retrieveMode" value="true"/>


EclipseLink via Oracle Coherence

Hibernate via Terracotta ehCache

Alternate JGroups cache coordination
Instead of using standard JMS if you are not on a full EE application server - you can use JGroups

http://ehcache.org/documentation/replication/jgroups-replicated-caching
http://bugs.eclipse.org/282074


Remote JVisualVM Security

        permission java.util.PropertyPermission "java.rmi.server.ignoreSubClasses", "write";
        permission java.lang.RuntimePermission  "accessClassInPackage.sun.tools.jstatd";
        permission java.lang.RuntimePermission  "accessClassInPackage.sun.jvmstat.*";
        permission java.lang.RuntimePermission  "accessClassInPackage.sun.management";
        permission java.lang.RuntimePermission  "sun.misc.Perf.getPerf";
        permission java.util.PropertyPermission "sun.jvmstat.monitor.package","read";
        permission java.util.PropertyPermission "sun.jvmstat.*", "read";
        permission java.util.RuntimePermission  "sun.jvmstat.*";
        permission java.util.PropertyPermission "java.io.tmpdir", "read";
        permission java.io.FilePermission "/tmp", "read";
        permission java.io.FilePermission "/tmp/hsperfdata_weblogic/*", "read";
        permission java.io.FilePermission "/tmp/*", "read";
        permission java.io.FilePermission "/tmp/hsperfdata_root/*", "read";
        permission java.net.SocketPermission "127.0.0.1:1099", "connect,resolve";      
        permission java.net.SocketPermission "127.0.0.1:*", "accept,resolve";

Total Pageviews

Followers