Configuring the DataTypeFactory when using a JdbcDatabaseTester in a test

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

Configuring the DataTypeFactory when using a JdbcDatabaseTester in a test

Christophe Bliard-2
Hi,

I am trying to use a Oracle10DataTypeFactory instead of the
DefaultDataTypeFactory. To do so I have the following test code:

public class SomeDatabaseTest {

  private final IDatabaseTester databaseTester;

  public SomeDatabaseTest() throws Exception {
    databaseTester = new JdbcDatabaseTester(
        "oracle.jdbc.driver.OracleDriver",
        "jdbc:oracle:thin:@localhost:1521:XE",
        "username",
        "password",
        "schema");
    databaseTester.getConnection().getConfig().setProperty(
        DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
        new Oracle10DataTypeFactory());
    databaseTester.setDataSet(createDataSet());
  }

  public void before() throws Exception {
    databaseTester.onSetup();
  }

  public void after() throws Exception {
    databaseTester.onTearDown();
  }

  @Test
  public void testSomething() {
    // do test stuff...
  }

  private IDataSet createDataSet()
      throws IOException, DataSetException {
    InputStream input;
    input = this.getClass().getResourceAsStream("myDataSet.xml");
    try {
      return new FlatXmlDataSet(input);
    } finally {
      input.close();
    }
  }
}

But when I run the test, I have this warning multiple times:

2010-09-03 14:54:34,393 [main] WARN
org.dbunit.dataset.AbstractTableMetaData - Potential problem found: The
configured data type factory 'class
org.dbunit.dataset.datatype.DefaultDataTypeFactory' might cause problems
with the current database 'Oracle' (e.g. some datatypes may not be
supported properly). In rare cases you might see this message because
the list of supported database products is incomplete (list=[postgresql,
derby]). If so please request a java-class update via the forums.

I have looked into the dbunit code (we are using dbunit 2.4.4) and it
appears that when calling getConnection(), a new DatabaseConnection
instance is created every time, and this connection has its own
DatabaseConfig object.

So it is useless to set the DataTypeFactory to Oracle10DataTypeFactory
in the getConnection().getConfig() instance: another config will be used
during the onSetup() and onTearDown() call because they call
getConnection().

I think I have missed something but I can't figure out what. Can you
help me please?

Best regards
--
Christophe Bliard <[hidden email]>



------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: Configuring the DataTypeFactory when using a JdbcDatabaseTester in a test

John Hurst-2
Christophe,

I think you're right: that may be a problem with IDatabaseTester.

Here's some code I used in preparing some DbUnit samples recently, which gives me what I need (with DataTypeFactory configuration, without using IDatabaseTester:

public class AbstractDbUnitTestCase {

  private DataSource dataSource;
  private IDatabaseConnection databaseConnection;

  @Before
  public void setupConnections() throws SQLException, DatabaseUnitException {
    OracleDataSource dataSource = new OracleDataSource();
    dataSource.setURL(System.getProperty("db.url"));
    dataSource.setUser(System.getProperty("db.userid"));
    dataSource.setPassword(System.getProperty("db.password"));
    this.dataSource = dataSource;
    DatabaseConnection databaseConnection = new DatabaseConnection(getDataSource().getConnection());
    databaseConnection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new Oracle10DataTypeFactory());
    this.databaseConnection = databaseConnection;
  }

  @After
  public void shutdownConnections() throws SQLException {
    if (databaseConnection != null) {
      databaseConnection.close();
    }
  }

  public DataSource getDataSource() {
    return dataSource;
  }

  public IDatabaseConnection getDatabaseConnection() {
    return databaseConnection;
  }
  
  public FlatXmlDataSet getDataSet(String fileName) throws DataSetException {
    return new FlatXmlDataSet(new FlatXmlProducer(new InputSource(getClass().getResourceAsStream(fileName))));
  }
}

This can easily be adapted to different requirements.

We'll need to look into the configuration of IDatabaseTester.

Hope this helps.

John Hurst

On Sat, Sep 4, 2010 at 2:18 AM, Christophe Bliard <[hidden email]> wrote:
Hi,

I am trying to use a Oracle10DataTypeFactory instead of the
DefaultDataTypeFactory. To do so I have the following test code:

public class SomeDatabaseTest {

 private final IDatabaseTester databaseTester;

