1313import java .time .OffsetDateTime ;
1414import java .time .OffsetTime ;
1515import java .util .HashMap ;
16- import java .util .HashSet ;
1716import java .util .Iterator ;
1817import java .util .LinkedHashMap ;
1918import java .util .Map ;
2019import java .util .Map .Entry ;
21- import java .util .Set ;
2220import java .util .UUID ;
2321
2422public final class SQLServerDataTable {
2523
2624 int rowCount = 0 ;
2725 int columnCount = 0 ;
2826 Map <Integer , SQLServerDataColumn > columnMetadata = null ;
29- Set <String > columnList = null ;
3027 Map <Integer , Object []> rows = null ;
3128
3229 private String tvpName = null ;
@@ -40,7 +37,6 @@ public final class SQLServerDataTable {
4037 // Name used in CREATE TYPE
4138 public SQLServerDataTable () throws SQLServerException {
4239 columnMetadata = new LinkedHashMap <>();
43- columnList = new HashSet <>();
4440 rows = new HashMap <>();
4541 }
4642
@@ -79,7 +75,7 @@ public synchronized Iterator<Entry<Integer, Object[]>> getIterator() {
7975 public synchronized void addColumnMetadata (String columnName ,
8076 int sqlType ) throws SQLServerException {
8177 // column names must be unique
82- checkDuplicateColumnName (columnName );
78+ Util . checkDuplicateColumnName (columnName , columnMetadata );
8379 columnMetadata .put (columnCount ++, new SQLServerDataColumn (columnName , sqlType ));
8480 }
8581
@@ -93,29 +89,10 @@ public synchronized void addColumnMetadata(String columnName,
9389 */
9490 public synchronized void addColumnMetadata (SQLServerDataColumn column ) throws SQLServerException {
9591 // column names must be unique
96- checkDuplicateColumnName (column .columnName );
92+ Util . checkDuplicateColumnName (column .columnName , columnMetadata );
9793 columnMetadata .put (columnCount ++, column );
9894 }
9995
100- /**
101- * Checks if duplicate columns exists, in O(n) time.
102- *
103- * @param columnName
104- * the name of the column
105- * @throws SQLServerException
106- * when a duplicate column exists
107- */
108- private void checkDuplicateColumnName (String columnName ) throws SQLServerException {
109- if (null != columnList ) {
110- //columnList.add will return false if the same column name already exists
111- if (!columnList .add (columnName )) {
112- MessageFormat form = new MessageFormat (SQLServerException .getErrString ("R_TVPDuplicateColumnName" ));
113- Object [] msgArgs = {columnName };
114- throw new SQLServerException (null , form .format (msgArgs ), null , 0 , false );
115- }
116- }
117- }
118-
11996 /**
12097 * Adds one row of data to the data table.
12198 *
0 commit comments