Announcement Announcement Module
Collapse
No announcement yet.
DataSource Switching Based on SiteCode Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • DataSource Switching Based on SiteCode

    Hi,

    We have a application using JDBC, the application serves multiple sites, and each site has its own datastore. The application uses site id to decide which datastore to use, so the code is same only the datastore changes. So no matter how many sites the application serves the transactions are all across a single datastore determined by the site id.

    I wanted to incorporate spring into the application for the following reasons

    - Transaction management
    - Auto management of connections

    I wanted to know how to go about (using spring):
    - Working with different datastores

    regards
    Ankur

  • #2
    Originally posted by ankurkaps View Post
    Hi,

    We have a application using JDBC, the application serves multiple sites, and each site has its own datastore. The application uses site id to decide which datastore to use, so the code is same only the datastore changes. So no matter how many sites the application serves the transactions are all across a single datastore determined by the site id.

    I wanted to incorporate spring into the application for the following reasons

    - Transaction management
    - Auto management of connections

    I wanted to know how to go about (using spring):
    - Working with different datastores

    regards
    Ankur
    you need to you AbstractDataSourceRouting

    You read this blog entry : http://blog.springsource.com/2007/01...ource-routing/

    Comment


    • #3
      Thanks looks exactly what i was looking for.

      Any ideas on integrating spring to legacy code without
      code rewrite ?

      Existing Dao's have something like

      Code:
      	public static List getUsers() throws Exception {
      		Connection con = null;
      		PreparedStatement ps = null;
      		ResultSet rs = null;
      
      		String sql = " select * from usertable" ;			
      		
      		List userList = new ArrrayList();
      		User user = null;
      
      		try{
      			con = ds.getConnection();
      			
      			ps = con.prepareStatement(sql);
      
      			rs = ps.executeQuery();
      			
      			while(rs.next()){
      				user = new User();
      
      				// set details to User Object
      				
      				userList.add(user);
      			}
      		}
      		finally{
      			closeResultSet(rs);
      			closePreparedStatement(ps);
      			closeConnection(con);			
      		}
      
      		return userList;
      	}

      Comment

      Working...
      X