You can subscribe to this list here.
2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(5) |
Jul
(7) |
Aug
(37) |
Sep
|
Oct
|
Nov
(1) |
Dec
(22) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(8) |
Feb
(68) |
Mar
(72) |
Apr
(149) |
May
(32) |
Jun
(46) |
Jul
(26) |
Aug
(59) |
Sep
(25) |
Oct
(18) |
Nov
(4) |
Dec
(3) |
2004 |
Jan
(90) |
Feb
(19) |
Mar
(38) |
Apr
(41) |
May
(44) |
Jun
(2) |
Jul
(10) |
Aug
|
Sep
(14) |
Oct
|
Nov
(1) |
Dec
|
2005 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(15) |
Jun
(1) |
Jul
|
Aug
(9) |
Sep
|
Oct
(17) |
Nov
|
Dec
|
2006 |
Jan
(1) |
Feb
(16) |
Mar
|
Apr
(1) |
May
(48) |
Jun
|
Jul
(2) |
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
(29) |
2007 |
Jan
|
Feb
(3) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2008 |
Jan
|
Feb
(23) |
Mar
(31) |
Apr
|
May
(26) |
Jun
(6) |
Jul
(1) |
Aug
|
Sep
(7) |
Oct
(1) |
Nov
(8) |
Dec
(8) |
2009 |
Jan
(5) |
Feb
(9) |
Mar
(1) |
Apr
|
May
(23) |
Jun
(3) |
Jul
|
Aug
(1) |
Sep
(9) |
Oct
(28) |
Nov
(18) |
Dec
(8) |
2010 |
Jan
(19) |
Feb
(24) |
Mar
(3) |
Apr
|
May
(5) |
Jun
(4) |
Jul
|
Aug
(1) |
Sep
(11) |
Oct
|
Nov
(2) |
Dec
(1) |
2011 |
Jan
|
Feb
(7) |
Mar
|
Apr
(6) |
May
(3) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(32) |
Oct
(6) |
Nov
|
Dec
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/xml In directory sc8-pr-cvs1:/tmp/cvs-serv30700/src/java/org/dbunit/dataset/xml Modified Files: Tag: branch-exml2sax FlatXmlWriter.java Added Files: Tag: branch-exml2sax FlatDtdProducer.java FlatXmlProducer.java Removed Files: Tag: branch-exml2sax FlatDtdProvider.java FlatXmlProvider.java Log Message: More class renaming. Renamed IDataSetProvider to IDataSetProducer. Subclasses have also been renamed to follow the same pattern. My initial intent to rename Source to Producer but for some strange reasons this ended up as Provider. Are you confused? Me I was! --- NEW FILE: FlatDtdProducer.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset.xml; import org.dbunit.dataset.Column; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.DefaultTableMetaData; import org.dbunit.dataset.IDataSetConsumer; import org.dbunit.dataset.IDataSetProducer; import org.dbunit.dataset.datatype.DataType; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; import org.xml.sax.XMLReader; import org.xml.sax.ext.DeclHandler; import org.xml.sax.ext.LexicalHandler; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import java.io.IOException; import java.io.StringReader; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.StringTokenizer; /** * @author Manuel Laflamme * @since Apr 27, 2003 * @version $Revision: 1.1.2.1 $ */ public class FlatDtdProducer implements IDataSetProducer, EntityResolver, DeclHandler, LexicalHandler { private static final String XML_CONTENT = "<?xml version=\"1.0\"?>\n<!DOCTYPE dataset SYSTEM \"urn:/dummy.dtd\">\n<dataset/>"; private static final String DECL_HANDLER_PROPERTY_NAME = "http://xml.org/sax/properties/declaration-handler"; private static final String LEXICAL_HANDLER_PROPERTY_NAME = "http://xml.org/sax/properties/lexical-handler"; private static final String REQUIRED = "#REQUIRED"; private static final String IMPLIED = "#IMPLIED"; private InputSource _inputSource; private IDataSetConsumer _consumer; private String _rootName; private String _rootModel; private final Map _columnListMap = new HashMap(); public FlatDtdProducer() { } public FlatDtdProducer(InputSource inputSource) { _inputSource = inputSource; } public static void setDeclHandler(XMLReader xmlReader, DeclHandler handler) throws SAXNotRecognizedException, SAXNotSupportedException { xmlReader.setProperty(DECL_HANDLER_PROPERTY_NAME, handler); } public static void setLexicalHandler(XMLReader xmlReader, LexicalHandler handler) throws SAXNotRecognizedException, SAXNotSupportedException { xmlReader.setProperty(LEXICAL_HANDLER_PROPERTY_NAME, handler); } //////////////////////////////////////////////////////////////////////////// // IDataSetProducer interface public void setConsumer(IDataSetConsumer consumer) throws DataSetException { _consumer = consumer; } public void produce() throws DataSetException { try { SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); XMLReader xmlReader = saxParser.getXMLReader(); setDeclHandler(xmlReader, this); setLexicalHandler(xmlReader, this); xmlReader.setEntityResolver(this); xmlReader.parse(new InputSource(new StringReader(XML_CONTENT))); } catch (ParserConfigurationException e) { throw new DataSetException(e); } catch (SAXException e) { Exception exception = e.getException() == null ? e : e.getException(); throw new DataSetException(exception); } catch (IOException e) { throw new DataSetException(e); } } //////////////////////////////////////////////////////////////////////////// // EntityResolver interface public InputSource resolveEntity(String publicId, String systemId) throws SAXException { return _inputSource; } //////////////////////////////////////////////////////////////////////////// // DeclHandler interface public void elementDecl(String name, String model) throws SAXException { // Root element if (name.equals(_rootName)) { // The root model defines the table sequence. Keep it for later used! _rootModel = model; } // Other elements else { _columnListMap.put(name, new LinkedList()); } } public void attributeDecl(String elementName, String attributeName, String type, String mode, String value) throws SAXException { // Each element attribute represent a table column Column.Nullable nullable = (REQUIRED.equals(mode)) ? Column.NO_NULLS : Column.NULLABLE; Column column = new Column(attributeName, DataType.UNKNOWN, nullable); List columnList = (List)_columnListMap.get(elementName); columnList.add(column); } public void internalEntityDecl(String name, String value) throws SAXException { // Not used! } public void externalEntityDecl(String name, String publicId, String systemId) throws SAXException { // Not used! } //////////////////////////////////////////////////////////////////////////// // LexicalHandler interface public void startDTD(String name, String publicId, String systemId) throws SAXException { try { _rootName = name; _consumer.startDataSet(); } catch (DataSetException e) { throw new SAXException(e); } } public void endDTD() throws SAXException { try { if (_rootModel != null) { // Remove enclosing model parenthesis String rootModel = _rootModel.substring(1, _rootModel.length() - 1); // Parse the root element model to determine the table sequence. // This implementation does not support choices yet and will never // support mixed model. StringTokenizer tokenizer = new StringTokenizer(rootModel, ","); while (tokenizer.hasMoreTokens()) { String tableName = tokenizer.nextToken(); // Prune ending occurrence operator if (tableName.endsWith("*") || tableName.endsWith("?") || tableName.endsWith("+")) { tableName = tableName.substring(0, tableName.length() - 1); } List columnList = (List)_columnListMap.get(tableName); Column[] columns = (Column[])columnList.toArray(new Column[0]); _consumer.startTable(new DefaultTableMetaData(tableName, columns)); _consumer.endTable(); } } _consumer.endDataSet(); } catch (DataSetException e) { throw new SAXException(e); } } public void startEntity(String name) throws SAXException { // Not used! } public void endEntity(String name) throws SAXException { // Not used! } public void startCDATA() throws SAXException { // Not used! } public void endCDATA() throws SAXException { // Not used! } public void comment(char ch[], int start, int length) throws SAXException { // Not used! } } --- NEW FILE: FlatXmlProducer.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset.xml; import org.dbunit.dataset.CachedDataSet; import org.dbunit.dataset.Column; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.DefaultTableMetaData; import org.dbunit.dataset.IDataSet; import org.dbunit.dataset.IDataSetConsumer; import org.dbunit.dataset.IDataSetProducer; import org.dbunit.dataset.ITableMetaData; import org.dbunit.dataset.datatype.DataType; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import java.io.IOException; import java.io.StringReader; /** * @author Manuel Laflamme * @since Apr 18, 2003 * @version $Revision: 1.1.2.1 $ */ public class FlatXmlProducer extends DefaultHandler implements IDataSetProducer, ContentHandler { private static final String DATASET = "dataset"; private final InputSource _inputSource; private XMLReader _xmlReader; private IDataSet _metaDataSet; boolean _ignoreDtd = false; private IDataSetConsumer _consumer; private ITableMetaData _activeMetaData; public FlatXmlProducer(InputSource xmlSource) { _inputSource = xmlSource; } public FlatXmlProducer(InputSource xmlSource, boolean ignoreDtd) { _inputSource = xmlSource; _ignoreDtd = ignoreDtd; } public FlatXmlProducer(InputSource xmlSource, IDataSet metaDataSet) { _inputSource = xmlSource; _metaDataSet = metaDataSet; _ignoreDtd = true; } // public FlatXmlProducer(InputSource inputSource, XMLReader xmlReader) // { // _inputSource = inputSource; // _xmlReader = xmlReader; // } private ITableMetaData createTableMetaData(String tableName, Attributes attributes) throws DataSetException { if (_metaDataSet != null) { return _metaDataSet.getTableMetaData(tableName); } // Create metadata from attributes Column[] columns = new Column[attributes.getLength()]; for (int i = 0; i < attributes.getLength(); i++) { columns[i] = new Column(attributes.getQName(i), DataType.UNKNOWN); } return new DefaultTableMetaData(tableName, columns); } //////////////////////////////////////////////////////////////////////////// // IDataSetProducer interface public void setConsumer(IDataSetConsumer consumer) throws DataSetException { _consumer = consumer; } public void produce() throws DataSetException { try { if (_xmlReader == null) { SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); _xmlReader = saxParser.getXMLReader(); } if (!_ignoreDtd) { FlatDtdHandler dtdHandler = new FlatDtdHandler(); FlatDtdHandler.setLexicalHandler(_xmlReader, dtdHandler); FlatDtdHandler.setDeclHandler(_xmlReader, dtdHandler); } _xmlReader.setContentHandler(this); _xmlReader.setEntityResolver(this); _xmlReader.parse(_inputSource); } catch (ParserConfigurationException e) { throw new DataSetException(e); } catch (SAXException e) { Exception exception = e.getException() == null ? e : e.getException(); throw new DataSetException(exception); } catch (IOException e) { throw new DataSetException(e); } } //////////////////////////////////////////////////////////////////////////// // EntityResolver interface public InputSource resolveEntity(String publicId, String systemId) throws SAXException { if (_ignoreDtd) { return new InputSource(new StringReader("")); } return null; } //////////////////////////////////////////////////////////////////////// // ContentHandler interface public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { try { // Start of dataset if (_activeMetaData == null && qName.equals(DATASET)) { _consumer.startDataSet(); return; } // New table if (_activeMetaData == null || !_activeMetaData.getTableName().equals(qName)) { // If not first table, notify end of previous table to consumer if (_activeMetaData != null) { _consumer.endTable(); } // Notify start of new table to consumer _activeMetaData = createTableMetaData(qName, attributes); _consumer.startTable(_activeMetaData); } // Row notification if (attributes.getLength() > 0) { Column[] columns = _activeMetaData.getColumns(); Object[] rowValues = new Object[columns.length]; for (int i = 0; i < columns.length; i++) { Column column = columns[i]; rowValues[i] = attributes.getValue(column.getColumnName()); } _consumer.row(rowValues); } } catch (DataSetException e) { throw new SAXException(e); } } public void endElement(String uri, String localName, String qName) throws SAXException { // End of dataset if (qName.equals(DATASET)) { try { // Notify end of active table to consumer if (_activeMetaData != null) { _consumer.endTable(); } // Notify end of dataset to consumer _consumer.endDataSet(); } catch (DataSetException e) { throw new SAXException(e); } } } private class FlatDtdHandler extends FlatDtdProducer { public FlatDtdHandler() { } //////////////////////////////////////////////////////////////////////////// // LexicalHandler interface public void startDTD(String name, String publicId, String systemId) throws SAXException { try { // Cache the DTD content to use it as metadata CachedDataSet metaDataSet = new CachedDataSet(); this.setConsumer(metaDataSet); _metaDataSet = metaDataSet; super.startDTD(name, publicId, systemId); } catch (DataSetException e) { throw new SAXException(e); } } } } Index: FlatXmlWriter.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/xml/Attic/FlatXmlWriter.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** FlatXmlWriter.java 28 Apr 2003 12:11:10 -0000 1.1.2.2 --- FlatXmlWriter.java 30 Apr 2003 00:27:46 -0000 1.1.2.3 *************** *** 26,30 **** import org.dbunit.dataset.ITableMetaData; import org.dbunit.dataset.datatype.DataType; ! import org.dbunit.dataset.DefaultDataSetProvider; import org.dbunit.dataset.IDataSetConsumer; --- 26,30 ---- import org.dbunit.dataset.ITableMetaData; import org.dbunit.dataset.datatype.DataType; ! import org.dbunit.dataset.DataSetProducerAdapter; import org.dbunit.dataset.IDataSetConsumer; *************** *** 50,56 **** DataWriter dataWriter = new DataWriter(writer); dataWriter.setIndentStep(1); ! DefaultDataSetProvider provider = new DefaultDataSetProvider(dataSet); provider.setConsumer(new Consumer(dataWriter)); ! provider.process(); } --- 50,56 ---- DataWriter dataWriter = new DataWriter(writer); dataWriter.setIndentStep(1); ! DataSetProducerAdapter provider = new DataSetProducerAdapter(dataSet); provider.setConsumer(new Consumer(dataWriter)); ! provider.produce(); } --- FlatDtdProvider.java DELETED --- --- FlatXmlProvider.java DELETED --- |
From: <mla...@us...> - 2003-04-30 00:27:51
|
Update of /cvsroot/dbunit/dbunit/src/test/org/dbunit In directory sc8-pr-cvs1:/tmp/cvs-serv30700/src/test/org/dbunit Modified Files: Tag: branch-exml2sax Main.java Log Message: More class renaming. Renamed IDataSetProvider to IDataSetProducer. Subclasses have also been renamed to follow the same pattern. My initial intent to rename Source to Producer but for some strange reasons this ended up as Provider. Are you confused? Me I was! Index: Main.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/Main.java,v retrieving revision 1.30.2.1 retrieving revision 1.30.2.2 diff -C2 -d -r1.30.2.1 -r1.30.2.2 *** Main.java 23 Apr 2003 02:30:34 -0000 1.30.2.1 --- Main.java 30 Apr 2003 00:27:47 -0000 1.30.2.2 *************** *** 28,35 **** --- 28,38 ---- import org.dbunit.dataset.xml.XmlDataSet; import org.dbunit.dataset.xml.FlatXmlWriter; + import org.dbunit.dataset.xml.FlatXmlProducer; import org.dbunit.dataset.excel.XlsDataSet; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.ITableIterator; import org.dbunit.dataset.IDataSet; + import org.dbunit.dataset.StreamingDataSet; + import org.dbunit.dataset.CachedDataSet; import org.dbunit.operation.DatabaseOperation; *************** *** 38,41 **** --- 41,46 ---- import java.io.*; + import org.xml.sax.InputSource; + /** * This class is a scratchpad used to try new features. *************** *** 50,57 **** // System.setProperty("dbunit.qualified.table.names", "true"); IDatabaseConnection connection = DatabaseEnvironment.getInstance().getConnection(); ! IDataSet dataSet = new FlatXmlDataSet(new File("src/xml/flatXmlDataSetTest.xml")); ! DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet); FileWriter writer = new FileWriter("writerTest.xml"); --- 55,66 ---- // System.setProperty("dbunit.qualified.table.names", "true"); + + IDatabaseConnection connection = DatabaseEnvironment.getInstance().getConnection(); ! ! InputSource source = new InputSource(new FileReader("src/xml/flatXmlDataSetTest.xml")); ! IDataSet dataSet = new CachedDataSet(new FlatXmlProducer(source)); ! DatabaseOperation.INSERT.execute(connection, dataSet); FileWriter writer = new FileWriter("writerTest.xml"); |
From: <mla...@us...> - 2003-04-29 21:27:36
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset In directory sc8-pr-cvs1:/tmp/cvs-serv15384/src/java/org/dbunit/dataset Modified Files: Tag: branch-exml2sax Column.java Log Message: Added some provider tests. Index: Column.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/Column.java,v retrieving revision 1.10 retrieving revision 1.10.6.1 diff -C2 -d -r1.10 -r1.10.6.1 *** Column.java 13 Jun 2002 17:24:56 -0000 1.10 --- Column.java 29 Apr 2003 21:27:01 -0000 1.10.6.1 *************** *** 159,162 **** --- 159,187 ---- } + public boolean equals(Object o) + { + if (this == o) return true; + if (!(o instanceof Column)) return false; + + final Column column = (Column)o; + + if (!_columnName.equals(column._columnName)) return false; + if (!_dataType.equals(column._dataType)) return false; + if (!_nullable.equals(column._nullable)) return false; + if (!_sqlTypeName.equals(column._sqlTypeName)) return false; + + return true; + } + + public int hashCode() + { + int result; + result = _columnName.hashCode(); + result = 29 * result + _dataType.hashCode(); + result = 29 * result + _sqlTypeName.hashCode(); + result = 29 * result + _nullable.hashCode(); + return result; + } + public static class Nullable { |
From: <mla...@us...> - 2003-04-29 21:27:10
|
Update of /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/xml In directory sc8-pr-cvs1:/tmp/cvs-serv15384/src/test/org/dbunit/dataset/xml Added Files: Tag: branch-exml2sax FlatXmlDataSetProviderTest.java Log Message: Added some provider tests. --- NEW FILE: FlatXmlDataSetProviderTest.java --- package org.dbunit.dataset.xml; import org.dbunit.dataset.CachedDataSet; import org.dbunit.dataset.Column; import org.dbunit.dataset.IDataSet; import org.dbunit.dataset.ITable; import org.xml.sax.InputSource; import java.io.File; import java.io.FileInputStream; /** * * <p> Copyright (c) 2002 OZ.COM. All Rights Reserved. </p> * @author manuel.laflamme$ * @since Apr 28, 2003$ */ public class FlatXmlDataSetProviderTest extends FlatXmlDataSetTest { public FlatXmlDataSetProviderTest(String s) { super(s); } protected IDataSet createDataSet() throws Exception { InputSource source = new InputSource(new FileInputStream(DATASET_FILE)); return new CachedDataSet(new FlatXmlProvider(source)); } protected IDataSet createDuplicateDataSet() throws Exception { InputSource source = new InputSource(new FileInputStream(DUPLICATE_DATASET_FILE)); return new CachedDataSet(new FlatXmlProvider(source)); } public void testMissingColumnAndEnableDtdMetadata() throws Exception { File file = new File("src/xml/flatXmlTableTest.xml"); InputSource source = new InputSource(file.toURL().toString()); IDataSet dataSet = new CachedDataSet(new FlatXmlProvider(source)); ITable table = dataSet.getTable("MISSING_VALUES"); Column[] columns = table.getTableMetaData().getColumns(); assertEquals("column count", 3, columns.length); } public void testMissingColumnAndDisableDtdMetadata() throws Exception { File file = new File("src/xml/flatXmlTableTest.xml"); InputSource source = new InputSource(file.toURL().toString()); FlatXmlProvider provider = new FlatXmlProvider(source, true); IDataSet dataSet = new CachedDataSet(provider); ITable table = dataSet.getTable("MISSING_VALUES"); Column[] columns = table.getTableMetaData().getColumns(); assertEquals("column count", 2, columns.length); } public void testProduce() throws Exception { } } |
From: <mla...@us...> - 2003-04-29 21:27:08
|
Update of /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset In directory sc8-pr-cvs1:/tmp/cvs-serv15384/src/test/org/dbunit/dataset Added Files: Tag: branch-exml2sax MockDataSetConsumer.java Log Message: Added some provider tests. --- NEW FILE: MockDataSetConsumer.java --- package org.dbunit.dataset; import com.mockobjects.Verifiable; import com.mockobjects.ExpectationList; import java.util.List; import java.util.ArrayList; import java.util.Arrays; import junit.framework.Assert; /** * * <p> Copyright (c) 2002 OZ.COM. All Rights Reserved. </p> * @author manuel.laflamme$ * @since Apr 29, 2003$ */ public class MockDataSetConsumer implements Verifiable, IDataSetConsumer { private static final Item START_DATASET = new Item("startDataSet()"); private static final Item END_DATASET = new Item("endDataSet()"); private final ExpectationList _expectedList = new ExpectationList(""); private String _actualTableName; private int _actualTableRow = 0; public void addExpectedStartDataSet() throws Exception { _expectedList.addExpected(START_DATASET); } public void addExpectedEndDataSet() throws Exception { _expectedList.addExpected(END_DATASET); } public void addExpectedStartTable(ITableMetaData metaData) throws Exception { _expectedList.addExpected(new StartTableItem(metaData)); } public void addExpectedStartTable(String tableName, Column[] columns) throws Exception { addExpectedStartTable(new DefaultTableMetaData(tableName, columns)); } public void addExpectedEndTable(String tableName) throws Exception { _expectedList.addExpected(new EndTableItem(tableName)); } public void addExpectedRow(String tableName, int row, Object[] values) throws Exception { _expectedList.addExpected(new RowItem(tableName, row, values)); } //////////////////////////////////////////////////////////////////////////// // Verifiable interface public void verify() { _expectedList.verify(); } //////////////////////////////////////////////////////////////////////////// // IDataSetConsumer interface public void startDataSet() throws DataSetException { _expectedList.addActual(START_DATASET); } public void endDataSet() throws DataSetException { _expectedList.addActual(END_DATASET); } public void startTable(ITableMetaData metaData) throws DataSetException { _expectedList.addActual(new StartTableItem(metaData)); _actualTableName = metaData.getTableName(); _actualTableRow = 0; } public void endTable() throws DataSetException { _expectedList.addActual(new EndTableItem(_actualTableName)); _actualTableName = null; _actualTableRow = 0; } public void row(Object[] values) throws DataSetException { _expectedList.addActual( new RowItem(_actualTableName, _actualTableRow, values)); _actualTableRow++; } //////////////////////////////////////////////////////////////////////////// // private static class Item { protected final String _name; public Item(String name) { _name = name; } public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Item)) return false; final Item item = (Item)o; if (!_name.equals(item._name)) return false; return true; } public int hashCode() { return _name.hashCode(); } public String toString() { return _name; } } private static class StartTableItem extends Item { private final String _tableName; private final Column[] _columns; public StartTableItem(ITableMetaData metaData) throws DataSetException { super("startTable()"); _tableName = metaData.getTableName(); _columns = metaData.getColumns(); } public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof StartTableItem)) return false; if (!super.equals(o)) return false; final StartTableItem startTableItem = (StartTableItem)o; if (!Arrays.equals(_columns, startTableItem._columns)) return false; if (!_tableName.equals(startTableItem._tableName)) return false; return true; } public int hashCode() { int result = super.hashCode(); result = 29 * result + _tableName.hashCode(); return result; } public String toString() { return _name + ": table=" + _tableName + ", columns=" + Arrays.asList(_columns); } } private static class EndTableItem extends Item { private final String _tableName; public EndTableItem(String tableName) { super("endTable()"); _tableName = tableName; } public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof EndTableItem)) return false; if (!super.equals(o)) return false; final EndTableItem endTableItem = (EndTableItem)o; if (!_tableName.equals(endTableItem._tableName)) return false; return true; } public int hashCode() { int result = super.hashCode(); result = 29 * result + _tableName.hashCode(); return result; } public String toString() { return _name + ": table=" + _tableName; } } private static class RowItem extends Item { private final String _tableName; private final int _row; private final Object[] _values; public RowItem(String tableName, int row, Object[] values) { super("row()"); _tableName = tableName; _row = row; _values = values; } public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof RowItem)) return false; if (!super.equals(o)) return false; final RowItem rowItem = (RowItem)o; if (_row != rowItem._row) return false; if (!_tableName.equals(rowItem._tableName)) return false; // Probably incorrect - comparing Object[] arrays with Arrays.equals if (!Arrays.equals(_values, rowItem._values)) return false; return true; } public int hashCode() { int result = super.hashCode(); result = 29 * result + _tableName.hashCode(); result = 29 * result + _row; return result; } public String toString() { return _name + ": table=" + _tableName + ", row=" + _row + ", values=" + Arrays.asList(_values); } } } |
From: <mla...@us...> - 2003-04-29 17:10:58
|
Update of /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/xml In directory sc8-pr-cvs1:/tmp/cvs-serv14742/src/test/org/dbunit/dataset/xml Modified Files: Tag: branch-exml2sax FlatXmlDataSetTest.java Log Message: Added DTD support to FlatXmlProvider. Index: FlatXmlDataSetTest.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/xml/FlatXmlDataSetTest.java,v retrieving revision 1.14 retrieving revision 1.14.2.1 diff -C2 -d -r1.14 -r1.14.2.1 *** FlatXmlDataSetTest.java 9 Apr 2003 22:52:17 -0000 1.14 --- FlatXmlDataSetTest.java 29 Apr 2003 17:10:23 -0000 1.14.2.1 *************** *** 41,44 **** --- 41,49 ---- public class FlatXmlDataSetTest extends AbstractDataSetTest { + protected static final File DATASET_FILE = + new File("src/xml/flatXmlDataSetTest.xml"); + protected static final File DUPLICATE_DATASET_FILE = + new File("src/xml/flatXmlDataSetDuplicateTest.xml"); + public FlatXmlDataSetTest(String s) { *************** *** 48,52 **** protected IDataSet createDataSet() throws Exception { ! return new FlatXmlDataSet(new File("src/xml/flatXmlDataSetTest.xml")); } --- 53,57 ---- protected IDataSet createDataSet() throws Exception { ! return new FlatXmlDataSet(DATASET_FILE); } *************** *** 54,58 **** { return new FlatXmlDataSet( ! new File("src/xml/flatXmlDataSetDuplicateTest.xml")); } --- 59,63 ---- { return new FlatXmlDataSet( ! DUPLICATE_DATASET_FILE); } |
From: <mla...@us...> - 2003-04-29 17:10:56
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/xml In directory sc8-pr-cvs1:/tmp/cvs-serv14742/src/java/org/dbunit/dataset/xml Modified Files: Tag: branch-exml2sax FlatDtdProvider.java FlatXmlProvider.java Log Message: Added DTD support to FlatXmlProvider. Index: FlatDtdProvider.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/xml/Attic/FlatDtdProvider.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** FlatDtdProvider.java 28 Apr 2003 21:23:35 -0000 1.1.2.2 --- FlatDtdProvider.java 29 Apr 2003 17:10:19 -0000 1.1.2.3 *************** *** 27,32 **** import org.dbunit.dataset.IDataSetProvider; import org.dbunit.dataset.datatype.DataType; - import org.dbunit.util.xml.BaseHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; --- 27,32 ---- import org.dbunit.dataset.IDataSetProvider; import org.dbunit.dataset.datatype.DataType; + import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; import org.xml.sax.SAXException; *************** *** 53,58 **** * @version $Revision$ */ ! public class FlatDtdProvider extends BaseHandler ! implements IDataSetProvider, DeclHandler, LexicalHandler { private static final String XML_CONTENT = --- 53,57 ---- * @version $Revision$ */ ! public class FlatDtdProvider implements IDataSetProvider, EntityResolver, DeclHandler, LexicalHandler { private static final String XML_CONTENT = *************** *** 168,171 **** --- 167,181 ---- } + public void internalEntityDecl(String name, String value) throws SAXException + { + // Not used! + } + + public void externalEntityDecl(String name, String publicId, + String systemId) throws SAXException + { + // Not used! + } + //////////////////////////////////////////////////////////////////////////// // LexicalHandler interface *************** *** 222,225 **** --- 232,260 ---- throw new SAXException(e); } + } + + public void startEntity(String name) throws SAXException + { + // Not used! + } + + public void endEntity(String name) throws SAXException + { + // Not used! + } + + public void startCDATA() throws SAXException + { + // Not used! + } + + public void endCDATA() throws SAXException + { + // Not used! + } + + public void comment(char ch[], int start, int length) throws SAXException + { + // Not used! } } Index: FlatXmlProvider.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/xml/Attic/FlatXmlProvider.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** FlatXmlProvider.java 28 Apr 2003 12:11:12 -0000 1.1.2.1 --- FlatXmlProvider.java 29 Apr 2003 17:10:21 -0000 1.1.2.2 *************** *** 21,33 **** package org.dbunit.dataset.xml; import org.dbunit.dataset.Column; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.DefaultTableMetaData; ! import org.dbunit.dataset.ITableMetaData; ! import org.dbunit.dataset.datatype.DataType; import org.dbunit.dataset.IDataSetConsumer; import org.dbunit.dataset.IDataSetProvider; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; --- 21,36 ---- package org.dbunit.dataset.xml; + import org.dbunit.dataset.CachedDataSet; import org.dbunit.dataset.Column; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.DefaultTableMetaData; ! import org.dbunit.dataset.IDataSet; import org.dbunit.dataset.IDataSetConsumer; import org.dbunit.dataset.IDataSetProvider; + import org.dbunit.dataset.ITableMetaData; + import org.dbunit.dataset.datatype.DataType; import org.xml.sax.Attributes; + import org.xml.sax.ContentHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; *************** *** 39,42 **** --- 42,46 ---- import javax.xml.parsers.SAXParserFactory; import java.io.IOException; + import java.io.StringReader; /** *************** *** 45,65 **** * @version $Revision$ */ ! public class FlatXmlProvider implements IDataSetProvider { private final InputSource _inputSource; private XMLReader _xmlReader; private IDataSetConsumer _consumer; ! public FlatXmlProvider(InputSource inputSource) { ! _inputSource = inputSource; } ! // public FlatXmlProvider(InputSource inputSource, SAXParser parser) // { // _inputSource = inputSource; ! // _xmlReader = parser; // } //////////////////////////////////////////////////////////////////////////// // IDataSetProvider interface --- 49,108 ---- * @version $Revision$ */ ! public class FlatXmlProvider extends DefaultHandler ! implements IDataSetProvider, ContentHandler { + private static final String DATASET = "dataset"; + private final InputSource _inputSource; private XMLReader _xmlReader; + private IDataSet _metaDataSet; + boolean _ignoreDtd = false; + private IDataSetConsumer _consumer; + private ITableMetaData _activeMetaData; ! public FlatXmlProvider(InputSource xmlSource) { ! _inputSource = xmlSource; } ! public FlatXmlProvider(InputSource xmlSource, boolean ignoreDtd) ! { ! _inputSource = xmlSource; ! _ignoreDtd = ignoreDtd; ! } ! ! public FlatXmlProvider(InputSource xmlSource, IDataSet metaDataSet) ! { ! _inputSource = xmlSource; ! _metaDataSet = metaDataSet; ! _ignoreDtd = true; ! } ! ! // public FlatXmlProvider(InputSource inputSource, XMLReader xmlReader) // { // _inputSource = inputSource; ! // _xmlReader = xmlReader; // } + private ITableMetaData createTableMetaData(String tableName, + Attributes attributes) throws DataSetException + { + if (_metaDataSet != null) + { + return _metaDataSet.getTableMetaData(tableName); + } + + // Create metadata from attributes + Column[] columns = new Column[attributes.getLength()]; + for (int i = 0; i < attributes.getLength(); i++) + { + columns[i] = new Column(attributes.getQName(i), + DataType.UNKNOWN); + } + + return new DefaultTableMetaData(tableName, columns); + } + //////////////////////////////////////////////////////////////////////////// // IDataSetProvider interface *************** *** 80,85 **** } ! FlatXmlHandler handler = new FlatXmlHandler(_consumer); ! _xmlReader.setContentHandler(handler); _xmlReader.parse(_inputSource); } --- 123,135 ---- } ! if (!_ignoreDtd) ! { ! FlatDtdHandler dtdHandler = new FlatDtdHandler(); ! FlatDtdHandler.setLexicalHandler(_xmlReader, dtdHandler); ! FlatDtdHandler.setDeclHandler(_xmlReader, dtdHandler); ! } ! ! _xmlReader.setContentHandler(this); ! _xmlReader.setEntityResolver(this); _xmlReader.parse(_inputSource); } *************** *** 90,94 **** catch (SAXException e) { ! throw new DataSetException(e.getException()); } catch (IOException e) --- 140,145 ---- catch (SAXException e) { ! Exception exception = e.getException() == null ? e : e.getException(); ! throw new DataSetException(exception); } catch (IOException e) *************** *** 98,163 **** } ! private class FlatXmlHandler extends DefaultHandler ! { ! private static final String DATASET = "dataset"; ! ! private final IDataSetConsumer _listener; ! private ITableMetaData _activeMetaData; ! public FlatXmlHandler(IDataSetConsumer listener) { ! _listener = listener; } ! //////////////////////////////////////////////////////////////////////// ! // ContentHandler interface ! public void startElement(String uri, String localName, String qName, ! Attributes attributes) throws SAXException { ! try { ! // Start of dataset ! if (_activeMetaData == null && qName.equals(DATASET)) ! { ! _listener.startDataSet(); ! return; ! } ! // New table ! if (_activeMetaData == null || ! !_activeMetaData.getTableName().equals(qName)) { ! // If not first table, notify end of previous table to listener ! if (_activeMetaData != null) ! { ! _listener.endTable(); ! } ! // Create metadata from attributes ! Column[] columns = new Column[attributes.getLength()]; ! for (int i = 0; i < attributes.getLength(); i++) ! { ! columns[i] = new Column(attributes.getQName(i), ! DataType.UNKNOWN); ! } ! // Notify start of new table to listener ! _activeMetaData = new DefaultTableMetaData(qName, columns); ! _listener.startTable(_activeMetaData); } ! // Row notification ! if (attributes.getLength() > 0) { ! Column[] columns = _activeMetaData.getColumns(); ! Object[] rowValues = new Object[columns.length]; ! for (int i = 0; i < columns.length; i++) ! { ! Column column = columns[i]; ! rowValues[i] = attributes.getValue(column.getColumnName()); ! } ! _listener.row(rowValues); } } catch (DataSetException e) --- 149,229 ---- } ! //////////////////////////////////////////////////////////////////////////// ! // EntityResolver interface ! public InputSource resolveEntity(String publicId, String systemId) ! throws SAXException ! { ! if (_ignoreDtd) { ! return new InputSource(new StringReader("")); } + return null; + } ! //////////////////////////////////////////////////////////////////////// ! // ContentHandler interface ! public void startElement(String uri, String localName, String qName, ! Attributes attributes) throws SAXException ! { ! try { ! // Start of dataset ! if (_activeMetaData == null && qName.equals(DATASET)) { ! _consumer.startDataSet(); ! return; ! } ! // New table ! if (_activeMetaData == null || ! !_activeMetaData.getTableName().equals(qName)) ! { ! // If not first table, notify end of previous table to consumer ! if (_activeMetaData != null) { ! _consumer.endTable(); ! } ! // Notify start of new table to consumer ! _activeMetaData = createTableMetaData(qName, attributes); ! _consumer.startTable(_activeMetaData); ! } ! // Row notification ! if (attributes.getLength() > 0) ! { ! Column[] columns = _activeMetaData.getColumns(); ! Object[] rowValues = new Object[columns.length]; ! for (int i = 0; i < columns.length; i++) ! { ! Column column = columns[i]; ! rowValues[i] = attributes.getValue(column.getColumnName()); } + _consumer.row(rowValues); + } + } + catch (DataSetException e) + { + throw new SAXException(e); + } + } ! public void endElement(String uri, String localName, String qName) throws SAXException ! { ! // End of dataset ! if (qName.equals(DATASET)) ! { ! try ! { ! // Notify end of active table to consumer ! if (_activeMetaData != null) { ! _consumer.endTable(); } + + // Notify end of dataset to consumer + _consumer.endDataSet(); } catch (DataSetException e) *************** *** 166,192 **** } } ! public void endElement(String uri, String localName, String qName) throws SAXException { ! // End of dataset ! if (qName.equals(DATASET)) { ! try ! { ! // Notify end of active table to listener ! if (_activeMetaData != null) ! { ! _listener.endTable(); ! } ! // End of dataset to listener ! _listener.endDataSet(); ! } ! catch (DataSetException e) ! { ! throw new SAXException(e); ! } } } } } --- 232,264 ---- } } + } ! private class FlatDtdHandler extends FlatDtdProvider ! { ! public FlatDtdHandler() { ! } ! ! //////////////////////////////////////////////////////////////////////////// ! // LexicalHandler interface ! ! public void startDTD(String name, String publicId, String systemId) ! throws SAXException ! { ! try { ! // Cache the DTD content to use it as metadata ! CachedDataSet metaDataSet = new CachedDataSet(); ! this.setConsumer(metaDataSet); ! _metaDataSet = metaDataSet; ! super.startDTD(name, publicId, systemId); ! } ! catch (DataSetException e) ! { ! throw new SAXException(e); } } } + } |
From: <mla...@us...> - 2003-04-29 17:10:28
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/util/xml In directory sc8-pr-cvs1:/tmp/cvs-serv14742/src/java/org/dbunit/util/xml Removed Files: Tag: branch-exml2sax ExtendedDefaultHandler.java Log Message: Added DTD support to FlatXmlProvider. --- ExtendedDefaultHandler.java DELETED --- |
From: <mla...@us...> - 2003-04-28 21:23:39
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset In directory sc8-pr-cvs1:/tmp/cvs-serv18869/src/java/org/dbunit/dataset Modified Files: Tag: branch-exml2sax CachedDataSet.java Log Message: Deprecated the IDataSet.getTables() method and replaced usage with the iterator() methods. Only code that explicitly test the getTable() method continue to use it. |
From: <mla...@us...> - 2003-04-28 12:11:48
|
Update of /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset In directory sc8-pr-cvs1:/tmp/cvs-serv3033/src/test/org/dbunit/dataset Modified Files: Tag: branch-exml2sax CachedDataSetTest.java StreamingDataSetTest.java StreamingTableTest.java Log Message: Renamed IDataSetSource to IDataSetProvider and IDataSetListener to IDataSetConsumer. Index: CachedDataSetTest.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/Attic/CachedDataSetTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** CachedDataSetTest.java 23 Apr 2003 02:30:36 -0000 1.1.2.1 --- CachedDataSetTest.java 28 Apr 2003 12:11:12 -0000 1.1.2.2 *************** *** 22,26 **** import org.dbunit.dataset.xml.FlatXmlDataSet; ! import org.dbunit.dataset.xml.FlatXmlSource; import org.xml.sax.InputSource; --- 22,26 ---- import org.dbunit.dataset.xml.FlatXmlDataSet; ! import org.dbunit.dataset.xml.FlatXmlProvider; import org.xml.sax.InputSource; *************** *** 43,49 **** { FileReader reader = new FileReader("src/xml/flatXmlDataSetTest.xml"); ! return new CachedDataSet(new FlatXmlSource(new InputSource(reader))); // return new CachedDataSet( ! // new StreamingDataSet(new FlatXmlSource(new InputSource(reader)))); // return new CachedDataSet(new ForwardOnlyDataSet(new FlatXmlDataSet(reader))); } --- 43,49 ---- { FileReader reader = new FileReader("src/xml/flatXmlDataSetTest.xml"); ! return new CachedDataSet(new FlatXmlProvider(new InputSource(reader))); // return new CachedDataSet( ! // new StreamingDataSet(new FlatXmlProvider(new InputSource(reader)))); // return new CachedDataSet(new ForwardOnlyDataSet(new FlatXmlDataSet(reader))); } Index: StreamingDataSetTest.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/Attic/StreamingDataSetTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** StreamingDataSetTest.java 23 Apr 2003 02:30:36 -0000 1.1.2.1 --- StreamingDataSetTest.java 28 Apr 2003 12:11:13 -0000 1.1.2.2 *************** *** 21,30 **** package org.dbunit.dataset; ! import org.dbunit.dataset.DefaultDataSetSource; import org.dbunit.dataset.ForwardOnlyDataSetTest; import org.dbunit.dataset.IDataSet; ! import org.dbunit.dataset.IDataSetSource; import org.dbunit.dataset.StreamingDataSet; ! import org.dbunit.dataset.xml.FlatXmlSource; import org.xml.sax.InputSource; --- 21,30 ---- package org.dbunit.dataset; ! import org.dbunit.dataset.DefaultDataSetProvider; import org.dbunit.dataset.ForwardOnlyDataSetTest; import org.dbunit.dataset.IDataSet; ! import org.dbunit.dataset.IDataSetProvider; import org.dbunit.dataset.StreamingDataSet; ! import org.dbunit.dataset.xml.FlatXmlProvider; import org.xml.sax.InputSource; *************** *** 46,54 **** protected IDataSet createDataSet() throws Exception { ! IDataSetSource source = new FlatXmlSource( new InputSource(new FileReader("src/xml/flatXmlDataSetTest.xml"))); return new StreamingDataSet(source); // return new StreamingDataSet( ! // new DefaultDataSetSource(super.createDataSet())); } --- 46,54 ---- protected IDataSet createDataSet() throws Exception { ! IDataSetProvider source = new FlatXmlProvider( new InputSource(new FileReader("src/xml/flatXmlDataSetTest.xml"))); return new StreamingDataSet(source); // return new StreamingDataSet( ! // new DefaultDataSetProvider(super.createDataSet())); } *************** *** 56,60 **** { return new StreamingDataSet( ! new DefaultDataSetSource(super.createDuplicateDataSet())); } } --- 56,60 ---- { return new StreamingDataSet( ! new DefaultDataSetProvider(super.createDuplicateDataSet())); } } Index: StreamingTableTest.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/Attic/StreamingTableTest.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** StreamingTableTest.java 23 Apr 2003 02:30:36 -0000 1.1.2.1 --- StreamingTableTest.java 28 Apr 2003 12:11:14 -0000 1.1.2.2 *************** *** 21,25 **** package org.dbunit.dataset; ! import org.dbunit.dataset.xml.FlatXmlSource; import org.xml.sax.InputSource; --- 21,25 ---- package org.dbunit.dataset; ! import org.dbunit.dataset.xml.FlatXmlProvider; import org.xml.sax.InputSource; *************** *** 45,50 **** FileReader reader = new FileReader("src/xml/flatXmlDataSetTest.xml"); ! // IDataSetSource source = new DefaultDataSetSource(new FlatXmlDataSet(reader)); ! IDataSetSource source = new FlatXmlSource(new InputSource(reader)); ITableIterator iterator = new StreamingDataSet(source).iterator(); while(iterator.next()) --- 45,50 ---- FileReader reader = new FileReader("src/xml/flatXmlDataSetTest.xml"); ! // IDataSetProvider source = new DefaultDataSetProvider(new FlatXmlDataSet(reader)); ! IDataSetProvider source = new FlatXmlProvider(new InputSource(reader)); ITableIterator iterator = new StreamingDataSet(source).iterator(); while(iterator.next()) |
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/xml In directory sc8-pr-cvs1:/tmp/cvs-serv3033/src/java/org/dbunit/dataset/xml Modified Files: Tag: branch-exml2sax FlatXmlWriter.java Added Files: Tag: branch-exml2sax FlatDtdProvider.java FlatXmlProvider.java Removed Files: Tag: branch-exml2sax FlatXmlSource.java Log Message: Renamed IDataSetSource to IDataSetProvider and IDataSetListener to IDataSetConsumer. --- NEW FILE: FlatDtdProvider.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset.xml; import org.dbunit.dataset.Column; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.DefaultTableMetaData; import org.dbunit.dataset.IDataSetConsumer; import org.dbunit.dataset.IDataSetProvider; import org.dbunit.dataset.datatype.DataType; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; import org.xml.sax.XMLReader; import org.xml.sax.ext.DeclHandler; import org.xml.sax.ext.LexicalHandler; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import java.io.IOException; import java.io.StringReader; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.StringTokenizer; /** * @author Manuel Laflamme * @since Apr 27, 2003 * @version $Revision: 1.1.2.1 $ */ public class FlatDtdProvider implements IDataSetProvider, EntityResolver, DeclHandler, LexicalHandler { private static final String XML_CONTENT = "<?xml version=\"1.0\"?>\n<!DOCTYPE dataset SYSTEM \"urn:/dummy.dtd\">\n<dataset/>"; private static final String DECL_HANDLER_PROPERTY_NAME = "http://xml.org/sax/properties/declaration-handler"; private static final String LEXICAL_HANDLER_PROPERTY_NAME = "http://xml.org/sax/properties/lexical-handler"; private static final String REQUIRED = "#REQUIRED"; private static final String IMPLIED = "#IMPLIED"; private final InputSource _inputSource; private IDataSetConsumer _consumer; private String _rootName; private String _rootModel; private final Map _columnListMap = new HashMap(); public FlatDtdProvider(InputSource inputSource) { _inputSource = inputSource; } public static void setDeclHandler(XMLReader xmlReader, DeclHandler handler) throws SAXNotRecognizedException, SAXNotSupportedException { xmlReader.setProperty(DECL_HANDLER_PROPERTY_NAME, handler); } public static void setLexicalHandler(XMLReader xmlReader, LexicalHandler handler) throws SAXNotRecognizedException, SAXNotSupportedException { xmlReader.setProperty(LEXICAL_HANDLER_PROPERTY_NAME, handler); } //////////////////////////////////////////////////////////////////////////// // IDataSetProvider interface public void setConsumer(IDataSetConsumer consumer) throws DataSetException { _consumer = consumer; } public void process() throws DataSetException { try { SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); XMLReader xmlReader = saxParser.getXMLReader(); setDeclHandler(xmlReader, this); setLexicalHandler(xmlReader, this); xmlReader.setEntityResolver(this); xmlReader.parse(new InputSource(new StringReader(XML_CONTENT))); } catch (ParserConfigurationException e) { throw new DataSetException(e); } catch (SAXException e) { Exception exception = e.getException() == null ? e : e.getException(); throw new DataSetException(exception); } catch (IOException e) { throw new DataSetException(e); } } //////////////////////////////////////////////////////////////////////////// // EntityResolver interface public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return _inputSource; } //////////////////////////////////////////////////////////////////////////// // DeclHandler interface public void elementDecl(String name, String model) throws SAXException { // Root element if (name.equals(_rootName)) { // The root model defines the table sequence. Keep it for later used! _rootModel = model; } // Other elements else { _columnListMap.put(name, new LinkedList()); } } public void attributeDecl(String elementName, String attributeName, String type, String mode, String value) throws SAXException { // Each element attribute represent a table column Column.Nullable nullable = (REQUIRED.equals(mode)) ? Column.NO_NULLS : Column.NULLABLE; Column column = new Column(attributeName, DataType.UNKNOWN, nullable); List columnList = (List)_columnListMap.get(elementName); columnList.add(column); } public void internalEntityDecl(String name, String value) throws SAXException { // Not used! } public void externalEntityDecl(String name, String publicId, String systemId) throws SAXException { // Not used! } //////////////////////////////////////////////////////////////////////////// // LexicalHandler interface public void startDTD(String name, String publicId, String systemId) throws SAXException { try { _rootName = name; _consumer.startDataSet(); } catch (DataSetException e) { throw new SAXException(e); } } public void endDTD() throws SAXException { try { // Remove enclosing model parenthesis String rootModel = _rootModel.substring(1, _rootModel.length() - 1); // Parse the root element model to determine the table sequence. // This implementation does not support choices yet and will never // support mixed model. StringTokenizer tokenizer = new StringTokenizer(rootModel, ","); while (tokenizer.hasMoreTokens()) { String tableName = tokenizer.nextToken(); // Prune ending occurrence operator if (tableName.endsWith("*") || tableName.endsWith("?") || tableName.endsWith("+")) { tableName = tableName.substring(0, tableName.length() - 1); } List columnList = (List)_columnListMap.get(tableName); Column[] columns = (Column[])columnList.toArray(new Column[0]); _consumer.startTable(new DefaultTableMetaData(tableName, columns)); _consumer.endTable(); } _consumer.endDataSet(); } catch (DataSetException e) { throw new SAXException(e); } } public void startEntity(String name) throws SAXException { // Not used! } public void endEntity(String name) throws SAXException { // Not used! } public void startCDATA() throws SAXException { // Not used! } public void endCDATA() throws SAXException { // Not used! } public void comment(char ch[], int start, int length) throws SAXException { // Not used! } } --- NEW FILE: FlatXmlProvider.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset.xml; import org.dbunit.dataset.Column; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.DefaultTableMetaData; import org.dbunit.dataset.ITableMetaData; import org.dbunit.dataset.datatype.DataType; import org.dbunit.dataset.IDataSetConsumer; import org.dbunit.dataset.IDataSetProvider; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import java.io.IOException; /** * @author Manuel Laflamme * @since Apr 18, 2003 * @version $Revision: 1.1.2.1 $ */ public class FlatXmlProvider implements IDataSetProvider { private final InputSource _inputSource; private XMLReader _xmlReader; private IDataSetConsumer _consumer; public FlatXmlProvider(InputSource inputSource) { _inputSource = inputSource; } // public FlatXmlProvider(InputSource inputSource, SAXParser parser) // { // _inputSource = inputSource; // _xmlReader = parser; // } //////////////////////////////////////////////////////////////////////////// // IDataSetProvider interface public void setConsumer(IDataSetConsumer consumer) throws DataSetException { _consumer = consumer; } public void process() throws DataSetException { try { if (_xmlReader == null) { SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); _xmlReader = saxParser.getXMLReader(); } FlatXmlHandler handler = new FlatXmlHandler(_consumer); _xmlReader.setContentHandler(handler); _xmlReader.parse(_inputSource); } catch (ParserConfigurationException e) { throw new DataSetException(e); } catch (SAXException e) { throw new DataSetException(e.getException()); } catch (IOException e) { throw new DataSetException(e); } } private class FlatXmlHandler extends DefaultHandler { private static final String DATASET = "dataset"; private final IDataSetConsumer _listener; private ITableMetaData _activeMetaData; public FlatXmlHandler(IDataSetConsumer listener) { _listener = listener; } //////////////////////////////////////////////////////////////////////// // ContentHandler interface public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { try { // Start of dataset if (_activeMetaData == null && qName.equals(DATASET)) { _listener.startDataSet(); return; } // New table if (_activeMetaData == null || !_activeMetaData.getTableName().equals(qName)) { // If not first table, notify end of previous table to listener if (_activeMetaData != null) { _listener.endTable(); } // Create metadata from attributes Column[] columns = new Column[attributes.getLength()]; for (int i = 0; i < attributes.getLength(); i++) { columns[i] = new Column(attributes.getQName(i), DataType.UNKNOWN); } // Notify start of new table to listener _activeMetaData = new DefaultTableMetaData(qName, columns); _listener.startTable(_activeMetaData); } // Row notification if (attributes.getLength() > 0) { Column[] columns = _activeMetaData.getColumns(); Object[] rowValues = new Object[columns.length]; for (int i = 0; i < columns.length; i++) { Column column = columns[i]; rowValues[i] = attributes.getValue(column.getColumnName()); } _listener.row(rowValues); } } catch (DataSetException e) { throw new SAXException(e); } } public void endElement(String uri, String localName, String qName) throws SAXException { // End of dataset if (qName.equals(DATASET)) { try { // Notify end of active table to listener if (_activeMetaData != null) { _listener.endTable(); } // End of dataset to listener _listener.endDataSet(); } catch (DataSetException e) { throw new SAXException(e); } } } } } Index: FlatXmlWriter.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/xml/Attic/FlatXmlWriter.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** FlatXmlWriter.java 23 Apr 2003 02:30:36 -0000 1.1.2.1 --- FlatXmlWriter.java 28 Apr 2003 12:11:10 -0000 1.1.2.2 *************** *** 26,31 **** import org.dbunit.dataset.ITableMetaData; import org.dbunit.dataset.datatype.DataType; ! import org.dbunit.dataset.DefaultDataSetSource; ! import org.dbunit.dataset.IDataSetListener; import org.dbunit.util.xml.DataWriter; --- 26,31 ---- import org.dbunit.dataset.ITableMetaData; import org.dbunit.dataset.datatype.DataType; ! import org.dbunit.dataset.DefaultDataSetProvider; ! import org.dbunit.dataset.IDataSetConsumer; import org.dbunit.util.xml.DataWriter; *************** *** 50,62 **** DataWriter dataWriter = new DataWriter(writer); dataWriter.setIndentStep(1); ! new DefaultDataSetSource(dataSet).process(new Listener(dataWriter)); } ! private class Listener implements IDataSetListener { private final XMLWriter _xmlWriter; private ITableMetaData _activeMetaData; ! public Listener(XMLWriter xmlWriter) { _xmlWriter = xmlWriter; --- 50,64 ---- DataWriter dataWriter = new DataWriter(writer); dataWriter.setIndentStep(1); ! DefaultDataSetProvider provider = new DefaultDataSetProvider(dataSet); ! provider.setConsumer(new Consumer(dataWriter)); ! provider.process(); } ! private class Consumer implements IDataSetConsumer { private final XMLWriter _xmlWriter; private ITableMetaData _activeMetaData; ! public Consumer(XMLWriter xmlWriter) { _xmlWriter = xmlWriter; *************** *** 64,68 **** //////////////////////////////////////////////////////////////////////////// ! // IDataSetListener interface public void startDataSet() throws DataSetException --- 66,70 ---- //////////////////////////////////////////////////////////////////////////// ! // IDataSetConsumer interface public void startDataSet() throws DataSetException --- FlatXmlSource.java DELETED --- |
From: <mla...@us...> - 2003-04-28 12:11:43
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset In directory sc8-pr-cvs1:/tmp/cvs-serv3033/src/java/org/dbunit/dataset Modified Files: Tag: branch-exml2sax CachedDataSet.java StreamingDataSet.java StreamingIterator.java Added Files: Tag: branch-exml2sax DefaultDataSetProvider.java IDataSetConsumer.java IDataSetProvider.java Removed Files: Tag: branch-exml2sax DefaultDataSetSource.java IDataSetListener.java IDataSetSource.java Log Message: Renamed IDataSetSource to IDataSetProvider and IDataSetListener to IDataSetConsumer. --- NEW FILE: DefaultDataSetProvider.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset; import org.dbunit.dataset.ITableIterator; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.ITableMetaData; import org.dbunit.dataset.ITable; import org.dbunit.dataset.Column; import org.dbunit.dataset.RowOutOfBoundsException; import org.dbunit.dataset.IDataSet; /** * @author Manuel Laflamme * @since Apr 17, 2003 * @version $Revision: 1.1.2.1 $ */ public class DefaultDataSetProvider implements IDataSetProvider { private final ITableIterator _iterator; private IDataSetConsumer _consumer; public DefaultDataSetProvider(ITableIterator iterator) { _iterator = iterator; } public DefaultDataSetProvider(IDataSet dataSet) throws DataSetException { _iterator = dataSet.iterator(); } //////////////////////////////////////////////////////////////////////////// // IDataSetProvider interface public void setConsumer(IDataSetConsumer consumer) throws DataSetException { _consumer = consumer; } public void process() throws DataSetException { _consumer.startDataSet(); while(_iterator.next()) { ITable table = _iterator.getTable(); ITableMetaData metaData = table.getTableMetaData(); _consumer.startTable(metaData); try { Column[] columns = metaData.getColumns(); if (columns.length == 0) { _consumer.endTable(); continue; } for (int i = 0; ; i++) { Object[] values = new Object[columns.length]; for (int j = 0; j < columns.length; j++) { Column column = columns[j]; values[j] = table.getValue(i, column.getColumnName()); } _consumer.row(values); } } catch (RowOutOfBoundsException e) { // end of table _consumer.endTable(); } } _consumer.endDataSet(); } } --- NEW FILE: IDataSetConsumer.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.ITableMetaData; /** * Receive notification of the content of a dataset. * * @author Manuel Laflamme * @since Apr 17, 2003 * @version $Revision: 1.1.2.1 $ */ public interface IDataSetConsumer { /** * Receive notification of the beginning of a dataset. This method is * invoked only once, before any other methods in this interface. */ public void startDataSet() throws DataSetException; /** * Receive notification of the end of a dataset. This method is invoked only * once, and it will be the last method invoked in this interface. */ public void endDataSet() throws DataSetException; /** * Receive notification of the beginning of a table. This method is invoked * at the beginning of every table in the dataset; there will be a * corresponding {@link #endDataSet} event for every <code>startTable</code> * event (even when the table is empty). * @param metaData the table metadata */ public void startTable(ITableMetaData metaData) throws DataSetException; /** * Receive notification of the end of a table. */ public void endTable() throws DataSetException; /** * Receive notification of a table row. This method is invoked to report * each row of a table. * @param values The row values. */ public void row(Object[] values) throws DataSetException; } --- NEW FILE: IDataSetProvider.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.IDataSetConsumer; /** * Interface for reading a dataset using callback. * * @author Manuel Laflamme * @since Apr 17, 2003 * @version $Revision: 1.1.2.1 $ */ public interface IDataSetProvider { public void setConsumer(IDataSetConsumer consumer) throws DataSetException; /** * Process this dataset source. During the processing, the IDataSetProvider * will provide information about the dataset through the specified event * listener. * <p> * This method is synchronous: it will not return until processing has ended. * If a client application wants to terminate parsing early, it should * throw an exception from the listener. */ public void process() throws DataSetException; } Index: CachedDataSet.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/Attic/CachedDataSet.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** CachedDataSet.java 23 Apr 2003 02:30:34 -0000 1.1.2.1 --- CachedDataSet.java 28 Apr 2003 12:10:59 -0000 1.1.2.2 *************** *** 29,41 **** * @version $Revision$ */ ! public class CachedDataSet extends AbstractDataSet { private ITable[] _tables; public CachedDataSet(IDataSet dataSet) throws DataSetException { List tableList = new ArrayList(); ITableIterator iterator = dataSet.iterator(); ! while(iterator.next()) { tableList.add(new CachedTable(iterator.getTable())); --- 29,45 ---- * @version $Revision$ */ ! public class CachedDataSet extends AbstractDataSet implements IDataSetConsumer { private ITable[] _tables; + private List _tableList = new ArrayList(); + private ITableMetaData _activeMetaData; + private List _activeRowList; + public CachedDataSet(IDataSet dataSet) throws DataSetException { List tableList = new ArrayList(); ITableIterator iterator = dataSet.iterator(); ! while (iterator.next()) { tableList.add(new CachedTable(iterator.getTable())); *************** *** 44,50 **** } ! public CachedDataSet(IDataSetSource source) throws DataSetException { ! source.process(new Listener()); } --- 48,55 ---- } ! public CachedDataSet(IDataSetProvider provider) throws DataSetException { ! provider.setConsumer(this); ! provider.process(); } *************** *** 58,98 **** } ! private class Listener implements IDataSetListener ! { ! List _tableList = new ArrayList(); ! ITableMetaData _activeMetaData; ! List _activeRowList; ! ! //////////////////////////////////////////////////////////////////////// ! // IDataSetListener interface ! public void startDataSet() throws DataSetException ! { ! } ! public void endDataSet() throws DataSetException ! { ! _tables = (ITable[])_tableList.toArray(new ITable[0]); ! } ! public void startTable(ITableMetaData metaData) throws DataSetException ! { ! _activeMetaData = metaData; ! _activeRowList = new ArrayList(); // System.out.println("START " + _activeMetaData.getTableName()); ! } ! public void endTable() throws DataSetException ! { // System.out.println("END " + _activeMetaData.getTableName()); ! _tableList.add(new DefaultTable(_activeMetaData, _activeRowList)); ! _activeRowList = null; ! _activeMetaData = null; ! } ! public void row(Object[] values) throws DataSetException ! { ! _activeRowList.add(values); ! } } } --- 63,97 ---- } ! //////////////////////////////////////////////////////////////////////// ! // IDataSetConsumer interface ! public void startDataSet() throws DataSetException ! { ! } ! public void endDataSet() throws DataSetException ! { ! _tables = (ITable[])_tableList.toArray(new ITable[0]); ! _tableList = null; ! } ! public void startTable(ITableMetaData metaData) throws DataSetException ! { ! _activeMetaData = metaData; ! _activeRowList = new ArrayList(); // System.out.println("START " + _activeMetaData.getTableName()); ! } ! public void endTable() throws DataSetException ! { // System.out.println("END " + _activeMetaData.getTableName()); ! _tableList.add(new DefaultTable(_activeMetaData, _activeRowList)); ! _activeRowList = null; ! _activeMetaData = null; ! } ! public void row(Object[] values) throws DataSetException ! { ! _activeRowList.add(values); } } Index: StreamingDataSet.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/Attic/StreamingDataSet.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** StreamingDataSet.java 23 Apr 2003 02:30:34 -0000 1.1.2.1 --- StreamingDataSet.java 28 Apr 2003 12:11:03 -0000 1.1.2.2 *************** *** 26,30 **** import org.dbunit.dataset.ITableIterator; import org.dbunit.dataset.ITableMetaData; ! import org.dbunit.dataset.IDataSetSource; /** --- 26,30 ---- import org.dbunit.dataset.ITableIterator; import org.dbunit.dataset.ITableMetaData; ! import org.dbunit.dataset.IDataSetProvider; /** *************** *** 35,42 **** public class StreamingDataSet extends AbstractDataSet { ! private IDataSetSource _source; private int _iteratorCount; ! public StreamingDataSet(IDataSetSource source) { _source = source; --- 35,42 ---- public class StreamingDataSet extends AbstractDataSet { ! private IDataSetProvider _source; private int _iteratorCount; ! public StreamingDataSet(IDataSetProvider source) { _source = source; Index: StreamingIterator.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/Attic/StreamingIterator.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** StreamingIterator.java 23 Apr 2003 02:30:34 -0000 1.1.2.1 --- StreamingIterator.java 28 Apr 2003 12:11:07 -0000 1.1.2.2 *************** *** 28,33 **** import org.dbunit.dataset.ITableMetaData; import org.dbunit.dataset.RowOutOfBoundsException; ! import org.dbunit.dataset.IDataSetListener; ! import org.dbunit.dataset.IDataSetSource; import org.dbunit.util.concurrent.BoundedBuffer; --- 28,33 ---- import org.dbunit.dataset.ITableMetaData; import org.dbunit.dataset.RowOutOfBoundsException; ! import org.dbunit.dataset.IDataSetConsumer; ! import org.dbunit.dataset.IDataSetProvider; import org.dbunit.util.concurrent.BoundedBuffer; *************** *** 50,59 **** private boolean _eod = false; ! public StreamingIterator(IDataSetSource source) throws DataSetException { Channel channel = new BoundedBuffer(30); _channel = channel; ! AsynchronousHandler handler = new AsynchronousHandler(source, channel); new Thread(handler).start(); --- 50,59 ---- private boolean _eod = false; ! public StreamingIterator(IDataSetProvider source) throws DataSetException { Channel channel = new BoundedBuffer(30); _channel = channel; ! AsynchronousConsumer handler = new AsynchronousConsumer(source, channel); new Thread(handler).start(); *************** *** 194,207 **** //////////////////////////////////////////////////////////////////////////// ! // AsynchronousHandler class ! private static class AsynchronousHandler implements Runnable, IDataSetListener { ! private final IDataSetSource _source; private final Puttable _channel; ! public AsynchronousHandler(IDataSetSource source, Puttable channel) { ! _source = source; _channel = channel; } --- 194,207 ---- //////////////////////////////////////////////////////////////////////////// ! // AsynchronousConsumer class ! private static class AsynchronousConsumer implements Runnable, IDataSetConsumer { ! private final IDataSetProvider _producer; private final Puttable _channel; ! public AsynchronousConsumer(IDataSetProvider source, Puttable channel) { ! _producer = source; _channel = channel; } *************** *** 214,218 **** try { ! _source.process(this); // System.out.println("End of thread! - " + System.currentTimeMillis()); } --- 214,219 ---- try { ! _producer.setConsumer(this); ! _producer.process(); // System.out.println("End of thread! - " + System.currentTimeMillis()); } *************** *** 224,228 **** //////////////////////////////////////////////////////////////////////// ! // IDataSetListener interface public void startDataSet() throws DataSetException --- 225,229 ---- //////////////////////////////////////////////////////////////////////// ! // IDataSetConsumer interface public void startDataSet() throws DataSetException --- DefaultDataSetSource.java DELETED --- --- IDataSetListener.java DELETED --- --- IDataSetSource.java DELETED --- |
From: <mla...@us...> - 2003-04-28 12:11:23
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/util/xml In directory sc8-pr-cvs1:/tmp/cvs-serv3033/src/java/org/dbunit/util/xml Added Files: Tag: branch-exml2sax ExtendedDefaultHandler.java Log Message: Renamed IDataSetSource to IDataSetProvider and IDataSetListener to IDataSetConsumer. --- NEW FILE: ExtendedDefaultHandler.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.util.xml; import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.ext.DeclHandler; import org.xml.sax.ext.LexicalHandler; import org.xml.sax.SAXException; /** * @author Manuel Laflamme * @since Apr 27, 2003 * @version $Revision: 1.1.2.1 $ */ public class ExtendedDefaultHandler extends DefaultHandler implements DeclHandler, LexicalHandler { //////////////////////////////////////////////////////////////////////////// // DeclHandler interface public void elementDecl(String name, String model) throws SAXException { } public void attributeDecl(String eName, String aName, String type, String valueDefault, String value) throws SAXException { } public void internalEntityDecl(String name, String value) throws SAXException { } public void externalEntityDecl(String name, String publicId, String systemId) throws SAXException { } //////////////////////////////////////////////////////////////////////////// // LexicalHandler interface public void startDTD(String name, String publicId, String systemId) throws SAXException { } public void endDTD() throws SAXException { } public void startEntity(String name) throws SAXException { } public void endEntity(String name) throws SAXException { } public void startCDATA() throws SAXException { } public void endCDATA() throws SAXException { } public void comment(char ch[], int start, int length) throws SAXException { } } |
From: <mla...@us...> - 2003-04-28 12:04:11
|
Update of /cvsroot/dbunit/dbunit/src/java/gnu In directory sc8-pr-cvs1:/tmp/cvs-serv32730/gnu Log Message: Directory /cvsroot/dbunit/dbunit/src/java/gnu added to the repository --> Using per-directory sticky tag `branch-exml2sax' |
From: <mla...@us...> - 2003-04-23 02:31:08
|
Update of /cvsroot/dbunit/dbunit/src/test/org/dbunit In directory sc8-pr-cvs1:/tmp/cvs-serv7057/src/test/org/dbunit Modified Files: Tag: branch-exml2sax Main.java Log Message: Added new StreamingDataSet class. Index: Main.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/Main.java,v retrieving revision 1.30 retrieving revision 1.30.2.1 diff -C2 -d -r1.30 -r1.30.2.1 *** Main.java 13 Apr 2003 02:40:10 -0000 1.30 --- Main.java 23 Apr 2003 02:30:34 -0000 1.30.2.1 *************** *** 27,33 **** --- 27,36 ---- import org.dbunit.dataset.xml.FlatXmlDataSet; import org.dbunit.dataset.xml.XmlDataSet; + import org.dbunit.dataset.xml.FlatXmlWriter; import org.dbunit.dataset.excel.XlsDataSet; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.ITableIterator; + import org.dbunit.dataset.IDataSet; + import org.dbunit.operation.DatabaseOperation; import electric.xml.Document; *************** *** 49,57 **** IDatabaseConnection connection = DatabaseEnvironment.getInstance().getConnection(); ! ITableIterator iterator = connection.createDataSet().iterator(); ! while(iterator.next()) ! { ! System.out.println(iterator.getTableMetaData().getTableName()); ! } // oldMain(); // testWrite(); --- 52,67 ---- IDatabaseConnection connection = DatabaseEnvironment.getInstance().getConnection(); ! IDataSet dataSet = new FlatXmlDataSet(new File("src/xml/flatXmlDataSetTest.xml")); ! DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet); ! ! FileWriter writer = new FileWriter("writerTest.xml"); ! // FlatXmlDataSet.write(connection.createDataSet(), writer); ! new FlatXmlWriter().write(connection.createDataSet(), writer); ! writer.close(); ! // ITableIterator iterator = connection.createDataSet().iterator(); ! // while(iterator.next()) ! // { ! // System.out.println(iterator.getTableMetaData().getTableName()); ! // } // oldMain(); // testWrite(); |
From: <mla...@us...> - 2003-04-23 02:31:08
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset In directory sc8-pr-cvs1:/tmp/cvs-serv7057/src/java/org/dbunit/dataset Modified Files: Tag: branch-exml2sax CachedTable.java Added Files: Tag: branch-exml2sax CachedDataSet.java DefaultDataSetSource.java IDataSetListener.java IDataSetSource.java StreamingDataSet.java StreamingIterator.java Log Message: Added new StreamingDataSet class. --- NEW FILE: CachedDataSet.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset; import java.util.ArrayList; import java.util.List; /** * @author Manuel Laflamme * @since Apr 18, 2003 * @version $Revision: 1.1.2.1 $ */ public class CachedDataSet extends AbstractDataSet { private ITable[] _tables; public CachedDataSet(IDataSet dataSet) throws DataSetException { List tableList = new ArrayList(); ITableIterator iterator = dataSet.iterator(); while(iterator.next()) { tableList.add(new CachedTable(iterator.getTable())); } _tables = (ITable[])tableList.toArray(new ITable[0]); } public CachedDataSet(IDataSetSource source) throws DataSetException { source.process(new Listener()); } //////////////////////////////////////////////////////////////////////////// // AbstractDataSet class protected ITableIterator createIterator(boolean reversed) throws DataSetException { return new DefaultTableIterator(_tables, reversed); } private class Listener implements IDataSetListener { List _tableList = new ArrayList(); ITableMetaData _activeMetaData; List _activeRowList; //////////////////////////////////////////////////////////////////////// // IDataSetListener interface public void startDataSet() throws DataSetException { } public void endDataSet() throws DataSetException { _tables = (ITable[])_tableList.toArray(new ITable[0]); } public void startTable(ITableMetaData metaData) throws DataSetException { _activeMetaData = metaData; _activeRowList = new ArrayList(); // System.out.println("START " + _activeMetaData.getTableName()); } public void endTable() throws DataSetException { // System.out.println("END " + _activeMetaData.getTableName()); _tableList.add(new DefaultTable(_activeMetaData, _activeRowList)); _activeRowList = null; _activeMetaData = null; } public void row(Object[] values) throws DataSetException { _activeRowList.add(values); } } } --- NEW FILE: DefaultDataSetSource.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset; import org.dbunit.dataset.ITableIterator; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.ITableMetaData; import org.dbunit.dataset.ITable; import org.dbunit.dataset.Column; import org.dbunit.dataset.RowOutOfBoundsException; import org.dbunit.dataset.IDataSet; /** * @author Manuel Laflamme * @since Apr 17, 2003 * @version $Revision: 1.1.2.1 $ */ public class DefaultDataSetSource implements IDataSetSource { private final ITableIterator _iterator; public DefaultDataSetSource(ITableIterator iterator) { _iterator = iterator; } public DefaultDataSetSource(IDataSet dataSet) throws DataSetException { _iterator = dataSet.iterator(); } //////////////////////////////////////////////////////////////////////////// // IDataSetSource interface public void process(IDataSetListener _handler) throws DataSetException { _handler.startDataSet(); while(_iterator.next()) { ITable table = _iterator.getTable(); ITableMetaData metaData = table.getTableMetaData(); _handler.startTable(metaData); try { Column[] columns = metaData.getColumns(); if (columns.length == 0) { _handler.endTable(); continue; } for (int i = 0; ; i++) { Object[] values = new Object[columns.length]; for (int j = 0; j < columns.length; j++) { Column column = columns[j]; values[j] = table.getValue(i, column.getColumnName()); } _handler.row(values); } } catch (RowOutOfBoundsException e) { // end of table _handler.endTable(); } } _handler.endDataSet(); } } --- NEW FILE: IDataSetListener.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.ITableMetaData; /** * Receive notification of the content of a dataset. * * @author Manuel Laflamme * @since Apr 17, 2003 * @version $Revision: 1.1.2.1 $ */ public interface IDataSetListener { /** * Receive notification of the beginning of a dataset. This method is * invoked only once, before any other methods in this interface. */ public void startDataSet() throws DataSetException; /** * Receive notification of the end of a dataset. This method is invoked only * once, and it will be the last method invoked in this interface. */ public void endDataSet() throws DataSetException; /** * Receive notification of the beginning of a table. This method is invoked * at the beginning of every table in the dataset; there will be a * corresponding {@link #endDataSet} event for every <code>startTable</code> * event (even when the table is empty). * @param metaData the table metadata */ public void startTable(ITableMetaData metaData) throws DataSetException; /** * Receive notification of the end of a table. */ public void endTable() throws DataSetException; /** * Receive notification of a table row. This method is invoked to report * each row of a table. * @param values The row values. */ public void row(Object[] values) throws DataSetException; } --- NEW FILE: IDataSetSource.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.IDataSetListener; /** * Interface for reading a dataset using callback. * * @author Manuel Laflamme * @since Apr 17, 2003 * @version $Revision: 1.1.2.1 $ */ public interface IDataSetSource { /** * Process this dataset source. During the processing, the IDataSetSource * will provide information about the dataset through the specified event * listener. * <p> * This method is synchronous: it will not return until processing has ended. * If a client application wants to terminate parsing early, it should * throw an exception from the listener. */ public void process(IDataSetListener listener) throws DataSetException; } --- NEW FILE: StreamingDataSet.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset; import org.dbunit.dataset.AbstractDataSet; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.ITable; import org.dbunit.dataset.ITableIterator; import org.dbunit.dataset.ITableMetaData; import org.dbunit.dataset.IDataSetSource; /** * @author Manuel Laflamme * @since Apr 18, 2003 * @version $Revision: 1.1.2.1 $ */ public class StreamingDataSet extends AbstractDataSet { private IDataSetSource _source; private int _iteratorCount; public StreamingDataSet(IDataSetSource source) { _source = source; } //////////////////////////////////////////////////////////////////////////// // AbstractDataSet class protected ITableIterator createIterator(boolean reversed) throws DataSetException { if (reversed) { throw new UnsupportedOperationException( "Reverse iterator not supported!"); } if (_iteratorCount > 0) { throw new UnsupportedOperationException( "Only one iterator allowed!"); } _iteratorCount++; return new StreamingIterator(_source); } //////////////////////////////////////////////////////////////////////////// // IDataSet interface public String[] getTableNames() throws DataSetException { throw new UnsupportedOperationException(); } public ITableMetaData getTableMetaData(String tableName) throws DataSetException { throw new UnsupportedOperationException(); } public ITable getTable(String tableName) throws DataSetException { throw new UnsupportedOperationException(); } } --- NEW FILE: StreamingIterator.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset; import org.dbunit.DatabaseUnitRuntimeException; import org.dbunit.dataset.AbstractTable; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.ITable; import org.dbunit.dataset.ITableIterator; import org.dbunit.dataset.ITableMetaData; import org.dbunit.dataset.RowOutOfBoundsException; import org.dbunit.dataset.IDataSetListener; import org.dbunit.dataset.IDataSetSource; import org.dbunit.util.concurrent.BoundedBuffer; import org.dbunit.util.concurrent.Channel; import org.dbunit.util.concurrent.Puttable; import org.dbunit.util.concurrent.Takable; /** * @author Manuel Laflamme * @since Apr 17, 2003 * @version $Revision: 1.1.2.1 $ */ public class StreamingIterator implements ITableIterator { private static final Object EOD = new Object(); // end of dataset marker private final Takable _channel; private StreamingTable _activeTable; private Object _taken = null; private boolean _eod = false; public StreamingIterator(IDataSetSource source) throws DataSetException { Channel channel = new BoundedBuffer(30); _channel = channel; AsynchronousHandler handler = new AsynchronousHandler(source, channel); new Thread(handler).start(); // Take first element from asyncronous handler try { _taken = _channel.take(); } catch (InterruptedException e) { throw new DataSetException(e); } } //////////////////////////////////////////////////////////////////////////// // ITableIterator interface public boolean next() throws DataSetException { // End of dataset has previously been reach if (_eod) { return false; } // Iterate to the end of current table. while (_activeTable != null && _activeTable.next()) ; // End of dataset is reach if (_taken == EOD) { _eod = true; _activeTable = null; // System.out.println("End of iterator! - " + System.currentTimeMillis()); return false; } // New table if (_taken instanceof ITableMetaData) { _activeTable = new StreamingTable((ITableMetaData)_taken); return true; } throw new IllegalStateException( "Unexpected object taken from asyncronous handler: " + _taken); } public ITableMetaData getTableMetaData() throws DataSetException { return _activeTable.getTableMetaData(); } public ITable getTable() throws DataSetException { return _activeTable; } //////////////////////////////////////////////////////////////////////////// // StreamingTable class private class StreamingTable extends AbstractTable { private ITableMetaData _metaData; private int _lastRow = -1; private boolean _eot = false; private Object[] _rowValues; public StreamingTable(ITableMetaData metaData) { _metaData = metaData; } boolean next() throws DataSetException { // End of table has previously been reach if (_eot) { return false; } try { _taken = _channel.take(); if (!(_taken instanceof Object[])) { _eot = true; return false; } _lastRow++; _rowValues = (Object[])_taken; return true; } catch (InterruptedException e) { throw new DataSetException(); } } //////////////////////////////////////////////////////////////////////// // ITable interface public ITableMetaData getTableMetaData() { return _metaData; } public int getRowCount() { throw new UnsupportedOperationException(); } public Object getValue(int row, String column) throws DataSetException { // Iterate up to specified row while (!_eot && row > _lastRow) { next(); } if (row < _lastRow) { throw new UnsupportedOperationException("Cannot go backward!"); } if (_eot || row > _lastRow) { throw new RowOutOfBoundsException(row + " > " + _lastRow); } return _rowValues[getColumnIndex(column)]; } } //////////////////////////////////////////////////////////////////////////// // AsynchronousHandler class private static class AsynchronousHandler implements Runnable, IDataSetListener { private final IDataSetSource _source; private final Puttable _channel; public AsynchronousHandler(IDataSetSource source, Puttable channel) { _source = source; _channel = channel; } //////////////////////////////////////////////////////////////////////// // Runnable interface public void run() { try { _source.process(this); // System.out.println("End of thread! - " + System.currentTimeMillis()); } catch (DataSetException e) { throw new DatabaseUnitRuntimeException(e); } } //////////////////////////////////////////////////////////////////////// // IDataSetListener interface public void startDataSet() throws DataSetException { } public void endDataSet() throws DataSetException { try { _channel.put(EOD); } catch (InterruptedException e) { throw new DataSetException(); } } public void startTable(ITableMetaData metaData) throws DataSetException { try { _channel.put(metaData); } catch (InterruptedException e) { throw new DataSetException(); } } public void endTable() throws DataSetException { } public void row(Object[] values) throws DataSetException { try { _channel.put(values); } catch (InterruptedException e) { throw new DataSetException(); } } } } Index: CachedTable.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/CachedTable.java,v retrieving revision 1.1 retrieving revision 1.1.2.1 diff -C2 -d -r1.1 -r1.1.2.1 *** CachedTable.java 13 Apr 2003 02:40:10 -0000 1.1 --- CachedTable.java 23 Apr 2003 02:30:33 -0000 1.1.2.1 *************** *** 28,41 **** { Column[] columns = table.getTableMetaData().getColumns(); ! ! for (int i = 0; ; i++) { ! Object[] rowValues = new Object[columns.length]; ! for (int j = 0; j < columns.length; j++) { ! Column column = columns[j]; ! rowValues[j] = table.getValue(i, column.getColumnName()); } - rowList.add(rowValues); } } --- 28,43 ---- { Column[] columns = table.getTableMetaData().getColumns(); ! if (columns.length > 0) { ! for (int i = 0; ; i++) { ! Object[] rowValues = new Object[columns.length]; ! for (int j = 0; j < columns.length; j++) ! { ! Column column = columns[j]; ! rowValues[j] = table.getValue(i, column.getColumnName()); ! } ! rowList.add(rowValues); } } } |
From: <mla...@us...> - 2003-04-23 02:30:41
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/util/xml In directory sc8-pr-cvs1:/tmp/cvs-serv7057/src/java/org/dbunit/util/xml Added Files: Tag: branch-exml2sax DataWriter.java XMLWriter.java Log Message: Added new StreamingDataSet class. --- NEW FILE: DataWriter.java --- // DataWriter.java - XML writer for data-oriented files. package org.dbunit.util.xml; import java.io.Writer; import java.util.Stack; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; /** * Write data- or field-oriented XML. * * <p>This filter pretty-prints field-oriented XML without mixed content. * all added indentation and newlines will be passed on down * the filter chain (if any).</p> * * <p>In general, all whitespace in an XML document is potentially * significant, so a general-purpose XML writing tool like the * {@link org.dbunit.util.xml.XMLWriter XMLWriter} class cannot * add newlines or indentation.</p> * * <p>There is, however, a large class of XML documents where information * is strictly fielded: each element contains either character data * or other elements, but not both. For this special case, it is possible * for a writing tool to provide automatic indentation and newlines * without requiring extra work from the user. Note that this class * will likely not yield appropriate results for document-oriented * XML like XHTML pages, which mix character data and elements together.</p> * * <p>This writer will automatically place each start tag on a new line, * optionally indented if an indent step is provided (by default, there * is no indentation). If an element contains other elements, the end * tag will also appear on a new line with leading indentation. Consider, * for example, the following code:</p> * * <pre> * DataWriter w = new DataWriter(); * * w.setIndentStep(2); * w.startDocument(); * w.startElement("Person"); * w.dataElement("name", "Jane Smith"); * w.dataElement("date-of-birth", "1965-05-23"); * w.dataElement("citizenship", "US"); * w.endElement("Person"); * w.endDocument(); * </pre> * * <p>This code will produce the following document:</p> * * <pre> * <?xml version="1.0" standalone="yes"?> * * <Person> * <name>Jane Smith</name> * <date-of-birth>1965-05-23</date-of-birth> * <citizenship>US</citizenship> * </Person> * </pre> * * <p>This class inherits from {@link org.dbunit.util.xml.XMLWriter * XMLWriter}, and provides all of the same support for Namespaces.</p> * * @author David Megginson, da...@me... * @version 0.2 * @see org.dbunit.util.xml.XMLWriter */ public class DataWriter extends XMLWriter { //////////////////////////////////////////////////////////////////// // Constructors. //////////////////////////////////////////////////////////////////// /** * Create a new data writer for standard output. */ public DataWriter () { super(); } /** * Create a new data writer for standard output. * * <p>Use the XMLReader provided as the source of events.</p> * * @param xmlreader The parent in the filter chain. */ public DataWriter (XMLReader xmlreader) { super(xmlreader); } /** * Create a new data writer for the specified output. * * @param writer The character stream where the XML document * will be written. */ public DataWriter (Writer writer) { super(writer); } /** * Create a new data writer for the specified output. * <p>Use the XMLReader provided as the source of events.</p> * * @param xmlreader The parent in the filter chain. * @param writer The character stream where the XML document * will be written. */ public DataWriter (XMLReader xmlreader, Writer writer) { super(xmlreader, writer); } //////////////////////////////////////////////////////////////////// // Accessors and setters. //////////////////////////////////////////////////////////////////// /** * Return the current indent step. * * <p>Return the current indent step: each start tag will be * indented by this number of spaces times the number of * ancestors that the element has.</p> * * @return The number of spaces in each indentation step, * or 0 or less for no indentation. * @see #setIndentStep */ public int getIndentStep () { return indentStep; } /** * Set the current indent step. * * @param indentStep The new indent step (0 or less for no * indentation). * @see #getIndentStep */ public void setIndentStep (int indentStep) { this.indentStep = indentStep; } //////////////////////////////////////////////////////////////////// // Override methods from XMLWriter. //////////////////////////////////////////////////////////////////// /** * Reset the writer so that it can be reused. * * <p>This method is especially useful if the writer failed * with an exception the last time through.</p> * * @see org.dbunit.util.xml.XMLWriter#reset */ public void reset () { depth = 0; state = SEEN_NOTHING; stateStack = new Stack(); super.reset(); } /** * Write a start tag. * * <p>Each tag will begin on a new line, and will be * indented by the current indent step times the number * of ancestors that the element has.</p> * * <p>The newline and indentation will be passed on down * the filter chain through regular characters events.</p> * * @param uri The element's Namespace URI. * @param localName The element's local name. * @param qName The element's qualified (prefixed) name. * @param atts The element's attribute list. * @exception org.xml.sax.SAXException If there is an error * writing the start tag, or if a filter further * down the chain raises an exception. * @see XMLWriter#startElement(String, String, String, Attributes) */ public void startElement (String uri, String localName, String qName, Attributes atts) throws SAXException { stateStack.push(SEEN_ELEMENT); state = SEEN_NOTHING; if (depth > 0) { super.characters("\n"); } doIndent(); super.startElement(uri, localName, qName, atts); depth++; } /** * Write an end tag. * * <p>If the element has contained other elements, the tag * will appear indented on a new line; otherwise, it will * appear immediately following whatever came before.</p> * * <p>The newline and indentation will be passed on down * the filter chain through regular characters events.</p> * * @param uri The element's Namespace URI. * @param localName The element's local name. * @param qName The element's qualified (prefixed) name. * @exception org.xml.sax.SAXException If there is an error * writing the end tag, or if a filter further * down the chain raises an exception. * @see XMLWriter#endElement(String, String, String) */ public void endElement (String uri, String localName, String qName) throws SAXException { depth--; if (state == SEEN_ELEMENT) { super.characters("\n"); doIndent(); } super.endElement(uri, localName, qName); state = stateStack.pop(); } /** * Write a empty element tag. * * <p>Each tag will appear on a new line, and will be * indented by the current indent step times the number * of ancestors that the element has.</p> * * <p>The newline and indentation will be passed on down * the filter chain through regular characters events.</p> * * @param uri The element's Namespace URI. * @param localName The element's local name. * @param qName The element's qualified (prefixed) name. * @param atts The element's attribute list. * @exception org.xml.sax.SAXException If there is an error * writing the empty tag, or if a filter further * down the chain raises an exception. * @see XMLWriter#emptyElement(String, String, String, Attributes) */ public void emptyElement (String uri, String localName, String qName, Attributes atts) throws SAXException { state = SEEN_ELEMENT; if (depth > 0) { super.characters("\n"); } doIndent(); super.emptyElement(uri, localName, qName, atts); } /** * Write a sequence of characters. * * @param ch The characters to write. * @param start The starting position in the array. * @param length The number of characters to use. * @exception org.xml.sax.SAXException If there is an error * writing the characters, or if a filter further * down the chain raises an exception. * @see XMLWriter#characters(char[], int, int) */ public void characters (char ch[], int start, int length) throws SAXException { state = SEEN_DATA; super.characters(ch, start, length); } //////////////////////////////////////////////////////////////////// // Internal methods. //////////////////////////////////////////////////////////////////// /** * Print indentation for the current level. * * @exception org.xml.sax.SAXException If there is an error * writing the indentation characters, or if a filter * further down the chain raises an exception. */ private void doIndent () throws SAXException { if (indentStep > 0 && depth > 0) { int n = indentStep * depth; char ch[] = new char[n]; for (int i = 0; i < n; i++) { ch[i] = '\t'; } characters(ch, 0, n); } } //////////////////////////////////////////////////////////////////// // Constants. //////////////////////////////////////////////////////////////////// private final static Object SEEN_NOTHING = new Object(); private final static Object SEEN_ELEMENT = new Object(); private final static Object SEEN_DATA = new Object(); //////////////////////////////////////////////////////////////////// // Internal state. //////////////////////////////////////////////////////////////////// private Object state = SEEN_NOTHING; private Stack stateStack = new Stack(); private int indentStep = 0; private int depth = 0; } // end of DataWriter.java --- NEW FILE: XMLWriter.java --- // XMLWriter.java - serialize an XML document. // Written by David Megginson, da...@me... // NO WARRANTY! This class is in the public domain. // $Id: XMLWriter.java,v 1.1.2.1 2003/04/23 02:30:37 mlaflamm Exp $ package org.dbunit.util.xml; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import java.util.Enumeration; import java.util.Hashtable; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.AttributesImpl; [...1204 lines suppressed...] private final Attributes EMPTY_ATTS = new AttributesImpl(); //////////////////////////////////////////////////////////////////// // Internal state. //////////////////////////////////////////////////////////////////// private Hashtable prefixTable; private Hashtable forcedDeclTable; private Hashtable doneDeclTable; private int elementLevel = 0; private Writer output; private NamespaceSupport nsSupport; private int prefixCounter = 0; } // end of XMLWriter.java |
From: <mla...@us...> - 2003-04-23 02:30:40
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/dataset/xml In directory sc8-pr-cvs1:/tmp/cvs-serv7057/src/java/org/dbunit/dataset/xml Added Files: Tag: branch-exml2sax FlatXmlSource.java FlatXmlWriter.java Log Message: Added new StreamingDataSet class. --- NEW FILE: FlatXmlSource.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset.xml; import org.dbunit.dataset.Column; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.DefaultTableMetaData; import org.dbunit.dataset.ITableMetaData; import org.dbunit.dataset.datatype.DataType; import org.dbunit.dataset.IDataSetListener; import org.dbunit.dataset.IDataSetSource; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import java.io.IOException; /** * @author Manuel Laflamme * @since Apr 18, 2003 * @version $Revision: 1.1.2.1 $ */ public class FlatXmlSource implements IDataSetSource { private final InputSource _inputSource; private SAXParser _parser; public FlatXmlSource(InputSource inputSource) { _inputSource = inputSource; } public FlatXmlSource(InputSource inputSource, SAXParser parser) { _inputSource = inputSource; _parser = parser; } //////////////////////////////////////////////////////////////////////////// // IDataSetSource interface public void process(IDataSetListener listener) throws DataSetException { try { if (_parser == null) { _parser = SAXParserFactory.newInstance().newSAXParser(); } _parser.parse(_inputSource, new FlatXmlHandler(listener)); } catch (ParserConfigurationException e) { throw new DataSetException(e); } catch (SAXException e) { throw new DataSetException(e.getException()); } catch (IOException e) { throw new DataSetException(e); } } private class FlatXmlHandler extends DefaultHandler { private static final String DATASET = "dataset"; private final IDataSetListener _listener; private ITableMetaData _activeMetaData; public FlatXmlHandler(IDataSetListener listener) { _listener = listener; } //////////////////////////////////////////////////////////////////////// // ContentHandler interface public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { try { // Start of dataset if (_activeMetaData == null && qName.equals(DATASET)) { _listener.startDataSet(); return; } // New table if (_activeMetaData == null || !_activeMetaData.getTableName().equals(qName)) { // If not first table, notify end of previous table to listener if (_activeMetaData != null) { _listener.endTable(); } // Create metadata from attributes Column[] columns = new Column[attributes.getLength()]; for (int i = 0; i < attributes.getLength(); i++) { columns[i] = new Column(attributes.getQName(i), DataType.UNKNOWN); } // Notify start of new table to listener _activeMetaData = new DefaultTableMetaData(qName, columns); _listener.startTable(_activeMetaData); } // Row notification if (attributes.getLength() > 0) { Column[] columns = _activeMetaData.getColumns(); Object[] rowValues = new Object[columns.length]; for (int i = 0; i < columns.length; i++) { Column column = columns[i]; rowValues[i] = attributes.getValue(column.getColumnName()); } _listener.row(rowValues); } } catch (DataSetException e) { throw new SAXException(e); } } public void endElement(String uri, String localName, String qName) throws SAXException { // End of dataset if (qName.equals(DATASET)) { try { // Notify end of active table to listener if (_activeMetaData != null) { _listener.endTable(); } // End of dataset to listener _listener.endDataSet(); } catch (DataSetException e) { throw new SAXException(e); } } } } } --- NEW FILE: FlatXmlWriter.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset.xml; import org.dbunit.dataset.Column; import org.dbunit.dataset.DataSetException; import org.dbunit.dataset.IDataSet; import org.dbunit.dataset.ITableMetaData; import org.dbunit.dataset.datatype.DataType; import org.dbunit.dataset.DefaultDataSetSource; import org.dbunit.dataset.IDataSetListener; import org.dbunit.util.xml.DataWriter; import org.dbunit.util.xml.XMLWriter; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; import java.io.Writer; /** * @author Manuel Laflamme * @since Apr 19, 2003 * @version $Revision: 1.1.2.1 $ */ public class FlatXmlWriter { private static final String CDATA = "CDATA"; private static final String DATASET = "dataset"; public void write(IDataSet dataSet, Writer writer) throws DataSetException { DataWriter dataWriter = new DataWriter(writer); dataWriter.setIndentStep(1); new DefaultDataSetSource(dataSet).process(new Listener(dataWriter)); } private class Listener implements IDataSetListener { private final XMLWriter _xmlWriter; private ITableMetaData _activeMetaData; public Listener(XMLWriter xmlWriter) { _xmlWriter = xmlWriter; } //////////////////////////////////////////////////////////////////////////// // IDataSetListener interface public void startDataSet() throws DataSetException { try { _xmlWriter.startDocument(); _xmlWriter.startElement("", DATASET, DATASET, new AttributesImpl()); } catch (SAXException e) { throw new DataSetException(e.getException() == null ? e : e.getException()); } } public void endDataSet() throws DataSetException { try { _xmlWriter.endDocument(); _xmlWriter.endElement("", DATASET, DATASET); } catch (SAXException e) { throw new DataSetException(e.getException() == null ? e : e.getException()); } } public void startTable(ITableMetaData metaData) throws DataSetException { _activeMetaData = metaData; } public void endTable() throws DataSetException { _activeMetaData = null; } public void row(Object[] values) throws DataSetException { try { AttributesImpl attributes = new AttributesImpl(); Column[] columns = _activeMetaData.getColumns(); for (int i = 0; i < columns.length; i++) { String columnName = columns[i].getColumnName(); Object value = values[i]; attributes.addAttribute("", columnName, columnName, CDATA, DataType.asString(value)); } String tableName = _activeMetaData.getTableName(); _xmlWriter.emptyElement("", tableName, tableName, attributes); } catch (SAXException e) { throw new DataSetException(e.getException() == null ? e : e.getException()); } } } } |
Update of /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset In directory sc8-pr-cvs1:/tmp/cvs-serv7057/src/test/org/dbunit/dataset Modified Files: Tag: branch-exml2sax AllTests.java Added Files: Tag: branch-exml2sax CachedDataSetTest.java StreamingDataSetTest.java StreamingTableTest.java Log Message: Added new StreamingDataSet class. --- NEW FILE: CachedDataSetTest.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset; import org.dbunit.dataset.xml.FlatXmlDataSet; import org.dbunit.dataset.xml.FlatXmlSource; import org.xml.sax.InputSource; import java.io.FileReader; /** * @author Manuel Laflamme * @since Apr 18, 2003 * @version $Revision: 1.1.2.1 $ */ public class CachedDataSetTest extends AbstractDataSetTest { public CachedDataSetTest(String s) { super(s); } protected IDataSet createDataSet() throws Exception { FileReader reader = new FileReader("src/xml/flatXmlDataSetTest.xml"); return new CachedDataSet(new FlatXmlSource(new InputSource(reader))); // return new CachedDataSet( // new StreamingDataSet(new FlatXmlSource(new InputSource(reader)))); // return new CachedDataSet(new ForwardOnlyDataSet(new FlatXmlDataSet(reader))); } protected IDataSet createDuplicateDataSet() throws Exception { FileReader reader = new FileReader("src/xml/flatXmlDataSetDuplicateTest.xml"); return new CachedDataSet(new ForwardOnlyDataSet(new FlatXmlDataSet(reader))); } public void testGetTable() throws Exception { super.testGetTable(); } } --- NEW FILE: StreamingDataSetTest.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset; import org.dbunit.dataset.DefaultDataSetSource; import org.dbunit.dataset.ForwardOnlyDataSetTest; import org.dbunit.dataset.IDataSet; import org.dbunit.dataset.IDataSetSource; import org.dbunit.dataset.StreamingDataSet; import org.dbunit.dataset.xml.FlatXmlSource; import org.xml.sax.InputSource; import java.io.FileReader; /** * @author Manuel Laflamme * @since Apr 18, 2003 * @version $Revision: 1.1.2.1 $ */ public class StreamingDataSetTest extends ForwardOnlyDataSetTest { public StreamingDataSetTest(String s) { super(s); } protected IDataSet createDataSet() throws Exception { IDataSetSource source = new FlatXmlSource( new InputSource(new FileReader("src/xml/flatXmlDataSetTest.xml"))); return new StreamingDataSet(source); // return new StreamingDataSet( // new DefaultDataSetSource(super.createDataSet())); } protected IDataSet createDuplicateDataSet() throws Exception { return new StreamingDataSet( new DefaultDataSetSource(super.createDuplicateDataSet())); } } --- NEW FILE: StreamingTableTest.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset; import org.dbunit.dataset.xml.FlatXmlSource; import org.xml.sax.InputSource; import java.io.FileReader; /** * @author Manuel Laflamme * @since Apr 11, 2003 * @version $Revision: 1.1.2.1 $ */ public class StreamingTableTest extends ForwardOnlyTableTest { private static final String TEST_TABLE = "TEST_TABLE"; public StreamingTableTest(String s) { super(s); } protected ITable createTable() throws Exception { FileReader reader = new FileReader("src/xml/flatXmlDataSetTest.xml"); // IDataSetSource source = new DefaultDataSetSource(new FlatXmlDataSet(reader)); IDataSetSource source = new FlatXmlSource(new InputSource(reader)); ITableIterator iterator = new StreamingDataSet(source).iterator(); while(iterator.next()) { ITable table = iterator.getTable(); String tableName = table.getTableMetaData().getTableName(); if (tableName.equals(TEST_TABLE)) { return table; } } throw new IllegalStateException(); } } Index: AllTests.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/AllTests.java,v retrieving revision 1.18 retrieving revision 1.18.2.1 diff -C2 -d -r1.18 -r1.18.2.1 *** AllTests.java 13 Apr 2003 02:40:11 -0000 1.18 --- AllTests.java 23 Apr 2003 02:30:35 -0000 1.18.2.1 *************** *** 59,62 **** --- 59,64 ---- suite.addTest(new TestSuite(SortedDataSetTest.class)); suite.addTest(new TestSuite(SortedTableTest.class)); + suite.addTest(new TestSuite(StreamingDataSetTest.class)); + suite.addTest(new TestSuite(StreamingTableTest.class)); return suite; |
From: <mla...@us...> - 2003-04-23 02:22:13
|
Update of /cvsroot/dbunit/dbunit/lib In directory sc8-pr-cvs1:/tmp/cvs-serv3619/lib Added Files: Tag: branch-exml2sax crimson.jar Log Message: Updated the crimson XML parser to version 1.1.3. JAXP is included in this version. |
From: <mla...@us...> - 2003-04-23 02:18:09
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/util/xml In directory sc8-pr-cvs1:/tmp/cvs-serv2168/xml Log Message: Directory /cvsroot/dbunit/dbunit/src/java/org/dbunit/util/xml added to the repository --> Using per-directory sticky tag `branch-exml2sax' |
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/util/concurrent In directory sc8-pr-cvs1:/tmp/cvs-serv31052/src/java/org/dbunit/util/concurrent Added Files: Tag: branch-exml2sax BoundedBuffer.java BoundedChannel.java BoundedLinkedQueue.java Channel.java DefaultChannelCapacity.java Executor.java LinkedNode.java LinkedQueue.java PropertyChangeMulticaster.java Puttable.java Semaphore.java SemaphoreControlledChannel.java Slot.java Sync.java SynchronizedInt.java SynchronizedVariable.java SynchronousChannel.java Takable.java TimeoutException.java Log Message: Added excellent Doug Lea util.concurrent package version 1.3.2 (http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html). Used in StreamingDataSet to synchronize SAX parsing performed in a worker thread. --- NEW FILE: BoundedBuffer.java --- /* File: BoundedBuffer.java Originally written by Doug Lea and released into the public domain. This may be used for any purposes whatsoever without acknowledgment. Thanks for the assistance and support of Sun Microsystems Labs, and everyone contributing, testing, and using this code. History: Date Who What 11Jun1998 dl Create public version 17Jul1998 dl Simplified by eliminating wait counts 25aug1998 dl added peek 5May1999 dl replace % with conditional (slightly faster) */ package org.dbunit.util.concurrent; /** * Efficient array-based bounded buffer class. * Adapted from CPJ, chapter 8, which describes design. * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] <p> **/ public class BoundedBuffer implements BoundedChannel { protected final Object[] array_; // the elements protected int takePtr_ = 0; // circular indices protected int putPtr_ = 0; protected int usedSlots_ = 0; // length protected int emptySlots_; // capacity - length /** * Helper monitor to handle puts. **/ protected final Object putMonitor_ = new Object(); /** * Create a BoundedBuffer with the given capacity. * @exception IllegalArgumentException if capacity less or equal to zero **/ public BoundedBuffer(int capacity) throws IllegalArgumentException { if (capacity <= 0) throw new IllegalArgumentException(); array_ = new Object[capacity]; emptySlots_ = capacity; } /** * Create a buffer with the current default capacity **/ public BoundedBuffer() { this(DefaultChannelCapacity.get()); } /** * Return the number of elements in the buffer. * This is only a snapshot value, that may change * immediately after returning. **/ public synchronized int size() { return usedSlots_; } public int capacity() { return array_.length; } protected void incEmptySlots() { synchronized(putMonitor_) { ++emptySlots_; putMonitor_.notify(); } } protected synchronized void incUsedSlots() { ++usedSlots_; notify(); } protected final void insert(Object x) { // mechanics of put --emptySlots_; array_[putPtr_] = x; if (++putPtr_ >= array_.length) putPtr_ = 0; } protected final Object extract() { // mechanics of take --usedSlots_; Object old = array_[takePtr_]; array_[takePtr_] = null; if (++takePtr_ >= array_.length) takePtr_ = 0; return old; } public Object peek() { synchronized(this) { if (usedSlots_ > 0) return array_[takePtr_]; else return null; } } public void put(Object x) throws InterruptedException { if (x == null) throw new IllegalArgumentException(); if (Thread.interrupted()) throw new InterruptedException(); synchronized(putMonitor_) { while (emptySlots_ <= 0) { try { putMonitor_.wait(); } catch (InterruptedException ex) { putMonitor_.notify(); throw ex; } } insert(x); } incUsedSlots(); } public boolean offer(Object x, long msecs) throws InterruptedException { if (x == null) throw new IllegalArgumentException(); if (Thread.interrupted()) throw new InterruptedException(); synchronized(putMonitor_) { long start = (msecs <= 0)? 0 : System.currentTimeMillis(); long waitTime = msecs; while (emptySlots_ <= 0) { if (waitTime <= 0) return false; try { putMonitor_.wait(waitTime); } catch (InterruptedException ex) { putMonitor_.notify(); throw ex; } waitTime = msecs - (System.currentTimeMillis() - start); } insert(x); } incUsedSlots(); return true; } public Object take() throws InterruptedException { if (Thread.interrupted()) throw new InterruptedException(); Object old = null; synchronized(this) { while (usedSlots_ <= 0) { try { wait(); } catch (InterruptedException ex) { notify(); throw ex; } } old = extract(); } incEmptySlots(); return old; } public Object poll(long msecs) throws InterruptedException { if (Thread.interrupted()) throw new InterruptedException(); Object old = null; synchronized(this) { long start = (msecs <= 0)? 0 : System.currentTimeMillis(); long waitTime = msecs; while (usedSlots_ <= 0) { if (waitTime <= 0) return null; try { wait(waitTime); } catch (InterruptedException ex) { notify(); throw ex; } waitTime = msecs - (System.currentTimeMillis() - start); } old = extract(); } incEmptySlots(); return old; } } --- NEW FILE: BoundedChannel.java --- /* File: BoundedChannel.java Originally written by Doug Lea and released into the public domain. This may be used for any purposes whatsoever without acknowledgment. Thanks for the assistance and support of Sun Microsystems Labs, and everyone contributing, testing, and using this code. History: Date Who What 11Jun1998 dl Create public version */ package org.dbunit.util.concurrent; /** * A channel that is known to have a capacity, signifying * that <code>put</code> operations may block when the * capacity is reached. Various implementations may have * intrinsically hard-wired capacities, capacities that are fixed upon * construction, or dynamically adjustable capacities. * @see DefaultChannelCapacity * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] <p> **/ public interface BoundedChannel extends Channel { /** * Return the maximum number of elements that can be held. * @return the capacity of this channel. **/ public int capacity(); } --- NEW FILE: BoundedLinkedQueue.java --- /* File: BoundedLinkedQueue.java Originally written by Doug Lea and released into the public domain. This may be used for any purposes whatsoever without acknowledgment. Thanks for the assistance and support of Sun Microsystems Labs, and everyone contributing, testing, and using this code. History: Date Who What 11Jun1998 dl Create public version 17Jul1998 dl Simplified by eliminating wait counts 25aug1998 dl added peek 10oct1999 dl lock on node object to ensure visibility 27jan2000 dl setCapacity forces immediate permit reconcile */ package org.dbunit.util.concurrent; /** * A bounded variant of * LinkedQueue * class. This class may be * preferable to * BoundedBuffer * because it allows a bit more * concurency among puts and takes, because it does not * pre-allocate fixed storage for elements, and allows * capacity to be dynamically reset. * On the other hand, since it allocates a node object * on each put, it can be slow on systems with slow * allocation and GC. * Also, it may be * preferable to * LinkedQueue * when you need to limit * the capacity to prevent resource exhaustion. This protection * normally does not hurt much performance-wise: When the * queue is not empty or full, most puts and * takes are still usually able to execute concurrently. * @see LinkedQueue * @see BoundedBuffer * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] <p> **/ public class BoundedLinkedQueue implements BoundedChannel { /* * It might be a bit nicer if this were declared as * a subclass of LinkedQueue, or a sibling class of * a common abstract class. It shares much of the * basic design and bookkeeping fields. But too * many details differ to make this worth doing. */ /** * Dummy header node of list. The first actual node, if it exists, is always * at head_.next. After each take, the old first node becomes the head. **/ protected LinkedNode head_; /** * The last node of list. Put() appends to list, so modifies last_ **/ protected LinkedNode last_; /** * Helper monitor. Ensures that only one put at a time executes. **/ protected final Object putGuard_ = new Object(); /** * Helper monitor. Protects and provides wait queue for takes **/ protected final Object takeGuard_ = new Object(); /** Number of elements allowed **/ protected int capacity_; /** * One side of a split permit count. * The counts represent permits to do a put. (The queue is full when zero). * Invariant: putSidePutPermits_ + takeSidePutPermits_ = capacity_ - length. * (The length is never separately recorded, so this cannot be * checked explicitly.) * To minimize contention between puts and takes, the * put side uses up all of its permits before transfering them from * the take side. The take side just increments the count upon each take. * Thus, most puts and take can run independently of each other unless * the queue is empty or full. * Initial value is queue capacity. **/ protected int putSidePutPermits_; /** Number of takes since last reconcile **/ protected int takeSidePutPermits_ = 0; /** * Create a queue with the given capacity * @exception IllegalArgumentException if capacity less or equal to zero **/ public BoundedLinkedQueue(int capacity) { if (capacity <= 0) throw new IllegalArgumentException(); capacity_ = capacity; putSidePutPermits_ = capacity; head_ = new LinkedNode(null); last_ = head_; } /** * Create a queue with the current default capacity **/ public BoundedLinkedQueue() { this(DefaultChannelCapacity.get()); } /** * Move put permits from take side to put side; * return the number of put side permits that are available. * Call only under synch on puGuard_ AND this. **/ protected final int reconcilePutPermits() { putSidePutPermits_ += takeSidePutPermits_; takeSidePutPermits_ = 0; return putSidePutPermits_; } /** Return the current capacity of this queue **/ public synchronized int capacity() { return capacity_; } /** * Return the number of elements in the queue. * This is only a snapshot value, that may be in the midst * of changing. The returned value will be unreliable in the presence of * active puts and takes, and should only be used as a heuristic * estimate, for example for resource monitoring purposes. **/ public synchronized int size() { /* This should ideally synch on putGuard_, but doing so would cause it to block waiting for an in-progress put, which might be stuck. So we instead use whatever value of putSidePutPermits_ that we happen to read. */ return capacity_ - (takeSidePutPermits_ + putSidePutPermits_); } /** * Reset the capacity of this queue. * If the new capacity is less than the old capacity, * existing elements are NOT removed, but * incoming puts will not proceed until the number of elements * is less than the new capacity. * @exception IllegalArgumentException if capacity less or equal to zero **/ public void setCapacity(int newCapacity) { if (newCapacity <= 0) throw new IllegalArgumentException(); synchronized (putGuard_) { synchronized(this) { takeSidePutPermits_ += (newCapacity - capacity_); capacity_ = newCapacity; // Force immediate reconcilation. reconcilePutPermits(); notifyAll(); } } } /** Main mechanics for take/poll **/ protected synchronized Object extract() { synchronized(head_) { Object x = null; LinkedNode first = head_.next; if (first != null) { x = first.value; first.value = null; head_ = first; ++takeSidePutPermits_; notify(); } return x; } } public Object peek() { synchronized(head_) { LinkedNode first = head_.next; if (first != null) return first.value; else return null; } } public Object take() throws InterruptedException { if (Thread.interrupted()) throw new InterruptedException(); Object x = extract(); if (x != null) return x; else { synchronized(takeGuard_) { try { for (;;) { x = extract(); if (x != null) { return x; } else { takeGuard_.wait(); } } } catch(InterruptedException ex) { takeGuard_.notify(); throw ex; } } } } public Object poll(long msecs) throws InterruptedException { if (Thread.interrupted()) throw new InterruptedException(); Object x = extract(); if (x != null) return x; else { synchronized(takeGuard_) { try { long waitTime = msecs; long start = (msecs <= 0)? 0: System.currentTimeMillis(); for (;;) { x = extract(); if (x != null || waitTime <= 0) { return x; } else { takeGuard_.wait(waitTime); waitTime = msecs - (System.currentTimeMillis() - start); } } } catch(InterruptedException ex) { takeGuard_.notify(); throw ex; } } } } /** Notify a waiting take if needed **/ protected final void allowTake() { synchronized(takeGuard_) { takeGuard_.notify(); } } /** * Create and insert a node. * Call only under synch on putGuard_ **/ protected void insert(Object x) { --putSidePutPermits_; LinkedNode p = new LinkedNode(x); synchronized(last_) { last_.next = p; last_ = p; } } /* put and offer(ms) differ only in policy before insert/allowTake */ public void put(Object x) throws InterruptedException { if (x == null) throw new IllegalArgumentException(); if (Thread.interrupted()) throw new InterruptedException(); synchronized(putGuard_) { if (putSidePutPermits_ <= 0) { // wait for permit. synchronized(this) { if (reconcilePutPermits() <= 0) { try { for(;;) { wait(); if (reconcilePutPermits() > 0) { break; } } } catch (InterruptedException ex) { notify(); throw ex; } } } } insert(x); } // call outside of lock to loosen put/take coupling allowTake(); } public boolean offer(Object x, long msecs) throws InterruptedException { if (x == null) throw new IllegalArgumentException(); if (Thread.interrupted()) throw new InterruptedException(); synchronized(putGuard_) { if (putSidePutPermits_ <= 0) { synchronized(this) { if (reconcilePutPermits() <= 0) { if (msecs <= 0) return false; else { try { long waitTime = msecs; long start = System.currentTimeMillis(); for(;;) { wait(waitTime); if (reconcilePutPermits() > 0) { break; } else { waitTime = msecs - (System.currentTimeMillis() - start); if (waitTime <= 0) { return false; } } } } catch (InterruptedException ex) { notify(); throw ex; } } } } } insert(x); } allowTake(); return true; } public boolean isEmpty() { synchronized(head_) { return head_.next == null; } } } --- NEW FILE: Channel.java --- /* File: Channel.java Originally written by Doug Lea and released into the public domain. This may be used for any purposes whatsoever without acknowledgment. Thanks for the assistance and support of Sun Microsystems Labs, and everyone contributing, testing, and using this code. History: Date Who What 11Jun1998 dl Create public version 25aug1998 dl added peek */ package org.dbunit.util.concurrent; /** * Main interface for buffers, queues, pipes, conduits, etc. * <p> * A Channel represents anything that you can put items * into and take them out of. As with the Sync * interface, both * blocking (put(x), take), * and timeouts (offer(x, msecs), poll(msecs)) policies * are provided. Using a * zero timeout for offer and poll results in a pure balking policy. * <p> * To aid in efforts to use Channels in a more typesafe manner, * this interface extends Puttable and Takable. You can restrict * arguments of instance variables to this type as a way of * guaranteeing that producers never try to take, or consumers put. * for example: * <pre> * class Producer implements Runnable { * final Puttable chan; * Producer(Puttable channel) { chan = channel; } * public void run() { * try { * for(;;) { chan.put(produce()); } * } * catch (InterruptedException ex) {} * } * Object produce() { ... } * } * * * class Consumer implements Runnable { * final Takable chan; * Consumer(Takable channel) { chan = channel; } * public void run() { * try { * for(;;) { consume(chan.take()); } * } * catch (InterruptedException ex) {} * } * void consume(Object x) { ... } * } * * class Setup { * void main() { * Channel chan = new SomeChannelImplementation(); * Producer p = new Producer(chan); * Consumer c = new Consumer(chan); * new Thread(p).start(); * new Thread(c).start(); * } * } * </pre> * <p> * A given channel implementation might or might not have bounded * capacity or other insertion constraints, so in general, you cannot tell if * a given put will block. However, * Channels that are designed to * have an element capacity (and so always block when full) * should implement the * BoundedChannel * subinterface. * <p> * Channels may hold any kind of item. However, * insertion of null is not in general supported. Implementations * may (all currently do) throw IllegalArgumentExceptions upon attempts to * insert null. * <p> * By design, the Channel interface does not support any methods to determine * the current number of elements being held in the channel. * This decision reflects the fact that in * concurrent programming, such methods are so rarely useful * that including them invites misuse; at best they could * provide a snapshot of current * state, that could change immediately after being reported. * It is better practice to instead use poll and offer to try * to take and put elements without blocking. For example, * to empty out the current contents of a channel, you could write: * <pre> * try { * for (;;) { * Object item = channel.poll(0); * if (item != null) * process(item); * else * break; * } * } * catch(InterruptedException ex) { ... } * </pre> * <p> * However, it is possible to determine whether an item * exists in a Channel via <code>peek</code>, which returns * but does NOT remove the next item that can be taken (or null * if there is no such item). The peek operation has a limited * range of applicability, and must be used with care. Unless it * is known that a given thread is the only possible consumer * of a channel, and that no time-out-based <code>offer</code> operations * are ever invoked, there is no guarantee that the item returned * by peek will be available for a subsequent take. * <p> * When appropriate, you can define an isEmpty method to * return whether <code>peek</code> returns null. * <p> * Also, as a compromise, even though it does not appear in interface, * implementation classes that can readily compute the number * of elements support a <code>size()</code> method. This allows careful * use, for example in queue length monitors, appropriate to the * particular implementation constraints and properties. * <p> * All channels allow multiple producers and/or consumers. * They do not support any kind of <em>close</em> method * to shut down operation or indicate completion of particular * producer or consumer threads. * If you need to signal completion, one way to do it is to * create a class such as * <pre> * class EndOfStream { * // Application-dependent field/methods * } * </pre> * And to have producers put an instance of this class into * the channel when they are done. The consumer side can then * check this via * <pre> * Object x = aChannel.take(); * if (x instanceof EndOfStream) * // special actions; perhaps terminate * else * // process normally * </pre> * <p> * In time-out based methods (poll(msecs) and offer(x, msecs), * time bounds are interpreted in * a coarse-grained, best-effort fashion. Since there is no * way in Java to escape out of a wait for a synchronized * method/block, time bounds can sometimes be exceeded when * there is a lot contention for the channel. Additionally, * some Channel semantics entail a ``point of * no return'' where, once some parts of the operation have completed, * others must follow, regardless of time bound. * <p> * Interruptions are in general handled as early as possible * in all methods. Normally, InterruptionExceptions are thrown * in put/take and offer(msec)/poll(msec) if interruption * is detected upon entry to the method, as well as in any * later context surrounding waits. * <p> * If a put returns normally, an offer * returns true, or a put or poll returns non-null, the operation * completed successfully. * In all other cases, the operation fails cleanly -- the * element is not put or taken. * <p> * As with Sync classes, spinloops are not directly supported, * are not particularly recommended for routine use, but are not hard * to construct. For example, here is an exponential backoff version: * <pre> * Object backOffTake(Channel q) throws InterruptedException { * long waitTime = 0; * for (;;) { * Object x = q.poll(0); * if (x != null) * return x; * else { * Thread.sleep(waitTime); * waitTime = 3 * waitTime / 2 + 1; * } * } * </pre> * <p> * <b>Sample Usage</b>. Here is a producer/consumer design * where the channel is used to hold Runnable commands representing * background tasks. * <pre> * class Service { * private final Channel channel = ... some Channel implementation; * * private void backgroundTask(int taskParam) { ... } * * public void action(final int arg) { * Runnable command = * new Runnable() { * public void run() { backgroundTask(arg); } * }; * try { channel.put(command) } * catch (InterruptedException ex) { * Thread.currentThread().interrupt(); // ignore but propagate * } * } * * public Service() { * Runnable backgroundLoop = * new Runnable() { * public void run() { * for (;;) { * try { * Runnable task = (Runnable)(channel.take()); * task.run(); * } * catch (InterruptedException ex) { return; } * } * } * }; * new Thread(backgroundLoop).start(); * } * } * * </pre> * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] * @see Sync * @see BoundedChannel **/ public interface Channel extends Puttable, Takable { /** * Place item in the channel, possibly waiting indefinitely until * it can be accepted. Channels implementing the BoundedChannel * subinterface are generally guaranteed to block on puts upon * reaching capacity, but other implementations may or may not block. * @param item the element to be inserted. Should be non-null. * @exception InterruptedException if the current thread has * been interrupted at a point at which interruption * is detected, in which case the element is guaranteed not * to be inserted. Otherwise, on normal return, the element is guaranteed * to have been inserted. **/ public void put(Object item) throws InterruptedException; /** * Place item in channel only if it can be accepted within * msecs milliseconds. The time bound is interpreted in * a coarse-grained, best-effort fashion. * @param item the element to be inserted. Should be non-null. * @param msecs the number of milliseconds to wait. If less than * or equal to zero, the method does not perform any timed waits, * but might still require * access to a synchronization lock, which can impose unbounded * delay if there is a lot of contention for the channel. * @return true if accepted, else false * @exception InterruptedException if the current thread has * been interrupted at a point at which interruption * is detected, in which case the element is guaranteed not * to be inserted (i.e., is equivalent to a false return). **/ public boolean offer(Object item, long msecs) throws InterruptedException; /** * Return and remove an item from channel, * possibly waiting indefinitely until * such an item exists. * @return some item from the channel. Different implementations * may guarantee various properties (such as FIFO) about that item * @exception InterruptedException if the current thread has * been interrupted at a point at which interruption * is detected, in which case state of the channel is unchanged. * **/ public Object take() throws InterruptedException; /** * Return and remove an item from channel only if one is available within * msecs milliseconds. The time bound is interpreted in a coarse * grained, best-effort fashion. * @param msecs the number of milliseconds to wait. If less than * or equal to zero, the operation does not perform any timed waits, * but might still require * access to a synchronization lock, which can impose unbounded * delay if there is a lot of contention for the channel. * @return some item, or null if the channel is empty. * @exception InterruptedException if the current thread has * been interrupted at a point at which interruption * is detected, in which case state of the channel is unchanged * (i.e., equivalent to a null return). **/ public Object poll(long msecs) throws InterruptedException; /** * Return, but do not remove object at head of Channel, * or null if it is empty. **/ public Object peek(); } --- NEW FILE: DefaultChannelCapacity.java --- /* File: DefaultChannelCapacity.java Originally written by Doug Lea and released into the public domain. This may be used for any purposes whatsoever without acknowledgment. Thanks for the assistance and support of Sun Microsystems Labs, and everyone contributing, testing, and using this code. History: Date Who What 11Jun1998 dl Create public version */ package org.dbunit.util.concurrent; /** * A utility class to set the default capacity of * BoundedChannel * implementations that otherwise require a capacity argument * @see BoundedChannel * [<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] <p> **/ public class DefaultChannelCapacity { /** The initial value of the default capacity is 1024 **/ public static final int INITIAL_DEFAULT_CAPACITY = 1024; /** the current default capacity **/ private static final SynchronizedInt defaultCapacity_ = new SynchronizedInt(INITIAL_DEFAULT_CAPACITY); /** * Set the default capacity used in * default (no-argument) constructor for BoundedChannels * that otherwise require a capacity argument. * @exception IllegalArgumentException if capacity less or equal to zero */ public static void set(int capacity) { if (capacity <= 0) throw new IllegalArgumentException(); defaultCapacity_.set(capacity); } /** * Get the default capacity used in * default (no-argument) constructor for BoundedChannels * that otherwise require a capacity argument. * Initial value is <code>INITIAL_DEFAULT_CAPACITY</code> * @see #INITIAL_DEFAULT_CAPACITY */ public static int get() { return defaultCapacity_.get(); } } --- NEW FILE: Executor.java --- /* File: Executor.java Originally written by Doug Lea and released into the public domain. This may be used for any purposes whatsoever without acknowledgment. Thanks for the assistance and support of Sun Microsystems Labs, and everyone contributing, testing, and using this code. History: Date Who What 19Jun1998 dl Create public version */ package org.dbunit.util.concurrent; /** * Interface for objects that execute Runnables, * as well as various objects that can be wrapped * as Runnables. * The main reason to use Executor throughout a program or * subsystem is to provide flexibility: You can easily * change from using thread-per-task to using pools or * queuing, without needing to change most of your code that * generates tasks. * <p> * The general intent is that execution be asynchronous, * or at least independent of the caller. For example, * one of the simplest implementations of <code>execute</code> * (as performed in ThreadedExecutor) * is <code>new Thread(command).start();</code>. * However, this interface allows implementations that instead * employ queueing or pooling, or perform additional * bookkeeping. * <p> * * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] **/ public interface Executor { /** * Execute the given command. This method is guaranteed * only to arrange for execution, that may actually * occur sometime later; for example in a new * thread. However, in fully generic use, callers * should be prepared for execution to occur in * any fashion at all, including immediate direct * execution. * <p> * The method is defined not to throw * any checked exceptions during execution of the command. Generally, * any problems encountered will be asynchronous and * so must be dealt with via callbacks or error handler * objects. If necessary, any context-dependent * catastrophic errors encountered during * actions that arrange for execution could be accompanied * by throwing context-dependent unchecked exceptions. * <p> * However, the method does throw InterruptedException: * It will fail to arrange for execution * if the current thread is currently interrupted. * Further, the general contract of the method is to avoid, * suppress, or abort execution if interruption is detected * in any controllable context surrounding execution. **/ public void execute(Runnable command) throws InterruptedException; } --- NEW FILE: LinkedNode.java --- /* File: LinkedNode.java Originally written by Doug Lea and released into the public domain. This may be used for any purposes whatsoever without acknowledgment. Thanks for the assistance and support of Sun Microsystems Labs, and everyone contributing, testing, and using this code. History: Date Who What 11Jun1998 dl Create public version 25may2000 dl Change class access to public 26nov2001 dl Added no-arg constructor, all public access. */ package org.dbunit.util.concurrent; /** A standard linked list node used in various queue classes **/ public class LinkedNode { public Object value; public LinkedNode next; public LinkedNode() {} public LinkedNode(Object x) { value = x; } public LinkedNode(Object x, LinkedNode n) { value = x; next = n; } } --- NEW FILE: LinkedQueue.java --- /* File: LinkedQueue.java Originally written by Doug Lea and released into the public domain. This may be used for any purposes whatsoever without acknowledgment. Thanks for the assistance and support of Sun Microsystems Labs, and everyone contributing, testing, and using this code. History: Date Who What 11Jun1998 dl Create public version 25aug1998 dl added peek 10dec1998 dl added isEmpty 10oct1999 dl lock on node object to ensure visibility */ package org.dbunit.util.concurrent; /** * A linked list based channel implementation. * The algorithm avoids contention between puts * and takes when the queue is not empty. * Normally a put and a take can proceed simultaneously. * (Although it does not allow multiple concurrent puts or takes.) * This class tends to perform more efficently than * other Channel implementations in producer/consumer * applications. * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] **/ public class LinkedQueue implements Channel { /** * Dummy header node of list. The first actual node, if it exists, is always * at head_.next. After each take, the old first node becomes the head. **/ protected LinkedNode head_; /** * Helper monitor for managing access to last node. **/ protected final Object putLock_ = new Object(); /** * The last node of list. Put() appends to list, so modifies last_ **/ protected LinkedNode last_; /** * The number of threads waiting for a take. * Notifications are provided in put only if greater than zero. * The bookkeeping is worth it here since in reasonably balanced * usages, the notifications will hardly ever be necessary, so * the call overhead to notify can be eliminated. **/ protected int waitingForTake_ = 0; public LinkedQueue() { head_ = new LinkedNode(null); last_ = head_; } /** Main mechanics for put/offer **/ protected void insert(Object x) { synchronized(putLock_) { LinkedNode p = new LinkedNode(x); synchronized(last_) { last_.next = p; last_ = p; } if (waitingForTake_ > 0) putLock_.notify(); } } /** Main mechanics for take/poll **/ protected synchronized Object extract() { synchronized(head_) { Object x = null; LinkedNode first = head_.next; if (first != null) { x = first.value; first.value = null; head_ = first; } return x; } } public void put(Object x) throws InterruptedException { if (x == null) throw new IllegalArgumentException(); if (Thread.interrupted()) throw new InterruptedException(); insert(x); } public boolean offer(Object x, long msecs) throws InterruptedException { if (x == null) throw new IllegalArgumentException(); if (Thread.interrupted()) throw new InterruptedException(); insert(x); return true; } public Object take() throws InterruptedException { if (Thread.interrupted()) throw new InterruptedException(); // try to extract. If fail, then enter wait-based retry loop Object x = extract(); if (x != null) return x; else { synchronized(putLock_) { try { ++waitingForTake_; for (;;) { x = extract(); if (x != null) { --waitingForTake_; return x; } else { putLock_.wait(); } } } catch(InterruptedException ex) { --waitingForTake_; putLock_.notify(); throw ex; } } } } public Object peek() { synchronized(head_) { LinkedNode first = head_.next; if (first != null) return first.value; else return null; } } public boolean isEmpty() { synchronized(head_) { return head_.next == null; } } public Object poll(long msecs) throws InterruptedException { if (Thread.interrupted()) throw new InterruptedException(); Object x = extract(); if (x != null) return x; else { synchronized(putLock_) { try { long waitTime = msecs; long start = (msecs <= 0)? 0 : System.currentTimeMillis(); ++waitingForTake_; for (;;) { x = extract(); if (x != null || waitTime <= 0) { --waitingForTake_; return x; } else { putLock_.wait(waitTime); waitTime = msecs - (System.currentTimeMillis() - start); } } } catch(InterruptedException ex) { --waitingForTake_; putLock_.notify(); throw ex; } } } } } --- NEW FILE: PropertyChangeMulticaster.java --- /* File: PropertyChangeMulticaster.java Originally written by Doug Lea and released into the public domain. This may be used for any purposes whatsoever without acknowledgment. Thanks for the assistance and support of Sun Microsystems Labs, and everyone contributing, testing, and using this code. This class is based on Sun JDK java.beans.VetoableChangeSupport, which is copyrighted by Sun. (It shares practically no code, but for consistency, the documentation was lifted and adapted here.) History: Date Who What 14Mar1999 dl first release */ package org.dbunit.util.concurrent; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import java.util.HashMap; import java.io.Serializable; import java.io.ObjectOutputStream; import java.io.ObjectInputStream; import java.io.IOException; /** * This class is interoperable with java.beans.PropertyChangeSupport, * but relies on a streamlined copy-on-write scheme similar to * that used in CopyOnWriteArrayList. This leads to much better * performance in most event-intensive programs. It also adheres to clarified * semantics of add and remove operations. * <p> * <b>Sample usage.</b> * * <pre> * class Thing { * protected Color myColor = Color.red; // an example property * * protected PropertyChangeMulticaster listeners = * new PropertyChangeMulticaster(this); * * // registration methods, including: * void addListener(PropertyChangeListener l) { * // Use the `ifAbsent' version to avoid duplicate notifications * listeners.addPropertyChangeListenerIfAbsent(l); * } * * public synchronized Color getColor() { // accessor * return myColor; * } * * // internal synchronized state change method; returns old value * protected synchronized Color assignColor(Color newColor) { * Color oldColor = myColor; * myColor = newColor; * return oldColor; * } * * public void setColor(Color newColor) { * // atomically change state * Color oldColor = assignColor(newColor); * // broadcast change notification without holding synch lock * listeners.firePropertyChange("color", oldColor, newColor); * } * } * </pre> * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] **/ public class PropertyChangeMulticaster implements Serializable { // In order to allow this class to be lifted out without using // the whole package, the basic mechanics of CopyOnWriteArrayList // are used here, but not the class itself. // This also makes it barely faster. /** * The array of listeners. Copied on each update **/ protected transient PropertyChangeListener[] listeners = new PropertyChangeListener[0]; /** * The object to be provided as the "source" for any generated events. * @serial */ protected final Object source; /** * HashMap for managing listeners for specific properties. * Maps property names to PropertyChangeMulticaster objects. * @serial */ protected HashMap children; /** * Return the child associated with property, or null if no such **/ protected synchronized PropertyChangeMulticaster getChild(String propertyName) { return (children == null)? null : ((PropertyChangeMulticaster)children.get(propertyName)); } /** * Constructs a <code>PropertyChangeMulticaster</code> object. * * @param sourceBean The bean to be given as the source for any events. * @exception NullPointerException if sourceBean is null */ public PropertyChangeMulticaster(Object sourceBean) { if (sourceBean == null) { throw new NullPointerException(); } source = sourceBean; } /** * Add a VetoableChangeListener to the listener list. * The listener is registered for all properties. * If the listener is added multiple times, it will * receive multiple change notifications upon any firePropertyChange * * @param listener The PropertyChangeListener to be added * @exception NullPointerException If listener is null */ public synchronized void addPropertyChangeListener(PropertyChangeListener listener) { if (listener == null) throw new NullPointerException(); int len = listeners.length; PropertyChangeListener[] newArray = new PropertyChangeListener[len + 1]; if (len > 0) System.arraycopy(listeners, 0, newArray, 0, len); newArray[len] = listener; listeners = newArray; } /** * Add a PropertyChangeListener to the listener list if it is * not already present. * The listener is registered for all properties. * The operation maintains Set semantics: If the listener is already * registered, the operation has no effect. * * @param listener The PropertyChangeListener to be added * @exception NullPointerException If listener is null */ public synchronized void addPropertyChangeListenerIfAbsent(PropertyChangeListener listener) { if (listener == null) throw new NullPointerException(); // Copy while checking if already present. int len = listeners.length; PropertyChangeListener[] newArray = new PropertyChangeListener[len + 1]; for (int i = 0; i < len; ++i) { newArray[i] = listeners[i]; if (listener.equals(listeners[i])) return; // already present -- throw away copy } newArray[len] = listener; listeners = newArray; } /** * Remove a PropertyChangeListener from the listener list. * It removes at most one occurrence of the given listener. * If the listener was added multiple times it must be removed * mulitple times. * This removes a PropertyChangeListener that was registered * for all properties, and has no effect if registered for only * one or more specified properties. * * @param listener The PropertyChangeListener to be removed */ public synchronized void removePropertyChangeListener(PropertyChangeListener listener) { int newlen = listeners.length-1; if (newlen < 0 || listener == null) return; // Copy while searching for element to remove PropertyChangeListener[] newArray = new PropertyChangeListener[newlen]; for (int i = 0; i < newlen; ++i) { if (listener.equals(listeners[i])) { // copy remaining and exit for (int k = i + 1; k <= newlen; ++k) newArray[k-1] = listeners[k]; listeners = newArray; return; } else newArray[i] = listeners[i]; } // special-case last cell if (listener.equals(listeners[newlen])) listeners = newArray; } /** * Add a PropertyChangeListener for a specific property. The listener * will be invoked only when a call on firePropertyChange names that * specific property. However, if a listener is registered both for all * properties and a specific property, it will receive multiple * notifications upon changes to that property. * * @param propertyName The name of the property to listen on. * @param listener The PropertyChangeListener to be added * @exception NullPointerException If listener is null */ public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { if (listener == null) throw new NullPointerException(); PropertyChangeMulticaster child = null; synchronized(this) { if (children == null) children = new HashMap(); else child = (PropertyChangeMulticaster)children.get(propertyName); if (child == null) { child = new PropertyChangeMulticaster(source); children.put(propertyName, child); } } child.addPropertyChangeListener(listener); } /** * Add a PropertyChangeListener for a specific property, if it is not * already registered. The listener * will be invoked only when a call on firePropertyChange names that * specific property. * * @param propertyName The name of the property to listen on. * @param listener The PropertyChangeListener to be added * @exception NullPointerException If listener is null */ public void addPropertyChangeListenerIfAbsent(String propertyName, PropertyChangeListener listener) { if (listener == null) throw new NullPointerException(); PropertyChangeMulticaster child = null; synchronized(this) { if (children == null) children = new HashMap(); else child = (PropertyChangeMulticaster)children.get(propertyName); if (child == null) { child = new PropertyChangeMulticaster(source); children.put(propertyName, child); } } child.addPropertyChangeListenerIfAbsent(listener); } /** * Remove a PropertyChangeListener for a specific property. * Affects only the given property. * If the listener is also registered for all properties, * then it will continue to be registered for them. * * @param propertyName The name of the property that was listened on. * @param listener The PropertyChangeListener to be removed */ public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { PropertyChangeMulticaster child = getChild(propertyName); if (child != null) child.removePropertyChangeListener(listener); } /** * Helper method to relay evt to all listeners. * Called by all public firePropertyChange methods. **/ protected void multicast(PropertyChangeEvent evt) { PropertyChangeListener[] array; // bind in synch block below PropertyChangeMulticaster child = null; synchronized (this) { array = listeners; if (children != null && evt.getPropertyName() != null) child = (PropertyChangeMulticaster)children.get(evt.getPropertyName()); } for (int i = 0; i < array.length; ++i) array[i].propertyChange(evt); if (child != null) child.multicast(evt); } /** * Report a bound property update to any registered listeners. * No event is fired if old and new are equal and non-null. * * @param propertyName The programmatic name of the property * that was changed. * @param oldValue The old value of the property. * @param newValue The new value of the property. */ public void firePropertyChange(String propertyName, Object oldValue, Object newValue) { if (oldValue == null || newValue == null || !oldValue.equals(newValue)) { multicast(new PropertyChangeEvent(source, propertyName, oldValue, newValue)); } } /** * Report an int bound property update to any registered listeners. * No event is fired if old and new are equal and non-null. * <p> * This is merely a convenience wrapper around the more general * firePropertyChange method that takes Object values. * * @param propertyName The programmatic name of the property * that was changed. * @param oldValue The old value of the property. * @param newValue The new value of the property. */ public void firePropertyChange(String propertyName, int oldValue, int newValue) { if (oldValue != newValue) { multicast(new PropertyChangeEvent(source, propertyName, new Integer(oldValue), new Integer(newValue))); } } /** * Report a boolean bound property update to any registered listeners. * No event is fired if old and new are equal and non-null. * <p> * This is merely a convenience wrapper around the more general * firePropertyChange method that takes Object values. * * @param propertyName The programmatic name of the property * that was changed. * @param oldValue The old value of the property. * @param newValue The new value of the property. */ public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) { if (oldValue != newValue) { multicast(new PropertyChangeEvent(source, propertyName, new Boolean(oldValue), new Boolean(newValue))); } } /** * Fire an existing PropertyChangeEvent to any registered listeners. * No event is fired if the given event's old and new values are * equal and non-null. * @param evt The PropertyChangeEvent object. */ public void firePropertyChange(PropertyChangeEvent evt) { Object oldValue = evt.getOldValue(); Object newValue = evt.getNewValue(); if (oldValue == null || newValue == null || !oldValue.equals(newValue)) multicast(evt); } /** * Check if there are any listeners for a specific property. * If propertyName is null, return whether there are any listeners at all. * * @param propertyName the property name. * @return true if there are one or more listeners for the given property * */ public boolean hasListeners(String propertyName) { PropertyChangeMulticaster child; synchronized (this) { if (listeners.length > 0) return true; else if (propertyName == null || children == null) return false; else { child = (PropertyChangeMulticaster)children.get(propertyName); if (child == null) return false; } } return child.hasListeners(null); } /** * @serialData Null terminated list of <code>PropertyChangeListeners</code>. * <p> * At serialization time we skip non-serializable listeners and * only serialize the serializable listeners. * */ private synchronized void writeObject(ObjectOutputStream s) throws IOException { s.defaultWriteObject(); for (int i = 0; i < listeners.length; i++) { PropertyChangeListener l = listeners[i]; if (listeners[i] instanceof Serializable) { s.writeObject(listeners[i]); } } s.writeObject(null); } private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException { listeners = new PropertyChangeListener[0]; // paranoically reset s.defaultReadObject(); Object listenerOrNull; while (null != (listenerOrNull = s.readObject())) { addPropertyChangeListener((PropertyChangeListener)listenerOrNull); } } } --- NEW FILE: Puttable.java --- /* File: Puttable.java Originally written by Doug Lea and released into the public domain. This may be used for any purposes whatsoever without acknowledgment. Thanks for the assistance and support of Sun Microsystems Labs, and everyone contributing, testing, and using this code. History: Date Who What 11Jun1998 dl Create public version */ package org.dbunit.util.concurrent; /** * This interface exists to enable stricter type checking * for channels. A method argument or instance variable * in a producer object can be declared as only a Puttable * rather than a Channel, in which case a Java compiler * will disallow take operations. * <p> * Full method descriptions appear in the Channel interface. * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] * @see Channel * @see Takable **/ public interface Puttable { /** * Place item in the channel, possibly waiting indefinitely until * it can be accepted. Channels implementing the BoundedChannel * subinterface are generally guaranteed to block on puts upon * reaching capacity, but other implementations may or may not block. * @param item the element to be inserted. Should be non-null. * @exception InterruptedException if the current thread has * been interrupted at a point at which interruption * is detected, in which case the element is guaranteed not * to be inserted. Otherwise, on normal return, the element is guaranteed * to have been inserted. **/ public void put(Object item) throws InterruptedException; /** * Place item in channel only if it can be accepted within * msecs milliseconds. The time bound is interpreted in * a coarse-grained, best-effort fashion. * @param item the element to be inserted. Should be non-null. * @param msecs the number of milliseconds to wait. If less than * or equal to zero, the method does not perform any timed waits, * but might still require * access to a synchronization lock, which can impose unbounded * delay if there is a lot of contention for the channel. * @return true if accepted, else false * @exception InterruptedException if the current thread has * been interrupted at a point at which interruption * is detected, in which case the element is guaranteed not * to be inserted (i.e., is equivalent to a false return). **/ public boolean offer(Object item, long msecs) throws InterruptedException; } --- NEW FILE: Semaphore.java --- /* File: Semaphore.java Originally written by Doug Lea and released into the public domain. This may be used for any purposes whatsoever without acknowledgment. Thanks for the assistance and support of Sun Microsystems Labs, and everyone contributing, testing, and using this code. History: Date Who What 11Jun1998 dl Create public version 5Aug1998 dl replaced int counters with longs 24Aug1999 dl release(n): screen arguments */ package org.dbunit.util.concurrent; /** * Base class for counting semaphores. * Conceptually, a semaphore maintains a set of permits. * Each acquire() blocks if necessary * until a permit is available, and then takes it. * Each release adds a permit. However, no actual permit objects * are used; the Semaphore just keeps a count of the number * available and acts accordingly. * <p> * A semaphore initialized to 1 can serve as a mutual exclusion * lock. * <p> * Different implementation subclasses may provide different * ordering guarantees (or lack thereof) surrounding which * threads will be resumed upon a signal. * <p> * The default implementation makes NO * guarantees about the order in which threads will * acquire permits. It is often faster than other implementations. * <p> * <b>Sample usage.</b> Here is a class that uses a semaphore to * help manage access to a pool of items. * <pre> * class Pool { * static final MAX_AVAILABLE = 100; * private final Semaphore available = new Semaphore(MAX_AVAILABLE); * * public Object getItem() throws InterruptedException { // no synch * available.acquire(); * return getNextAvailableItem(); * } * * public void putItem(Object x) { // no synch * if (markAsUnused(x)) * available.release(); * } * * // Not a particularly efficient data structure; just for demo * * protected Object[] items = ... whatever kinds of items being managed * protected boolean[] used = new boolean[MAX_AVAILABLE]; * * protected synchronized Object getNextAvailableItem() { * for (int i = 0; i < MAX_AVAILABLE; ++i) { * if (!used[i]) { * used[i] = true; * return items[i]; * } * } * return null; // not reached * } * * protected synchronized boolean markAsUnused(Object item) { * for (int i = 0; i < MAX_AVAILABLE; ++i) { * if (item == items[i]) { * if (used[i]) { * used[i] = false; * return true; * } * else * return false; * } * } * return false; * } * * } *</pre> * <p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>] **/ public class Semaphore implements Sync { /** current number of available permits **/ protected long permits_; /** * Create a Semaphore with the given initial number of permits. * Using a seed of one makes the semaphore act as a mutual exclusion lock. * Negative seeds are also allowed, in which case no acquires will proceed * until the number of releases has pushed the number of permits past 0. **/ public Semaphore(long initialPermits) { permits_ = initialPermits; } /** Wait until a permit is available, and take one **/ public void acquire() throws InterruptedException { if (Thread.interrupted()) throw new InterruptedException(); synchronized(this) { try { while (permits_ <= 0) wait(); --permits_; } catch (InterruptedException ex) { notify(); throw ex; } } } /** Wait at most msecs millisconds for a permit. **/ public boolean attempt(long msecs) throws InterruptedException { if (Thread.interrupted()) throw new InterruptedException(); synchronized(this) { if (permits_ > 0) { --permits_; return true; } else if (msecs <= 0) return false; else { try { long startTime = System.currentTimeMillis(); long waitTime = msecs; for (;;) { wait(waitTime); if (permits_ > 0) { --permits_; return true; } else { waitTime = msecs - (System.currentTimeMillis() - startTime); if (waitTime <= 0) return false; } } } catch(InterruptedException ex) { notify(); throw ex; } } } } /** Release a permit **/ public synchronized void release() { ++permits_; notify(); } /** * Release N permits. <code>release(n)</code> is * ... [truncated message content] |
From: <mla...@us...> - 2003-04-23 02:03:42
|
Update of /cvsroot/dbunit/dbunit/src/java/org/dbunit/util/concurrent In directory sc8-pr-cvs1:/tmp/cvs-serv29468a/concurrent Log Message: Directory /cvsroot/dbunit/dbunit/src/java/org/dbunit/util/concurrent added to the repository --> Using per-directory sticky tag `branch-exml2sax' |
From: <mla...@us...> - 2003-04-23 02:02:54
|
Update of /cvsroot/dbunit/dbunit/lib In directory sc8-pr-cvs1:/tmp/cvs-serv29086/lib Removed Files: Tag: branch-exml2sax crimson.jar jaxp.jar Log Message: Updated the crimson XML parser to version 1.1.3. JAXP is included in this version. --- crimson.jar DELETED --- --- jaxp.jar DELETED --- |
From: <mla...@us...> - 2003-04-13 17:46:14
|
Update of /cvsroot/dbunit/dbunit/src/test/org/dbunit/operation In directory sc8-pr-cvs1:/tmp/cvs-serv27639/src/test/org/dbunit/operation Modified Files: AllTests.java DeleteAllOperationTest.java Added Files: TruncateTableOperationTest.java Log Message: New TRUNCATE_TABLE operation.. --- NEW FILE: TruncateTableOperationTest.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.operation; /** * @author Manuel Laflamme * @since Apr 13, 2003 * @version $Revision: 1.1 $ */ public class TruncateTableOperationTest extends DeleteAllOperationTest { public TruncateTableOperationTest(String s) { super(s); } protected DatabaseOperation getDeleteAllOperation() { return new TruncateTableOperation(); } protected String getExpectedStament(String tableName) { return "truncate table " + tableName; } } Index: AllTests.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/operation/AllTests.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** AllTests.java 13 Apr 2003 02:40:12 -0000 1.8 --- AllTests.java 13 Apr 2003 17:46:11 -0000 1.9 *************** *** 51,55 **** if (environment.support(TestFeature.TRANSACTION)) { ! suite.addTest(new TestSuite(TransactionOperationTest.class)); } --- 51,60 ---- if (environment.support(TestFeature.TRANSACTION)) { ! suite.addTest(new TestSuite(TransactionOperationTest.class)); ! } ! ! if (environment.support(TestFeature.TRUNCATE_TABLE)) ! { ! suite.addTest(new TestSuite(TruncateTableOperationTest.class)); } Index: DeleteAllOperationTest.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/operation/DeleteAllOperationTest.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** DeleteAllOperationTest.java 18 Feb 2003 21:51:20 -0000 1.12 --- DeleteAllOperationTest.java 13 Apr 2003 17:46:11 -0000 1.13 *************** *** 24,39 **** import org.dbunit.AbstractDatabaseTest; - import org.dbunit.DatabaseUnitException; import org.dbunit.database.MockDatabaseConnection; import org.dbunit.database.statement.MockBatchStatement; import org.dbunit.database.statement.MockStatementFactory; ! import org.dbunit.dataset.*; ! ! import java.sql.SQLException; /** * @author Manuel Laflamme * @author Eric Pugh ! * @todo Refactor all the references to AbstractDataSetTest.removeExtraTestTables() to something better. * @version $Revision$ */ --- 24,42 ---- import org.dbunit.AbstractDatabaseTest; import org.dbunit.database.MockDatabaseConnection; import org.dbunit.database.statement.MockBatchStatement; import org.dbunit.database.statement.MockStatementFactory; ! import org.dbunit.dataset.AbstractDataSetTest; ! import org.dbunit.dataset.DataSetUtils; ! import org.dbunit.dataset.DefaultDataSet; ! import org.dbunit.dataset.DefaultTable; ! import org.dbunit.dataset.IDataSet; ! import org.dbunit.dataset.ITable; ! import org.dbunit.dataset.LowerCaseDataSet; /** * @author Manuel Laflamme * @author Eric Pugh ! * TODO Refactor all the references to AbstractDataSetTest.removeExtraTestTables() to something better. * @version $Revision$ */ *************** *** 45,53 **** } public void testMockExecute() throws Exception { String schemaName = "schema"; String tableName = "table"; ! String expected = "delete from schema.table"; IDataSet dataSet = new DefaultDataSet(new DefaultTable(tableName)); --- 48,66 ---- } + protected DatabaseOperation getDeleteAllOperation() + { + return new DeleteAllOperation(); + } + + protected String getExpectedStament(String tableName) + { + return "delete from " + tableName; + } + public void testMockExecute() throws Exception { String schemaName = "schema"; String tableName = "table"; ! String expected = getExpectedStament(schemaName + "." + tableName); IDataSet dataSet = new DefaultDataSet(new DefaultTable(tableName)); *************** *** 71,75 **** // execute operation ! new DeleteAllOperation().execute(connection, dataSet); statement.verify(); --- 84,88 ---- // execute operation ! getDeleteAllOperation().execute(connection, dataSet); statement.verify(); *************** *** 82,86 **** String schemaName = "schema"; String tableName = "table"; ! String expected = "delete from 'schema'.'table'"; IDataSet dataSet = new DefaultDataSet(new DefaultTable(tableName)); --- 95,99 ---- String schemaName = "schema"; String tableName = "table"; ! String expected = getExpectedStament("'" + schemaName + "'.'" + tableName +"'"); IDataSet dataSet = new DefaultDataSet(new DefaultTable(tableName)); *************** *** 107,111 **** try { ! new DeleteAllOperation().execute(connection, dataSet); } finally --- 120,124 ---- try { ! getDeleteAllOperation().execute(connection, dataSet); } finally *************** *** 123,127 **** String schemaName = "schema"; String tableName = "table"; ! String expected = "delete from schema.table"; ITable table = new DefaultTable(tableName); --- 136,140 ---- String schemaName = "schema"; String tableName = "table"; ! String expected = getExpectedStament(schemaName + "." + tableName); ITable table = new DefaultTable(tableName); *************** *** 147,151 **** // execute operation ! new DeleteAllOperation().execute(connection, dataSet); statement.verify(); --- 160,164 ---- // execute operation ! getDeleteAllOperation().execute(connection, dataSet); statement.verify(); *************** *** 180,184 **** //dataSet = dataSet); ITable[] tablesBefore = DataSetUtils.getTables(AbstractDataSetTest.removeExtraTestTables(_connection.createDataSet())); ! DatabaseOperation.DELETE_ALL.execute(_connection, dataSet); ITable[] tablesAfter = DataSetUtils.getTables(AbstractDataSetTest.removeExtraTestTables(_connection.createDataSet())); --- 193,197 ---- //dataSet = dataSet); ITable[] tablesBefore = DataSetUtils.getTables(AbstractDataSetTest.removeExtraTestTables(_connection.createDataSet())); ! getDeleteAllOperation().execute(_connection, dataSet); ITable[] tablesAfter = DataSetUtils.getTables(AbstractDataSetTest.removeExtraTestTables(_connection.createDataSet())); *************** *** 206,212 **** public void testExecuteWithEmptyDataset() throws Exception { ! DatabaseOperation.DELETE_ALL.execute(_connection, new DefaultDataSet(new ITable[0])); } - } --- 219,225 ---- public void testExecuteWithEmptyDataset() throws Exception { ! getDeleteAllOperation().execute( ! _connection, new DefaultDataSet(new ITable[0])); } } |