Ejemplo n.º 1
0
 /**
  * Override this method if you aren't using HSQL DB.
  *
  * <p>Execute whatever statement is necessary to enable integrity constraint checks after dataset
  * operations.
  *
  * @param con A DBUnit connection wrapper, before it is used by the application again
  */
 protected void enableReferentialIntegrity(IDatabaseConnection con) {
   try {
     if (database.equals(Database.hsql)) {
       con.getConnection().prepareStatement("set referential_integrity TRUE").execute(); // HSQL DB
     } else if (database.equals(Database.mysql)) {
       con.getConnection().prepareStatement("set foreign_key_checks=1").execute(); // MySQL > 4.1.1
     }
   } catch (Exception ex) {
     throw new RuntimeException(ex);
   }
 }
Ejemplo n.º 2
0
  public Database getDatabase(final boolean evictCache) {
    if (!evictCache && cachedIntrospections.contains(lastDatabase)) {
      for (final Database database : cachedIntrospections) {
        if (database.equals(lastDatabase)) {
          return lastDatabase;
        }
      }
    }
    if (evictCache && cachedIntrospections.contains(lastDatabase)) {
      cachedIntrospections.remove(lastDatabase);
    }

    final String dbreXmlPath = getDbreXmlPath();
    if (StringUtils.isBlank(dbreXmlPath) || !fileManager.exists(dbreXmlPath)) {
      return null;
    }

    Database database = null;
    InputStream inputStream = null;
    try {
      inputStream = fileManager.getInputStream(dbreXmlPath);
      database = DatabaseXmlUtils.readDatabase(inputStream);
      cacheDatabase(database);
      return database;
    } catch (final Exception e) {
      throw new IllegalStateException(e);
    } finally {
      IOUtils.closeQuietly(inputStream);
    }
  }
Ejemplo n.º 3
0
 /**
  * Override this method if you require DBUnit configuration features or additional properties.
  *
  * <p>Called after a connection has been obtaind and before the connection is used. Can be a NOOP
  * method if no additional settings are necessary for your DBUnit/DBMS setup.
  *
  * @param config A DBUnit <tt>DatabaseConfig</tt> object for setting properties and features
  */
 protected void editConfig(DatabaseConfig config) {
   if (database.equals(Database.hsql)) {
     // DBUnit/HSQL bugfix
     // http://www.carbonfive.com/community/archives/2005/07/dbunit_hsql_and.html
     config.setProperty(
         DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
         new DefaultDataTypeFactory() {
           public DataType createDataType(int sqlType, String sqlTypeName)
               throws DataTypeException {
             if (sqlType == Types.BOOLEAN) {
               return DataType.BOOLEAN;
             }
             return super.createDataType(sqlType, sqlTypeName);
           }
         });
   }
 }