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";

Sunday, February 17, 2013

Google Web Toolkit and Google App Engine With PhoneGap for Mobile Apps

Google Web Toolkit and Google App Engine With PhoneGap for Mobile Apps

To write Java EE server side code and Java client code that deploys to the cloud and serves thin, mobile and headless clients - I find Google Web Toolkit used within Eclipse that deploys to Google App Engine using a Google Cloud SQL instance works very well.  If you go one step further and package your client HTML5/JS client code using PhoneGap for iOS and Android then you have a full end to end solution.

The following diagram illustrates various start and end points when developing thin or mobile clients.

Options for generating native, thin and hybrid mobile clients


Sequence diagram for generating HTML5 based mobile apps from Java using GWT and PhoneGap

Getting Started

I am interested in getting the JPA 2.0 provider working in Google App Engine.  Unfortunately Google does not use the open source EclipseLink JPA 2.0 provider - instead it uses the DataNucleus provider.

There are a lot of differences and constraints on the JPA 2 provider - here are some of the highlights.

You must use the Key PK wrapper - which shares implementation with JDO

import com.google.appengine.api.datastore.Key
[0] Nutrient (id=164) id Key (id=169) jdoDetachedState null jdoFlags 1 jdoStateManager JDOStateManager (id=171) name "aName" (id=178)


Software

Eclipse 3.8/4.2 with DTP, GWT
Google Web Toolkit 2.5
Vaadin for GWT - use the Eclipse Plugin
Google App Engine
PhoneGap/Cordova 2.4

Google App Services

Google Datastore using the paxos algorithm:  

Links


Sunday, February 10, 2013

Blackberry 10 Development

Blackberry Z10 Development


20140720: Update: After 14 years using RIM devices from the 957,6700,8800,9000,bold and Q10 - I have retired using blackberrys - for the first time my Q10 keyboard has become defective - I officially move to full time iPhone 5s usage with Android 4.4 on the side.  The lack of support for clinical devices such as the hexoskin, muse and Bluetooth Smart based systems is also a factor.  The iOS 8 ecosystem is also easier to use.

RIM/Blackberry has done an excellent job bringing out Blackberry OS 10 and the Z10/Q10 devices (I have both) which I like better than the iPhone 4s except for the # of apps available ofcourse.  The Q10 device however has a darker and slightly inferior screen compared to the Z10 but the keyboard is excellent.

The following blog details steps in getting up and running developing natively, using PhonGap or porting over Android apps.

Development Environment

see https://developer.blackberry.com/ as of 20130210 the 10.1 beta is out.
Start by downloading both the Native API - Cascades for and Blackberry 10
Get the API's https://developer.blackberry.com/develop/platform_choice/index.html
Android 4.2 for Blackberry http://developer.blackberry.com/android/
Get the simulators https://developer.blackberry.com/develop/simulator/index.html

Before running a native C/C++ app on the Blackberry Z10 or Q10 you need to enable development mode and download .bar certificates to the devices - do this by selecting to generate a new debug key.

PhoneGap/HTML5


Android Emulation

Get the eclipse plugin for android porting http://developer.blackberry.com/android/documentation/install_plugin_prerequisites_1895476_11.html
Currently only Android 2.3.3 (API 10) is supported on the Blackberry.
Install the eclipse plugin for Blackberry / Android development tools (using jcommon-1.0.12.jar and kxml2-2.3.0.jar) https://developer.blackberry.com/android/downloads/eclipseplugin/.
To get around Unable to read repository at https://dl-ssl.google.com/android/eclipse/plugins/com.android.ide.eclipse.ddms_21.0.1.v201212060256-543035.jar.
try the install again
To get around the error after restarting eclipse

java.lang.RuntimeException: Application "org.eclipse.ui.ide.workbench" could not be found in the registry. The applications available are: org.eclipse.cdt.codan.core.application, org.eclipse.cdt.core.GeneratePDOM, org.eclipse.equinox.app.error, org.eclipse.equinox.p2.director, org.eclipse.equinox.p2.garbagecollector.application, org.eclipse.equinox.p2.publisher.InstallPublisher, org.eclipse.equinox.p2.publisher.EclipseGenerator, org.eclipse.equinox.p2.publisher.ProductPublisher, org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher, org.eclipse.equinox.p2.reconciler.application, org.eclipse.equinox.p2.repository.repo2runnable, org.eclipse.equinox.p2.repository.metadataverifier, org.eclipse.equinox.p2.artifact.repository.mirrorApplication, org.eclipse.equinox.p2.metadata.repository.mirrorApplication, org.eclipse.equinox.p2.updatesite.UpdateSitePublisher, org.eclipse.equinox.p2.publisher.UpdateSitePublisher, org.eclipse.equinox.p2.publisher.CategoryPublisher, org.eclipse.ant.core.antRunner, org.eclipse.help.base.infocenterApplication, org.eclipse.help.base.helpApplication, org.eclipse.help.base.indexTool, org.eclipse.jdt.apt.core.aptBuild, org.eclipse.jdt.core.JavaCodeFormatter, org.eclipse.jdt.core.JavaIndexer.




Saturday, December 1, 2012

HTML5 Geolocation API for thin clients and PhoneGap/Cordova mobile clients

The HTML5 version of the "South March Highlands Trails" GPS tracking application is running as a prototype at the following location: http://www.objectivej.com/gps/gps.html
The application allows anyone with a GPS enabled phone/laptop/device to see their location overlaid on top of the map created by the Ottawa Mountain Bike Association.

Everything GPS is possible via the HTML5 call:
    navigator.geolocation.getCurrentPosition(showPosition);

This works well in the iPhone app for "South March Highlands Trails" I am developing that will require a lot of additional work before I can submit it for review at Apple.


Artifacts:
1) An application server - WebLogic 12.1.1 (12c) in this case
2) An EAR - An Eclipse managed OEPE EAR/EJB/WAR project set
3) A database - The Derby 10.8 instance shipped with JDK 7
4) Web content (html 5 pages, css, javascript - possibly JQuery)
5) Several installations of PhoneGap 2.5 (for iOS6.1.1, BB10 and Android 4.2 at least)








References:
http://dev.w3.org/geo/api/spec-source.html

Wednesday, November 21, 2012

Java 7 SE Raspberry PI Parallel Processing ARM Cluster of 32 boards

Raspberry PI cluster of 32 boards - Under Construction:

Disclaimer: For serious computational power - build your own i7-5820 and use CUDA on an nVidia GTX-970.  The raspberry PI cluster is more of a "build it - and they will come" exploration exercise.

http://eclipsejpa.blogspot.ca/2015/03/haswell-intel-i7-5820k-overclock-pc.html

