Spring Batch

When we need to perform batch jobs, better to use Spring Batch.
This is matured framework with many options.

1. Easy to configure
2. Repeat options / Retry options
3. Scalability with parallel process
4. Support for multiline records
Many more

http://docs.spring.io/spring-batch/reference/html/index.html

Advertisements

New Webapp – Spring, GWT EXT, Restlet, Hibernate,….etc

Problem Statement: How to build very nice rich website?

Option 1: Single tier architecture
Advantages: Saves Time, Easy to implement
Disadvantages: Difficult to break up later to support other user interfaces.

Option 2: Two tier architecture
Advantages: Both are in its own spheres. Easy to modify and re-write later if required.
Disadvantages: Takes more time to setup the environment and looks like more code.

Technologies:
UI: GWT
Services: Spring, RESTful Services, Hibernate

Notes:
RESTful – http://www.xfront.com/REST-Web-Services.html
Restlet with Spring – http://jgoday.wordpress.com/2009/04/10/restlet-with-spring/
RESTful from Wiki: http://en.wikipedia.org/wiki/Representational_State_Transfer
Archtypes:
Archetype – HibernateSpringGwt https://opensource.fastconnect.org/redmine/projects/show/spring-gwt-archetype
maven-gwtext-archetype http://code.google.com/p/maven-gwtext-archetype/

-o-

Spring Bean – Order of injecting properties

Problem Statement: We need to start some task, after injecting all properties. How to resolve this?

Solution: Dont / Never depend on order of injecting values into bean. It is not controlled.


import org.springframework.beans.factory.InitializingBean;

public class BeanName implements InitializingBean
{

public void afterPropertiesSet() throws Exception
  {
    System.out.println( "It will be called after completion of properties setting.");
    //do whatever is required here.
  }

}

Spring – Inject Properties file into Bean

Problem Statement: Spring – Inject Properties file into Bean

Spring Bean configuration file

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">

<util:properties id="propertiesFileID1" location="classpath:complete_file_pathfilename.properties"/>

<bean name="BeadID" class = "com.abc.ClassNameABCD" >
	<property name="propFile1" ref="propertiesFileID1"/>
</bean>

</beans>

Source code


package com.abc;

import java.util.Properties;

public class ClassNameABCD
{

 private Properties propFile1;

 //Prepare getter and setters for propFile1;

}

Read this for more information
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/apcs02.html#xsd-config-body-schemas-util-properties

Spring – Oracle Connection Pool Configuration

Problem Statement: Configure Oracle Connection Pool in Spring

This is basic data source (Only testing)

&lt;bean id=&quot;datasource1&quot;
 class=&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;&gt;
&lt;property name=&quot;driverClassName&quot;&gt;
         &lt;value&gt;oracle.jdbc.driver.OracleDriver&lt;/value&gt;
    &lt;/property&gt;
&lt;property name=&quot;url&quot;&gt;
         &lt;value&gt;ORACLE URL&lt;/value&gt;
    &lt;/property&gt;
&lt;property name=&quot;username&quot;&gt;
         &lt;value&gt;user id&lt;/value&gt;
    &lt;/property&gt;
&lt;property name=&quot;password&quot;&gt;
         &lt;value&gt;user password&lt;/value&gt;
    &lt;/property&gt;
&lt;/bean&gt;

This is dbcp data source (Preferred for Testing.)

&lt;bean id=&quot;datasource2&quot;
 class=&quot;org.apache.commons.dbcp.BasicDataSource&quot; destroy-method=&quot;close&quot;&gt;
&lt;property name=&quot;driverClassName&quot;&gt;
         &lt;value&gt;org.apache.commons.dbcp.BasicDataSource&lt;/value&gt;
    &lt;/property&gt;
&lt;property name=&quot;url&quot;&gt;
         &lt;value&gt;ORACLE URL&lt;/value&gt;
    &lt;/property&gt;
&lt;property name=&quot;username&quot;&gt;
         &lt;value&gt;user id&lt;/value&gt;
    &lt;/property&gt;
&lt;property name=&quot;password&quot;&gt;
         &lt;value&gt;user password&lt;/value&gt;
    &lt;/property&gt;
&lt;property name=&quot;initialSize&quot; value=&quot;5&quot;/&gt;
&lt;property name=&quot;maxActive&quot; value=&quot;20&quot;/&gt;
&lt;/bean&gt;

This is Oracle Connection Pool (Production Quality)


&lt;bean id=&quot;connectionPool1&quot; class=&quot;oracle.jdbc.pool.OracleDataSource&quot; destroy-method=&quot;close&quot;&gt;
&lt;property name=&quot;connectionCachingEnabled&quot; value=&quot;true&quot; /&gt;
&lt;property name=&quot;URL&quot;&gt;
         &lt;value&gt;ORACLE URL&lt;/value&gt;
    &lt;/property&gt;
&lt;property name=&quot;user&quot;&gt;
         &lt;value&gt;user id&lt;/value&gt;
    &lt;/property&gt;
&lt;property name=&quot;password&quot;&gt;
         &lt;value&gt;user password&lt;/value&gt;
    &lt;/property&gt;
&lt;property name=&quot;connectionCacheProperties&quot;&gt;
      &lt;value&gt;
		MinLimit:1
		MaxLimit:5
		InitialLimit:1
		ConnectionWaitTimeout:120
		InactivityTimeout:180
		ValidateConnection:true
      &lt;/value&gt;
   &lt;/property&gt;
&lt;/bean&gt;

Oracle Connection Pool is better than DBCP and C3P0

-o-

select * from v$version;

“BANNER”
“Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 – 64bit Production”
“PL/SQL Release 11.2.0.1.0 – Production”
“CORE 11.2.0.1.0 Production”
“TNS for Linux: Version 11.2.0.1.0 – Production”
“NLSRTL Version 11.2.0.1.0 – Production”

Go to Oracle and Choose correct Driver and Download it.
http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html

Option 1: Added to Maven Repo and pom.xml

Add jar to maven Repo
http://www.mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository/

Refer it in pom file.

&lt;project ...&gt;
 
	&lt;dependencies&gt;&gt;
 
		&lt;!-- ORACLE database driver --&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.oracle&lt;/groupId&gt;
			&lt;artifactId&gt;ojdbc6&lt;/artifactId&gt;
			&lt;version&gt;11.2.0.1.0&lt;/version&gt;
		&lt;/dependency&gt;
 
	&lt;/dependencies&gt;
&lt;/project&gt;

Option 2: Add the jar file to Lib folder.