Menu

How to get the replicating connection in a IDataLoaderFilter

Developers
jmdiazlr
2013-04-07
2013-04-09
  • jmdiazlr

    jmdiazlr - 2013-04-07

    I am using 2.1.2, i developed a IDataLoaderFilter, my requirement is to redirect to a diferent table, so I neet to get the connection in which symmetric is replicating, i get connection like this but I think this is wrong:

    @Override
    public boolean filterUpdate(IDataLoaderContext context, String[] columnValues, String[] keyValues) {
    
                  Map<String, DataSource> beans = appContext.getBeansOfType(DataSource.class);
        DataSource ds = (DataSource) beans.get("dataSource");  
        Connection con = null;
        Statement st = null;
        ResultSet rs = null;
    
        try {
            con = ds.getConnection();
    

    ...
    I think that the IDataLoader is called in the replicating transaction, and the way i get the connection is wrong because i get a new connection, not the same connection of the replicating transaction.

    What is the right way to get the replicating connection so that my DML's are done in the same replicating transaction?

     
  • Austin Brougher

    Austin Brougher - 2013-04-08

    "If work needs to occur on the target database itself within the same database transaction that the load is taking place in, then the IDataLoaderContext should be used to access a JdbcTemplate. The JdbcTemplate contains the connection that is being used for the data load."

    http://www.symmetricds.org/doc/2.5/javadoc/org/jumpmind/symmetric/load/IDataLoaderFilter.html

     

    Last edit: Austin Brougher 2013-04-08
    • jmdiazlr

      jmdiazlr - 2013-04-09

      Great, many thanks!

       

Log in to post a comment.