This article is an ongoing discussion of how to get a cluster of 32 raspberry pi boards up and running.

32 node/board Raspberry PI cluster for parallel processing experimentation

The ARM based Raspberry PI board is an excellent platform to investigate various parallel processing configurations.  If we are looking for pure performance then I would stick with an Intel core i7 and a CUDA based NVidia GPU because a single core raspberry PI is about 40 times slower than a single core of an 2nd gen i7-2600 or 3rd gen i7-3610 (about 140 times slower than an 8-thread ForkJoin implementation).  This however is not our goal, we need an efficient and accessible way to run multiple servers - and the pi does this at about $70 per server (board + connectors + 16GB SD) and 4 watts/node.  For example: it would take $9800 of raspberry PI boards with 70G ram to equal one 3rd gen i7 at $1300 with 24G ram.  But we can build a cluster of 8 raspberry PI servers with $560 as opposed to 8 i7 boxes with $10000.

 We need the proper power supplies and network switches for a cluster of 32 raspberry pi boards.
 Raspberry pi boards mount very nicely on standard breadboards using properly bent arduiono headers.


Raspberry PI Cluster
8 board Raspberry PI cluster
In this configuration I am running a research cluster of 8 raspberry PI boards to run distributed Java EE RMI/EJB remote session bean clients of a central Oracle WebLogic 12c server (running on an i7 host)


This tutorial details how to get a networked cluster (bramble) of (eight for now) Raspberry PI boards running as a single distributed auxillary processing unit to a controlling Java EE server - ideally using Hadoop.  The primary goal of this exercise is for distributed experimentation.  As I configure and acquire multiple raspberry pi boards and work out power distribution issues my cluster will increase in size.  I currently work with 8 boards and 8 spares.  The cluster of raspberry PI s can be distributed work using a custom RPC API like remote stateless sessions beans on top of RMI or they can use a formal MapReduce implementation like Hadoop or even MPI.

After running the Oracle embedded ARM JVM with no problems on the REV A raspberry PI using the distribution from Element14, I was not immediately successfull running the JVM on the new REV B (512Mb) version because the default Debian distribution from Element 14 no longer uses the soft float version.  I get the following missing library error.

pi@raspberrypi ~/java/ejre1.7.0_06 $ java -version
java: error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory

Download a new OS compatible with the Java 7 JDK here
http://www.raspberrypi.org/downloads

Choose "Soft-float Debian “wheezy”" = 2012-08-08-wheezy-armel.zip

Write it to your SD card
https://launchpad.net/win32-image-writer/+download

Reinstall Java (curently 1.7.0_10 from Oracle)

You are good to go [Java 7 SE on the Raspberry PI Rev B].  So we can now use Fork-Join, JAXB and JAX-WS webservices (using a single thread however).

DI 1: Powering your Raspberry PI cluster

On some routers you will not get a DHCP assigned address if all the clustered raspberry PI boards are powered up in sync - you will need to stagger the powerup - this only occurs if not enough amps are available.

Using a good Agilent power supply we use from 3 (idle) to 3.5A (startup) (6-7W @ 5V) for 8 boards.


You can use a powered USB router for 4 boards, but 8 will require a better power supply like a bench one from Agilent. A bench supply will usually supply up to 40A power  - but normally 5A which is good for up to 12 Raspberry PI's running at 100% CPU but we will need a better supply for a cluster of 32 raspberry pi boards for example.
A good ATX power supply will suffice to power a cluster of raspberry pi boards.  In this example I have a 450W supply which supplies 30A of 5V power (make sure you put some load on the 5V and 12V rails as well).

Get the ATX adapter and breakout board from SparkFun and make sure you use multiple 24 guage or higher wires to distribute the load (1 wire will overheat, 2 wires go to 28 deg C. - use at least 4 if you go over 8 boards).



As you can see I have yet to fully integrate the power supply interface between the ATX supply and the breadboard bus for the 8 pi's - but we are functioning fine and are no longer limited by the bench supplies or individual 5V USB connectors.  (the blue LED boards are Parallax Propeller 8-core microcontrollers uses a per/core output indicator for now.
I need some sort of protection fuse - in case of a short circuit.  It was very stressful connecting up my 8 raspberry pi boards up to the ATX after testing on one.  I recommend working with all GPIO pins (one 1 header is populated instead of 2 on the latest rev B board) covered by a flat cable connector.

20130126:  I now have 24 of 32 raspberry pi boards powered up however running the full peak 15A off an ATX power supply is not practical as it requires some serious wire guage as my 3 wire 24 guage setup is overheating.  Also if you accidently short the power supply you will use the full 15-40A and burn your wire.  I accidentally shorted the leads on a 5A supply on my metal breadboard and the supply wire started to smell and melt.  This brings us to the recommend way to power a large cluster of raspberry pi boards - separate bench power supplies.  When I shorted the supply the bench supply held stead at 5.2A which is safe enough not to burn your house down before you notice it.

 

Recommended power supply setup for 32 raspberry pi board cluster

No more than 8 raspberry pi boards per 5A power supply will allow you to add some peripherals like an adafruit display or a propeller 8-core coprocessor on an SPI bus.
So this is kind of expensive but instead of using a 40A bench supply at around $350 I use 4 separate 5A bench supplies (3 Circuit-Test PSC-520 supplies @ 3 x $225 and 1 Agilent U8002A supply @ $450).

DI 2: Updating your board for 512mb RAM (470Mb from 224Mb)

The Rev 2 board has double the ram but will require updated firmware to enable it.
https://github.com/Hexxeh/rpi-update
sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update && sudo chmod +x /usr/bin/rpi-update
sudo apt-get install git-core
sudo rpi-update
- reboot after firmware update

DI 3: Overclocking

The lan chip heats up to 52 degrees celsius from a normal 45 when the raspberry pi is overclocked from 700 to 800 MHz.



DI 4: Setup Networking

Wireless is kind of unreliable, I recommend wired.
The WiPi module from Element 14 works essentially out of the box

Wired networking

After duplicating all the 32 SD cards, put one at a time into one of the raspberry pi boards and change the hostname, hosts and static network interfaces settings

sudo nano /etc/hostname

sudo nano /etc/hosts


sudo nano /etc/network/interfaces
iface eth0 inet static
address 192.168.4.101
netmask 255.255.255.0
gateway 192.168.4.1
nameserver 4.2.2.1

# here we do not rely on our internet providers's DNS servers - we use the google server at 4.2.2.1 as more reliable DNS server

sudo nano /etc/resolv.conf
nameserver 4.2.2.1

DI 5: Setup Java



Setup Tomcat
login in to the manager app using "system:raspberry"




Setup Fortran and MPICH


