Results 1 to 3 of 3

Thread: DataSource Switching Based on SiteCode

  1. #1
    Join Date
    Dec 2009
    Posts
    2

    Question 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. #2
    Join Date
    Aug 2009
    Location
    Montréal
    Posts
    23

    Default

    Quote 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/

  3. #3
    Join Date
    Dec 2009
    Posts
    2

    Post

    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;
    	}

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •