Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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;
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
/**
* Represents the data table for SQL Server.
*/
public final class SQLServerDataTable {
int rowCount = 0;
int columnCount = 0;
Map columnMetadata = null;
Set columnNames = null;
Map> rows = null;
private String tvpName = null;
/**
* The constant in the Java programming language, sometimes referred to as a type code, that identifies the type
* TVP.
*
* @throws SQLServerException
* when an error occurs
*/
// Name used in CREATE TYPE
public SQLServerDataTable() throws SQLServerException {
columnMetadata = new LinkedHashMap<>();
columnNames = new HashSet<>();
rows = new HashMap<>();
}
/**
* Clears this data table.
*/
public synchronized void clear() {
rowCount = 0;
columnCount = 0;
columnMetadata.clear();
columnNames.clear();
rows.clear();
}
/**
* Returns an iterator on the rows of the data table.
*
* @return an iterator on the rows of the data table.
*/
public synchronized Iterator>> getIterator() {
if ((null != rows) && (null != rows.entrySet())) {
return rows.entrySet().iterator();
}
return null;
}
/**
* Adds meta data for the specified column.
*
* @param columnName
* the name of the column
* @param sqlType
* the sql type of the column
* @throws SQLServerException
* when an error occurs
*/
public synchronized void addColumnMetadata(String columnName, int sqlType) throws SQLServerException {
// column names must be unique
Util.checkDuplicateColumnName(columnName, columnNames);
columnMetadata.put(columnCount++, new SQLServerDataColumn(columnName, sqlType));
}
/**
* Adds meta data for the specified column.
*
* @param column
* the name of the column
* @throws SQLServerException
* when an error occurs
*/
public synchronized void addColumnMetadata(SQLServerDataColumn column) throws SQLServerException {
// column names must be unique
Util.checkDuplicateColumnName(column.columnName, columnNames);
columnMetadata.put(columnCount++, column);
}
/**
* Adds one row of data to the data table.
*
* @param values
* values to be added in one row of data to the data table.
* @throws SQLServerException
* when an error occurs
*/
public synchronized void addRow(Object... values) throws SQLServerException {
try {
int columnCount = columnMetadata.size();
if ((null != values) && values.length > columnCount) {
MessageFormat form = new MessageFormat(
SQLServerException.getErrString("R_moreDataInRowThanColumnInTVP"));
Object[] msgArgs = {};
throw new SQLServerException(null, form.format(msgArgs), null, 0, false);
}
Iterator> columnsIterator = columnMetadata.entrySet().iterator();
List