Issue is that I lower performance (likely network overhead) when I increase the number of nodes (currently 6 pi's)

pi@rpi0 ~ $ mpiexec -f machinefile -n 1 ~/mpich_build/examples/cpi
Process 0 of 1 is on rpi0
pi is approximately 3.1415926544231341, Error is 0.0000000008333410
wall clock time = 0.017286

pi@rpi0 ~ $ mpiexec -f machinefile -n 2 ~/mpich_build/examples/cpi
Process 0 of 2 is on rpi0
Process 1 of 2 is on rpi1
pi is approximately 3.1415926544231318, Error is 0.0000000008333387
wall clock time = 0.020435

pi@rpi0 ~ $ mpiexec -f machinefile -n 4 ~/mpich_build/examples/cpi
Process 1 of 4 is on rpi1
Process 0 of 4 is on rpi0
Process 2 of 4 is on rpi2
Process 3 of 4 is on rpi3
pi is approximately 3.1415926544231239, Error is 0.0000000008333307
wall clock time = 0.037727

pi@rpi0 ~ $ mpiexec -f machinefile -n 6 ~/mpich_build/examples/cpi
Process 2 of 6 is on rpi0
Process 1 of 6 is on rpi1
Process 0 of 6 is on rpi2
Process 3 of 6 is on rpi3
Process 4 of 6 is on rpi4
Process 5 of 6 is on rpi5
pi is approximately 3.1415926544231239, Error is 0.0000000008333307
wall clock time = 0.043331

Log:
20121121: Setup 4 networked PIs
20130127: power up of 24 raspberry pi boards

BOM:

32 Raspberry PI boards from Element 14 @ $35 = $1120
32 Sandisk Ultra 16GB SD cards @ $10-18 = $320-576
0 micro USB cables = $0
1 HDMI cable from Apple = $20
8 power supply cables @ 10 = $80
4 bench 5A power supplies from Agilent or Circuit-Test @224-450 = $896-1800
4 large breadboards (that fit 8 raspberry pi boards) @ 45 = $180
64 bendable arduino headers from www.evilmadscience.com @ $1 = $64
5 Gigabit 8 node network hubs or 2 16 node hubs from Dlink @ 65 = $325
32 belkin flexible network cables from the Apple store @ 15 = $480

Total = $3885.00

Copies of this article
http://www.framboise314.fr/32-raspberry-pi-pour-du-calcul-parallele-en-java/

Links


Monday, October 15, 2012

Java SE 7 Embedded on Raspberry PI

Getting Java SE 7 Embedded running on the Raspberry PI Linux device

I like the British - they gave cracked the Enigma, they created the Transputer and then the XCore and now they give us easily accessible embedded Java.

Eben - Thank you for developing this excellent device.  Now we can use our corporate development skills in Java SE/EE when we program hardware/software combinations off hours.  The XMOS 4-core/32-thread and Parallax 8-core/8-thread microcontrollers may collect dust now - very unlikely as they don't have an issue with symmetric parallel processing.


It is official - the latest Oracle/SUN Java VM works out of the box for SE Java applications (no ME) on the default Debian distribution for Raspberry PI (Rev B) because of it's use of ARM.

root@raspberrypi:/home/pi/java/ejre1.7.0_06# ./bin/java -version
java version "1.7.0_06"
Java(TM) SE Embedded Runtime Environment (build 1.7.0_06-b24, headless)
Java HotSpot(TM) Embedded Client VM (build 23.2-b09, mixed mode)
root@raspberrypi:/home/pi/java/ejre1.7.0_06#


I bypassed the configuration steps on the Oracle article and WinSCP'd the GZ directly to the Element 14 provided Debian OS on the Raspberry PI device, extracted it, downloaded a test .class file and was running about 32 times slower than a Core i7-3610M or about 12% the speed of the slowest 1.3Ghz mobile P4 - about the speed of a Pentium III or II.  This slowdown of 2-3 times expected speed is likely due to the JIT or lack thereoff.

The instructions at Oracle are incomplete - you will need to perform extra config detailed at
http://www.savagehomeautomation.com/pi-jdk

After expanding using...


tar xvzf ejre1.7.0*.gz


you would get the following if installed to the latest hard-float debian image on the REV B distributed by Element 14 - change to the
pi@raspberrypi ~/java/ejre1.7.0_06 $ ./bin/java -version"Wheezy Armel" soft float distribution.
http://eclipsejpa.blogspot.ca/2012/11/java-7-se-parallel-processing-cluster.html

./bin/java: error while loading shared libraries: libjli.so: cannot open shared

If you didn't do
pi@raspberrypi ~/java/ejre1.7.0_06 $ sudo mv -v ~/java/ejre1.7.0_06 /opt/java
`/home/pi/java/ejre1.7.0_06' -> `/opt/java'
pi@raspberrypi ~/java/ejre1.7.0_06 $ sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/bin/java" 1
update-alternatives: using /opt/java/bin/java to provide /usr/bin/java (java) in auto mode.

I don't know how I was able to get 2 boards in late Sept 2012 - I ordered them off Element 14 Canada - they arrived in 24 hours - My next 12 ordered on Oct 23 arrived as they predicted on 28 Nov 2012.  A 5 amp bench supply should be able to at least run 8 of them at a minimum power draw of 0.39A/board (with only ethernet connected).  After running 5 headless - I am running at 1.6A.


Java 7 Fork Join on the Raspberry PI

    I took a collatz ForkJoin application and varied the fork from 2^16 to 1 fork.  Results were expected - the overhead of using the single thread in the ForkJoinPool slows down the application.  So ForkJoin should only be used on the controlling server and not on the actual devices themselves.
   Running the ARM at 100% CPU for 2 days caused the Broadcom chip to reach 48 C.
   The speed of the run was around 11 times slower than a P4-3.2 GHz system or 138 times slower than a Core i7-3610.

    So we get about 1.3 MIPS/GHz on the ARM vs 35 MIPS/GHz on the 3610 series i7 without using SSE or GPU processing on either system.

root@raspberrypi:/home/pi/java# ./ejre1.7.0_06/bin/java org.obrienscience.collatz.server.ForkJoinCollatzServer
4446843 ms for: 16
4434227 ms for: 32
4382020 ms for: 64
4342838 ms for: 128
4344761 ms for: 256
4345003 ms for: 512
4315240 ms for: 1024
4306938 ms for: 2048
4287915 ms for: 4096
4263907 ms for: 8192
4360612 ms for: 16384
4751604 ms for: 32768
4467843 ms for: 65536
4386337 ms for: 131072
4340696 ms for: 262144
4273932 ms for: 524288
4301385 ms for: 1048576
4240190 ms for: 2097152
4230078 ms for: 4194304
4237989 ms for: 8388608
4223808 ms for: 16777216


Compare this to a P4-3.2 GHz system with 1-cores/2-threads
388031 ms for : 16
384641 ms for : 32
385609 ms for : 64
385360 ms for : 128
388953 ms for : 256
386562 ms for : 512
383766 ms for : 1024
384453 ms for : 2048
385344 ms for : 4096
382578 ms for : 8192
383656 ms for : 16384
387266 ms for : 32768
382843 ms for : 65536
381438 ms for : 131072
375312 ms for : 262144
374750 ms for : 524288
378547 ms for : 1048576
385407 ms for : 2097152
390078 ms for : 4194304
393062 ms for : 8388608
389297 ms for : 16777216

Compare this to a Core i7-3610 2.7 Ghz system (Asus G75VW) with 4-cores/8-threads - which is around 8% faster than a Core i7-2600 at 2.7 Ghz
32184 ms for : 128
31779 ms for : 256
31322 ms for : 512
31541 ms for : 1024
31079 ms for : 2048
31264 ms for : 4096
30911 ms for : 8192
31186 ms for : 16384
30786 ms for : 32768
31915 ms for : 65536
30998 ms for : 131072
31121 ms for : 262144
31376 ms for : 524288
31779 ms for : 1048576
32347 ms for : 2097152
37294 ms for : 4194304
31644 ms for : 8388608
39499 ms for : 16777216



Next: Running a JPA 2.0 application using EclipseLink 2.4 against Derby 10.8 on Spring in either Jetty or Tomcat on the Raspberry PI 512Mb rev B.

This is our current 8 node raspberry pi cluster - ready for 16 nodes at it has 30 amps (P = VA = (5V * 30A) = 150 watts) of available power.

Eight Raspberry PI boards running as a cluster powered by an ATX power supply


References:

http://www.oracle.com/technetwork/articles/java/raspberrypi-1704896.html
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=34&t=17992&p=193993&hilit=java#p193993
Hinkmond Wong's wiki about low level file based GPIO - nice.
https://blogs.oracle.com/hinkmond/entry/rpi_and_java_embedded_gpio3

Monday, April 2, 2012

Running both EclipseLink and Hibernate JPA 2.0 Implementations

This article details differences in running EclipseLink (2.3) and Hibernate (3.6.8/4.00) primarily using the JPA 2.0 API and native ORM where appropriate.

persist vs merge:

EclipseLink is 30% faster for inserts using persist than Hibernate is for merge.  This may be the fact that the entities continue to be managed in EclipseLink but are persisted as clones by Hibernate.

Hibernate 5450 insertions @ 14.6 tx-inserts/sec to sybase
EclipseLink 4911 insertions @ 18.9 tx-inserts/sec to sybase

Switch persistence.xml provider tags
       <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
       <provider>org.hibernate.ejb.HibernatePersistence</provider> 
@Entity
@Table(name="VIG_DRUG")
public class Drug implements Serializable {
    private static final long serialVersionUID = 3132063814489287035L;
    @Id
    // keep the sequence column name under 30 chars to avoid an ORA-00972   
    @SequenceGenerator(name="JPA_SEQUENCE_DRUG", sequenceName="JPA_DRUG_SEQ", allocationSize=15)
    @GeneratedValue(generator="JPA_SEQUENCE_DRUG")
    @Column(name="DRUG_ID")    
    private Long id;

    @Version
    @Column(name="DRUG_VERSION")
    private int version;
    
    @Basic
    @Column(name="compID")//, updatable=false, insertable=false);
    private String compositeID;

    @Basic
    @Column(name="DIN")//, updatable=false, insertable=false)
    private long din;

EclipseLink Logs:
[EL Fine]: 2012-04-02 11:41:34.596--ClientSession(9012544)--Connection(20436132)--Thread(Thread[main,5,main])--INSERT INTO VIG_DRUG (compID, DIN, DRUG_VERSION) VALUES (?, ?, ?)
    bind => [ORTAB, 0, 1]

Hibernate Logs:

Hibernate: select drug0_.DRUG_ID as DRUG1_0_0_, drug0_.compID as compID0_0_, drug0_.DIN as DIN0_0_, drug0_.DRUG_VERSION as DRUG4_0_0_ from VIG_DRUG drug0_ where drug0_.DRUG_ID=?
Hibernate:
insert into VIG_DRUG (compID, DIN, DRUG_VERSION) values (?, ?, ?)

Tuesday, February 14, 2012

Web Services using JAX-RPC, JAX-WS or JAX-RS

Quickstart WebServices Tutorial


JAX-RS 

Weblogic 12c version 12.1.2.1 now ships by default with JAX-RS 1.1 as a core library.  Previously in Weblogic 12.1.1.0 the following shared web applications were required - now we just use the specification library.

 Library jackson-core-asl(1.0,1.1.1) Active  Library
 Library jersey-bundle(1.1.1,1.1.5.1) Active  Library
 Library jettison(1.1,1.1) Active  Library
 Library jsr311-api(1.1.1,1.1.1) Active  Library

Now in eclipse just add the JAX-RS facet which will add the jersey servlet to your web.xml

  <servlet>
    <description>JAX-RS Tools Generated - Do not modify</description>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <url-pattern>/jaxrs/*</url-pattern>
  </servlet-mapping>



JAX-RPC

Jax-RPC has fallen out of favor for most new web services in favor of JAX-RS 1.1 or REST.
A simple java SE example that is single threaded and runs off of Metro included in Java SE 1.6.
This example does not need a web container or a full application server to run - however it is non-scalable and thread-blocking simple example.


ServiceEndpoint.java
package org.dataparallel.example.jaxws;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

/**
* definitions targetNamespace="http://jaxws.example.dataparallel.org/" name="ServiceEndpointImplService
* 
*/

@WebService
@SOAPBinding(style = Style.RPC)
public interface ServiceEndpoint {
    public static final String URL = http://127.0.0.1;
    public static final String PORT = "8980";
    public static final String SERVICE_NAME = "service";
    public static final String SERVICE_URI = URL + ":" + PORT + "/" + SERVICE_NAME;
    public static final String DOMAIN_NAME = "http://jaxws.example.dataparallel.org/";


    @WebMethod
    public String getImage();
}

ServiceEndpointImpl.java
package org.dataparallel.example.jaxws;

import javax.jws.WebService;

@WebService(endpointInterface="org.dataparallel.example.jaxws.ServiceEndpoint")
public class ServiceEndpointImpl implements ServiceEndpoint {
    @Override
    public String getImage() {
        System.out.println("_ServiceEndpointImpl.getImage()");
        return "aString";
    }
}

ServiceEndpointPublisher.java
package org.dataparallel.example.jaxws;

import javax.xml.ws.Endpoint;
public class ServiceEndpointPublisher {
    public void publish() {
        publish(ServiceEndpoint.SERVICE_URI, new ServiceEndpointImpl());
    }

    public void publish(String url, ServiceEndpoint service) {
        Endpoint.publish(url, service);
    }

    /**
     * http://127.0.0.1:8980/service?wsdl
     */
    public static void main(String[] args) {
        // single threaded testing service
        ServiceEndpointPublisher aPublisher = new ServiceEndpointPublisher();
        aPublisher.publish(); 
    }

ServiceClient.java
package org.dataparallel.example.jaxws;


import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;

public class ServiceClient {
    public void callService() {
        try {
            URL aWsdlURL = new URL(ServiceEndpoint.SERVICE_URI + "?wsdl");
            QName aQName = new QName(ServiceEndpoint.DOMAIN_NAME,ServiceEndpointImpl.class.getSimpleName() + "Service");
            Service aService = Service.create(aWsdlURL, aQName);
            ServiceEndpoint anEndpointInterface = aService.getPort(ServiceEndpoint.class);
            System.out.println("Service.getImage: " + anEndpointInterface.getImage());
        } catch (MalformedURLException mue) {
            mue.printStackTrace();
    }
}

    public static void main(String[] args) {
        ServiceClient aClient = new ServiceClient();
        aClient.callService();
    }
}



JAX-WS
Jax-WS has fallen out of favor for most new web services in favor of JAX-RS 1.1 or REST - it still has a place for specific SOAP clients or data types.

JAX-RS
- in queue - see
http://wiki.eclipse.org/EclipseLink/Development/2.4.0/JPA-RS/REST-API

Tuesday, January 31, 2012

iOS 7.0 Development

Updated: 20130303: Don't even think about using a MacBook Pro below the top 15 ich with SSD/16g-ram/2.6 Ghz.  Also there seems to be a defect in the original iPhone 5 where continous motion updates overloads the acceleration sensor resulting in a missing gravity vector - the iPhone 5s with the M7 coprocessor works fine for the 7 hours of 100ms granularity I have tested so far.

This is a really interesting time at Apple.
I just discovered that Objective C is partially based on Smalltalk.  Since I learned Smalltalk V as part of my first 2 years in university just before Java arrived - i needed to start developing in Objective C (for the iPhone, iPad and iPodt Touch) immediately.

1) Get a Mac - goto your nearest Apple store and ask for the Mac Mini to start.
2) Connect it to any keyboard, monitor, mouse
3) Set any http, https proxies
4) Get an ITunes account
5) Enter into an IOS developer agreement
6) Download Xcode
7) Get an iTunes Connect account and sign up for iOS Free and iOS Paid
     - fill out paid app legal forms
     - fill out banking info