 public SomeDatabaseTest() throws Exception {
   databaseTester = new JdbcDatabaseTester(
       "oracle.jdbc.driver.OracleDriver",
       "jdbc:oracle:thin:@localhost:1521:XE",
       "username",
       "password",
       "schema");
   databaseTester.getConnection().getConfig().setProperty(
       DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
       new Oracle10DataTypeFactory());
   databaseTester.setDataSet(createDataSet());
 }

 public void before() throws Exception {
   databaseTester.onSetup();
 }

 public void after() throws Exception {
   databaseTester.onTearDown();
 }

 @Test
 public void testSomething() {
   // do test stuff...
 }

 private IDataSet createDataSet()
     throws IOException, DataSetException {
   InputStream input;
   input = this.getClass().getResourceAsStream("myDataSet.xml");
   try {
     return new FlatXmlDataSet(input);
   } finally {
     input.close();
   }
 }
}

But when I run the test, I have this warning multiple times:

2010-09-03 14:54:34,393 [main] WARN
org.dbunit.dataset.AbstractTableMetaData - Potential problem found: The
configured data type factory 'class
org.dbunit.dataset.datatype.DefaultDataTypeFactory' might cause problems
with the current database 'Oracle' (e.g. some datatypes may not be
supported properly). In rare cases you might see this message because
the list of supported database products is incomplete (list=[postgresql,
derby]). If so please request a java-class update via the forums.

I have looked into the dbunit code (we are using dbunit 2.4.4) and it
appears that when calling getConnection(), a new DatabaseConnection
instance is created every time, and this connection has its own
DatabaseConfig object.

So it is useless to set the DataTypeFactory to Oracle10DataTypeFactory
in the getConnection().getConfig() instance: another config will be used
during the onSetup() and onTearDown() call because they call
getConnection().

I think I have missed something but I can't figure out what. Can you
help me please?

Best regards
--
Christophe Bliard <[hidden email]>



------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user



--
Life is interfering with my game

------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: Configuring the DataTypeFactory when using a JdbcDatabaseTester in a test

Christophe Bliard-2
Hi John,

Thank you for your quick answer. In fact, all our database infrastructure is based on the IDatabaseTester. We are always getting these annoying warning messages about the data type factory but we did not have any problem. I just wanted to have a look at it to see if there was an easy fix.

Thanks again for your support
--
Christophe Bliard <[hidden email]>

Le samedi 04 septembre 2010 à 08:02 +1200, John Hurst a écrit :
Christophe,


I think you're right: that may be a problem with IDatabaseTester.


Here's some code I used in preparing some DbUnit samples recently, which gives me what I need (with DataTypeFactory configuration, without using IDatabaseTester:


public class AbstractDbUnitTestCase {


  private DataSource dataSource;
  private IDatabaseConnection databaseConnection;


  @Before
  public void setupConnections() throws SQLException, DatabaseUnitException {
    OracleDataSource dataSource = new OracleDataSource();
    dataSource.setURL(System.getProperty("db.url"));
    dataSource.setUser(System.getProperty("db.userid"));
    dataSource.setPassword(System.getProperty("db.password"));
    this.dataSource = dataSource;
    DatabaseConnection databaseConnection = new DatabaseConnection(getDataSource().getConnection());
    databaseConnection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new Oracle10DataTypeFactory());
    this.databaseConnection = databaseConnection;
  }


  @After
  public void shutdownConnections() throws SQLException {
    if (databaseConnection != null) {
      databaseConnection.close();
    }
  }


  public DataSource getDataSource() {
    return dataSource;
  }


  public IDatabaseConnection getDatabaseConnection() {
    return databaseConnection;
  }
  
  public FlatXmlDataSet getDataSet(String fileName) throws DataSetException {
    return new FlatXmlDataSet(new FlatXmlProducer(new InputSource(getClass().getResourceAsStream(fileName))));
  }
}


This can easily be adapted to different requirements.


We'll need to look into the configuration of IDatabaseTester.


Hope this helps.


John Hurst

On Sat, Sep 4, 2010 at 2:18 AM, Christophe Bliard <[hidden email]> wrote:
Hi,

I am trying to use a Oracle10DataTypeFactory instead of the
DefaultDataTypeFactory. To do so I have the following test code:

public class SomeDatabaseTest {

 private final IDatabaseTester databaseTester;

