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);

criteria.setMaxResults(100);

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

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

{

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

}

return list;

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

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;

SQL Functions

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

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.

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

#end

-----------------------------------

Java code:

List> campaings = new ArrayList>();

List c1 = new ArrayList();

c1.add("1a");

c1.add("2a");

c1.add("3a");

c1.add("4a");

campaings.add(c1);

List c2 = new ArrayList();

c2.add("1b");

c2.add("2b");

c2.add("3b");

c2.add("4b");

campaings.add(c2);

map.put("campaigns", campaings);

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

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.

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:

GWT: hour dropdown

 private ListBox createHourSelectorListBox(String hours)

    {

ListBox listBox = new ListBox();

listBox.ensureDebugId("listbox_hourSelector_configAttributes");

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.setSelectedIndex(index);

}

listBox.addChangeListener(new ChangeListener()

{

    public void onChange(Widget sender)

    {

saveButton.setVisible(true);

    }

});

return listBox;

    }

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).