8) Get some iOS and Objective C books
9) Start learning or transitioning to the unique syntax of Objective C
10) Leverage your knowledge of ORM and Rest
11) get apache Cordova / PhoneGap 2.2 and repackage your HTML 5 applications



You will need a Rest backend server - preferably on  Oracle Cloud, Google AppEngine or Amazon EC2.
https://cloud.oracle.com/mycloud/f?p=service:home:0
https://console.aws.amazon.com/ec2/home?region=us-east-1#s=Instances
http://blog.restbackup.com/2011/01/how-to-use-amazon-ec2-as-your-desktop.html

101) A year later when your provisioning profile is near expiration - purchase a new one (I was not able to update it).
102) If you upgrade your device past what your iOS SDK is at (IE: iOS 6.1 on my iPhone 4s but Xcode 4.5 - not 4.6 for  6.1) you need to upgrade the XCode dev environment as well.
https://developer.apple.com/devcenter/ios/index.action#downloads
103) When you upgrade to using a proper Macbook Pro - install a new copy of XCode 4.6 and re-setup your provisioning and developer profiles.
104) fix for "valid signing identity not found" is to refresh in the provisioning profile tab of the organizer

105) renaming GUI elements - see p.54 of Beginning iOS 6 Development
ctrl drag ui element to controller.h file to name it and create a IBOutlet wrapper