 public SomeDatabaseTest() throws Exception {
   databaseTester = new JdbcDatabaseTester(
       "oracle.jdbc.driver.OracleDriver",
       "jdbc:oracle:thin:@localhost:1521:XE",
       "username",
       "password",
       "schema");
   databaseTester.getConnection().getConfig().setProperty(
       DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
       new Oracle10DataTypeFactory());
   databaseTester.setDataSet(createDataSet());
 }

 public void before() throws Exception {
   databaseTester.onSetup();
 }

 public void after() throws Exception {
   databaseTester.onTearDown();
 }

 @Test
 public void testSomething() {
   // do test stuff...
 }

 private IDataSet createDataSet()
     throws IOException, DataSetException {
   InputStream input;
   input = this.getClass().getResourceAsStream("myDataSet.xml");
   try {
     return new FlatXmlDataSet(input);
   } finally {
     input.close();
   }
 }
}

But when I run the test, I have this warning multiple times:

2010-09-03 14:54:34,393 [main] WARN
org.dbunit.dataset.AbstractTableMetaData - Potential problem found: The
configured data type factory 'class
org.dbunit.dataset.datatype.DefaultDataTypeFactory' might cause problems
with the current database 'Oracle' (e.g. some datatypes may not be
supported properly). In rare cases you might see this message because
the list of supported database products is incomplete (list=[postgresql,
derby]). If so please request a java-class update via the forums.

I have looked into the dbunit code (we are using dbunit 2.4.4) and it
appears that when calling getConnection(), a new DatabaseConnection
instance is created every time, and this connection has its own
DatabaseConfig object.

So it is useless to set the DataTypeFactory to Oracle10DataTypeFactory
in the getConnection().getConfig() instance: another config will be used
during the onSetup() and onTearDown() call because they call
getConnection().

I think I have missed something but I can't figure out what. Can you
help me please?

Best regards
--
Christophe Bliard <[hidden email]>



------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user



--
Life is interfering with my game

------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________ dbunit-user mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/dbunit-user

------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: Configuring the DataTypeFactory when using a JdbcDatabaseTester in a test

Frank Troia
I ran in to this same problem and when I searched for the answer, I found this thread. However, I didn't see a good solution, so I came up with my own. Since it's returning a new connection object on every call to getConnection, simply override the method and set your factory every call. Cheers!

                databaseTester = new JdbcDatabaseTester(
                                "oracle.jdbc.driver.OracleDriver",
                                "jdbc:oracle:thin:@localhost:1521:XE", "username", "password",
                                "schema") {
                        @Override
                        public IDatabaseConnection getConnection() throws Exception {
                                IDatabaseConnection connection = super.getConnection();

                                        connection.getConfig().setProperty(
                                                        DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
                                                        new Oracle10DataTypeFactory());

                                return connection;
                        }
                };

Christophe Bliard-2 wrote
Hi John,

Thank you for your quick answer. In fact, all our database
infrastructure is based on the IDatabaseTester. We are always getting
these annoying warning messages about the data type factory but we did
not have any problem. I just wanted to have a look at it to see if there
was an easy fix.

Thanks again for your support
--
Christophe Bliard <cbliard@besancon.parkeon.com>

Le samedi 04 septembre 2010 à 08:02 +1200, John Hurst a écrit :

