Wednesday, June 22, 2011

Why I bought iPad1 after buying iPad2 ?

I needed a new Touch device for my 2yr old girl, though she already has an iPod Touch but she likes playing games and YouTube on my iPad 2 (bigger screen), so I thought of buying her a new touch device like an iPad.

Following were my requirements and options.

Requirements
  1. Touch device (bigger than iPod) with Toddler games and YouTube.
  2. Liter (Ultra Portable) and Durable (should last an year with ruff usage).
  3. Don't care for - Camera, Multitasking, Big CPU, RAM.
Options


Device                    Price  Weight     Pros / Cons                            
iPad1                       349      680 g       Less expensive then others                          
                                                          Transfer purchased apps from iTunes
                                                          Same OS of iPad2 
                                                          Slower CPU, RAM

iPad2                       499      601 g     Transfer purchased apps from iTunes                                         
                                                          Great User Experience
                                                          $150 Expensive then iPad1

Samsung 10.1          499      599 g     Expensive then iPad1                                  
                                                         New OS to try/learn                                   
                                                          Better CPU, RAM
                                                          Pay for new apps.
                                                          Will I like this as iPad2 ?

Vizio                        349                    Perfect price                                                
                                                         Smaller screen
                                                         New OS to try/learn
                                                         Pay for new Apps
                                         
Xoom                      599                    Price too high

HP TouchPad          499                    15 more days to release
                                                         I can't wait like how I do for Apple products

As you can see iPad1 made more sense to me as their is not much difference in weight with other devices, and is more durable with aluminium casing compare to plastic casing offered by non-Apple and it saves me a sweet $150.

Why I was open for Non-iPad ?
   If you are buying your first touch product you most likely will go for iPad but if you already owns one and is bored of the same good experience and looking for a change then you have interesting options lined up.

Why companies will never sell something serious under 499 ?
I know all non-Apple devices will never be listed cheaper then iPad2 (i.e 499) and they have reasons for this.
Because if they list their products cheaper then iPad's which will show that they have accepted 2nd place and will eventually kill their brand for good so they can't effort to do that and will keep building products with same price until they really beat iPad's or equals. Also looking from $499 point of view its not much to pay for these devices in US though the strategy can differ in other parts of the world.

Suggestion to Non-iPad's
  The other option I feel will make more sense to lure a lot of consumers is to give away at-least $50 App purchase coupons so then they can start locking in these customers and can sell significantly more devices and can also save lot on expensive marketing.


 



Thursday, June 16, 2011

Why companies don't launch Mobile/Touch products at same time in Asia ?


This question came recently in our daily meeting and my colleagues were explaining all the benefits of launching Mobile/Touch Products same time in US and in Asia (China, India, Middle East). These are the few points/advantages of introducing products same time in Asia.
  1. Huge Consumer market ( 600 Millions) and is as mature as US.
  2. People love/admire for great products (Apple, Android, Samsung etc)
  3. Duty/Tax free destinations (Dubai etc)
  4. Seems a very potential market for launching products same time.
So why biggies hold off their product for atleast 6 months before they really enter these markets and some people might argue its because of import/export regulations and shipment on the contrary all these products are assembled in Asia and these companies have bigger footprint in these markets.

People directly involved in these decisions are the right person the give us inside but here is my opinion.

  Brand Building 
     Silicon Valley/USA is the best place to Build Brand cheaply i.e. you don't have to pay for expensive celebs to promote your products and the community is so rich (Intellectually) and and strong (opinion) they can tear down or create buzz (Hype) about a product and the rest of the folks will simply follow the buzz,

  Contrarily you don't want to launch something outside Silicon-Valley (USA) coz the buzz created outside will not reach far enough and will not create much consumer confidence.

I guess all the companies wan't to cheaply build the great brands/products first here and then will be in better shape to move to the rest of the markets.


     

Saturday, June 11, 2011

How to use Jpa Hibernate Lifecycle Events Feature

Consider two possibilities to understand a typical usage and its not about Validation its all about Integration.
   
     1. You wrote a Bug Tracking Application and deployed it at your client, client has a new requirement that when a new bug is created it wants to send its information to other internal System via Web Service.

   2. You wrote an Enterprise Application and a new features requires that when a new Product is added to database via JPA Hibernate its details should be sent to other departments via Web Service call.

And this is where the feature kick-ins.
  We need to design and implement the capability with these features
  1. Scalable (should be able to use separate threat to do its job).
  2. Simple Design and Usable.
  3. Extendable i.e. No procedural junk code.
Consider following design and Code snippet where Manufacturer and Product are JPA Entities and PartnerXNotifier and PartnerYNotifier are Web Service Clients.
   





@EntityListeners({EventListener.class})
@Entity
public class Product implements Serializable {

}


@EntityListeners({EventListener.class})
@Entity
public class Manufacturer implements Serializable {
}

