Monday, January 31, 2011

Getting back into Java

What a day! I've been doing some Java dev again and its amazing to struggle with the differences between PHP and Java. Although I originally started with C/Java I've really become almost lazy in some of my PHP practices. PHP being a 'scripting' language makes life easy as you don't have to cast everything in a 'type'. You also don't need to use good OO, which I guess you could say is a down side.

During my exploration with Java over the last couple of days I've come across a couple of problems and solution that I thought I'd write about here.

First problem that cropped up was that Eclipse kept on crashing. Some really weird error but after a bit of Googling I found the solution. Basically the problem was causing by having two versions of xulrunner installed. A quick 'sudo dpkg --remove xulrunner-1.9.1' got the problem sorted. Here's a ref to some a posting about it: https://bugs.eclipse.org/bugs/show_bug.cgi?id=303372 and http://www.eclipse.org/forums/index.php?t=msg&goto=539642&

Second thing I decide to do was give Eclipse some more memory, by changing my run.sh to ./eclipse -vmargs -Xms1024m -Xmx1024m  -XX:PermSize=256m  -XX:MaxPermSize=512m

Next error I run into was Eclipse moaning about Jboss taking too long to start. So had to edit Jboss setting for this. Here's a screen shot on where to find the setting:

Basically you need to right click on the server in the button pane to bring up these properties. I also find it very difficult to find the correct settings for stuff in Eclipse.

Next thing I needed a bit of an update on was Vectors. Well I've been using Vectors for a while and they seem a bit clunky. So I decided to check out ArrayLists. The nice thing with ArrayLists is that they are quicker than Vectors and I found a really cool one liner to convert an ArrayList back to String array.

String[] yourArray = (String[])yourList.toArray(new String[yourList.size()]);

This also works for any other object type.

Ok, on to the next thing. JSON. So I've been playing with JSON and JQuery for awhile but never used it in Java. I first tried to use the standard JSON libraries but found them a bit of a pain. Then I found Gson (http://code.google.com/p/google-gson/). This worked much better and I was able to convert my Object array to JSON with two lines of code:

Gson gson = new Gson();       
String json = gson.toJson(resources);


Ok next thing I found out was really crazy. It took me about an hour to troubleshoot what the heck was going on here. So the reason I'm doing all this Java dev is so that I can plug a custom approval form into Novell's Roles Based Provisioning Module (RBPM). The only thing they don't tell you in this really cool article (http://www.novell.com/communities/node/9210/using-jquery-identity-manager-roles-based-provisioning-module-workflow-forms) is that if you use a HTML field type, the content of the HTML is obtained only after the page is loaded. Which results in alot of fun and games when using JQuery with dynamic content thats not on the page when .ready() function runs. So for now I would highly recommend make use of the TEXT field type in RBPM. This field is loaded already on the page and no .live() Jquery is required. I do however recommend using .live() when re-writing a page with Jquery and needed to keep track of changing items.

Any way think thats more than enough for one day.

Cheers.

Tuesday, January 25, 2011

Listen to Radio 702 on Ubuntu

Just use this one simple command:

mplayer mms://196.35.64.36/702_16

Wednesday, January 19, 2011

Oracle and PHP

Today seems to be the day the Oracle DB in Dev would start giving problems. I was running an SQL command from my PHP script, but it was never returning results. The SQL was an update command. I found this very strange as I could run the exact same command in Oracle SQL Developer. After alot of hair pulling I found that Oracle SQL Developer had a 'lock' on the table where I was trying to run the update SQL command. Once I closed // committed the outstanding transaction in SQL Developer my PHP script run fine. The problem I have however identified here is that there does not seem to be any may using the OCI library with PHP to put a time limit on the SQL query (more digging required). So I guess for now I may try putting a limit on the PHP script, but I'm really hoping there's some way to put a time limit on the SQL query to Oracle from PHP.

Followers