1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.hack23.cia.testfoundation;
20
21 import java.sql.Connection;
22 import java.sql.SQLException;
23
24 import org.dbunit.DatabaseUnitException;
25 import org.dbunit.database.DatabaseConnection;
26 import org.dbunit.database.DatabaseSequenceFilter;
27 import org.dbunit.database.QueryDataSet;
28 import org.dbunit.dataset.FilteredDataSet;
29 import org.dbunit.dataset.IDataSet;
30 import org.dbunit.dataset.filter.ITableFilter;
31
32
33
34
35 public final class DataSetConnectionFactory {
36
37
38
39
40 public DataSetConnectionFactory() {
41 super();
42 }
43
44
45
46
47
48
49
50
51
52
53 public IDataSet getDataSet(final Connection connection) throws DatasetFactoryException {
54 DatabaseConnection databaseConnection;
55 try {
56 databaseConnection = new DatabaseConnection(connection);
57 final ITableFilter filter = new DatabaseSequenceFilter(databaseConnection);
58 return new FilteredDataSet(filter, databaseConnection.createDataSet());
59 } catch (DatabaseUnitException | SQLException e) {
60 throw new DatasetFactoryException(e);
61 }
62 }
63
64
65
66
67
68
69
70
71
72
73
74 public QueryDataSet getQueryDataset(final Connection connection) throws DatasetFactoryException {
75 try {
76 return new QueryDataSet(new DatabaseConnection(connection));
77 } catch (DatabaseUnitException e) {
78 throw new DatasetFactoryException(e);
79 }
80 }
81
82 }