本文整理汇总了Java中org.dbunit.dataset.datatype.DataType类的典型用法代码示例。如果您正苦于以下问题:Java DataType类的具体用法?Java DataType怎么用?Java DataType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataType类属于org.dbunit.dataset.datatype包,在下文中一共展示了DataType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMetaData
import org.dbunit.dataset.datatype.DataType; //导入依赖的package包/类
/**
* Gets the table meta data based on the rows for a table
*
* @param tableName
* The name of the table
* @param rows
* The rows of the table
* @return The table metadata for the table
*/
private ITableMetaData getMetaData(String tableName,
List<Map<String, Object>> rows) {
Set<String> columns = new LinkedHashSet<String>();
// iterate through the dataset and add the column names to a set
for (Map<String, Object> row : rows) {
for (Map.Entry<String, Object> column : row.entrySet()) {
columns.add(column.getKey());
}
}
List<Column> list = new ArrayList<Column>(columns.size());
// create a list of DBUnit columns based on the column name set
for (String s : columns) {
list.add(new Column(s, DataType.UNKNOWN));
}
return new DefaultTableMetaData(tableName,
list.toArray(new Column[list.size()]));
}
示例2: addRows
import org.dbunit.dataset.datatype.DataType; //导入依赖的package包/类
/**
* Adds the rows of the DbUnit table to the given table.
*
* @param dbUnitTable The DbUnit table containing the rows, not null
* @param table The table to add the rows to, not null
* @param primaryKeyColumnNames The names of the pk columns, empty if there are none
*/
protected void addRows(ITable dbUnitTable, Table table, List<String> primaryKeyColumnNames) throws DataSetException {
org.dbunit.dataset.Column[] columns = dbUnitTable.getTableMetaData().getColumns();
int rowCount = dbUnitTable.getRowCount();
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
Row row = new Row();
table.addRow(row);
for (org.dbunit.dataset.Column dbUnitColumn : columns) {
String columnName = dbUnitColumn.getColumnName();
DataType columnType = dbUnitColumn.getDataType();
Object value = dbUnitTable.getValue(rowIndex, columnName);
Column column = new Column(columnName, columnType, value);
if (primaryKeyColumnNames.contains(columnName)) {
row.addPrimaryKeyColumn(column);
} else {
row.addColumn(column);
}
}
}
}
示例3: createTableMetaData
import org.dbunit.dataset.datatype.DataType; //导入依赖的package包/类
private ITableMetaData createTableMetaData() throws DataSetException {
if (beans.isEmpty()) {
return new DefaultTableMetaData(tableName, new Column[0]);
} else {
try {
List<Column> columns = new ArrayList<Column>();
BeanInfo info = Introspector.getBeanInfo(beans.get(0).getClass());
PropertyDescriptor[] descs = info.getPropertyDescriptors();
for (PropertyDescriptor desc : descs) {
if (!isIgnoreProperty(desc)) {
System.out.println(desc.getName());
columns.add(new Column(desc.getName(), DataType.UNKNOWN));
}
}
Column[] c = (Column[]) columns.toArray(new Column[columns.size()]);
return new DefaultTableMetaData(tableName, c);
} catch (IntrospectionException e) {
throw new DataSetException(e);
}
}
}
示例4: getMetaData
import org.dbunit.dataset.datatype.DataType; //导入依赖的package包/类
/**
* Gets the table meta data based on the rows for a table
*
* @param tableName
* The name of the table
* @param rows
* The rows of the table
* @return The table metadata for the table
*/
private ITableMetaData getMetaData(String tableName,
List<Map<String, Object>> rows) {
Set<String> columns = new LinkedHashSet<String>();
// iterate through the dataset and add the column names to a set
for (Map<String, Object> row : rows) {
for (Map.Entry<String, Object> column : row.entrySet()) {
columns.add(column.getKey());
}
}
List<Column> list = new ArrayList<Column>(columns.size());
// create a list of DBUnit columns based on the column name set
for (String s : columns) {
list.add(new Column(s, DataType.UNKNOWN));
}
return new DefaultTableMetaData(tableName,
list.toArray(new Column[list.size()]));
}
示例5: readTable
import org.dbunit.dataset.datatype.DataType; //导入依赖的package包/类
/**
* Выполняет формирование таблицы из файла
*
* @param tableName название таблицы
* @param reader сервис чтения файла
*/
protected void readTable(String tableName, ICsvListReader reader) throws DataSetException, IOException {
String[] headers = reader.getHeader(true);
if (headers == null) {
throw new DataSetException(String.format("Table '%s' must contains headers", tableName));
}
Column[] columns = new Column[headers.length];
for (int i = 0; i < headers.length; i++) {
columns[i] = new Column(headers[i], DataType.UNKNOWN);
}
consumer.startTable(new DefaultTableMetaData(tableName, columns));
List<String> row;
while ((row = reader.read()) != null) {
consumer.row(row.toArray());
}
consumer.endTable();
}
示例6: testConvert
import org.dbunit.dataset.datatype.DataType; //导入依赖的package包/类
public void testConvert() throws Exception {
ITableMetaData tableMetaData = new DefaultTableMetaData(
"testDictionary",
new Column[]{new Column("column1", DataType.UNKNOWN), new Column("column2", DataType.UNKNOWN)}
);
Dictionary dictionary = converter.convert(tableMetaData);
assertNotNull(dictionary);
assertEquals(dictionary.getName(), "testDictionary");
// check META-fields
List<MetaField> metaFields = ModelUtils.sortMetaFieldsByOrdinal(dictionary.getDescendants());
assertEquals(metaFields.size(), 2);
for (int i = 0; i < metaFields.size(); i++) {
assertMetaField(metaFields.get(i), tableMetaData.getColumns(), i, i == 0);
}
// check serialize
assertObjectSerialization(dictionary);
}
示例7: testConvert
import org.dbunit.dataset.datatype.DataType; //导入依赖的package包/类
public void testConvert() throws Exception {
DefaultTable table = new DefaultTable(new DefaultTableMetaData(
"testDictionary" + MetaFieldsConverter.DEFAULT_TABLE_POSTFIX,
new Column[]{
new Column(MetaField.NAME, DataType.UNKNOWN),
new Column(MetaField.DESCRIPTION, DataType.UNKNOWN),
new Column(MetaField.FLAG_PRIMARY_NAME, DataType.UNKNOWN),
new Column(MetaField.FLAG_UNIQUE_NAME, DataType.UNKNOWN),
new Column(MetaField.FLAG_HIDDEN_NAME, DataType.UNKNOWN)
}
));
table.addRow(new Object[]{"mf1", "meta_field_1", true, true, false});
table.addRow(new Object[]{"mf2", "meta_field_2", false, true, false});
table.addRow(new Object[]{"mf3", "meta_field_3", false, false, true});
Dictionary dictionary = converter.convert(table);
assertEquals(dictionary.getName(), "testDictionary");
List<MetaField> metaFields = ModelUtils.sortMetaFieldsByOrdinal(dictionary.getDescendants());
// check meta fields
assertEquals(metaFields.size(), 3);
for (int i = 0; i < table.getRowCount(); i++) {
assertMetaField(metaFields.get(i), table, i);
}
// check serialize
assertObjectSerialization(dictionary);
}
示例8: createDataType
import org.dbunit.dataset.datatype.DataType; //导入依赖的package包/类
@Override
public DataType createDataType(int sqlType, String sqlTypeName) throws DataTypeException {
if (sqlType == 1111) {
if ("jsonb".equals(sqlTypeName)) {
return new JsonbDataType();
}
}
return super.createDataType(sqlType, sqlTypeName);
}
示例9: createMeta
import org.dbunit.dataset.datatype.DataType; //导入依赖的package包/类
ITableMetaData createMeta(String name, List<String> columnNames) {
Column[] columns = null;
if (columnNames != null) {
columns = new Column[columnNames.size()];
for (int i = 0; i < columnNames.size(); i++)
columns[i] = new Column(columnNames.get(i), DataType.UNKNOWN);
} else {
columns = new Column[0];
}
return new DefaultTableMetaData(name, columns);
}
示例10: addTable
import org.dbunit.dataset.datatype.DataType; //导入依赖的package包/类
private void addTable(Schema schema, String tableName, String value) {
Row row = new Row();
row.addColumn(new Column("column", DataType.VARCHAR, value));
Table table = new Table(tableName);
table.addRow(row);
schema.addTable(table);
}
示例11: getCastedValue
import org.dbunit.dataset.datatype.DataType; //导入依赖的package包/类
/**
* Gets the value casted to the given type.
*
* @param castType The type to cast the value to, not null
* @return The casted value
* @throws UnitilsException When the value cannot be cast
*/
public Object getCastedValue(DataType castType) {
try {
return castType.typeCast(value);
} catch (TypeCastException e) {
throw new UnitilsException("Unable to convert \"" + value + "\" to " + castType.toString() + ". Column name: " + name + ", current type: " + type.toString(), e);
}
}
示例12: relosveDataType
import org.dbunit.dataset.datatype.DataType; //导入依赖的package包/类
/**
* clazzに対応するデータベースの型を返す.
* @param clazz class
* @return データベースの型
*/
public DataType relosveDataType(Class<?> clazz) {
if (String.class == clazz) {
return DataType.VARCHAR;
} else if (Integer.class == clazz) {
return DataType.NUMERIC;
} else if (Long.class == clazz) {
return DataType.NUMERIC;
} else if (Date.class == clazz) {
return DataType.TIMESTAMP;
}
return null;
}
示例13: createDataType
import org.dbunit.dataset.datatype.DataType; //导入依赖的package包/类
@Override
public DataType createDataType(int sqlType, String sqlTypeName) throws DataTypeException {
logger.debug("createDataType(sqlType={}, sqlTypeName={}) - start", new Integer(sqlType),
sqlTypeName);
DataType customDataType = customDataTypeMap.get(sqlTypeName);
if (customDataType != null) {
logger.debug("use custom dataType(sqlTypeName={}, dataType=)", sqlTypeName, customDataType);
return customDataType;
} else {
return super.createDataType(sqlType, sqlTypeName);
}
}
示例14: addCustomType
import org.dbunit.dataset.datatype.DataType; //导入依赖的package包/类
public void addCustomType(String sqlTypeName, DataType dataType) {
if (sqlTypeName == null || "".equals(sqlTypeName)) {
throw new NullPointerException("sqlType is null or empty.");
}
if (dataType == null) {
throw new NullPointerException("dataType is null or empty.");
}
logger.debug("add custom type ('{}' is {})", sqlTypeName, dataType.getClass());
customDataTypeMap.put(sqlTypeName, dataType);
}
示例15: addValue
import org.dbunit.dataset.datatype.DataType; //导入依赖的package包/类
@Override
public void addValue(Object value, DataType dataType) throws TypeCastException, SQLException {
logger.debug("addValue(value={}, dataType={}) - start", value, dataType);
if(value instanceof SqlDefaultValueObject) {
value = SqlDefaultValueObject.getDefaultValue(dataType.getSqlType());
}
super.addValue(value, dataType);
}