public class EventListener {

    @PrePersist
    public void prePersist(Object object) {
        EventObserver.getIntance().prePersist(object);
    }

    @PostPersist
    public void postPersist(Object object) {
        EventObserver.getIntance().postPersist(object);
    }

    @PreUpdate
    public void preUpdate(Object object) {
        EventObserver.getIntance().preUpdate(object);
    }

    @PostUpdate
    public void postUpdate(Object object) {
        EventObserver.getIntance().postUpdate(object);
    }

    @PreRemove
    public void preRemove(Object object) {
        EventObserver.getIntance().preRemove(object);
    }

    @PostLoad
    public void postLoad(Object object) {
        EventObserver.getIntance().postLoad(object);
    }
}

public class EventObserver {

    private Map<Class, Set<Handler>> map = new HashMap<Class, Set<Handler>>();
    private static final EventObserver observer = new EventObserver();

    private EventObserver() {
    }

    public static EventObserver getIntance() {
        return observer;
    }

    public void clear() {
        map = new HashMap<Class, Set<Handler>>();
    }

    public void loadPropertiesFileOnChange() {
        // Todo  entity_listener.properties from classpath
        // sample file contents
        // Product=com.company.project.PartnerXNotifier
       // Manufacturer=com.company.project.PartnerYNotifier
    }
    public void registerHandler(Class clazz, Handler handler) {
        Set<Handler> handlers = map.get(clazz);
        if (handlers == null) {
            handlers = new HashSet<Handler>();
        }
        handlers.add(handler);
        map.put(clazz, handlers);
    }

    public void prePersist(Object object) {
        Set<Handler> set = map.get(object.getClass());
        for (Handler handler : set) {
            handler.prePersist(object);
        }
    }

    public void postPersist(Object object) {
        Set<Handler> set = map.get(object.getClass());
        for (Handler handler : set) {
            handler.postPersist(object);
        }
    }

    public void preUpdate(Object object) {
    }

    public void postUpdate(Object object) {
    }

    public void preRemove(Object object) {
    }

    public void postLoad(Object object) {
    }
}


public interface Handler {
    public void prePersist(Object object);
    public void postPersist(Object object);
    public void preUpdate(Object object);
    public void postUpdate(Object object);
    public void preRemove(Object object);
    public void postLoad(Object object);
}

public class PartnerXNotifier implements Handler {
    public void prePersist(Object object) {
        // Call the webservice of the partner and pass the object.
    }
    public void postPersist(Object object) {
    }
}

public class PartnerYNotifier extends AbstractHandler {
    @Override
    public void preRemove(Object object) {
        // update partnery webservice 
    }
}

public abstract class AbstractHandler implements Handler {
    public void prePersist(Object object) {}
    public void postPersist(Object object) {}
    public void preUpdate(Object object) {}
    public void postUpdate(Object object) {}
    public void preRemove(Object object) {}
    public void postLoad(Object object) {}
}




Above design can significantly improve by introducing
  •    Generics in Handler
  •    ThreadExecutor in EventObserver
  •    Properly implementing loadPropertiesFileOnChange() to load properties file from multiple    classpath locations
Hope make sense and opens door for seamless integration with other Systems.

Monday, June 6, 2011

JPA Hibernate Lifecycle Callback Events Simple Explanation

Typical Entity Life-cycle

  • Persist   - Creating Entity for the first time.
  • Merge    - Saving detached Entity
  • Load      - Loading Entity from Database
  • Delete    - Deleting Entity from Database


JPA provides total of 6 Annotations for Life-Cycle Callback events.

  1. @PrePersist
  2. @PostPersist
  3. @PreUpdate
  4. @PostUpdate
  5. @PreRemove
  6. @PostLoad


This is how we can use the above annotations.

Solution 1: Defining inside Entity class

Any method can be annotated with one or all annotations, though they should follow these rules.
  1.  Method can have any name
  2.  No parameters
  3.  Return type of void
  4.  Method should not be final or static
  5.  No Checked exceptions should be thrown
  6.  Any annotation can be only used on one method


Example Code Snippet - 1

@Entity
public class Employee implements Serializable {
...

@PrePersist
@PostPersist
@PreUpdate
@PostUpdate
@PreRemove
@PostLoad
public void updateDate() {
    // this method will executed on all the lifecycle events.
}
}

Solution 2 : Using Entity Listeners Classes
This is very nice way of using the annotations. Clean code and same rules from above applies.

Example Code Snippet - 2


@EntityListeners({LastAccessDateListener.class})
public class Employee implements NamedEntity {
...
}

public class LastAccessDateListener {
@PrePersist
@PostPersist
@PreUpdate
@PostUpdate
@PreRemove
@PostLoad
public void updateDate(Employee e) {
  // this method is in totally separate class
}

}

LastAccessDateListener class doesn't have to be annotated or extend any other class.