qualified table names with datasource

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

qualified table names with datasource

_Eric_
Hi list,

I came to the dbUnit today and so in a problem. I want to use the same
datasource for the tests as the application does. We have some schemes
in the database. And I figured out that I have to set
FEATURE_QUALIFIED_TABLE_NAMES to true. The problem is that the
datasource takes a connection from a connection pool, where
FEATURE_QUALIFIED_TABLE_NAMES is set to false :-( Because I am until now
not that familiar with dbUnit, I don't know where to enable the feature.
Here is some code:

@Before
    public void setUpDatabase() throws Exception {
        this.databaseTester = new DataSourceDatabaseTester(
this.dataSource );
        try {
           
            this.databaseTester.setSetUpOperation(
DatabaseOperation.INSERT );
            this.databaseTester.setTearDownOperation(
DatabaseOperation.NONE );
            IDataSet dataSet = this.getDataSet();
            this.databaseTester.setDataSet( dataSet );
            DatabaseConfig config =
this.databaseTester.getConnection().getConfig();
           
config.setProperty(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, true);
           
            if( (Boolean) config.getProperty(
DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES ) ){
                logger.debug(
DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES + "is enabled" );
            } else {
                logger.debug(
DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES + "is not enabled" );
            }
            this.databaseTester.onSetup();
        } catch (Exception e) {
            logger.error( e );
            DatabaseConfig config =
this.databaseTester.getConnection().getConfig();
            if( (Boolean) config.getProperty(
DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES ) ){
                logger.debug(
DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES + "is enabled" );
            } else {
                logger.debug(
DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES + "is not enabled" );
            }
            throw e;
        }
    }

The problem the first debug output shows that the feature is enabled,
the output in the catch clause shows that it is disabled.

Would be kind to get some help.

Greetings
Eric

------------------------------------------------------------------------------
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: qualified table names with datasource

John Hurst-2
You are correct -- your use of DataSource and a connection pool prevents the feature being retained. Each time you call getConnection() on a DataSourceDatabaseTester, it creates a new IDatabaseConnection, regardless of whether the JDBC Connection it's using is the same or not.

There are several things you could do. Possibly the simplest thing would be to wrap or subclass DataSourceDatabaseTester so that you can intercept the getConnection() method and set the feature on each IDatabaseConnection as it is created.

Hope this helps.

John Hurst
Wellington, New Zealand

On Thu, Apr 22, 2010 at 5:08 AM, Eric Härtel <[hidden email]> wrote:
Hi list,

I came to the dbUnit today and so in a problem. I want to use the same
datasource for the tests as the application does. We have some schemes
in the database. And I figured out that I have to set
FEATURE_QUALIFIED_TABLE_NAMES to true. The problem is that the
datasource takes a connection from a connection pool, where
FEATURE_QUALIFIED_TABLE_NAMES is set to false :-( Because I am until now
not that familiar with dbUnit, I don't know where to enable the feature.
Here is some code:

@Before
   public void setUpDatabase() throws Exception {
       this.databaseTester = new DataSourceDatabaseTester(
this.dataSource );
       try {

           this.databaseTester.setSetUpOperation(
DatabaseOperation.INSERT );
           this.databaseTester.setTearDownOperation(
DatabaseOperation.NONE );
           IDataSet dataSet = this.getDataSet();
           this.databaseTester.setDataSet( dataSet );
           DatabaseConfig config =
this.databaseTester.getConnection().getConfig();

config.setProperty(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, true);

           if( (Boolean) config.getProperty(
DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES ) ){
               logger.debug(
DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES + "is enabled" );
           } else {
               logger.debug(
DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES + "is not enabled" );
           }
           this.databaseTester.onSetup();
       } catch (Exception e) {
           logger.error( e );
           DatabaseConfig config =
this.databaseTester.getConnection().getConfig();
           if( (Boolean) config.getProperty(
DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES ) ){
               logger.debug(
DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES + "is enabled" );
           } else {
               logger.debug(
DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES + "is not enabled" );
           }
           throw e;
       }
   }

The problem the first debug output shows that the feature is enabled,
the output in the catch clause shows that it is disabled.

Would be kind to get some help.

Greetings
Eric

------------------------------------------------------------------------------
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user



--
Life is interfering with my game

------------------------------------------------------------------------------

_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: qualified table names with datasource

_Eric_

Perfect, works fine, quick and easy to implement. Thanks to John for the
rapid and well explained help.

Eric

John Hurst schrieb:

> You are correct -- your use of DataSource and a connection pool
> prevents the feature being retained. Each time you call
> getConnection() on a DataSourceDatabaseTester, it creates a new
> IDatabaseConnection, regardless of whether the JDBC Connection it's
> using is the same or not.
>
> There are several things you could do. Possibly the simplest thing
> would be to wrap or subclass DataSourceDatabaseTester so that you can
> intercept the getConnection() method and set the feature on each
> IDatabaseConnection as it is created.
>
> Hope this helps.
>
> John Hurst
> Wellington, New Zealand
>
> On Thu, Apr 22, 2010 at 5:08 AM, Eric Härtel <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Hi list,
>
>     I came to the dbUnit today and so in a problem. I want to use the same
>     datasource for the tests as the application does. We have some schemes
>     in the database. And I figured out that I have to set
>     FEATURE_QUALIFIED_TABLE_NAMES to true. The problem is that the
>     datasource takes a connection from a connection pool, where
>     FEATURE_QUALIFIED_TABLE_NAMES is set to false :-( Because I am
>     until now
>     not that familiar with dbUnit, I don't know where to enable the
>     feature.
>     Here is some code:
>
>     @Before
>        public void setUpDatabase() throws Exception {
>            this.databaseTester = new DataSourceDatabaseTester(
>     this.dataSource );
>            try {
>
>                this.databaseTester.setSetUpOperation(
>     DatabaseOperation.INSERT );
>                this.databaseTester.setTearDownOperation(
>     DatabaseOperation.NONE );
>                IDataSet dataSet = this.getDataSet();
>                this.databaseTester.setDataSet( dataSet );
>                DatabaseConfig config =
>     this.databaseTester.getConnection().getConfig();
>
>     config.setProperty(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES,
>     true);
>
>                if( (Boolean) config.getProperty(
>     DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES ) ){
>                    logger.debug(
>     DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES + "is enabled" );
>                } else {
>                    logger.debug(
>     DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES + "is not enabled" );
>                }
>                this.databaseTester.onSetup();
>            } catch (Exception e) {
>                logger.error( e );
>                DatabaseConfig config =
>     this.databaseTester.getConnection().getConfig();
>                if( (Boolean) config.getProperty(
>     DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES ) ){
>                    logger.debug(
>     DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES + "is enabled" );
>                } else {
>                    logger.debug(
>     DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES + "is not enabled" );
>                }
>                throw e;
>            }
>        }
>
>     The problem the first debug output shows that the feature is enabled,
>     the output in the catch clause shows that it is disabled.
>
>     Would be kind to get some help.
>
>     Greetings
>     Eric
>
>     ------------------------------------------------------------------------------
>     _______________________________________________
>     dbunit-user mailing list
>     [hidden email]
>     <mailto:[hidden email]>
>     https://lists.sourceforge.net/lists/listinfo/dbunit-user
>
>
>
>
> --
> Life is interfering with my game
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
>  
> ------------------------------------------------------------------------
>
> _______________________________________________
> dbunit-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>  

------------------------------------------------------------------------------
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user