1 21 package org.dbunit.operation; 22 23 import org.dbunit.DatabaseUnitException; 24 import org.dbunit.database.DatabaseConfig; 25 import org.dbunit.database.IDatabaseConnection; 26 import org.dbunit.dataset.*; 27 28 import java.sql.SQLException ; 29 import java.util.ArrayList ; 30 import java.util.List ; 31 32 37 public abstract class AbstractOperation extends DatabaseOperation 38 { 39 protected String getQualifiedName(String prefix, String name, IDatabaseConnection connection) 40 { 41 String escapePattern = (String )connection.getConfig().getProperty( 42 DatabaseConfig.PROPERTY_ESCAPE_PATTERN); 43 44 return DataSetUtils.getQualifiedName(prefix, name, escapePattern); 45 } 46 47 53 static ITableMetaData getOperationMetaData(IDatabaseConnection connection, 54 ITableMetaData metaData) throws DatabaseUnitException, SQLException 55 { 56 IDataSet databaseDataSet = connection.createDataSet(); 57 String tableName = metaData.getTableName(); 58 59 ITableMetaData databaseMetaData = databaseDataSet.getTableMetaData(tableName); 60 Column[] databaseColumns = databaseMetaData.getColumns(); 61 Column[] columns = metaData.getColumns(); 62 63 List columnList = new ArrayList (); 64 for (int j = 0; j < columns.length; j++) 65 { 66 String columnName = columns[j].getColumnName(); 67 Column column = DataSetUtils.getColumn( 68 columnName, databaseColumns); 69 if (column == null) 70 { 71 throw new NoSuchColumnException(tableName + "." + columnName); 72 } 73 columnList.add(column); 74 } 75 76 return new DefaultTableMetaData(databaseMetaData.getTableName(), 77 (Column[])columnList.toArray(new Column[0]), 78 databaseMetaData.getPrimaryKeys()); 79 } 80 } 81 | Popular Tags |