forked from microsoft/mssql-jdbc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBulkCopyTestWrapper.java
235 lines (191 loc) · 7.27 KB
/
BulkCopyTestWrapper.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
* Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
* available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc.bulkCopy;
import java.util.LinkedList;
import com.microsoft.sqlserver.jdbc.ISQLServerDataSource;
import com.microsoft.sqlserver.jdbc.SQLServerBulkCopyOptions;
/**
* Wrapper class that has all the data/values needed to execute BulkCopy test case
*/
class BulkCopyTestWrapper {
/**
* Test case name
*/
String testName;
/**
* <code>true</code> if SQLServerBulkCopy should use connection object
*/
private boolean isUsingConnection = false;
/**
* <code>true</code> if SQLServerBulkCopy should use XA connection object
*/
private boolean isUsingXAConnection = false;
/**
* <code>true</code> if SQLServerBulkCopy should use pooled connection object
*/
private boolean isUsingPooledConnection = false;
/**
* <code>true</code> if SQLServerBulkCopy should include SQLServerBulkCopyOptions
*/
private boolean useBulkCopyOptions = false;
/**
* <code>true</code> if SQLServerBulkCopy should use column mapping
*/
private boolean isUsingColumnMapping = false;
public LinkedList<ColumnMap> cm = new LinkedList<>();
private SQLServerBulkCopyOptions bulkOptions;
private String connectionString;
private ISQLServerDataSource dataSource;
BulkCopyTestWrapper(String connectionString) {
this.connectionString = connectionString;
}
/**
* Returns boolean value <code>true</code> if connection object is used for testing bulk copy
*
* @return isUsingConnection
*/
public boolean isUsingConnection() {
return isUsingConnection;
}
/**
* Returns boolean value <code>true</code> if XA connection object is used for testing bulk copy
*
* @return isUsingXAConnection
*/
public boolean isUsingXAConnection() {
return isUsingXAConnection;
}
/**
* Returns boolean value <code>true</code> if pooled connection object is used for testing bulk copy
*
* @return isUsingPooledConnection
*/
public boolean isUsingPooledConnection() {
return isUsingPooledConnection;
}
/**
* @param isUsingConnection
* <code>true</code> if connection object should be passed in BulkCopy constructor <code>false</code> if
* connection string is to be passed to constructor
*/
public void setUsingConnection(boolean isUsingConnection, ISQLServerDataSource ds) {
this.isUsingConnection = isUsingConnection;
testName += "isUsingConnection=" + isUsingConnection + ";";
setDataSource(ds);
}
/**
* Sets boolean property if XA Connection must be used to test bulk Copy
*
* @param isUsingXAConnection
* <code>true</code> if XA connection object should be passed in BulkCopy constructor <code>false</code> if
* otherwise
*/
public void setUsingXAConnection(boolean isUsingXAConnection, ISQLServerDataSource ds) {
if (!isUsingConnection) {
// Cannot use XA Connection if connection itself is not in use.
isUsingXAConnection = false;
}
this.isUsingXAConnection = isUsingXAConnection;
testName += "isUsingXAConnection=" + isUsingXAConnection + ";";
if (isUsingXAConnection)
setDataSource(ds);
}
/**
* Sets boolean property if Pooled Connection must be used to test bulk Copy
*
* @param isUsingPooledConnection
* <code>true</code> if Pooled connection object should be passed in BulkCopy constructor <code>false</code>
* if otherwise
*/
public void setUsingPooledConnection(boolean isUsingPooledConnection, ISQLServerDataSource ds) {
if (!isUsingConnection || isUsingXAConnection) {
// Cannot use Pooled connection if connection itself is not in use or we are already using XA Connection
isUsingPooledConnection = false;
}
this.isUsingPooledConnection = isUsingPooledConnection;
testName += "isUsingPooledConnection=" + isUsingPooledConnection + ";";
if (isUsingPooledConnection)
setDataSource(ds);
}
public boolean isUsingBulkCopyOptions() {
return useBulkCopyOptions;
}
public void useBulkCopyOptions(boolean useBulkCopyOptions) {
this.useBulkCopyOptions = useBulkCopyOptions;
testName += "useBulkCopyOptions=" + useBulkCopyOptions + ";";
}
public SQLServerBulkCopyOptions getBulkOptions() {
return bulkOptions;
}
public void setBulkOptions(SQLServerBulkCopyOptions bulkOptions) {
this.bulkOptions = bulkOptions;
}
public String getConnectionString() {
return connectionString;
}
public void setConnectionString(String connectionString) {
this.connectionString = connectionString;
}
public ISQLServerDataSource getDataSource() {
return dataSource;
}
public void setDataSource(ISQLServerDataSource dataSource) {
this.dataSource = dataSource;
}
public void setUsingColumnMapping() {
this.isUsingColumnMapping = true;
}
public boolean isUsingColumnMapping() {
return isUsingColumnMapping;
}
public void setColumnMapping(int sourceColOrdinal, int destColOrdinal) {
setUsingColumnMapping();
cm.add(new ColumnMap(sourceColOrdinal, destColOrdinal));
}
public void setColumnMapping(int sourceColOrdinal, String destColName) {
setUsingColumnMapping();
cm.add(new ColumnMap(sourceColOrdinal, destColName));
}
public void setColumnMapping(String sourceColName, String destColName) {
setUsingColumnMapping();
cm.add(new ColumnMap(sourceColName, destColName));
}
public void setColumnMapping(String sourceColName, int destColOrdinal) {
setUsingColumnMapping();
cm.add(new ColumnMap(sourceColName, destColOrdinal));
}
class ColumnMap {
boolean sourceIsInt = false;
boolean destIsInt = false;
int srcInt = -1;
String srcString = null;
int destInt = -1;
String destString = null;
ColumnMap(int src, int dest) {
this.sourceIsInt = true;
this.destIsInt = true;
this.srcInt = src;
this.destInt = dest;
}
ColumnMap(String src, int dest) {
this.sourceIsInt = false;
this.destIsInt = true;
this.srcString = src;
this.destInt = dest;
}
ColumnMap(int src, String dest) {
this.sourceIsInt = true;
this.destIsInt = false;
this.srcInt = src;
this.destString = dest;
}
ColumnMap(String src, String dest) {
this.sourceIsInt = false;
this.destIsInt = false;
this.srcString = src;
this.destString = dest;
}
}
}