conversations on all interesting things related to technology and innovation ...

in collaboration with

De-proxying Hibernate objects

Share |

Rishabh Joshi, a product engineer, a friend and a once in a blue-moon blogger, encountered a requirement to create clones of database objects such that even if their relationships get modified the cloning process remains unaffected. Here is his article and the code he wrote for de-proxying hibernate objects and visiting the entire object tree.

The Requirement:

The business requirement was to get an object from the database, create its copy (or clone it), modify the required fields (through-out the object tree), and save as a new row. An, added requirement was, to be able to specify the fields one wants to clone (again, through-out the object tree) and ignore the rest.

Problems faced:

Simple bean copy would not work for us, because, Read more…

Integer Cache in JDK1.5

Share |

Integer Cache is an interesting concept in Java 1.5 that I recently discovered while reading a blog post.

Here is a post on another blog that explains the concept of Caching Integer Objects in detail: Integer Cache in JDK1.5.

Uninformed Search – BFS and DFS

Share |

Breadth first search is a strategy in which root node is expanded first and then all successors are expanded. It means that all the nodes at a given depth are expanded before any other node at the next depth level can be expanded. While expanding the nodes the information of the successors needs to be stored in the memory so that in the next iteration those particular nodes can be expanded.

Binary tree, BFS and DFS traversal

For the given tree the BFS expansion will be :

1 2 3 4 5 6 7 8 9 10 11 12
Read more…

What is Spurious Wakeup

Share |

If a waiting thread wakes up without notify being called it is called Spurious wakeup.
synchronized (obj) {
while (){
obj.wait();
… // Perform action appropriate to condition

}

}

This is the standard idiom to use wait() method. In above scenario if a notify() is sent by any other thread then the condition will not hold and wait() will be skipped. Consider if there is no while loop and some other thread calls notify before wait() is called by this thread, then it may happen that it could wait forever or till next notify is called.

The javadoc of wait method in JDK 5 has also been updated

A thread can also wake up without being notified, interrupted, or timing out, a so-called spurious wakeup. While this will rarely occur in practice, applications must guard against it by testing for the condition that should have caused the thread to be awakened, and continuing to wait if the condition is not satisfied. In other words, waits should always occur in loops.

Src : Effective Java By Joshua Bloch

Lucene basics

Share |

A compilation of some of the basics of Lucene taken from multiple sources.

The various topics include:

- Types of Fields in Lucene Index
- Core Searching classes
- Score Boosting and relevance ranking
- Scoring Algorithm
- Sorting search results
- Handling multiple pages of search results
- Security
- Composition of Segments in Lucene Index
- Debugging lucene indexing process
- Lucene in Alfresco
- Caching
- Good articles on Lucene

Indexing database tables into Solr

Share |

Often when creating web/enterprise applications, there is a requirement to index data from multiple data sources like content management systems and databases .

Here I present a basic strategy to index database data into Solr using a Batch indexing strategy (instead of a realtime one).

Thoughts on Code Review

Share |

A nice code review methodology i discovered recently.

One hour once a week for Code Review Discussion.

Code Review Discussion: would be a meeting with all the team members where they give their feedback when a file is projected onto a screen.

File Selection and Review : 2-3 days before the actual Code Review Discussion the team lead needs to send 3-4 files (different each week) to the team. The team members need to find a few minutes over the 2-3 days everyday to do the review and come to the Code Review discussion with their comments.

What files to select for review: The list of the files should be such that probably one week only server side code is taken up (or may be just controllers or models or taglibs) and one day on the UI stuff like JS files. In this way it becomes a session where the team members start clarifying doubts about a certain technology and coding style and philosophy related to it. And also shift the focus from a certain individual to that particular piece of technology.

Key Points: More emphasis on healthy discussion than reflecting badly on the person whose code is being reviewed. Everyone should be encouraged to look into the code (juniors and seniors), and come up with reviews if possible. Its fine if all files are not reviewed but this gives understanding to the whole team as to what is the expectation with the code.

Introduction to Enterprise Search

Share |

Every web application or enterprise application today is search enabled. Behind the scenes, search is generally takes care of by “Search Engines”.

The powerpoint presentation here introduces Search Engines, indexing and search and briefly touches upon Solr and Lucene the mos popular open source search engine and library respectively.

