Sunday, February 10, 2013

Abstraction ui elements with labels

You always have the issue, that you need next to ui elements a label to name the element.
There are many options to solve the problem. First the easy way:
ListBox box=new ListBox();
Label lbl=new Label("Countrys");

this.add(box);
this.add(lbl);
This code a lot of programmers have to do for hundrets of input fields, comboboxes and so on.I would recomment, to build up for your most needed UI Elements a class, which also contains the label and the data containing element.
public class MisTextAreaWithLabel extends MisVerticalPanel {
 private TextArea area;
 private Label lbl;

 public MisTextAreaWithLabel(String label) {
  this.lbl = new Label(label);
  this.area = new TextArea();

  this.add(area);
  this.add(lbl);
 }

 public void setValue(String newValue) {
  this.area.setValue(newValue);
 }

 public String getValue() {
  return this.area.getValue();
 }
}
This code is easyly useable with:
MisTextAreaWithLabel  area=new MisTextAreaWithLabel("firstname");
this.add(area);
By creating a new Panel where the element and it’s description is on, you can save a lot of code and you will be able to change the behavior of all your UI Elements easyly.

hibernate configure transaction Isolation Level

In the hibernate config file you can configure the default jdbc-transaction level. Hibernate uses the codes of the java.sql.Connection  class, which are listed above.
  •   public static final int TRANSACTION_NONE = 0;
  •   public static final int TRANSACTION_READ_UNCOMMITTED = 1;
  •   public static final int TRANSACTION_READ_COMMITTED = 2;
  •   public static final int TRANSACTION_REPEATABLE_READ = 4;
  •   public static final int TRANSACTION_SERIALIZABLE = 8;
To use Repeatable Read transactions you just have to type the number 4 in your isolation property.
<property name=”hibernate.connection.isolation”>4</property>
Here a short list, what each level means:
  • TRANSACTION_READ_UNCOMMITTED -> Allows dirty reads, non-repeatable reads, and phantom reads to occur.
  • TRANSACTION_READ_COMMITTED -> Ensures only committed data can be read.
  • TRANSACTION_REPEATABLE_READ -> Is close to being “serializable,” however, “phantom” reads are possible.
  • TRANSACTION_SERIALIZABLE -> Dirty reads, non-repeatable reads, and phantom reads are prevented. Serializable.
Performance of the software decreased by a higher transaction level. So you should check if you need more stability or performance. Depends always by the software you build up.