Thursday, December 27, 2007
java.lang.String replaceAll case insensitive
Pattern myPattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
/*for space,new line, tab checks*/
//Pattern myPattern = Pattern.compile(regex+"[ /n/t/r]", Pattern.CASE_INSENSITIVE);
string = myPattern.matcher(string).replaceAll(replaceWith);
return string;
}
Thursday, December 20, 2007
Inversion of Control / Dependency Injection
i)setter-based dependency injection is realized by calling setters on your beans after invoking a no-argument constructor or no-argument static factory method to instantiate your bean. Beans defined in the BeanFactory that use setter-based dependency injection are true JavaBeans. Spring generally advocates usage of setter-based dependency injection, since a large number of constructor arguments can get unwieldy, especially when some properties are optional.
ii)constructor-based dependency injection is realized by invoking a constructor with a number of arguments, each representing a collaborator or property. Additionally, calling a static factory method with specific arguments, to construct the bean, can be considered almost equivalent, and the rest of this text will consider arguments to a constructor and arguments to a static factory method similarly.
Wednesday, December 19, 2007
Libraries required for a Spring-Hibernate project
ojdbc14.jar - driver
commons-beanutils-1.6.1.jar
commons-collections-2.1.1.jar
commons-digester-1.3.jar
commons-lang-2.1.jar
commons-logging-1.0.4.jar
asm.jar - Java byte code manipulation framework
cglib-2.1.3.jar - Code Generation Library
spring.jar
dom4j-1.6.1.jar - XML parsing
jta.jar - Transaction
Tuesday, December 18, 2007
Hibernate Life Cycle
The state of an object reflects the values contained in the attributes of an object at a given time. So whenever the values change, the state also changes to reflect the current values. The total number of states traversed by an object to reach its initial state is known as the life-cycle of the object. Following are the states that form the life-cycle of a persistent object, also known as life-cycle of persistence:
1. Transient State:
Transient is the state of an object when it is not associated with any database. Transient objects don’t come under the context of a transaction.
2. Persistent State:
An object is said to be in a persistent state when it has a database identity.To make any transient object persistent, the save method of the Persistence manager has to be called. The most important characteristic feature of an object in the persistent state is that it takes part in transactional activities.
3. Detached State:
In Hibernate, when the transaction completes by calling the close() method on the Session object, the instances of persistence class lose their association with the Persistence manager. Thus the detached state is attained. In this state the object is no longer in sync with the database. Also Hibernate doesn’t care about the modifications being done to the object, as the object is no longer under the management of Hibernate.