JavaChap Blog Java and Technology musings for the masses


ExtJS Fix for Selection model returning wrong record when Grouping feature is enabled

The selection model of grid returns random record using getSelection() method when grouping feature is enabled, In order to fix this issue i added the following code in app.js.

 * Selection Model returns wrong record when grouping feature is enabled
Ext.define('Ext.overrides.view.Table', {
	override: 'Ext.view.Table',
	getRecord: function(node) {
		node = this.getNode(node);
		if (node) {
	indexInStore: function(node) {
		node = this.getNode(node, true);
		if (!node && node !== 0) {
			return -1;
		return this.dataSource.indexOf(this.getRecord(node));

How to Alias a Host Name on Mac OS X

I Recently moved from Windows to Mac. It wasn't easy. While i'm still getting used to Mac, I decided to document certain things so that it might be useful for other Mac newbies.

In this blog i will explain how to alias a host name on Mac.

All host aliases are configured in a file /etc/hosts. So lets open that file.

  sudo nano /etc/hosts  

Now lets add a new host alias

Save the file by pressing Ctrl + O (^O)

To make sure host is configured properly, we can issue a ping command to the newly configured host.


Just incase if doesn't work, we can flush the cache using dscacheutil

sudo dscacheutil -flushcache

Voila, there you go, you have a new host alias configured.

Tagged as: , No Comments

How I Fixed Battery Life On my Mac Book Pro with Retina Display

After upgrading to Mountain Lion, Battery life of my Mac Book Pro with Retina Display has gone worst. Max that i'm getting is around 4 hours. So today i have decided to fix it. According to the Apple Support Forums we can do fix few things that we can do on software side to fix the battery life.

Delete Corrupted Settings File

Many people have commented that this method has worked and this is a very method and doesn't need a reboot either. Type in the following commands in your terminal.

cd ~/Library/Preferences/
killall Dock


  • Shut down your Mac.
  • Locate the following keys on the keyboard: Command (⌘), Option, P, and R. You will need to hold these keys down simultaneously in step 4.
  • Turn on the computer.
  • Press and hold the Command-Option-P-R keys before the gray screen appears.
  • Hold the keys down until the computer restarts and you hear the startup sound for the second time.
  • Release the keys.

Reset SMC

  • Shut down the computer.
  • Plug in the MagSafe power adapter to a power source, connecting it to the Mac if its not already connected.
  • On the built-in keyboard, press the (left side) Shift-Control-Option keys and the power button at the same time.
  • Release all the keys and the power button at the same time.
  • Press the power button to turn on the computer.  
    : The LED on the MagSafe power adapter may change states or temporarily turn off when you reset the SMC.

I did all the above and now i get 8 hours of battery.

Tagged as: , , No Comments

Space shuttle Endeavour’s trip through the streets of LA

Mission 26 The Big Endeavour from Givot on Vimeo.

Filed under: General No Comments

Script to Backup MySQL and CVS to Amazon S3

Here is a simple script that i wrote to backup mysql and cvs root folder to Amazon S3. For the script to work you need to have S3Sync to be in path.


# Database Configurations
NOW=$(date +_%m_%d_%y)



# tar the cvsroot folder

# list MySQL databases and dump each
DB_LIST=`mysql -u $DB_USER -p"$DB_PWD" -e'show databases;'`
for DB in $DB_LIST;
  mysqldump -u $DB_USER -p$DB_PWD --opt --flush-logs $DB | gzip > $FILENAME

tar czvf $MYSQL_BACKUP_NAME mysql*
rm -f mysql*

cd /opt/s3sync
ruby s3sync.rb -r -v -s --exclude="archieves$|" /opt/s3backup/ $BUCKET:

mv /opt/s3backup/*.gz /opt/s3backup/archieves/


6th Grader and iPhone Application Developer

Not sure which makes me feel like more of a slacker, his mutliple apps in the App Store or his excellent public speaking

Filed under: General No Comments

The 5 Biggest Ways to Boost MySQL Scalability

Sean Hall with some really good MySQL advice:

  1. Tune those queries. Biggest bang for your buck. Enable the slow query log and watch it. Once you've found a heavy resource intensive query, optimize it! Tune what receives real-world traffic.
  2. Employ Master-Master Replication. Immediately have a read-only slave for your application to hit as well.
  3. Use Your Memory. Set innodb_buffer_pool_size, key_buffer_size and other key options.
  4. RAID Your Disk I/O. Use RAID 10 mirroring and striping. On EC2 striping across a number of EBS volumes using the Linux md software raid.
  5. Tune Key Parameters. speeds up inserts & updates with innodb_flush_log_at_trx_commit=2; create a tablespace and underlying datafile for each table with innodb_file_per_table.

Full details at the original article.


Enumeration Mapping in Hibernate

In this simple tutorial i will show you, how to map a Java 5 Enumeration (enum) to a varchar column in Hibernate. The use-case that i'm going to demonstrate is very simple, I have a User class which has a reference to an Enumeration Gender.

Gender Enumeration
package com.javachap.domain.user;
 * Male or Female. Used to customize Account messages (e.g. he or she usage) and
 * to choose the default profile picture.
public enum Gender {
    Male, Female;
User Domain:
package com.javachap.domain.user;

public class User {

    private String firstName;
    private String lastName;
    private Gender gender;
    private String email

     * Gets the <code>User</code>'s firstName
     * @return the firstName
    public String getFirstName() {
        return firstName;

     * Sets the <code>User</code>'s firstName
     * @param firstName the firstName to set
    public void setFirstName(String firstName) {
        this.firstName = firstName;

     * Gets the <code>User</code>'s lastName
     * @return the lastName
    public String getLastName() {
        return lastName;

     * Sets the <code>User</code>'s lastName
     * @param lastName the lastName to set
    public void setLastName(String lastName) {
        this.lastName = lastName;

     * Gets the <code>User</code>'s email
     * @return the email
    public String getEmail() {
        return email;

     * Sets the <code>User</code>'s email
     * @param email the email to set
    public void setEmail(String email) { = email;
Hibernate Mapping (HBM):
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 

  <class table="user" name="com.javachap.domain.user.User">

    <id name="uid" column="usr_uid">
      <generator class="increment"/>

    <property name="firstName" type="java.lang.String" column="usr_first_name"/>

    <property name="lastName" type="java.lang.String" column="usr_last_name" />

    <property name="gender" column="usr_gender" not-null="true">
	  <type name="org.hibernate.type.EnumType">
         <param name="enumClass">com.javaachap.domain.user.Gender</param>
         <param name="type">12</param>

    <property name="email" type="java.lang.String" column="usr_email"/>


By default Hibernate persists the enumeration value as integer in the database when type param is not specified, In order to store the enum display name, we use a param type, which should be pointed to value in java.sql.Types. Since we want to store the enum display name in database we have mapped it to 12 which is equivalent to java.sql.Types.VARCHAR.

Hibernate Annotation Based Mapping:

If you prefer convention over configuration, below is the way to map an enum using annotation.

public class User {

   Gender gender


Java 7’s Fork/Join Framework

Eric Bruno:

Fork/Join is an enhancement to the ExecutorService implementation that allows you to more easily break up processing to be executed concurrently, and recursively, with little effort on your part. It's based on the work of Doug Lea, a thought leader on Java concurrency, at SUNY Oswego. Fork/Join deals with the threading hassles; you just indicate to the framework which portions of the work can be broken apart and handled recursively. It employs adivide and conquer algorithm that works like this in pseudocode (as taken from Doug Lea's paper on the subject):


Understanding Java Weak References

Ethan Nicholas :

I'm sure some of you are grumbling by now, as I'm talking about an API which is nearly a decade old and haven't said anything which hasn't been said before. While that's certainly true, in my experience many Java programmers really don't know very much (if anything) about weak references, and I felt that a refresher course was needed. Hopefully you at least learned a little something from this review.

weak reference, simply put, is a reference that isn't strong enough to force an object to remain in memory. Weak references allow you to leverage the garbage collector's ability to determine reachability for you, so you don't have to do it yourself.