> Christophe,
>
>
>
> I think you're right: that may be a problem with IDatabaseTester.
>
>
> Here's some code I used in preparing some DbUnit samples recently,
> which gives me what I need (with DataTypeFactory configuration,
> without using IDatabaseTester:
>
>
> public class AbstractDbUnitTestCase {
>
>
>   private DataSource dataSource;
>   private IDatabaseConnection databaseConnection;
>
>
>   @Before
>   public void setupConnections() throws SQLException,
> DatabaseUnitException {
>     OracleDataSource dataSource = new OracleDataSource();
>     dataSource.setURL(System.getProperty("db.url"));
>     dataSource.setUser(System.getProperty("db.userid"));
>     dataSource.setPassword(System.getProperty("db.password"));
>     this.dataSource = dataSource;
>     DatabaseConnection databaseConnection = new
> DatabaseConnection(getDataSource().getConnection());
>
>  databaseConnection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new Oracle10DataTypeFactory());
>     this.databaseConnection = databaseConnection;
>   }
>
>
>   @After
>   public void shutdownConnections() throws SQLException {
>     if (databaseConnection != null) {
>       databaseConnection.close();
>     }
>   }
>
>
>   public DataSource getDataSource() {
>     return dataSource;
>   }
>
>
>   public IDatabaseConnection getDatabaseConnection() {
>     return databaseConnection;
>   }
>  
>   public FlatXmlDataSet getDataSet(String fileName) throws
> DataSetException {
>     return new FlatXmlDataSet(new FlatXmlProducer(new
> InputSource(getClass().getResourceAsStream(fileName))));
>   }
> }
>
>
> This can easily be adapted to different requirements.
>
>
> We'll need to look into the configuration of IDatabaseTester.
>
>
> Hope this helps.
>
>
> John Hurst
>
>
>
> On Sat, Sep 4, 2010 at 2:18 AM, Christophe Bliard
> <cbliard@besancon.parkeon.com> wrote:
>
>         Hi,
>        
>         I am trying to use a Oracle10DataTypeFactory instead of the
>         DefaultDataTypeFactory. To do so I have the following test
>         code:
>        
>         public class SomeDatabaseTest {
>        
>          private final IDatabaseTester databaseTester;
>        
>          public SomeDatabaseTest() throws Exception {
>            databaseTester = new JdbcDatabaseTester(
>                "oracle.jdbc.driver.OracleDriver",
>                "jdbc:oracle:thin:@localhost:1521:XE",
>                "username",
>                "password",
>                "schema");
>            databaseTester.getConnection().getConfig().setProperty(
>                DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
>                new Oracle10DataTypeFactory());
>            databaseTester.setDataSet(createDataSet());
>          }
>        
>          public void before() throws Exception {
>            databaseTester.onSetup();
>          }
>        
>          public void after() throws Exception {
>            databaseTester.onTearDown();
>          }
>        
>          @Test
>          public void testSomething() {
>            // do test stuff...
>          }
>        
>          private IDataSet createDataSet()
>              throws IOException, DataSetException {
>            InputStream input;
>            input =
>         this.getClass().getResourceAsStream("myDataSet.xml");
>            try {
>              return new FlatXmlDataSet(input);
>            } finally {
>              input.close();
>            }
>          }
>         }
>        
>         But when I run the test, I have this warning multiple times:
>        
>         2010-09-03 14:54:34,393 [main] WARN
>         org.dbunit.dataset.AbstractTableMetaData - Potential problem
>         found: The
>         configured data type factory 'class
>         org.dbunit.dataset.datatype.DefaultDataTypeFactory' might
>         cause problems
>         with the current database 'Oracle' (e.g. some datatypes may
>         not be
>         supported properly). In rare cases you might see this message
>         because
>         the list of supported database products is incomplete
>         (list=[postgresql,
>         derby]). If so please request a java-class update via the
>         forums.
>        
>         I have looked into the dbunit code (we are using dbunit 2.4.4)
>         and it
>         appears that when calling getConnection(), a new
>         DatabaseConnection
>         instance is created every time, and this connection has its
>         own
>         DatabaseConfig object.
>        
>         So it is useless to set the DataTypeFactory to
>         Oracle10DataTypeFactory
>         in the getConnection().getConfig() instance: another config
>         will be used
>         during the onSetup() and onTearDown() call because they call
>         getConnection().
>        
>         I think I have missed something but I can't figure out what.
>         Can you
>         help me please?
>        
>         Best regards
>         --
>         Christophe Bliard <cbliard@besancon.parkeon.com>
>        
>        
>        
>         ------------------------------------------------------------------------------
>         This SF.net Dev2Dev email is sponsored by:
>        
>         Show off your parallel programming skills.
>         Enter the Intel(R) Threading Challenge 2010.
>         http://p.sf.net/sfu/intel-thread-sfd
>         _______________________________________________
>         dbunit-user mailing list
>         dbunit-user@lists.sourceforge.net
>         https://lists.sourceforge.net/lists/listinfo/dbunit-user
>
>
>
>
> --
> Life is interfering with my game
>
>
> ------------------------------------------------------------------------------
> This SF.net Dev2Dev email is sponsored by:
>
> Show off your parallel programming skills.
> Enter the Intel(R) Threading Challenge 2010.
> http://p.sf.net/sfu/intel-thread-sfd
> _______________________________________________ dbunit-user mailing list dbunit-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/dbunit-user

------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
dbunit-user mailing list
dbunit-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dbunit-user