Sunday, January 31, 2010

Basic Spring application

Here is a very basic spring application. This can be used to play around with various spring features.

This moment in the future

In the future you should be able to look at this moment and say to yourself that you couldn't have spent it better.

- Nithya (my wife)

Saturday, January 30, 2010

Fear is not what’s important, it’s how you deal with it.

“Fear is not what’s important, it’s how you deal with it. It would be like asking a marathon runner if they feel pain. It’s not a matter of whether you feel it, it’s how you manage it.”

- James Nachtwey - War Photographer (2001) through Julie911

...You’re not the first person who was ever confused and frightened and even sickened by human behavior

“Among other things, you’ll find that you’re not the first person who was ever confused and frightened and even sickened by human behavior. You’re by no means alone on that score, you’ll be excited and stimulated to know. Many, many men have been just as troubled morally and spiritually as you are right now. Happily, some of them kept records of their troubles. You’ll learn from them”

- J.D. Salinger, The Catcher in the Rye, Chapter 24 through Julie911

Thursday, January 28, 2010

Indexing tip

Searching by more than one column (i.e. more than one predicate in the where clause) is a very common scenario. To fasten such queries, creating indices is a common practice. The question: How to reuse the same index for both single column and multi column searches? For example, consider a student table with id, first_name and last_name columns. If the DB receives numerous queries with first_name and last_name in there where clause, then what should the indexing strategy be?

 

To elaborate on the question, the indexing strategy needs to support the following queries

 

Select * from student where first_name like ‘blah%’; -- Scenario 1

Select * from student where last_name like ‘blah%’; -- Scenario 2

Select * from student where first_name like ‘blah%’ and last_name like ‘blah%’; -- Scenario 3

 

One possible solution is to create 3 indices for the 3 scenarios (one for first_name, one for last_name and one for first_name and last_name). This is not so interesting.

 

The other alternative leverages on the fact that a query based on first_name only will also use an multi-column index (index on more than one column) provided first_name is the first column in the multi-column index.

 

So in the above scenario, the following indices need to be created:

 

CREATE INDEX idx_student_firstName_last_name ON student (first_name, last_name); -- takes care of first_name only (scenario 1) and first_name and last_name queries (scenario 3)

CREATE INDEX idx_student_last_name ON student(last_name); -- takes care of last_name queries (scenario 2)

Attributes of pure consciousness

Attributes of pure consciousness are pure knowledge, infinite silence, perfect balance, invincibility, simplicity and bliss.

 

-          Deepak Chopra in “The Seven Spiritual Laws Of Success

Wednesday, January 27, 2010

Never let negative feelings block the path to your goal

“One of the first principles of applied mindism is to never let negative feelings block the path to your goal. Otherwise you are always sinking back into discouragement.”

- Jack Nicholson through Julie911

The world will freely offer itself to you to be unmasked....it will roll in ecstasy at your feet

“You need not even leave your room. Remain sitting at your table and listen. You need not even listen simply wait. You need not even wait, just learn to become quiet and still, and solitary. The world will freely offer itself to you to be unmasked. It has not choice; it will roll in ecstasy at your feet”

 

-          Franz Kafka from “The Seven Spiritual Laws Of Success” by Deepak Chopra

Friday, January 22, 2010

The best portion of a good man’s life is....

"The best portion of a good man's life is the little, nameless, unremembered acts of kindness and love."

- William Wordsworth through Julie911

Failure Atomic

When a method invocation on an object fails, the object should revert back to the state that it was in prior to the invocation. If it does this, then the method is failure atomic.

Coining user messages in a failure scenario

When an operation (such as save) is triggered from an UI application, the call trickles down to underling APIs. If something wrong happens with the operation, then the user needs to be notified of the failure on the UI. The question: how and where should this UI message be coined?

 

Consider the following (over simplified) code to achieve a save operation

 

// 1. UI code calls setNewStudent(Student) with the student data entered in UI form (xhtml, JSP, etc…)

 

// 2. An action on the UI (button click for example) invoked the following method

StudentUIController.saveNewStudent()

{

    StudentDAO.SaveOfUpdate(getNewStudent()); // 3. UI Code makes DAO layer call to persist object

}

 

StudentDAO.saveOrUpdate( Student )  // 3.

{

    // Persist the student

}

 

One of the best practices to handle the failure scenario is to have the DAO layer (StudentDAO in this example) throw a custom exception. The UI layer (StudentUIController) must catch this exception and coin a message for the user. The custom exception should have enough information in it for the UI layer to coin a meaningful message for the user from the exception. In some cases, the DAO layer may also give a brief message of what went wrong in the exception.

 

Will update this post soon with the code after I have a working example of how this is to work.

 

Wednesday, January 20, 2010

"Don't be afraid to give your best to what seemingly are small jobs. Every time you conquer one it makes you that much stronger. If you do the little jobs well, the big ones will tend to take care of themselves."

“Don’t be afraid to give your best to what seemingly are small jobs. Every time you conquer one it makes you that much stronger. If you do the little jobs well, the big ones will tend to take care of themselves.”

- Dale Carnegie through Julie911

Tuesday, January 19, 2010

Remember no man is a failure who has friends.

"
Dear George,

Remember no man is a failure who has friends.

Thanks for the wings!

Love,
Clarence"

- Its a wonderful life

Ideals without common sense can ruin this town

Ideals without common sense can ruin this town - it's a wonderful life

Monday, January 18, 2010

Creating an index on a column using hibernate mapping

Mapping:

 

<property

  name="name"

  column="student_name"

  type="string"

  index="xyz__student_name"/>

 

Table Structure (in PostgreSQL)

 

CREATE TABLE xyz

(

  id bigint NOT NULL,

  student_name character varying(255),

  CONSTRAINT xyz_pkey PRIMARY KEY (id)

)

 

CREATE INDEX xyz__student_name

  ON xyz

  USING btree

  (student_name);

Creating a unique contraint on a column through hibernate mapping

Mapping:

 

<class …>

  <natural-id>

    <property

      name="name"

      column="name"

      type="string" />

  </natural-id>

</class>

 

Table Structure (in PostgreSQL):

 

CREATE TABLE xyz

(

  id bigint NOT NULL,

  "name" character varying(255) NOT NULL,

  CONSTRAINT xyz_pkey PRIMARY KEY (id),

  CONSTRAINT xyz_name_ukey UNIQUE (name)

)

 

Friday, January 15, 2010

may God turn their ...ankles, so that we may know them by their limping :-)

“May those who love us, love us. And those who don’t love us, may God turn their hearts. And if He cannot turn their hearts, may He turn their ankles, so that we may know them by their limping.”

- Keeping The Faith / Irish Prayer through Julie911

Wednesday, January 06, 2010

Don't be afraid

“Don’t be afraid. Don’t be daunted. Just do your job. Continue to show up for your piece of it, whatever that might be. If your job is to dance, do your dance. If the divine cock-eyed genius assigned to your case decides to let some sort of wonderment be glimpsed for just one moment, through your efforts, then olé! And if not, do your dance anyhow, and olé to you nonetheless.”

- 
Elizabeth Gilbert through Julie911