Tuesday, December 07, 2010

Setting up usb modem for ubuntu 10.10

If you want to setup the drivers for your usb modem, firstly check out this link. It shows the list of 3G hardware and the test result along with the necessary information.
In my case, I have Option Wireless iCON 225 (HSDPA) and I'm quite lucky to have mine listed as working and there's enough information for preparing the drivers.

Here's the summary of how I prepare the drivers:
1. Download and compile ozerocdoff --> udev.tar.gz (http://www.pharscape.org/ozerocdoff.html)
2. Skip installing hso driver kernel module since my kernel version is 2.6.35 (which is above or equal 2.6.31) --> http://www.pharscape.org/hso.html
3. Install HSOConnect (http://www.pharscape.org/hsoconnect.html) which requires hsolinkcontrol (http://www.peck.org.uk/hsolinkcontrol.html). And it turns out it just didn't work for me and I opt to use the default Network Manager.
4. Check if all works fine:
- Make sure hso module is already installed
find /lib/modules/`uname -r` -name 'hso.ko'
- Plug in the usb modem device and execute command below
lsmod | grep hso
If you see that hso is listed that's a good sign for you
- Check if the ports have been created
ls /dev/ttyHS*
My output is: /dev/ttyHS0 /dev/ttyHS1 /dev/ttyHS2
If you can see the output that also means ozerocdoff is already working
5. Go to my Network Manager, edit connections and add a new Mobile broadband connection.

6. Go online with my new broadband connection :)


References:
  1. Network Manager - Hardware 3G (https://wiki.ubuntu.com/NetworkManager/Hardware/3G)
  2. PHARscape iCon 255 (http://www.pharscape.org/icon225.html)
  3. ozerocdoff (http://www.pharscape.org/forum/index.php?topic=545.0)
  4. HSOConnect (http://www.pharscape.org/forum/index.php/topic,743.0.html)
  5. Using Network Manager (http://www.pharscape.org/networkmanager-0.7.0-and-3g-wwan-modems.html)

Saturday, December 04, 2010

Aspire 4741z battery is not charging

If a battery is not charging then the cause is either the battery is broken or the charging module needs replacement or could be BIOS problem. In my case the cause is neither above, apparently after taking out my battery I just realized that somehow I left the lock switch to unlock position. And indeed that's the cause of the battery is not charging.

Friday, December 03, 2010

Configuring mic in aspire 4741z - ubuntu 10.10

Luckily for me, my installed alsa is already the latest one. All that is needed is just to add 2 lines below to /etc/modprobe.d/alsa-base.conf

alias snd-card-0 snd-hda-intel
options snd-hda-intel model=acer


My mic works now but it seems a bit quiet. Hopefully I can find the way to boost the mic.

A nice tool that might help is alsamixer, run it from a terminal.

Tuesday, November 30, 2010

Ubuntu 10.10 brightness problem in Acer Aspire 4741

To those who have problem with brightness configuration after installing Ubuntu 10.10 and you are using Acer Aspire 4741, here's a solution for you:
  1. sudo gedit /etc/default/grub
  2. Change the line GRUB_CMDLINE_LINUX="" into
    GRUB_CMDLINE_LINUX="acpi_osi=Linux"
  3. sudo update-grub
  4. Restart your linux

Hopefully it helps.

Tuesday, October 19, 2010

Spring security core build path problem

First time trying Grails 1.3.5, creating a new test project. Installing spring-security-core plugin (following the tutorial) and then importing the project to STS 2.5M1 and letting STS know that it's a Grail project (Configure->Convert to a Grails project... something like this). I was hoping for an easy ride here, expecting no errors since I haven't add anything, all are auto generated.

But as usual, with programming world, there ain't no such things as a bug/error free codes. I got compile errors like this in my LoginController.groovy.



I know that I'm missing org.springframework.security.core-3.0.3.RELEASE.jar release in this case and the shortcut to solve this is just to add the jar to the project build path. But, is this going to happen for each plugin jar that I'm going to use? and anyway I don't like the solution to put the jar manually on the build path, it does look an ugly solution.

Fortunately I find a menu to refresh Grails' dependencies and the good news is it works for me, no more compile errors. Here's the context menu that pops up when I right click on my project:



I think this is caused by me adding the plugin from command prompt and then importing the project in STS. Imho, if the plugin is added thru STS' grails command prompt it should works without refreshing.

Hmm... just remember that this is similar to when I add a new file to my project using my file manager. Eclipse can't see the file, until I refresh the project.

Tuesday, September 14, 2010

Using hibernate generated collection in h:dataTable

It's a bit difficult to pick the correct title for the thing that I'm going to write :) It's about having your POJO generated by hibernate and then feed it to h:dataTable.

When your object has a collection properties and the elements contained are unique within the collection, hibernate will create a Set to contains it. The thing with a Set is h:dataTable just can't accept it. The simplest solution is to change Set to Collection object and h:dataTable can accept it and Hibernate won't complain about it :)

Rolling back transaction (Seam managed transaction)

JSF+Seam is what I'm learning at the moment. And the case is I need to rollback the transaction due to business exception but I don't want to not catch the transaction (when a runtime exception is uncaught the transaction will be rollback automatically). The business exception here is a new exception class extending RuntimeException.

At first try, I add ApplicationException annotation with rollback = true in my BusinessException class. The controller class which invokes the business service class and under certain condition an exception of BusinessException type is thrown. In my scenario my transaction should be rolled back, the thing is... it was not rolled back.

This forced me to dive into seam's code (that's why I love open source) and find out how to handle the transaction. And I came into Transaction class, which I can use to do what I want.
Here's how to use it to mark the transaction as rollback:

Transaction.instance().rollback();

Actually all I wish is when the exception is thrown by the service class (already registered to seam) the transaction will be rolled back automatically, unfortunately for me it doesn't work :(

Entity inheritance-single table per class hierarchy strategy with JPA + Hibernate

I happened to have the chance to implement entity inheritance using single table per class hierarchy strategy. At first I though I would sail smooth and arrive at the promised land easily :) but as usual with programming, it is a rare thing a code would sail smooth at the first time.
Persisting entity works like charm, retrieving it makes me speechless. Here's an example:

The base class (ItemReference)


Subclass#1 (ItemReferenceAge)


Subclass#2 (ItemReferenceSex)


DDL


One class that I don't include here is the class which has a collection of ItemReferenceSex and a collection of ItemReferenceAge, let's call this class Wrapper.

The scenario is I add 2 instances of ItemReferenceAge to wrapper collection and persisted it. What happened when I try to load the same wrapper instance is both collections are having elements in them. Remember, I only add ItemReferenceAge instance which means the collection of ItemReferenceSex should be empty.
Looking at the query generated shows that the discriminator column is not used in the where clause of the select query. What I can think of the design reasoning is that it is assumed that there will not be two or more type of instances loaded in the same parent object which in my case it is.
Luckily for me, there's a solution for this and unfortunately it's hibernate specific annotation (is it maybe because of JPA doesn't state how to handle my case or is it hibernate implementation?). All I need to do is to add ForceDiscriminator annotation in my base class and the problem is solved!

Thursday, August 19, 2010

Eclipse fails to start?

Your eclipse fails to start? actually we could say your workspace fails to start. I've gone through it several times and my solution was to create a new workspace and import the existing projects into the new workspace.
However, this time I'm trying to solve it once for all (as though it's possible :). Googled around and I found, imho, a rough solution that works for me. It's as simple as deleting org.eclipse.core.resources folder inside {workspace}/.metadata/.plugins and then run eclipse -clean.
The result is eclipse is working but I still have to import the existing projects back. The good thing is I don't lost all the preferences and server setting (though I could just import the preferences file I once exported).

Check the link on the title and also this one, tools from eclipse team that maybe could help with the broken workspace (I never tried it yet... my workspace already fixed :)

Tuesday, August 17, 2010

A bit on classloader

At first glance, I thought java could face the same problem as dll was (dll hell). But then classloader scoping comes to the rescue. And by the way, I won't explain the theory of classloading here. By having classloader scope set to the application, it will allow each application to bring their own libraries without worrying of library conflict.

For example, I built a library of common utilities and there are already 2 versions of it. And 2 of my web applications are using the library, however each with a different versions from the other. If the flat classloading is used, only one of the 2 versions of the library will be used and the impact is the web application which used the version not loaded will have strange errors such as ClassCastException, IllegalAccessErrors and possibly many others. Having classloader scoping will allow each of my web application to use its respective library.

One thing cross my mind, how could I have a smaller deployment size for a web application and still having the classloader scoping. Smaller deployment size here refers to my classes only without the whole bunch of libraries. Usually when people delivers a patch for the web application, all is packed in war file which size is quite large. On my case, the library size are around 80% of the war file size. Up to now, all I can do is to deploy the application as exploded. Thus allowing me to deploy patches by replacing the content/libraries. Not an elegant solution but still a viable one, until I can find a nicer solution.....

Sunday, August 15, 2010

Initialize static List and Map

If you intend to create a List or Map for your constants, here's how you do it.

List

public static String CONSTANT_1 = "1";
public static String CONSTANT_2 = "2";

public static List CONSTANTS = new ArrayList() { {
add(CONSTANT_1);
add(CONSTANT_2);
}};


Map


public static Map CONSTANTS = new HashMap() { {
put("key1", "value1");
put("key2", "value2");
}};


Even better is to wrap the ArrayList/HashMap by passing them to Collections.unmodifiableList or Collections.unmodifiableMap. Thus making sure that it is truly a constant list/map.

Wednesday, July 28, 2010

How to search for column reference in oracle

Imagine that you need to find out which code update a column in a table. Some developer tools could point out who refers to the table but so far I couldn't find the one that could answer my need.

All_source comes to the rescue, I'd say that it is a special view that holds all the database objects accessible by the user.

Here is the description on the view's columns:
OWNER VARCHAR2(30) NOT NULL Owner of the object
NAME VARCHAR2(30) NOT NULL Name of the object
TYPE VARCHAR2(12)
Type of object: FUNCTION, JAVA SOURCE, PACKAGE, PACKAGE BODY, PROCEDURE, TRIGGER, TYPE, TYPE BODY
LINE NUMBER NOT NULL Line number of this line of source
TEXT VARCHAR2(4000)
Text source of the stored object

Example:
I need to find out who refers to column FK_USER.

select * from all_source where text like '%FK_USER%'

And I will get all the places which have reference to FK_USER.

If you would take it further, you could utilize it for searching almost anything (e.g. comments in the code, TODO tag, exception).

... wondering if there're more "magical" view like this.

Saturday, July 24, 2010

Retrieving generic's Class type

Quite few times I've been using generic and I needed the Class type. I found out that I've to pass the class type instead of extracting the class type from the type parameter. This story comes to an end when I found out a way to extract the type, thanks to Type interface :)

Here's the recipe:
- First extract the genericSuperclass
- Retrieve the actual type arguments

.. and the code is:
ParameterizedType type = (ParameterizedType) getClass().getGenericSuperclass();
Class classType = (Class) type.getActualTypeArguments()[0];

ParameterizedType represents an invocation of a generic class or interface, better explanation could be read in the javadoc.

That's all... :)

Saturday, June 12, 2010

Knowing the exact location of error in your jsp

Actually it's been several times I have to deal with error happening during jsp rendering. To be more exact, the error doesn't lie in the jsp page but in the content prepared before rendering the jsp. Usually what I do is just removing part by part of the jsp page until I can locate the part that caused the rendering error. I keep on doing it until I remember that during page rendering a buffer is used and the buffer size itself is configurable.

Here's in short of how to do it:
- Insert the following page direction to the top of the jsp page
<%@ page buffer="none" %>
- Try to open the page again in the browser and view the source
- The last position of the source page will show exactly the position of the error, i.e. the position before the source of the error
- After you've managed to fix the error, don't forget to remove the page directive. It will certainly degrade the performance if you leave it there

Tuesday, April 27, 2010

Configuring static IP in Fedora

If all you have is a CLI, then you might find this to be of benefit. Otherwise you could just use the Network Device Control GUI.

Here are the steps:
  1. Execute ifconfig and find out your ethernet configuration name (e.g. eth0)
  2. Go to /etc/sysconfig/network-script
  3. edit ifcfg-eth0 (depends on your ethernet)
  4. Update the file as follow (set the IPADDR, BROADCAST according to your desired configuration)

  5. Restart the network service
    service network restart

Here's a brief explanation on the configuration:
  • BOOTPROTO : telling the network that we're configuring it as static ip
  • ONBOOT : the configuration will be set at boot time
  • BROADCAST : your gateway
  • NETMASK : your netmask


.