Popular Posts

Friday, October 4, 2013

Working with Enums in Java

Definition:
Enums are special kind of datatype which we can use in application as constants. 

Where to Use:
 In java application  we have requirements where we need to keep some values that should be constant throughout the application. There we use enums to keep thos values in meaningful way.Why Enums instead of constants:In java Enums are objects. They can have variables, methods etc. like any other objects. But constants are just like some primitive values. 


package com.technobash.enums;

public enum Months {

 JANUARY(1), 
 FEBRUARY(2),
 MARCH(3),
 APRIL(4),
 MAY(5),
 JUNE(6),
 JULY(7),
 AUGUST(8),
 SEPTEMBER(9),
 OCTOBER(10),
 NOVEMBER(11),
 DECEMBER(12);

 // This is a constructor where we pass the integer value to initialize enums
 Months(int x) {
  this.x = x;
 }

 int x;

 public int getValue() {
  return this.x;
 }
}

Here are some useful links about enums:
Enum Tricks
Enum Examples
Enums Documentation





Tuesday, October 1, 2013

Problem faced while configuring Liferay with MySQL

Today, I faced an issue while I started configuring MySQL with Liferay 6.1.
In the logs I started getting following errors:
impossible to write to binary log since BINLOG_FORMAT=STATEMENT and at least one table uses a storage engine limited to row-based logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED
This issue is very common with MySQL version 5.6. because by default, BINLOG_FORMAT=STATEMENT here. I have changed it to ROW and I got rid of this error.

The command to be used :
mysql> SET GLOBAL binlog_format = 'ROW';


Now I have encountered another kind of problem. In logs it is started giving below error.

check the manual that corresponds to your MySQL server version for the right syntax to use near 'OPTION SQL_SELECT_LIMIT=DEFAULT.

 This error is due to mysql jdbc connector issue. We need to change the jar in {Liferay_home}/{TOMCAT_HOME}/lib/ext folder.

Steps to be followed:
1. Download latest MySQL connector jar from here. It will be an installer.
2. After installing this you will get the jar is stored under <Directory>:\Program Files (x86)\MySQL\MySQL Connector J
3. Take the jar and put that into {Liferay_home}/{TOMCAT_HOME}/lib/ext folder
4. Remove mysql.jar from this directory.
5. Rename the new jar to mysql.jar

The errors are gone.