Tuesday, January 27, 2009

Hibernate: limit result number of using Criteria

To limit the number of records/results returned by the search criteria(notice we are not using DetachedCriteria): 

Criteria criteria = getSession().createCriteria(MyClass.class);


List< MyClass > list = criteria.list();

if (list != null && list.size() > 0)


    log.warn("Found " + list.size() + " Impressions");


return list;

Monday, January 19, 2009

SQL: update statement

update table_namer set column_id = 5 where column_id = 3;

CSS: inheritance with GWT

We are using CSS to represent system metrics in the form of colored columns in a graph

Define CSS styles as below:

.graph_column {
vertical-align: top;
width: 6px;
border-left: 1px;
border-top: 1px;
border-right: 1px gray solid;
border-bottom: 1px gray solid;
cursor: pointer;

.bg_red {
background-color: red;

.bg_red {
background-color: red;

Here is how you use it in GWT code:

column.setStyleName("graph_column bg_red");
column.setStyleName("graph_column bg_green");

CLICK HERE for useful html color palette

Thursday, January 15, 2009

SQL: is not null

update address set address_type = '8' where organization_id is null;

update address set address_type = '7' where organization_id is not null;

Monday, January 12, 2009

SQL Functions

 count(*) as 'total users',
 max(id) as 'biggest id',
 min(id) as 'smallest id',
 avg(id) as 'average' 
 from user;

Friday, January 9, 2009

Imitation is the highest compliment

Palm OS and pretty much every other manufacturer makes phones to look
practically indistinguishable from the iPhone.
The beauty is not just skin deep, it is what's inside that counts.
The soul and spirit.

Thursday, January 8, 2009

Velocity Template #foreach & #end loop with Java List

To create a foreach loop to go iterate through a list of items :

#set($campaigns = ["one", "two", "three"])

#foreach($campaign in $campaigns)

  List Item: $campaign



Java code:

List> campaings = new ArrayList>();

List c1 = new ArrayList();






List c2 = new ArrayList();






map.put("campaigns", campaings);

Example of how you loop thru the above Java List of List(s) of String(s) using #foreach loops:

Wednesday, January 7, 2009

MYSQL: text field size

A text field in mysql has a size of 65,000 bytes, which means it can have appx. 65,000 characters.

Tuesday, January 6, 2009

Velocity Template and Mime Message Prepartor

To output a test to velocity template, use the MimeMessage to prepare the actual template:

 public void createTemplateContent(final Object obj)


MimeMessagePreparator preparator = new MimeMessagePreparator()


    public void prepare(MimeMessage mimeMessage) throws Exception


Map map = new HashMap();

String content = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "name_of_your_template_file.vm", map);




Generate setters and getters method

Add bean definition in your bean.xml file:

Monday, January 5, 2009

GWT: hour dropdown

 private ListBox createHourSelectorListBox(String hours)


ListBox listBox = new ListBox();


listBox.addItem("0:00 AM", "0");

listBox.addItem("1:00 AM", "1");

listBox.addItem("2:00 AM", "2");

listBox.addItem("3:00 AM", "3");

listBox.addItem("4:00 AM", "4");

listBox.addItem("5:00 AM", "5");

listBox.addItem("6:00 AM", "6");

listBox.addItem("7:00 AM", "7");

listBox.addItem("8:00 AM", "8");

listBox.addItem("9:00 AM", "9");

listBox.addItem("10:00 AM", "10");

listBox.addItem("11:00 AM", "11");

listBox.addItem("12:00 PM", "12");

listBox.addItem("13:00 PM", "13");

listBox.addItem("14:00 PM", "14");

listBox.addItem("15:00 PM", "15");

listBox.addItem("16:00 PM", "16");

listBox.addItem("17:00 PM", "17");

listBox.addItem("18:00 PM", "18");

listBox.addItem("19:00 PM", "19");

listBox.addItem("20:00 PM", "20");

listBox.addItem("21:00 PM", "21");

listBox.addItem("22:00 PM", "22");

listBox.addItem("23:00 PM", "23");

if (hours != null && hours.length() > 0)


    int index = (new Integer(hours)).intValue();



listBox.addChangeListener(new ChangeListener()


    public void onChange(Widget sender)





return listBox;


Thursday, January 1, 2009

Advertise here...

You can advertise your business (software, hardware, technical recruiting) for as little as $150 per month and reach a highly targeted audience of cutting edge Java developers.

Email us at UkiDLucas@mac.com for details.

Attach an image of your advertisement (max. 190x120 pixel).