My first hello world collate program in Objective C
#import 
#include 

int main(int argc, const char * argv[]) {

    @autoreleasepool {
        int64_t current = 0;
        int64_t maxValue = 0;
        int maxPath = 0;
        int path = 0;
        int64_t max; // 64 bit signed integer, like Java's long
        for (int64_t i=27; i<(1 << 30); i+=2) {
            current = i;
            path = 0;
            while (current > 1) {
                 if (current % 2 == 0) {
                    current = current >> 1;
                    
                } else {
                    current = 1 + current + (current << 1);
                }
                path++;
                if(max < current) {
                    max = current;
                }
            }
            bool maxSet = false;
            if(maxValue < max) {
                maxValue = max;
                maxSet = true;
            }
            if(maxPath < path) {
                maxPath = path;
                maxSet = true;
            }
            if(maxSet) {
                NSLog(@"%lld: %lld: %i",i, max, path);
            }
        }
    }
    return 0;
}

Monday, October 17, 2011

Android Development

Android Development

The purpose of this article is to provide minimal quickstart instructions on moving to native thick-client Android development from the perspective of traditional Oracle/SUN Java EE 6 enterprise application development.  We will also discuss how to adjust Java EE 6 applications to be able to run on the Chrome based browser in the Android browser as thin-client front ends.

Development Environment:

1) Download the Eclipse.org Eclipse IDE - use the latest EE 3.7.1 version
http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/indigosr1
2) Download the Android SDK from http://developer.android.com/index.html
- select installer_r16-windows.exe and run it to get the extended libraries online
- leave "Start SDK Manager" selected to download all versions of the Android API
- verify that your proxy is set if you are behind a firewall - and use http substitution for https


3) Update Eclipse with the ADT by adding the following site to Help | Install new software
4) Update Eclipse to point to the Android SDK

5) Load an example project using the new project wizard in Eclipse
6) Run as Android Application to either bring up the Android simulator or deploy to an Android device  or AVD - if one is connected
6b) create a new Android Virtual Device

Get a Google Play merchant account at https://play.google.com/apps/publish/v2/signup/?pli=1

References:
Android Developer Site : http://developer.android.com/index.html

Monday, May 16, 2011

Using the Eclipse IDE

Running multiple workspaces or multiple instances of Eclipse:
You will find the need to identify your workspace - place the -showlocation option before any -product or org.eclipse.platform option.  Here is an example modified eclipse.ini file for a 32 bit Java EE install of Eclipse 3.6.

