New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve internal design of DataSetBuilder to enhance maintainability #2
Comments
Starting from the basics, the domain model, I added the following classes (using pseuco-code to clarify): A class for Row.
A class for Table.
A class for Table Metadata.
As we can see, the classes Table and Row were designed to be easy to be built, similar to the builder pattern fashion. So, there's little need, if any, to write specific builders to construct objects of these classes (although we'll see a counterexample for row in a bit). However, CustomTableMetaData extends DefaultTableMetaData and it is quite complex to be created, so we need a specific builder in order to create such objects. We will also need a builder for the DataSet itself and another builder for rows, specifically designed to build rows in such a way that makes it easy to build the dataset working directly with rows (rather than only allowing to build from pre-built tables), so that we can simplify the usage of the dataset builder. I'll leave the builders to the next comment. |
In order to make it easy to join all the pieces together, I added/changed the following builder classes: TableMetaDataBuilder (changed the already existing class)
DataSetBuilder (changed the already existing class)
AbstractDataSetRowBuilder
RawDataSetRowBuilder
I'll leave the usage of the builders to the next comment. |
All of the work previously showed was done so that we can build IDataSet's like this:
First, we need to create the concrete AbstractDataSetRowBuilder (only once per table):
Note that PERSON_TABLE_META_DATA was made static, so there will be only one instance in memory. Then, the actual usage is as simple as this:
And the resulting IDataSet would be similar to this FlatXmlDataSet:
|
org.dbunit.dataset.streamIDataSetConsumer works best when the source is a document that is being parsed while reading in streams, like XML.
To build a IDataSet from objects created purely in Java, a better approach should be to design a domain model with objects that are easy to create so that they can be used by the DataSetBuilder in order to build the IDataSet.
Basically, IDataSet requires the implementation to store a collection of ITable's along with their Metadata (interface ITableMetaData) and the data (composed by rows with their respective columns), so that it can provide information required by IDataSet interface.
Basically, ITableMetaData requires the implementation to provide information about the table, like its name and its columns metadata.
So we need a builder for ITableMetaData and a builder for a collection of tables with rows and columns.
The text was updated successfully, but these errors were encountered: