1 21 22 package org.dbunit.operation; 23 24 import org.dbunit.DatabaseUnitException; 25 import org.dbunit.database.IDatabaseConnection; 26 import org.dbunit.dataset.*; 27 28 import java.math.BigInteger ; 29 import java.util.BitSet ; 30 31 40 public class DeleteOperation extends AbstractBatchOperation 41 { 42 DeleteOperation() 43 { 44 _reverseRowOrder = true; 45 } 46 47 50 protected ITableIterator iterator(IDataSet dataSet) throws DatabaseUnitException 51 { 52 return dataSet.reverseIterator(); 53 } 54 55 public OperationData getOperationData(ITableMetaData metaData, BitSet ignoreMapping, IDatabaseConnection connection) throws DataSetException 56 { 57 Column[] primaryKeys = metaData.getPrimaryKeys(); 59 if (primaryKeys.length == 0) 60 { 61 throw new NoPrimaryKeyException(metaData.getTableName()); 62 } 63 64 StringBuffer sqlBuffer = new StringBuffer (128); 66 sqlBuffer.append("delete from "); 67 sqlBuffer.append(getQualifiedName(connection.getSchema(), 68 metaData.getTableName(), connection)); 69 70 sqlBuffer.append(" where "); 72 for (int i = 0; i < primaryKeys.length; i++) 73 { 74 String columnName = getQualifiedName(null, 76 primaryKeys[i].getColumnName(), connection); 77 sqlBuffer.append(columnName); 78 79 sqlBuffer.append(" = ?"); 80 if (i + 1 < primaryKeys.length) 81 { 82 sqlBuffer.append(" and "); 83 } 84 } 85 86 return new OperationData(sqlBuffer.toString(), primaryKeys); 87 } 88 89 } 90 91 92 93 94 95 96 97 98 | Popular Tags |