Tuesday, October 23, 2012

SQL Express with JDBC : Connection refused

By default SQL Server Express 2012 is installed with protocol TCP/IP disabled. Follow the steps to enable JDBC connection:

Step 1:
 
Open SQL Server Configuration Manager. Navigate to SQL Server Nework Configuration, then Protocol for SQLEXPRESS. Double click the TCP/IP protocol at right hand pane.


Change the Enabled property to Yes.

Go to tab IP Address.


Scroll all the way to the bottom. Clear the TCP Dynamic Ports. Specify 1433 in TCP Port.
Restart SQL Express.
Done.

Wednesday, February 22, 2012

LDAP Basics

LDAP Entry
dn: cn=Tridib Samanta,dc=sample,dc=com
cn: Tridib Samanta
givenName: Tridib
sn: Samanta
telephoneNumber: +1 111 222 3333
telephoneNumber: +1 444 555 6666
mail: tridib@example.com
manager: cn=Swarnali Kumar,dc=sample,dc=com
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
objectClass: top

dn - Distinguished Name
dc - Domain Component
cn - Common Name
sn - Surname

Tuesday, February 14, 2012

ThreadLocal Best Practices

  • Be careful to initialize the ThreadLocal object whenever the thread starts working, or you might end up connecting a logged-off user's data to another user's thread. When you're using ThreadLocals in a situation in which a filter initializes the object with user data, make sure there are no other entries to your servlet application—except through the filter.
  • Always remember that the ThreadLocal data is connected to the thread, not the user or anything else. A good idea is to delete the ThreadLocal data when it's no longer used.
  • Use InheritableThreadLocal to pass parent ThreadLocal data to child threads.


References

Monday, February 6, 2012

Performance : Parameterized Constructor in Grails for Domain Objects

Don't use parametereized constructor in Grails for domain objects. This is slower than empty constructor.

This performance issue become significant when creating large number of domain objects in loop.

Wednesday, February 1, 2012

Overriding equals in Groovy

I was overriding equals method in for a Groovy class and got into StackOverflow error.




class ObjKey {
long id
String value

public boolean equals(Object obj) {
if (!(obj instanceof ObjKey)) {
return false;
}
if (this == obj) {
return true;
}
ObjKey rhs = (ObjKey) obj;
return new EqualsBuilder()
.append(id, rhs?.id)
.append(value, rhs?.value)
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(id)
.append(value)
.toHashCode();
}
}



I was getting stackoverflow at line: if (this == obj). Groovy's equals calls the equals method instead of comparing the reference.

I fixed it using bellow syntax: if (this.is(obj)). The corrected code looks like:


class ObjKey {
long id
String value

public boolean equals(Object obj) {
if (!(obj instanceof ObjKey)) {
return false;
}
if (this.is(obj)) {
return true;
}
ObjKey rhs = (ObjKey) obj;
return new EqualsBuilder()
.append(id, rhs?.id)
.append(value, rhs?.value)
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(id)
.append(value)
.toHashCode();
}
}