-startup
plugins/org.eclipse.equinox.launcher_1.1.1.R36x_v20101122_1400.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.2.R36x_v20101222
-showsplash
-showlocation
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
org.eclipse.platform
--launcher.XXMaxPermSize
512m
--launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.5
-clean
-XX:MaxPermSize=256m
-Xms1024m
-Xmx1024m
-XX:+UseParallelGC
-XX:PermSize=256M

Tuesday, May 3, 2011

EclipseLink JPA and Sybase

Q) How do we integrate EclipseLink with Sybase?

Lets start with the persistence unit configuration for a simple Java SE application managed example.
We require access to the JConnect 5.5 JDBC driver jar or Sybase Adaptive Server Enterprise JDBC driver - usually your /sybase/jConnect-6_0/classes/jconn3.jar



  
    org.eclipse.persistence.jpa.PersistenceProvider
    com.oacis.example.jpa.model.BugNumber
    
       
       
      
      
      
       
      
      
      
      

      
      
      
      
       
    
  



Minimal Source - No Transaction code (only a query at thes point) no MVC separation via Locator, ApplicationContext or any EE container managed @Session or @PersistenceContext annotions.

Note: for a complete Java EE 6 distributed application example involving JPA refer to my tutorial page at EclipseLink

public class SEClient {

    // Application managed EMF and EM
    private EntityManagerFactory emf  = null;
    private EntityManager entityManager = null;
    // Reference the database specific persistence unit in persistence.xml
    public static final String PU_NAME_CREATE = "sybase_remote";    
    private List@lt;bugnumber@gt; bugs;
    
