-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #40
- Loading branch information
Showing
7 changed files
with
251 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
core/src/main/java/com/github/dbunit/rules/api/dbunit/DBUnitConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.github.dbunit.rules.api.dbunit; | ||
|
||
import com.github.dbunit.rules.dataset.DataSetExecutorImpl; | ||
|
||
import java.lang.annotation.*; | ||
|
||
import org.dbunit.database.DatabaseConfig; | ||
|
||
/** | ||
* Created by rafael-pestano on 30/08/2016. | ||
* | ||
* This annotation configures DBUnit properties | ||
* (http://dbunit.sourceforge.net/properties.html) for a given dataset executor. | ||
* | ||
* It can be used at class or method level. | ||
*/ | ||
@Target({ ElementType.METHOD, ElementType.TYPE }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@Inherited | ||
public @interface DBUnitConfig { | ||
|
||
/** | ||
* | ||
* Executor id for which the properties will be setup. | ||
*/ | ||
String executor() default DataSetExecutorImpl.DEFAULT_EXECUTOR_ID; | ||
|
||
|
||
boolean cacheConnection() default false; | ||
|
||
|
||
boolean cacheTableNames() default false; | ||
|
||
|
||
/** | ||
* configures DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES. Defaults to false. | ||
*/ | ||
boolean qualifiedTableNames() default false; | ||
|
||
/** | ||
* | ||
* DatabaseConfig.FEATURE_BATCHED_STATEMENTS | ||
*/ | ||
boolean batchedStatements() default false; | ||
|
||
/** | ||
* configures DatabaseConfig.FEATURE_ALLOW_EMPTY_FIELDS. Defaults to false. | ||
*/ | ||
boolean allowEmptyFields() default false; | ||
|
||
/** | ||
* | ||
* DatabaseConfig.PROPERTY_FETCH_SIZE. Defaults to 100 | ||
*/ | ||
int fetchSize() default 100; | ||
|
||
/** | ||
* DatabaseConfig.PROPERTY_BATCH_SIZE. Defaults to 100 | ||
*/ | ||
int batchSize() default 100; | ||
|
||
/** | ||
* DatabaseConfig.PROPERTY_ESCAPE_PATTERN. Defaults to none | ||
*/ | ||
String escapePattern() default ""; | ||
} |
83 changes: 83 additions & 0 deletions
83
core/src/main/java/com/github/dbunit/rules/api/dbunit/DBUnitConfigModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.github.dbunit.rules.api.dbunit; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.dbunit.database.DatabaseConfig; | ||
|
||
import com.github.dbunit.rules.dataset.DataSetExecutorImpl; | ||
|
||
public class DBUnitConfigModel { | ||
|
||
private String executorId; | ||
|
||
private boolean cacheConnection = false; | ||
|
||
private boolean cacheTables = false; | ||
|
||
private Map<String,Object> dbunitProperties; | ||
|
||
public DBUnitConfigModel(String executor) { | ||
dbunitProperties = new HashMap<>(); | ||
this.executorId = executor; | ||
if("".equals(this.executorId)){ | ||
this.executorId = DataSetExecutorImpl.DEFAULT_EXECUTOR_ID; | ||
} | ||
} | ||
|
||
|
||
public static DBUnitConfigModel from(DBUnitConfig dbUnitConfig){ | ||
DBUnitConfigModel dbUnitConfigModel = new DBUnitConfigModel(dbUnitConfig.executor()); | ||
|
||
dbUnitConfigModel.cacheConnection(dbUnitConfig.cacheConnection()). | ||
cacheTables(dbUnitConfig.cacheTables()). | ||
addDBUnitProperty(DatabaseConfig.FEATURE_BATCHED_STATEMENTS, dbUnitConfig.batchedStatements()). | ||
addDBUnitProperty(DatabaseConfig.PROPERTY_BATCH_SIZE, dbUnitConfig.batchSize()). | ||
addDBUnitProperty(DatabaseConfig.FEATURE_ALLOW_EMPTY_FIELDS, dbUnitConfig.allowEmptyFields()). | ||
addDBUnitProperty(DatabaseConfig.PROPERTY_FETCH_SIZE, dbUnitConfig.fetchSize()). | ||
addDBUnitProperty(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, dbUnitConfig.qualifiedTableNames()); | ||
|
||
if(!"".equals(dbUnitConfig.escapePattern())){ | ||
dbUnitConfigModel.addDBUnitProperty(DatabaseConfig.PROPERTY_ESCAPE_PATTERN, dbUnitConfig.escapePattern()); | ||
} | ||
|
||
return dbUnitConfigModel; | ||
} | ||
|
||
|
||
public DBUnitConfigModel cacheConnection(boolean cacheConnection){ | ||
this.cacheConnection = cacheConnection; | ||
return this; | ||
} | ||
|
||
|
||
public DBUnitConfigModel cacheTables(boolean cacheTables){ | ||
this.cacheTables = cacheTables; | ||
return this; | ||
} | ||
|
||
public DBUnitConfigModel addDBUnitProperty(String name, Object value){ | ||
dbunitProperties.put(name,value); | ||
return this; | ||
} | ||
|
||
public boolean isCacheConnection() { | ||
return cacheConnection; | ||
} | ||
|
||
|
||
public boolean isCacheTables() { | ||
return cacheTables; | ||
} | ||
|
||
|
||
public Map<String, Object> getDbunitProperties() { | ||
return dbunitProperties; | ||
} | ||
|
||
public String getExecutorId() { | ||
return executorId; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.