JavaScript framework comparison

Share |

I was going through the web to find out about the various JavaScript framework. After some research this is what I could compile from a lots of sources. This article is intended to be conversation so that everyone can comment and share their experiences in order to made it a more holistic comparison.

The first thing to figure out when choosing a JavaScript framework is
identifying your need correctly:

  • Need 1: DOM Manipulation (Enhancing your site by adding behavior) : If you’re looking only to enhance your site by adding behavior and to extend it with plug-ins of your own you can do it with jQuery. I.E. if DOM manipulation is the key feature you need, then JQuery is the best. Ext JS has recently released a free library Ext Core to counter JQuery and it seems to be pretty good.
  • Need 2: Making widgets, custom JavaScript based GUI : Dojo is good bet here. YUI also provides good widgets.But if you want to give a more desktop like look and feel (windows, panels), EXT JS is the best. Though important to note is that its paid (developer license when you go to production).
  • Need 3: Building a large application that will do a lot :Dojo is fantastic for building a large scale application that will do a lot, and end up with a ton of JavaScript. Everything you need will be found there.
  • Need 4: Creating rich dashboards and admin consoles :Ext JS has a great usage in creating here. Its already created look and feel makes it very easy to reuse. But again its paid. It provides a lot of extensible, uniform-looking components (layout manager, templating support, trees, grids, tabbed panels, windows, etc.).

Some Criteria that you need to take into account:

  • Criteria 1: Learning curve and speed of development : JQuery wins here, as its easy to learn and uses less lines of code. But its basically for DOM manipulation. Dojo is huge but then you can learn only what you want to use. Prototype fits somewhere in between these worlds. It is small enough to feel small (not a huge library to learn) yet large enough that you don’t jump out into creating a lot of your own code.
  • Criteria 2: Code readability and Maintainability : Prototype is much more readable than JQuery. Ext Core and Dojo also are pretty readable. Complex JQuery code is difficult to maintain and to reuse.
  • Criteria 3: Speed and Code Size : For basic JavaScript functionality, you could even use Robert Nymans DOMAssistant or DLite. ExtJs (not Ext Core) is comparatively heavier than the rest.
  • Criteria 4: Good Ajax support :Generally all frameworks now a days have Ajax support but JQuery seems slightly lacking here.
  • Criteria 5: Coding Style : JQuery doesnot follw what we could call the traditional class based style of coding but is more intutive. This is why its great for designers wanting to add some dynamic magic to their webpage. But a traditional developer will find better coding style followed in Prototye, Ext Core, Mootools and even Dojo. This makes the code more maintanable.

  • Criteria 6: Cost : Well this is only a problem with ExtJs, but i bet they have got things in their library that are worth the money. Note: Ext Core is not paid though.

Some Good Resources which helped me compile the article:

Find the questions to ask when choosing a framework here:

http://blog.reindel.com/2007/10/30/how-to-choose-a-javascript-framework/

Find an overview of JavaScript libraries here:

http://www.slideshare.net/jeresig/javascript-library-overview-presentation

Great resource to work with JQuery:
JQuery :
http://visualjquery.com/1.1.2.html

List of Pros and cons of JQuery, ExtJs and Dojo
http://fictionalrealm.com/2009/04/javascript-ui-framework-comparison-or-why-i-choose-extjs-jquery/

Ext JS vs JQuery
(http://coderseye.com/2008/why-i-didnt-switch-from-jquery-to-extjs-after-all.html)
(http://forum.lessthandot.com/viewtopic.php?f=44&t=2660)

Prototype vs Jquery
http://blog.thinkrelevance.com/2009/1/12/why-i-still-prefer-prototype-to-jquery

JQuery vs Mootools
http://jqueryvsmootools.com/

JQuery vs Dojo
http://almaer.com/blog/why-i-often-prefer-prototype-too

Performance comparison between mootools, jquery, prototype, yui and dojo
http://blog.creonfx.com/javascript/mootools-vs-jquery-vs-prototype-vs-yui-vs-dojo-comparison-revised:

Some Positives and Negatives about JQuery: http://stackoverflow.com/questions/176324/why-does-everyone-like-jquery-more-than-prototypescriptaclous-or-mootools-or-wh