    private void initialize(String puName) {
        Metamodel metamodel = null;
        try {
            // Initialize an application managed JPA emf and em via META-INF
            emf  = Persistence.createEntityManagerFactory(puName);
            System.out.println("Metamodel: " + emf.getMetamodel());            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void finalize() {
        // close JPA
        try {
            if(null != entityManager) {
                entityManager.close();
                emf.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public void connect() {
        // JPA 1.0
        Query query = getEntityManager().createQuery("select object(c) from BugNumber c");
        try {
            bugs = query.getResultList();
        } catch (NoResultException nre) {
            System.out.println("_collatz: " + System.currentTimeMillis() + ": server was redeployed mid-session: computeGrid is null");
            
        }
    }
    
 public static void main(String[] args) {
  SEClient client = new SEClient();
  client.initialize(PU_NAME_CREATE);
  client.connect();
 }

    public EntityManagerFactory getEmf() {  return emf; }
 public void setEmf(EntityManagerFactory emf) {  this.emf = emf; }
 
 public EntityManager getEntityManager() {
        if(null == entityManager) {
            entityManager = emf.createEntityManager();
        }
        return entityManager;
 }
 
 public void setEntityManager(EntityManager entityManager) {  this.entityManager = entityManager; } 
}


@Entity
@Table(name="JPA_BUGNUMBER")
public class BugNumber implements Serializable {
    private static final long serialVersionUID = 3132063814489287035L;

    @Id
    // keep the sequence column name under 30 chars to avoid an ORA-00972   
    @SequenceGenerator(name="JPA_SEQUENCE_BUGN", sequenceName="JPA_BUGN_SEQ", allocationSize=15)
    @GeneratedValue(generator="JPA_SEQUENCE_BUGN")
    @Column(name="BUG_ID")    
    private Long id;

    @Version
    @Column(name="BUG_VERSION")
    private int version;
    
    @Basic
    private long number;
    private int priority;
    private boolean assignedStatus;
    private String assignedTo;
    
    public BugNumber() {            }
    
    public BugNumber(String aNumber) {
        number = Integer.parseInt(aNumber);
    }
    
    public char[] getCharDigits() {
        return Long.toString(number).toCharArray();
    }
    
    public List getIntDigits() {
        List digits = new ArrayList();
        for(Character aChar : getCharDigits()) {
            digits.add(new Integer(Character.getNumericValue(aChar.charValue())));            
        }
        return digits;
    }
    
    public int getLastDigit() {
        List numbers = getIntDigits();        
        return numbers.get(numbers.size() - 1);
    }
    
    public long getNumber() {        return number;    }
    public void setNumber(long number) {        this.number = number;    }
    public int getPriority() {        return priority;    }
    public void setPriority(int priority) {        this.priority = priority;    }
    public boolean isAssignedStatus() {        return assignedStatus;    }
    public void setAssignedStatus(boolean assignedStatus) {        this.assignedStatus = assignedStatus;    }
    public String getAssignedTo() {        return assignedTo;    }
    public void setAssignedTo(String assignedTo) {        this.assignedTo = assignedTo;    }
    public Long getId() {        return id;    }
    public void setId(Long id) {        this.id = id;    }
    public int getVersion() {        return version;    }
    public void setVersion(int version) {        this.version = version;    }
    
}


Console Log output:
EL Finest]: 2011-05-03 09:46:19.777--ServerSession(27379847)--Thread(Thread[main,5,main])--Begin predeploying Persistence Unit sybase_remote; session file:/D:/wse/view_w36b/com.corp.example.jpa.SEClient/bin/_sybase_remote; state Initial; factoryCount 0
[EL Finest]: 2011-05-03 09:46:19.792--ServerSession(27379847)--Thread(Thread[main,5,main])--property=eclipselink.orm.throw.exceptions; default value=true
[EL Finest]: 2011-05-03 09:46:19.824--ServerSession(27379847)--Thread(Thread[main,5,main])--property=eclipselink.jpa.uppercase-column-names; default value=false
[EL Finer]: 2011-05-03 09:46:19.824--ServerSession(27379847)--Thread(Thread[main,5,main])--Searching for default mapping file in file:/D:/wse/view_w36b/com.corp.example.jpa.SEClient/bin/
[EL Finer]: 2011-05-03 09:46:19.839--ServerSession(27379847)--Thread(Thread[main,5,main])--Searching for default mapping file in file:/D:/wse/view_w36b/com.corp.example.jpa.SEClient/bin/
[EL Config]: 2011-05-03 09:46:19.964--ServerSession(27379847)--Thread(Thread[main,5,main])--The access type for the persistent class [class com.corp.example.jpa.model.BugNumber] is set to [FIELD].
[EL Config]: 2011-05-03 09:46:19.996--ServerSession(27379847)--Thread(Thread[main,5,main])--The alias name for the entity class [class com.corp.example.jpa.model.BugNumber] is being defaulted to: BugNumber.
[EL Config]: 2011-05-03 09:46:20.011--ServerSession(27379847)--Thread(Thread[main,5,main])--The column name for element [field assignedStatus] is being defaulted to: ASSIGNEDSTATUS.
[EL Config]: 2011-05-03 09:46:20.011--ServerSession(27379847)--Thread(Thread[main,5,main])--The column name for element [field priority] is being defaulted to: PRIORITY.
[EL Config]: 2011-05-03 09:46:20.011--ServerSession(27379847)--Thread(Thread[main,5,main])--The column name for element [field assignedTo] is being defaulted to: ASSIGNEDTO.
[EL Config]: 2011-05-03 09:46:20.011--ServerSession(27379847)--Thread(Thread[main,5,main])--The column name for element [field number] is being defaulted to: NUMBER.
[EL Finest]: 2011-05-03 09:46:20.011--ServerSession(27379847)--Thread(Thread[main,5,main])--End predeploying Persistence Unit sybase_remote; session file:/D:/wse/view_w36b/com.corp.example.jpa.SEClient/bin/_sybase_remote; state Predeployed; factoryCount 0
[EL Finer]: 2011-05-03 09:46:20.011--Thread(Thread[main,5,main])--JavaSECMPInitializer - transformer is null.
[EL Finest]: 2011-05-03 09:46:20.011--ServerSession(27379847)--Thread(Thread[main,5,main])--Begin predeploying Persistence Unit sybase_remote; session file:/D:/wse/view_w36b/com.corp.example.jpa.SEClient/bin/_sybase_remote; state Predeployed; factoryCount 0
[EL Finest]: 2011-05-03 09:46:20.011--ServerSession(27379847)--Thread(Thread[main,5,main])--End predeploying Persistence Unit sybase_remote; session file:/D:/wse/view_w36b/com.corp.example.jpa.SEClient/bin/_sybase_remote; state Predeployed; factoryCount 1
[EL Finest]: 2011-05-03 09:46:20.027--ServerSession(27379847)--Thread(Thread[main,5,main])--Begin deploying Persistence Unit sybase_remote; session file:/D:/wse/view_w36b/com.corp.example.jpa.SEClient/bin/_sybase_remote; state Predeployed; factoryCount 1
[EL Finer]: 2011-05-03 09:46:20.042--ServerSession(27379847)--Thread(Thread[main,5,main])--Could not initialize Validation Factory. Encountered following exception: javax.validation.ValidationException: Unable to find a default provider
[EL Finest]: 2011-05-03 09:46:20.042--ServerSession(27379847)--Thread(Thread[main,5,main])--property=eclipselink.logging.level; value=ALL; translated value=ALL
[EL Finest]: 2011-05-03 09:46:20.042--ServerSession(27379847)--Thread(Thread[main,5,main])--property=eclipselink.logging.level; value=ALL; translated value=ALL
[EL Finest]: 2011-05-03 09:46:20.042--ServerSession(27379847)--Thread(Thread[main,5,main])--property=javax.persistence.jdbc.user; value=dblfwk
[EL Finest]: 2011-05-03 09:46:20.042--ServerSession(27379847)--Thread(Thread[main,5,main])--property=javax.persistence.jdbc.password; value=xxxxxx
[EL Finest]: 2011-05-03 09:46:20.292--ServerSession(27379847)--Thread(Thread[main,5,main])--property=eclipselink.target-database; value=Sybase; translated value=org.eclipse.persistence.platform.database.SybasePlatform
[EL Finest]: 2011-05-03 09:46:20.292--ServerSession(27379847)--Thread(Thread[main,5,main])--property=javax.persistence.jdbc.driver; value=com.sybase.jdbc3.jdbc.SybDriver
[EL Finest]: 2011-05-03 09:46:20.292--ServerSession(27379847)--Thread(Thread[main,5,main])--property=javax.persistence.jdbc.url; value=jdbc:sybase:Tds:server:5000
[EL Info]: 2011-05-03 09:46:20.308--ServerSession(27379847)--Thread(Thread[main,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.1
[EL Config]: 2011-05-03 09:46:20.308--ServerSession(27379847)--Connection(13366030)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(
 platform=>SybasePlatform
 user name=> "user"
 datasource URL=> "jdbc:sybase:Tds:server:5000"
))
[EL Config]: 2011-05-03 09:46:20.433--ServerSession(27379847)--Connection(29194312)--Thread(Thread[main,5,main])--Connected: jdbc:sybase:Tds:server:5000
 User: user
 Database: Adaptive Server Enterprise  Version: Adaptive Server Enterprise/15.x/*/Fri *
 Driver: jConnect (TM) for JDBC (TM)  Version: jConnect (TM) for JDBC(TM)/6.0x* 2010
[EL Finest]: 2011-05-03 09:46:20.433--ServerSession(27379847)--Connection(29194312)--Thread(Thread[main,5,main])--Connection acquired from connection pool [default].
[EL Finest]: 2011-05-03 09:46:20.433--ServerSession(27379847)--Connection(29194312)--Thread(Thread[main,5,main])--Connection released to connection pool [default].
[EL Finest]: 2011-05-03 09:46:20.449--ServerSession(27379847)--Thread(Thread[main,5,main])--sequencing connected, state is NoPreallocation_State
[EL Finest]: 2011-05-03 09:46:20.449--ServerSession(27379847)--Thread(Thread[main,5,main])--sequence JPA_BUGN_SEQ: preallocation size 15
[EL Info]: 2011-05-03 09:46:20.48--ServerSession(27379847)--Thread(Thread[main,5,main])--file:/D:/wse/view_w36b/com.o.example.jpa.SEClient/bin/_sybase_remote login successful
[EL Finest]: 2011-05-03 09:46:20.761--ServerSession(27379847)--Thread(Thread[main,5,main])--Execute query DataModifyQuery(sql="DROP TABLE JPA_BUGNUMBER")
[EL Finest]: 2011-05-03 09:46:20.761--ServerSession(27379847)--Connection(29194312)--Thread(Thread[main,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2011-05-03 09:46:20.761--ServerSession(27379847)--Connection(29194312)--Thread(Thread[main,5,main])--DROP TABLE JPA_BUGNUMBER
[EL Fine]: 2011-05-03 09:46:20.824--ServerSession(27379847)--Thread(Thread[main,5,main])--SELECT 1
[EL Finest]: 2011-05-03 09:46:20.824--ServerSession(27379847)--Connection(29194312)--Thread(Thread[main,5,main])--Connection released to connection pool [default].
[EL Warning]: 2011-05-03 09:46:20.824--ServerSession(27379847)--Thread(Thread[main,5,main])--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.1: org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.sybase.jdbc3.jdbc.SybSQLException: Cannot drop the table 'JPA_BUGNUMBER', because it doesn't exist in the system catalogs.

Error Code: 3701
Call: DROP TABLE JPA_BUGNUMBER
Query: DataModifyQuery(sql="DROP TABLE JPA_BUGNUMBER")
[EL Finest]: 2011-05-03 09:46:20.824--ServerSession(27379847)--Thread(Thread[main,5,main])--Execute query DataModifyQuery(sql="CREATE TABLE JPA_BUGNUMBER (BUG_ID NUMERIC(19) IDENTITY NOT NULL, ASSIGNEDSTATUS BIT default 0 NOT NULL, ASSIGNEDTO VARCHAR(255) NULL, NUMBER NUMERIC(19) NULL, PRIORITY INTEGER NULL, BUG_VERSION INTEGER NULL, PRIMARY KEY (BUG_ID))")
[EL Finest]: 2011-05-03 09:46:20.824--ServerSession(27379847)--Connection(29194312)--Thread(Thread[main,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2011-05-03 09:46:20.839--ServerSession(27379847)--Connection(29194312)--Thread(Thread[main,5,main])--CREATE TABLE JPA_BUGNUMBER (BUG_ID NUMERIC(19) IDENTITY NOT NULL, ASSIGNEDSTATUS BIT default 0 NOT NULL, ASSIGNEDTO VARCHAR(255) NULL, NUMBER NUMERIC(19) NULL, PRIORITY INTEGER NULL, BUG_VERSION INTEGER NULL, PRIMARY KEY (BUG_ID))
[EL Finest]: 2011-05-03 09:46:20.933--ServerSession(27379847)--Connection(29194312)--Thread(Thread[main,5,main])--Connection released to connection pool [default].
[EL Finer]: 2011-05-03 09:46:20.949--ServerSession(27379847)--Thread(Thread[main,5,main])--Canonical Metamodel class [com.corp.example.jpa.model.BugNumber_] not found during initialization.
[EL Finest]: 2011-05-03 09:46:20.949--ServerSession(27379847)--Thread(Thread[main,5,main])--End deploying Persistence Unit sybase_remote; session file:/D:/wse/view_w36b/com.corp.example.jpa.SEClient/bin/_sybase_remote; state Deployed; factoryCount 1
Metamodel: MetamodelImpl@31706449 [ 6 Types: , 1 ManagedTypes: , 1 EntityTypes: , 0 MappedSuperclassTypes: , 0 EmbeddableTypes: ]
[EL Finer]: 2011-05-03 09:46:21.136--ServerSession(27379847)--Thread(Thread[main,5,main])--client acquired: 3916915
[EL Finer]: 2011-05-03 09:46:21.152--ClientSession(3916915)--Thread(Thread[main,5,main])--acquire unit of work: 19647819
[EL Finest]: 2011-05-03 09:46:21.152--UnitOfWork(19647819)--Thread(Thread[main,5,main])--Execute query ReadAllQuery(referenceClass=BugNumber sql="SELECT BUG_ID, ASSIGNEDSTATUS, ASSIGNEDTO, NUMBER, PRIORITY, BUG_VERSION FROM JPA_BUGNUMBER")
[EL Finest]: 2011-05-03 09:46:21.152--ServerSession(27379847)--Connection(29194312)--Thread(Thread[main,5,main])--Connection acquired from connection pool [default].
[EL Fine]: 2011-05-03 09:46:21.152--ServerSession(27379847)--Connection(29194312)--Thread(Thread[main,5,main])--SELECT BUG_ID, ASSIGNEDSTATUS, ASSIGNEDTO, NUMBER, PRIORITY, BUG_VERSION FROM JPA_BUGNUMBER
[EL Finest]: 2011-05-03 09:46:21.152--ServerSession(27379847)--Connection(29194312)--Thread(Thread[main,5,main])--Connection released to connection pool [default].

Thursday, March 3, 2011

Object Relational Mapping

 
    A question by C. J. Date in point #1 on page 81 chapter 5 "Relational Algebra" of the 2005 book : "Database In Depth - Relational Theory for Practitioners" has caught my attention. I quote:

"First, the operators are generic; they apply, in effect, to all possible relations. For example, we don't need one specific join operator to join employees and departments and another, different join operator to join suppliers and shipments. (Incidentally, do you think ano analogous observation applies to object-oriented systems?)" 

I would like to comment on this shortly

Saturday, February 5, 2011

JEE6 Tutorial for a Distributed Enterprise Application incorporating EJB 3.1, JPA 2.0, JSF 2.0, Servlet 3.0 and JAX-RS on Oracle GlassFish Server 3.1

20110209: This tutorial has widened in scope and is being developed at the following URL.
http://wiki.eclipse.org/EclipseLink/Examples/Distributed

    This tutorial describes the analysis, design, implementation and deployment of a distributed JEE6 application that makes use of the EJB 3.1, JPA 2.0, JSF 2.0, Servlet 3.0 and JAX-RS API implemented as part of the Oracle GlassFish Server 3.1 distribution.  The Java IDE used for this tutorial is the tightly integrated SUN NetBeans 7.0 release that will be in beta until April 2011.

Technology Summary:
    Normally we do not decide on what APIs will be in use before we analyse the requirements.  However, here is the list of technologies we are using - as we finalize the implementation.

Problem:
    The Collatz conjecture or (3n + 1) problem is currently not proved.  There have been attempts at verifying collatz up to 2^61 - however, massive amounts of scalar processing power is required to do this because the problem is non-linear and therefore must be brute force simulated even with optimizations.

    The algorithm is as follows for the set of positive integers to infinity.
  • odd numbers are transformed by 3n + 1
  • even numbers are divided by 2
    If you think in base 2, we see that for odd numbers we shift bits to the left, add the number to the result and set bit 0.   For even numbers we shift bits to the right.  We therefore have a simplified algorithm as follows.
  • odd: next binary = number << 1 + number + 1
  • even: next binary = number >> 1

    Observation 1: the maximum value remains at or around 2x the number of bits in the start number - at least so far in my own simulations up to 640 billion. 

    We stop iteration and record the max path and max value when the sequence enters the 4-2-1 loop after the first 1 is reached.  This sequence must be simulated for all positive integers up to the limit of the software being used.  Fortunately, in Java (and .NET3) we can use BigInteger which supports unlimited length integers - as we would quickly overflow using a 64 bit long as soon as we started iterating numbers over 32 bits.

    Observation 2: I have determined - via a week of simulation distributed among 16 different machines in parallel  - that we will need native computation. 

Requirements:

Analysis:

Use Cases:

Design:

Data Model:
    The following UML class diagram details the data model for the business objects.  We will be using JPA entities and mappedsuperclass artifacts.
Figure 1-1: UML Class Diagram - Data Model


Implementation:

Deployment:

References:


/ Michael O'Brien 20110205

Total Pageviews

Followers