Source Code Cross Referenced for MockResultSet.java in  » Testing » mockrunner-0.4 » com » mockrunner » mock » jdbc » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » mockrunner 0.4 » com.mockrunner.mock.jdbc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package com.mockrunner.mock.jdbc;
0002:
0003:        import java.io.ByteArrayInputStream;
0004:        import java.io.InputStream;
0005:        import java.io.Reader;
0006:        import java.io.StringReader;
0007:        import java.io.UnsupportedEncodingException;
0008:        import java.math.BigDecimal;
0009:        import java.net.MalformedURLException;
0010:        import java.net.URL;
0011:        import java.sql.Array;
0012:        import java.sql.Blob;
0013:        import java.sql.Clob;
0014:        import java.sql.Date; //import java.sql.NClob;
0015:        import java.sql.Ref;
0016:        import java.sql.ResultSet;
0017:        import java.sql.ResultSetMetaData; //import java.sql.RowId;
0018:        import java.sql.SQLException;
0019:        import java.sql.SQLWarning; //import java.sql.SQLXML;
0020:        import java.sql.Statement;
0021:        import java.sql.Time;
0022:        import java.sql.Timestamp;
0023:        import java.util.ArrayList;
0024:        import java.util.Arrays;
0025:        import java.util.Calendar;
0026:        import java.util.Collections;
0027:        import java.util.Iterator;
0028:        import java.util.List;
0029:        import java.util.Map;
0030:
0031:        import com.mockrunner.base.NestedApplicationException;
0032:        import com.mockrunner.jdbc.ParameterUtil;
0033:        import com.mockrunner.jdbc.SQLUtil;
0034:        import com.mockrunner.util.common.CaseAwareMap;
0035:        import com.mockrunner.util.common.CollectionUtil;
0036:        import com.mockrunner.util.common.StreamUtil;
0037:        import com.mockrunner.util.common.StringUtil;
0038:
0039:        /**
0040:         * Mock implementation of <code>ResultSet</code>.
0041:         * Can be used to add simulated database entries.
0042:         * You can add Java objects of any type. This
0043:         * mock implementation does not care about SQL
0044:         * data types. It tries to perform the necessary
0045:         * type conversions for the Java objects (e.g. it will convert a 
0046:         * <code>String</code> "1" to <code>int</code> 1). 
0047:         * Please check out the documentation of <code>ResultSet</code> 
0048:         * for the description of the methods in this interface. 
0049:         * The additional methods are described here.
0050:         */
0051:        public class MockResultSet implements  ResultSet, Cloneable {
0052:            private Statement statement;
0053:            private String id;
0054:            private Map columnMap;
0055:            private Map columnMapCopy;
0056:            private Map insertRow;
0057:            private List columnNameList;
0058:            private List updatedRows;
0059:            private List deletedRows;
0060:            private List insertedRows;
0061:            private int cursor;
0062:            private boolean isCursorInInsertRow;
0063:            private boolean wasNull;
0064:            private String cursorName;
0065:            private int fetchSize = 0;
0066:            private int fetchDirection = ResultSet.FETCH_FORWARD;
0067:            private int resultSetType = ResultSet.TYPE_SCROLL_INSENSITIVE;
0068:            private int resultSetConcurrency = ResultSet.CONCUR_READ_ONLY;
0069:            private int resultSetHoldability = ResultSet.HOLD_CURSORS_OVER_COMMIT;
0070:            private boolean isDatabaseView;
0071:            private ResultSetMetaData resultSetMetaData;
0072:            private boolean closed;
0073:            private boolean columnsCaseSensitive;
0074:
0075:            public MockResultSet(String id) {
0076:                this (id, "");
0077:            }
0078:
0079:            public MockResultSet(String id, String cursorName) {
0080:                init();
0081:                this .cursorName = cursorName;
0082:                this .id = id;
0083:                columnsCaseSensitive = false;
0084:            }
0085:
0086:            private void init() {
0087:                columnMap = createCaseAwareMap();
0088:                columnNameList = new ArrayList();
0089:                updatedRows = new ArrayList();
0090:                deletedRows = new ArrayList();
0091:                insertedRows = new ArrayList();
0092:                cursor = -1;
0093:                wasNull = false;
0094:                closed = false;
0095:                isCursorInInsertRow = false;
0096:                isDatabaseView = false;
0097:                resultSetMetaData = null;
0098:                copyColumnMap();
0099:                adjustInsertRow();
0100:            }
0101:
0102:            /**
0103:             * Set if column names are case sensitive. Default is
0104:             * <code>false</code>. Please note, that switching this
0105:             * attribute clears and resets the complete <code>ResultSet</code>.
0106:             * @param columnsCaseSensitive are column names case sensitive
0107:             */
0108:            public void setColumnsCaseSensitive(boolean columnsCaseSensitive) {
0109:                this .columnsCaseSensitive = columnsCaseSensitive;
0110:                init();
0111:            }
0112:
0113:            /**
0114:             * Copies this <code>ResultSet</code>. The data of the
0115:             * <code>ResultSet</code> is copied using the
0116:             * {@link com.mockrunner.jdbc.ParameterUtil#copyParameter}
0117:             * method.
0118:             * @return a copy of this <code>ResultSet</code>
0119:             */
0120:            public Object clone() {
0121:                try {
0122:                    MockResultSet copy = (MockResultSet) super .clone();
0123:                    copy.columnNameList = new ArrayList(columnNameList);
0124:                    copy.updatedRows = new ArrayList(updatedRows);
0125:                    copy.deletedRows = new ArrayList(deletedRows);
0126:                    copy.insertedRows = new ArrayList(insertedRows);
0127:                    copy.insertRow = copyColumnDataMap(insertRow);
0128:                    copy.columnMap = copyColumnDataMap(columnMap);
0129:                    copy.columnMapCopy = copyColumnDataMap(columnMapCopy);
0130:                    if (null != resultSetMetaData
0131:                            && resultSetMetaData instanceof  MockResultSetMetaData) {
0132:                        copy.resultSetMetaData = (ResultSetMetaData) ((MockResultSetMetaData) resultSetMetaData)
0133:                                .clone();
0134:                    }
0135:                    return copy;
0136:                } catch (CloneNotSupportedException exc) {
0137:                    throw new NestedApplicationException(exc);
0138:                }
0139:            }
0140:
0141:            /**
0142:             * Returns the id of this <code>ResultSet</code>. Ids are used
0143:             * to identify <code>ResultSet</code> objects in tests, because
0144:             * they are usually cloned when executing statements, so
0145:             * you cannot rely on the object identity.
0146:             * @return the id of this <code>ResultSet</code>
0147:             */
0148:            public String getId() {
0149:                return id;
0150:            }
0151:
0152:            /**
0153:             * Returns if this <code>ResultSet</code> is closed.
0154:             * @return <code>true</code> if this <code>ResultSet</code> is closed,
0155:             *         <code>false</code> otherwise
0156:             */
0157:            public boolean isClosed() {
0158:                return closed;
0159:            }
0160:
0161:            /**
0162:             * Sets the <code>ResultSetMetaData</code> for this <code>ResultSet</code>.
0163:             * The specified object will be returned when calling {@link #getMetaData}.
0164:             * If no <code>ResultSetMetaData</code> is set, the method {@link #getMetaData}
0165:             * will return an object of {@link MockResultSetMetaData}. The
0166:             * <code>MockResultSetMetaData</code> returns default values for most
0167:             * of its attributes (however the correct number of columns will be
0168:             * returned). Usually you do not have to set the <code>ResultSetMetaData</code>.
0169:             * @param resultSetMetaData the <code>ResultSetMetaData</code>
0170:             */
0171:            public void setResultSetMetaData(ResultSetMetaData resultSetMetaData) {
0172:                this .resultSetMetaData = resultSetMetaData;
0173:            }
0174:
0175:            /**
0176:             * Sets the <code>Statement</code> for this <code>ResultSet</code>.
0177:             * The <code>ResultSet</code> takes the result set type, result
0178:             * set concurrency and the fetch direction from the specified
0179:             * <code>Statement</code>.
0180:             * @param statement the statement
0181:             */
0182:            public void setStatement(Statement statement) {
0183:                this .statement = statement;
0184:                try {
0185:                    fetchDirection = statement.getFetchDirection();
0186:                    resultSetType = statement.getResultSetType();
0187:                    resultSetConcurrency = statement.getResultSetConcurrency();
0188:                    resultSetHoldability = statement.getResultSetHoldability();
0189:                    fetchSize = statement.getFetchSize();
0190:                    cursorName = ((MockStatement) statement).getCursorName();
0191:                } catch (SQLException exc) {
0192:
0193:                }
0194:            }
0195:
0196:            /**
0197:             * Sets the cursor name. It's not possible to set
0198:             * this in a real <code>ResultSet</code>.
0199:             * @param cursorName the cursor name
0200:             */
0201:            public void setCursorName(String cursorName) {
0202:                this .cursorName = cursorName;
0203:            }
0204:
0205:            /**
0206:             * Sets the result set type. It's not possible to set
0207:             * this in a real <code>ResultSet</code>, but in tests
0208:             * it can make sense to change it.
0209:             * @param resultSetType the result set type
0210:             */
0211:            public void setResultSetType(int resultSetType) {
0212:                this .resultSetType = resultSetType;
0213:            }
0214:
0215:            /**
0216:             * Sets the result set concurrency. It's not possible to set
0217:             * this in a real <code>ResultSet</code>, but in tests
0218:             * it can make sense to change it.
0219:             * @param resultSetConcurrency the result set concurrency
0220:             */
0221:            public void setResultSetConcurrency(int resultSetConcurrency) {
0222:                this .resultSetConcurrency = resultSetConcurrency;
0223:            }
0224:
0225:            /**
0226:             * Sets the result set holdability. It's not possible to set
0227:             * this in a real <code>ResultSet</code>, but in tests
0228:             * it can make sense to change it.
0229:             * @param resultSetHoldability the result set holdability
0230:             */
0231:            public void setResultSetHoldability(int resultSetHoldability) {
0232:                this .resultSetHoldability = resultSetHoldability;
0233:            }
0234:
0235:            /**
0236:             * The <code>MockResultSet</code> keeps the data that's
0237:             * stored in the simulated database and a copy of the data
0238:             * that represents the current <code>ResultSet</code> data.
0239:             * The <code>update</code> methods only update the 
0240:             * <code>ResultSet</code> data. This data will be persisted
0241:             * when you call {@link #updateRow}. When you set <i>databaseView</i> 
0242:             * to <code>true</code> the <code>get</code> methods will return the 
0243:             * data in the database, otherwise the current <code>ResultSet</code> 
0244:             * data is returned.
0245:             * @param databaseView <code>false</code> = get the data from the 
0246:             *        <code>ResultSet</code>, <code>true</code> = get the data
0247:             *        from the database, default is <code>false</code>
0248:             *
0249:             */
0250:            public void setDatabaseView(boolean databaseView) {
0251:                this .isDatabaseView = databaseView;
0252:            }
0253:
0254:            /**
0255:             * Adds a row to the simulated database table.
0256:             * If there are not enough columns (initially there
0257:             * are no columns, you have to specify them with the
0258:             * <code>addColumn</code> methods) the missing columns will
0259:             * be added automatically. Automatically created columns
0260:             * will get the name <i>ColumnX</i> where <i>X</i> is
0261:             * the column index.
0262:             * @param values the row data as array, the array index
0263:             *        corresponds to the column index, i.e.
0264:             *        values[0] will be stored in the first column
0265:             *        and so on
0266:             */
0267:            public void addRow(Object[] values) {
0268:                List valueList = Arrays.asList(values);
0269:                addRow(valueList);
0270:            }
0271:
0272:            /**
0273:             * Adds a row to the simulated database table.
0274:             * If there are not enough columns (initially there
0275:             * are no columns, you have to specify them with the
0276:             * <code>addColumn</code> methods) the missing columns will
0277:             * be added automatically. Automatically created columns
0278:             * will get the name <i>ColumnX</i> where <i>X</i> is
0279:             * the column index.
0280:             * @param values the row data as <code>List</code>, the index
0281:             *        in the <code>List</code> corresponds to the column 
0282:             *        index, i.e. values.get(0) will be stored in the first 
0283:             *        column and so on
0284:             */
0285:            public void addRow(List values) {
0286:                int missingColumns = values.size() - columnNameList.size();
0287:                for (int yy = 0; yy < missingColumns; yy++) {
0288:                    addColumn();
0289:                }
0290:                adjustColumns();
0291:                for (int ii = 0; ii < values.size(); ii++) {
0292:                    Object nextValue = values.get(ii);
0293:                    String nextColumnName = (String) columnNameList.get(ii);
0294:                    List nextColumnList = (List) columnMap.get(nextColumnName);
0295:                    nextColumnList.add(nextValue);
0296:                }
0297:                adjustColumns();
0298:                copyColumnMap();
0299:                adjustFlags();
0300:            }
0301:
0302:            /**
0303:             * Adds a column to the simulated database table.
0304:             * The column will get the name <i>ColumnX</i> where 
0305:             * <i>X</i> is the column index. The first added column
0306:             * will have the name <i>Column1</i>. No data will be stored
0307:             * in the column.
0308:             */
0309:            public void addColumn() {
0310:                addColumn(determineValidColumnName());
0311:            }
0312:
0313:            /**
0314:             * Adds a column to the simulated database table.
0315:             * The column will get the specified name.
0316:             * No data will be stored in the column.
0317:             * @param columnName the column name
0318:             */
0319:            public void addColumn(String columnName) {
0320:                addColumn(columnName, new ArrayList());
0321:            }
0322:
0323:            /**
0324:             * Adds a column to the simulated database table.
0325:             * The column will get the name <i>ColumnX</i> where 
0326:             * <i>X</i> is the column index. 
0327:             * The specified data will be stored in the new column. If there
0328:             * are other columns with not enough rows, the other
0329:             * columns will be extended and filled with <code>null</code>
0330:             * values.
0331:             * @param values the column data as array, the array index
0332:             *        corresponds to the row index, i.e.
0333:             *        values[0] will be stored in the first row
0334:             *        and so on
0335:             */
0336:            public void addColumn(Object[] values) {
0337:                addColumn(determineValidColumnName(), values);
0338:            }
0339:
0340:            /**
0341:             * Adds a column to the simulated database table.
0342:             * The column will get the name <i>ColumnX</i> where 
0343:             * <i>X</i> is the column index. 
0344:             * The specified data will be stored in the new column. If there
0345:             * are other columns with not enough rows, the other
0346:             * columns will be extended and filled with <code>null</code>
0347:             * values.
0348:             * @param values the column data as <code>List</code>, the index
0349:             *        in the <code>List</code> corresponds to the row 
0350:             *        index, i.e. values.get(0) will be stored in the first 
0351:             *        row and so on
0352:             */
0353:            public void addColumn(List values) {
0354:                addColumn(determineValidColumnName(), values);
0355:            }
0356:
0357:            /**
0358:             * Adds a column to the simulated database table.
0359:             * The column will get the specified name.
0360:             * The specified data will be stored in the new column. If there
0361:             * are other columns with not enough rows, the other
0362:             * columns will be extended and filled with <code>null</code>
0363:             * values.
0364:             * @param columnName the column name
0365:             * @param values the column data as array, the array index
0366:             *        corresponds to the row index, i.e.
0367:             *        values[0] will be stored in the first row
0368:             *        and so on
0369:             */
0370:            public void addColumn(String columnName, Object[] values) {
0371:                List columnValues = Arrays.asList(values);
0372:                addColumn(columnName, columnValues);
0373:            }
0374:
0375:            /**
0376:             * Adds a column to the simulated database table.
0377:             * The column will get the specified name.
0378:             * The specified data will be stored in the new column. If there
0379:             * are other columns with not enough rows, the other
0380:             * columns will be extended and filled with <code>null</code>
0381:             * values.
0382:             * @param columnName the column name
0383:             * @param values the column data as <code>List</code>, the index
0384:             *        in the <code>List</code> corresponds to the row 
0385:             *        index, i.e. values.get(0) will be stored in the first 
0386:             *        row and so on
0387:             */
0388:            public void addColumn(String columnName, List values) {
0389:                List column = new ArrayList(values);
0390:                columnMap.put(columnName, column);
0391:                columnNameList.add(columnName);
0392:                adjustColumns();
0393:                adjustInsertRow();
0394:                copyColumnMap();
0395:                adjustFlags();
0396:            }
0397:
0398:            /**
0399:             * Returns the current number of rows.
0400:             * @return the number of rows
0401:             */
0402:            public int getRowCount() {
0403:                if (columnMapCopy.size() == 0)
0404:                    return 0;
0405:                List column = (List) columnMapCopy.values().iterator().next();
0406:                return column.size();
0407:            }
0408:
0409:            /**
0410:             * Returns the current number of columns.
0411:             * @return the number of columns
0412:             */
0413:            public int getColumnCount() {
0414:                return columnMapCopy.size();
0415:            }
0416:
0417:            /**
0418:             * Returns if the row with the specified number was inserted
0419:             * The first row has the number 1.
0420:             * @param number the number of the row
0421:             * @return <code>true</code> if the row was inserted,
0422:             *         <code>false</code> otherwise
0423:             */
0424:            public boolean rowInserted(int number) {
0425:                if (number < 1)
0426:                    return false;
0427:                return ((Boolean) insertedRows.get(number - 1)).booleanValue();
0428:            }
0429:
0430:            /**
0431:             * Returns if the row with the specified number was deleted
0432:             * The first row has the number 1.
0433:             * @param number the number of the row
0434:             * @return <code>true</code> if the row was deleted,
0435:             *         <code>false</code> otherwise
0436:             */
0437:            public boolean rowDeleted(int number) {
0438:                if (number < 1)
0439:                    return false;
0440:                return ((Boolean) deletedRows.get(number - 1)).booleanValue();
0441:            }
0442:
0443:            /**
0444:             * Returns if the row with the specified number was updated
0445:             * The first row has the number 1.
0446:             * @param number the number of the row
0447:             * @return <code>true</code> if the row was updated,
0448:             *         <code>false</code> otherwise
0449:             */
0450:            public boolean rowUpdated(int number) {
0451:                if (number < 1)
0452:                    return false;
0453:                return ((Boolean) updatedRows.get(number - 1)).booleanValue();
0454:            }
0455:
0456:            /**
0457:             * Returns if the row with the specified number is
0458:             * equal to the specified data. Uses {@link com.mockrunner.jdbc.ParameterUtil#compareParameter}.
0459:             * The first row has the number 1. If the compared parameters are not of
0460:             * the same type (and cannot be equal according to the 
0461:             * {@link com.mockrunner.jdbc.ParameterUtil#compareParameter} method) they
0462:             * will be converted to a string with the <code>toString()</code> method before
0463:             * comparison.
0464:             * @param number the number of the row
0465:             * @param rowData the row data
0466:             * @return <code>true</code> if the row is equal to the specified data,
0467:             *         <code>false</code> otherwise
0468:             */
0469:            public boolean isRowEqual(int number, List rowData) {
0470:                List currentRow = getRow(number);
0471:                if (null == currentRow)
0472:                    return false;
0473:                if (currentRow.size() != rowData.size())
0474:                    return false;
0475:                for (int ii = 0; ii < currentRow.size(); ii++) {
0476:                    Object source = currentRow.get(ii);
0477:                    Object target = rowData.get(ii);
0478:                    if (null != source && null != target) {
0479:                        if (!source.getClass().isAssignableFrom(
0480:                                target.getClass())
0481:                                && !target.getClass().isAssignableFrom(
0482:                                        source.getClass())) {
0483:                            source = source.toString();
0484:                            target = target.toString();
0485:                        }
0486:                    }
0487:                    if (!ParameterUtil.compareParameter(source, target)) {
0488:                        return false;
0489:                    }
0490:                }
0491:                return true;
0492:            }
0493:
0494:            /**
0495:             * Returns if the column with the specified number is
0496:             * equal to the specified data. Uses {@link com.mockrunner.jdbc.ParameterUtil#compareParameter}.
0497:             * The first column has the number 1. If the compared parameters are not of
0498:             * the same type (and cannot be equal according to the 
0499:             * {@link com.mockrunner.jdbc.ParameterUtil#compareParameter} method) they
0500:             * will be converted to a string with the <code>toString()</code> method before
0501:             * comparison.
0502:             * @param number the number of the column
0503:             * @param columnData the column data
0504:             * @return <code>true</code> if the column is equal to the specified data,
0505:             *         <code>false</code> otherwise
0506:             */
0507:            public boolean isColumnEqual(int number, List columnData) {
0508:                List currentColumn = getColumn(number);
0509:                if (null == currentColumn)
0510:                    return false;
0511:                if (currentColumn.size() != columnData.size())
0512:                    return false;
0513:                for (int ii = 0; ii < currentColumn.size(); ii++) {
0514:                    Object source = currentColumn.get(ii);
0515:                    Object target = columnData.get(ii);
0516:                    if (null != source && null != target) {
0517:                        if (!source.getClass().isAssignableFrom(
0518:                                target.getClass())
0519:                                && !target.getClass().isAssignableFrom(
0520:                                        source.getClass())) {
0521:                            source = source.toString();
0522:                            target = target.toString();
0523:                        }
0524:                    }
0525:                    if (!ParameterUtil.compareParameter(source, target)) {
0526:                        return false;
0527:                    }
0528:                }
0529:                return true;
0530:            }
0531:
0532:            /**
0533:             * Returns if the column with the specified name is
0534:             * equal to the specified data. Uses {@link com.mockrunner.jdbc.ParameterUtil#compareParameter}.
0535:             * The first column has the number 1. If the compared parameters are not of
0536:             * the same type (and cannot be equal according to the 
0537:             * {@link com.mockrunner.jdbc.ParameterUtil#compareParameter} method) they
0538:             * will be converted to a string with the <code>toString()</code> method before
0539:             * comparison.
0540:             * @param name the name of the column
0541:             * @param columnData the column data
0542:             * @return <code>true</code> if the column is equal to the specified data,
0543:             *         <code>false</code> otherwise
0544:             */
0545:            public boolean isColumnEqual(String name, List columnData) {
0546:                List currentColumn = getColumn(name);
0547:                if (null == currentColumn)
0548:                    return false;
0549:                if (currentColumn.size() != columnData.size())
0550:                    return false;
0551:                for (int ii = 0; ii < currentColumn.size(); ii++) {
0552:                    Object source = currentColumn.get(ii);
0553:                    Object target = columnData.get(ii);
0554:                    if (null != source && null != target) {
0555:                        if (!source.getClass().isAssignableFrom(
0556:                                target.getClass())
0557:                                && !target.getClass().isAssignableFrom(
0558:                                        source.getClass())) {
0559:                            source = source.toString();
0560:                            target = target.toString();
0561:                        }
0562:                    }
0563:                    if (!ParameterUtil.compareParameter(source, target)) {
0564:                        return false;
0565:                    }
0566:                }
0567:                return true;
0568:            }
0569:
0570:            /**
0571:             * Returns if the specified <code>ResultSet</code> is equal to
0572:             * this <code>ResultSet</code>. If the compared parameters are not of
0573:             * the same type (and cannot be equal according to the 
0574:             * {@link com.mockrunner.jdbc.ParameterUtil#compareParameter} method) they
0575:             * will be converted to a string with the <code>toString()</code> method before
0576:             * comparison.
0577:             * @return <code>true</code> if the two <code>ResultSet</code> objects are equal,
0578:             *         <code>false</code> otherwise
0579:             */
0580:            public boolean isEqual(MockResultSet resultSet) {
0581:                if (null == resultSet)
0582:                    return false;
0583:                Map this Map;
0584:                Map otherMap;
0585:                if (isDatabaseView) {
0586:                    this Map = columnMap;
0587:                } else {
0588:                    this Map = columnMapCopy;
0589:                }
0590:                if (resultSet.isDatabaseView) {
0591:                    otherMap = resultSet.columnMap;
0592:                } else {
0593:                    otherMap = resultSet.columnMapCopy;
0594:                }
0595:                Iterator keys = this Map.keySet().iterator();
0596:                while (keys.hasNext()) {
0597:                    String currentKey = (String) keys.next();
0598:                    List this List = (List) this Map.get(currentKey);
0599:                    List otherList = (List) otherMap.get(currentKey);
0600:                    if (null == otherList)
0601:                        return false;
0602:                    if (this List.size() != otherList.size())
0603:                        return false;
0604:                    for (int ii = 0; ii < this List.size(); ii++) {
0605:                        Object source = this List.get(ii);
0606:                        Object target = otherList.get(ii);
0607:                        if (null != source && null != target) {
0608:                            if (!source.getClass().isAssignableFrom(
0609:                                    target.getClass())
0610:                                    && !target.getClass().isAssignableFrom(
0611:                                            source.getClass())) {
0612:                                source = source.toString();
0613:                                target = target.toString();
0614:                            }
0615:                        }
0616:                        if (!ParameterUtil.compareParameter(source, target)) {
0617:                            return false;
0618:                        }
0619:                    }
0620:                }
0621:                return true;
0622:            }
0623:
0624:            /**
0625:             * Returns the row with the specified number.
0626:             * The first row has the number 1.
0627:             * If number is less than 1 or higher than the
0628:             * current row count, <code>null</code> will
0629:             * be returned. The result of this method depends
0630:             * on the setting of <i>databaseView</i>. 
0631:             * See {@link #setDatabaseView}.
0632:             * @param number the number of the row
0633:             * @return the row data as <code>List</code>
0634:             */
0635:            public List getRow(int number) {
0636:                if (number > getRowCount())
0637:                    return null;
0638:                if (number < 1)
0639:                    return null;
0640:                int index = number - 1;
0641:                List list = new ArrayList();
0642:                for (int ii = 0; ii < columnNameList.size(); ii++) {
0643:                    String nextColumnName = (String) columnNameList.get(ii);
0644:                    List nextColumnList;
0645:                    if (isDatabaseView) {
0646:                        nextColumnList = (List) columnMap.get(nextColumnName);
0647:                    } else {
0648:                        nextColumnList = (List) columnMapCopy
0649:                                .get(nextColumnName);
0650:                    }
0651:                    list.add(nextColumnList.get(index));
0652:                }
0653:                return list;
0654:            }
0655:
0656:            /**
0657:             * Returns the column with the specified number.
0658:             * The first column has the number 1.
0659:             * If number is less than 1 or higher than the
0660:             * current column count, <code>null</code> will
0661:             * be returned.
0662:             * @param number the number of the column
0663:             * @return the column data as <code>List</code>
0664:             */
0665:            public List getColumn(int number) {
0666:                if (number > getColumnCount())
0667:                    return null;
0668:                if (number < 1)
0669:                    return null;
0670:                int index = number - 1;
0671:                String columnName = (String) columnNameList.get(index);
0672:                return getColumn(columnName);
0673:            }
0674:
0675:            /**
0676:             * Returns the column with the specified name.
0677:             * If a column with that name does not exist, 
0678:             * <code>null</code> will be returned.
0679:             * @param name the name of the column
0680:             * @return the column data as <code>List</code>
0681:             */
0682:            public List getColumn(String name) {
0683:                List list = new ArrayList();
0684:                List columnList;
0685:                if (isDatabaseView) {
0686:                    columnList = (List) columnMap.get(name);
0687:                } else {
0688:                    columnList = (List) columnMapCopy.get(name);
0689:                }
0690:                if (null == columnList)
0691:                    return null;
0692:                list.addAll(columnList);
0693:                return list;
0694:            }
0695:
0696:            public void close() throws SQLException {
0697:                closed = true;
0698:            }
0699:
0700:            public boolean wasNull() throws SQLException {
0701:                return wasNull;
0702:            }
0703:
0704:            public Object getObject(int columnIndex) throws SQLException {
0705:                checkColumnBounds(columnIndex);
0706:                checkRowBounds();
0707:                String columnName = (String) columnNameList
0708:                        .get(columnIndex - 1);
0709:                return getObject(columnName);
0710:            }
0711:
0712:            public Object getObject(String columnName) throws SQLException {
0713:                checkColumnName(columnName);
0714:                checkRowBounds();
0715:                if (rowDeleted())
0716:                    throw new SQLException("row was deleted");
0717:                List column;
0718:                if (isDatabaseView) {
0719:                    column = (List) columnMap.get(columnName);
0720:                } else {
0721:                    column = (List) columnMapCopy.get(columnName);
0722:                }
0723:                Object value = column.get(cursor);
0724:                wasNull = (null == value);
0725:                return value;
0726:            }
0727:
0728:            public Object getObject(int columnIndex, Map map)
0729:                    throws SQLException {
0730:                return getObject(columnIndex);
0731:            }
0732:
0733:            public Object getObject(String colName, Map map)
0734:                    throws SQLException {
0735:                return getObject(colName);
0736:            }
0737:
0738:            public String getString(int columnIndex) throws SQLException {
0739:                Object value = getObject(columnIndex);
0740:                if (null != value)
0741:                    return value.toString();
0742:                return null;
0743:            }
0744:
0745:            public String getString(String columnName) throws SQLException {
0746:                Object value = getObject(columnName);
0747:                if (null != value)
0748:                    return value.toString();
0749:                return null;
0750:            }
0751:
0752:            public String getNString(int columnIndex) throws SQLException {
0753:                return getString(columnIndex);
0754:            }
0755:
0756:            public String getNString(String columnLabel) throws SQLException {
0757:                return getString(columnLabel);
0758:            }
0759:
0760:            public boolean getBoolean(int columnIndex) throws SQLException {
0761:                Object value = getObject(columnIndex);
0762:                if (null != value) {
0763:                    if (value instanceof  Boolean)
0764:                        return ((Boolean) value).booleanValue();
0765:                    return new Boolean(value.toString()).booleanValue();
0766:                }
0767:                return false;
0768:            }
0769:
0770:            public boolean getBoolean(String columnName) throws SQLException {
0771:                Object value = getObject(columnName);
0772:                if (null != value) {
0773:                    if (value instanceof  Boolean)
0774:                        return ((Boolean) value).booleanValue();
0775:                    return new Boolean(value.toString()).booleanValue();
0776:                }
0777:                return false;
0778:            }
0779:
0780:            public byte getByte(int columnIndex) throws SQLException {
0781:                Object value = getObject(columnIndex);
0782:                if (null != value) {
0783:                    if (value instanceof  Number)
0784:                        return ((Number) value).byteValue();
0785:                    return new Byte(value.toString()).byteValue();
0786:                }
0787:                return 0;
0788:            }
0789:
0790:            public byte getByte(String columnName) throws SQLException {
0791:                Object value = getObject(columnName);
0792:                if (null != value) {
0793:                    if (value instanceof  Number)
0794:                        return ((Number) value).byteValue();
0795:                    return new Byte(value.toString()).byteValue();
0796:                }
0797:                return 0;
0798:            }
0799:
0800:            public short getShort(int columnIndex) throws SQLException {
0801:                Object value = getObject(columnIndex);
0802:                if (null != value) {
0803:                    if (value instanceof  Number)
0804:                        return ((Number) value).shortValue();
0805:                    return new Short(value.toString()).shortValue();
0806:                }
0807:                return 0;
0808:            }
0809:
0810:            public short getShort(String columnName) throws SQLException {
0811:                Object value = getObject(columnName);
0812:                if (null != value) {
0813:                    if (value instanceof  Number)
0814:                        return ((Number) value).shortValue();
0815:                    return new Short(value.toString()).shortValue();
0816:                }
0817:                return 0;
0818:            }
0819:
0820:            public int getInt(int columnIndex) throws SQLException {
0821:                Object value = getObject(columnIndex);
0822:                if (null != value) {
0823:                    if (value instanceof  Number)
0824:                        return ((Number) value).intValue();
0825:                    return new Integer(value.toString()).intValue();
0826:                }
0827:                return 0;
0828:            }
0829:
0830:            public int getInt(String columnName) throws SQLException {
0831:                Object value = getObject(columnName);
0832:                if (null != value) {
0833:                    if (value instanceof  Number)
0834:                        return ((Number) value).intValue();
0835:                    return new Integer(value.toString()).intValue();
0836:                }
0837:                return 0;
0838:            }
0839:
0840:            public long getLong(int columnIndex) throws SQLException {
0841:                Object value = getObject(columnIndex);
0842:                if (null != value) {
0843:                    if (value instanceof  Number)
0844:                        return ((Number) value).longValue();
0845:                    return new Long(value.toString()).longValue();
0846:                }
0847:                return 0;
0848:            }
0849:
0850:            public long getLong(String columnName) throws SQLException {
0851:                Object value = getObject(columnName);
0852:                if (null != value) {
0853:                    if (value instanceof  Number)
0854:                        return ((Number) value).longValue();
0855:                    return new Long(value.toString()).longValue();
0856:                }
0857:                return 0;
0858:            }
0859:
0860:            public float getFloat(int columnIndex) throws SQLException {
0861:                Object value = getObject(columnIndex);
0862:                if (null != value) {
0863:                    if (value instanceof  Number)
0864:                        return ((Number) value).floatValue();
0865:                    return new Float(value.toString()).floatValue();
0866:                }
0867:                return 0;
0868:            }
0869:
0870:            public float getFloat(String columnName) throws SQLException {
0871:                Object value = getObject(columnName);
0872:                if (null != value) {
0873:                    if (value instanceof  Number)
0874:                        return ((Number) value).floatValue();
0875:                    return new Float(value.toString()).floatValue();
0876:                }
0877:                return 0;
0878:            }
0879:
0880:            public double getDouble(int columnIndex) throws SQLException {
0881:                Object value = getObject(columnIndex);
0882:                if (null != value) {
0883:                    if (value instanceof  Number)
0884:                        return ((Number) value).doubleValue();
0885:                    return new Double(value.toString()).doubleValue();
0886:                }
0887:                return 0;
0888:            }
0889:
0890:            public double getDouble(String columnName) throws SQLException {
0891:                Object value = getObject(columnName);
0892:                if (null != value) {
0893:                    if (value instanceof  Number)
0894:                        return ((Number) value).doubleValue();
0895:                    return new Double(value.toString()).doubleValue();
0896:                }
0897:                return 0;
0898:            }
0899:
0900:            public BigDecimal getBigDecimal(int columnIndex, int scale)
0901:                    throws SQLException {
0902:                BigDecimal value = getBigDecimal(columnIndex);
0903:                if (null != value) {
0904:                    return value.setScale(scale);
0905:                }
0906:                return null;
0907:            }
0908:
0909:            public BigDecimal getBigDecimal(String columnName, int scale)
0910:                    throws SQLException {
0911:                BigDecimal value = getBigDecimal(columnName);
0912:                if (null != value) {
0913:                    return value.setScale(scale);
0914:                }
0915:                return null;
0916:            }
0917:
0918:            public BigDecimal getBigDecimal(int columnIndex)
0919:                    throws SQLException {
0920:                Object value = getObject(columnIndex);
0921:                if (null != value) {
0922:                    if (value instanceof  Number)
0923:                        return new BigDecimal(((Number) value).doubleValue());
0924:                    return new BigDecimal(value.toString());
0925:                }
0926:                return null;
0927:            }
0928:
0929:            public BigDecimal getBigDecimal(String columnName)
0930:                    throws SQLException {
0931:                Object value = getObject(columnName);
0932:                if (null != value) {
0933:                    if (value instanceof  Number)
0934:                        return new BigDecimal(((Number) value).doubleValue());
0935:                    return new BigDecimal(value.toString());
0936:                }
0937:                return null;
0938:            }
0939:
0940:            public byte[] getBytes(int columnIndex) throws SQLException {
0941:                Object value = getObject(columnIndex);
0942:                if (null != value) {
0943:                    if (value instanceof  byte[])
0944:                        return (byte[]) value;
0945:                    try {
0946:                        return value.toString().getBytes("ISO-8859-1");
0947:                    } catch (UnsupportedEncodingException exc) {
0948:                        throw new NestedApplicationException(exc);
0949:                    }
0950:                }
0951:                return null;
0952:            }
0953:
0954:            public byte[] getBytes(String columnName) throws SQLException {
0955:                Object value = getObject(columnName);
0956:                if (null != value) {
0957:                    if (value instanceof  byte[])
0958:                        return (byte[]) value;
0959:                    try {
0960:                        return value.toString().getBytes("ISO-8859-1");
0961:                    } catch (UnsupportedEncodingException exc) {
0962:                        throw new NestedApplicationException(exc);
0963:                    }
0964:                }
0965:                return null;
0966:            }
0967:
0968:            public Date getDate(int columnIndex) throws SQLException {
0969:                Object value = getObject(columnIndex);
0970:                if (null != value) {
0971:                    if (value instanceof  Date)
0972:                        return (Date) value;
0973:                    return Date.valueOf(value.toString());
0974:                }
0975:                return null;
0976:            }
0977:
0978:            public Date getDate(String columnName) throws SQLException {
0979:                Object value = getObject(columnName);
0980:                if (null != value) {
0981:                    if (value instanceof  Date)
0982:                        return (Date) value;
0983:                    return Date.valueOf(value.toString());
0984:                }
0985:                return null;
0986:            }
0987:
0988:            public Date getDate(int columnIndex, Calendar calendar)
0989:                    throws SQLException {
0990:                return getDate(columnIndex);
0991:            }
0992:
0993:            public Date getDate(String columnName, Calendar calendar)
0994:                    throws SQLException {
0995:                return getDate(columnName);
0996:            }
0997:
0998:            public Time getTime(int columnIndex) throws SQLException {
0999:                Object value = getObject(columnIndex);
1000:                if (null != value) {
1001:                    if (value instanceof  Time)
1002:                        return (Time) value;
1003:                    return Time.valueOf(value.toString());
1004:                }
1005:                return null;
1006:            }
1007:
1008:            public Time getTime(String columnName) throws SQLException {
1009:                Object value = getObject(columnName);
1010:                if (null != value) {
1011:                    if (value instanceof  Time)
1012:                        return (Time) value;
1013:                    return Time.valueOf(value.toString());
1014:                }
1015:                return null;
1016:            }
1017:
1018:            public Time getTime(int columnIndex, Calendar calendar)
1019:                    throws SQLException {
1020:                return getTime(columnIndex);
1021:            }
1022:
1023:            public Time getTime(String columnName, Calendar calendar)
1024:                    throws SQLException {
1025:                return getTime(columnName);
1026:            }
1027:
1028:            public Timestamp getTimestamp(int columnIndex) throws SQLException {
1029:                Object value = getObject(columnIndex);
1030:                if (null != value) {
1031:                    if (value instanceof  Timestamp)
1032:                        return (Timestamp) value;
1033:                    return Timestamp.valueOf(value.toString());
1034:                }
1035:                return null;
1036:            }
1037:
1038:            public Timestamp getTimestamp(String columnName)
1039:                    throws SQLException {
1040:                Object value = getObject(columnName);
1041:                if (null != value) {
1042:                    if (value instanceof  Timestamp)
1043:                        return (Timestamp) value;
1044:                    return Timestamp.valueOf(value.toString());
1045:                }
1046:                return null;
1047:            }
1048:
1049:            public Timestamp getTimestamp(int columnIndex, Calendar calendar)
1050:                    throws SQLException {
1051:                return getTimestamp(columnIndex);
1052:            }
1053:
1054:            public Timestamp getTimestamp(String columnName, Calendar calendar)
1055:                    throws SQLException {
1056:                return getTimestamp(columnName);
1057:            }
1058:
1059:            public URL getURL(int columnIndex) throws SQLException {
1060:                Object value = getObject(columnIndex);
1061:                if (null != value) {
1062:                    if (value instanceof  URL)
1063:                        return (URL) value;
1064:                    try {
1065:                        return new URL(value.toString());
1066:                    } catch (MalformedURLException exc) {
1067:
1068:                    }
1069:                }
1070:                return null;
1071:            }
1072:
1073:            public URL getURL(String columnName) throws SQLException {
1074:                Object value = getObject(columnName);
1075:                if (null != value) {
1076:                    if (value instanceof  URL)
1077:                        return (URL) value;
1078:                    try {
1079:                        return new URL(value.toString());
1080:                    } catch (MalformedURLException exc) {
1081:
1082:                    }
1083:                }
1084:                return null;
1085:            }
1086:
1087:            public Blob getBlob(int columnIndex) throws SQLException {
1088:                Object value = getObject(columnIndex);
1089:                if (null != value) {
1090:                    if (value instanceof  Blob)
1091:                        return (Blob) value;
1092:                    return new MockBlob(getBytes(columnIndex));
1093:                }
1094:                return null;
1095:            }
1096:
1097:            public Blob getBlob(String columnName) throws SQLException {
1098:                Object value = getObject(columnName);
1099:                if (null != value) {
1100:                    if (value instanceof  Blob)
1101:                        return (Blob) value;
1102:                    return new MockBlob(getBytes(columnName));
1103:                }
1104:                return null;
1105:            }
1106:
1107:            public Clob getClob(int columnIndex) throws SQLException {
1108:                Object value = getObject(columnIndex);
1109:                if (null != value) {
1110:                    if (value instanceof  Clob)
1111:                        return (Clob) value;
1112:                    return new MockClob(getString(columnIndex));
1113:                }
1114:                return null;
1115:            }
1116:
1117:            public Clob getClob(String columnName) throws SQLException {
1118:                Object value = getObject(columnName);
1119:                if (null != value) {
1120:                    if (value instanceof  Clob)
1121:                        return (Clob) value;
1122:                    return new MockClob(getString(columnName));
1123:                }
1124:                return null;
1125:            }
1126:
1127:            /*public NClob getNClob(int columnIndex) throws SQLException
1128:            {
1129:                Object value = getObject(columnIndex);
1130:                if(null != value)
1131:                {
1132:                    if(value instanceof NClob) return (NClob)value;
1133:                    if(value instanceof Clob) return getNClobFromClob((Clob)value);
1134:                    return new MockNClob(getString(columnIndex));
1135:                }
1136:                return null;
1137:            }*/
1138:
1139:            /*public NClob getNClob(String columnName) throws SQLException
1140:            {
1141:                Object value = getObject(columnName);
1142:                if(null != value)
1143:                {
1144:                    if(value instanceof NClob) return (NClob)value;
1145:                    if(value instanceof Clob) return getNClobFromClob((Clob)value);
1146:                    return new MockNClob(getString(columnName));
1147:                }
1148:                return null;
1149:            }*/
1150:
1151:            /*public SQLXML getSQLXML(int columnIndex) throws SQLException
1152:            {
1153:                Object value = getObject(columnIndex);
1154:                if(null != value)
1155:                {
1156:                    if(value instanceof SQLXML) return (SQLXML)value;
1157:                    return new MockSQLXML(getString(columnIndex));
1158:                }
1159:                return null;
1160:            }*/
1161:
1162:            /*public SQLXML getSQLXML(String columnName) throws SQLException
1163:            {
1164:                Object value = getObject(columnName);
1165:                if(null != value)
1166:                {
1167:                    if(value instanceof SQLXML) return (SQLXML)value;
1168:                    return new MockSQLXML(getString(columnName));
1169:                }
1170:                return null;
1171:            }*/
1172:
1173:            public Array getArray(int columnIndex) throws SQLException {
1174:                Object value = getObject(columnIndex);
1175:                if (null != value) {
1176:                    if (value instanceof  Array)
1177:                        return (Array) value;
1178:                    return new MockArray(value);
1179:                }
1180:                return null;
1181:            }
1182:
1183:            public Array getArray(String columnName) throws SQLException {
1184:                Object value = getObject(columnName);
1185:                if (null != value) {
1186:                    if (value instanceof  Array)
1187:                        return (Array) value;
1188:                    return new MockArray(value);
1189:                }
1190:                return null;
1191:            }
1192:
1193:            public Ref getRef(int columnIndex) throws SQLException {
1194:                Object value = getObject(columnIndex);
1195:                if (null != value) {
1196:                    if (value instanceof  Ref)
1197:                        return (Ref) value;
1198:                    return new MockRef(value);
1199:                }
1200:                return null;
1201:            }
1202:
1203:            public Ref getRef(String columnName) throws SQLException {
1204:                Object value = getObject(columnName);
1205:                if (null != value) {
1206:                    if (value instanceof  Ref)
1207:                        return (Ref) value;
1208:                    return new MockRef(value);
1209:                }
1210:                return null;
1211:            }
1212:
1213:            /*public RowId getRowId(int columnIndex) throws SQLException
1214:            {
1215:                Object value = getObject(columnIndex);
1216:                if(null != value)
1217:                {
1218:                    if(value instanceof RowId) return (RowId)value;
1219:                    return new MockRowId(getBytes(columnIndex));
1220:                }
1221:                return null;
1222:            }*/
1223:
1224:            /*public RowId getRowId(String columnName) throws SQLException
1225:            {
1226:                Object value = getObject(columnName);
1227:                if(null != value)
1228:                {
1229:                    if(value instanceof RowId) return (RowId)value;
1230:                    return new MockRowId(getBytes(columnName));
1231:                }
1232:                return null;
1233:            }*/
1234:
1235:            public InputStream getAsciiStream(int columnIndex)
1236:                    throws SQLException {
1237:                return getBinaryStream(columnIndex);
1238:            }
1239:
1240:            public InputStream getAsciiStream(String columnName)
1241:                    throws SQLException {
1242:                return getBinaryStream(columnName);
1243:            }
1244:
1245:            public InputStream getBinaryStream(int columnIndex)
1246:                    throws SQLException {
1247:                Object value = getObject(columnIndex);
1248:                if (null != value) {
1249:                    if (value instanceof  InputStream)
1250:                        return (InputStream) value;
1251:                    return new ByteArrayInputStream(getBytes(columnIndex));
1252:                }
1253:                return null;
1254:            }
1255:
1256:            public InputStream getBinaryStream(String columnName)
1257:                    throws SQLException {
1258:                Object value = getObject(columnName);
1259:                if (null != value) {
1260:                    if (value instanceof  InputStream)
1261:                        return (InputStream) value;
1262:                    return new ByteArrayInputStream(getBytes(columnName));
1263:                }
1264:                return null;
1265:            }
1266:
1267:            public InputStream getUnicodeStream(int columnIndex)
1268:                    throws SQLException {
1269:                Object value = getObject(columnIndex);
1270:                if (null != value) {
1271:                    if (value instanceof  InputStream)
1272:                        return (InputStream) value;
1273:                    try {
1274:                        return new ByteArrayInputStream(getString(columnIndex)
1275:                                .getBytes("UTF-8"));
1276:                    } catch (UnsupportedEncodingException exc) {
1277:                        throw new NestedApplicationException(exc);
1278:                    }
1279:                }
1280:                return null;
1281:            }
1282:
1283:            public InputStream getUnicodeStream(String columnName)
1284:                    throws SQLException {
1285:                Object value = getObject(columnName);
1286:                if (null != value) {
1287:                    if (value instanceof  InputStream)
1288:                        return (InputStream) value;
1289:                    try {
1290:                        return new ByteArrayInputStream(getString(columnName)
1291:                                .getBytes("UTF-8"));
1292:                    } catch (UnsupportedEncodingException exc) {
1293:                        throw new NestedApplicationException(exc);
1294:                    }
1295:                }
1296:                return null;
1297:            }
1298:
1299:            public Reader getCharacterStream(int columnIndex)
1300:                    throws SQLException {
1301:                Object value = getObject(columnIndex);
1302:                if (null != value) {
1303:                    if (value instanceof  Reader)
1304:                        return (Reader) value;
1305:                    return new StringReader(getString(columnIndex));
1306:                }
1307:                return null;
1308:            }
1309:
1310:            public Reader getCharacterStream(String columnName)
1311:                    throws SQLException {
1312:                Object value = getObject(columnName);
1313:                if (null != value) {
1314:                    if (value instanceof  Reader)
1315:                        return (Reader) value;
1316:                    return new StringReader(getString(columnName));
1317:                }
1318:                return null;
1319:            }
1320:
1321:            public Reader getNCharacterStream(int columnIndex)
1322:                    throws SQLException {
1323:                return getCharacterStream(columnIndex);
1324:            }
1325:
1326:            public Reader getNCharacterStream(String columnLabel)
1327:                    throws SQLException {
1328:                return getCharacterStream(columnLabel);
1329:            }
1330:
1331:            public SQLWarning getWarnings() throws SQLException {
1332:                return null;
1333:            }
1334:
1335:            public void clearWarnings() throws SQLException {
1336:
1337:            }
1338:
1339:            public String getCursorName() throws SQLException {
1340:                return cursorName;
1341:            }
1342:
1343:            public ResultSetMetaData getMetaData() throws SQLException {
1344:                if (null != resultSetMetaData)
1345:                    return resultSetMetaData;
1346:                MockResultSetMetaData metaData = new MockResultSetMetaData();
1347:                metaData.setColumnCount(getColumnCount());
1348:                for (int ii = 0; ii < columnNameList.size(); ii++) {
1349:                    metaData.setColumnName(ii + 1, (String) columnNameList
1350:                            .get(ii));
1351:                }
1352:                return metaData;
1353:            }
1354:
1355:            public Statement getStatement() throws SQLException {
1356:                return statement;
1357:            }
1358:
1359:            public boolean isBeforeFirst() throws SQLException {
1360:                // Counterintuitively, this method is supposed to return false when the
1361:                // result set is empty.
1362:                return (getRowCount() != 0) && (cursor == -1);
1363:            }
1364:
1365:            public boolean isAfterLast() throws SQLException {
1366:                return cursor >= getRowCount();
1367:            }
1368:
1369:            public boolean isFirst() throws SQLException {
1370:                return cursor == 0;
1371:            }
1372:
1373:            public boolean isLast() throws SQLException {
1374:                return (cursor != -1) && (cursor == getRowCount() - 1);
1375:            }
1376:
1377:            public void beforeFirst() throws SQLException {
1378:                if (isCursorInInsertRow)
1379:                    throw new SQLException("cursor is in insert row");
1380:                checkResultSetType();
1381:                cursor = -1;
1382:            }
1383:
1384:            public void afterLast() throws SQLException {
1385:                if (isCursorInInsertRow)
1386:                    throw new SQLException("cursor is in insert row");
1387:                checkResultSetType();
1388:                if (getRowCount() == 0)
1389:                    return;
1390:                cursor = getRowCount();
1391:            }
1392:
1393:            public boolean next() throws SQLException {
1394:                if (isCursorInInsertRow)
1395:                    throw new SQLException("cursor is in insert row");
1396:                if (getRowCount() == 0)
1397:                    return false;
1398:                cursor++;
1399:                adjustCursor();
1400:                return isCurrentRowValid();
1401:            }
1402:
1403:            public boolean first() throws SQLException {
1404:                if (isCursorInInsertRow)
1405:                    throw new SQLException("cursor is in insert row");
1406:                checkResultSetType();
1407:                if (getRowCount() == 0)
1408:                    return false;
1409:                cursor = 0;
1410:                return true;
1411:            }
1412:
1413:            public boolean last() throws SQLException {
1414:                if (isCursorInInsertRow)
1415:                    throw new SQLException("cursor is in insert row");
1416:                checkResultSetType();
1417:                if (getRowCount() == 0)
1418:                    return false;
1419:                cursor = getRowCount() - 1;
1420:                return true;
1421:            }
1422:
1423:            public boolean absolute(int row) throws SQLException {
1424:                if (isCursorInInsertRow)
1425:                    throw new SQLException("cursor is in insert row");
1426:                checkResultSetType();
1427:                if (getRowCount() == 0)
1428:                    return false;
1429:                if (row > 0)
1430:                    cursor = row - 1;
1431:                if (row < 0)
1432:                    cursor = getRowCount() + row;
1433:                adjustCursor();
1434:                return isCurrentRowValid();
1435:            }
1436:
1437:            public boolean relative(int rows) throws SQLException {
1438:                if (isCursorInInsertRow)
1439:                    throw new SQLException("cursor is in insert row");
1440:                checkResultSetType();
1441:                if (getRowCount() == 0)
1442:                    return false;
1443:                cursor += rows;
1444:                adjustCursor();
1445:                return isCurrentRowValid();
1446:            }
1447:
1448:            public int getRow() throws SQLException {
1449:                return cursor + 1;
1450:            }
1451:
1452:            public boolean previous() throws SQLException {
1453:                if (isCursorInInsertRow)
1454:                    throw new SQLException("cursor is in insert row");
1455:                checkResultSetType();
1456:                if (getRowCount() == 0)
1457:                    return false;
1458:                cursor--;
1459:                adjustCursor();
1460:                return isCurrentRowValid();
1461:            }
1462:
1463:            public void setFetchDirection(int fetchDirection)
1464:                    throws SQLException {
1465:                checkFetchDirectionArguments(fetchDirection);
1466:                if (this .fetchDirection == fetchDirection)
1467:                    return;
1468:                if (this .fetchDirection == ResultSet.FETCH_UNKNOWN
1469:                        || fetchDirection == ResultSet.FETCH_UNKNOWN) {
1470:                    this .fetchDirection = fetchDirection;
1471:                    return;
1472:                }
1473:                this .fetchDirection = fetchDirection;
1474:                Iterator columns = columnMapCopy.values().iterator();
1475:                while (columns.hasNext()) {
1476:                    List column = (List) columns.next();
1477:                    Collections.reverse(column);
1478:                }
1479:                if (-1 != cursor)
1480:                    cursor = getRowCount() - cursor - 1;
1481:            }
1482:
1483:            public int getFetchDirection() throws SQLException {
1484:                return fetchDirection;
1485:            }
1486:
1487:            public void setFetchSize(int fetchSize) throws SQLException {
1488:                this .fetchSize = fetchSize;
1489:            }
1490:
1491:            public int getFetchSize() throws SQLException {
1492:                return fetchSize;
1493:            }
1494:
1495:            public int getType() throws SQLException {
1496:                return resultSetType;
1497:            }
1498:
1499:            public int getConcurrency() throws SQLException {
1500:                return resultSetConcurrency;
1501:            }
1502:
1503:            public int getHoldability() throws SQLException {
1504:                return resultSetHoldability;
1505:            }
1506:
1507:            public int findColumn(String columnName) throws SQLException {
1508:                for (int ii = 0; ii < columnNameList.size(); ii++) {
1509:                    if (columnName.equals(columnNameList.get(ii)))
1510:                        return ii + 1;
1511:                }
1512:                throw new SQLException("No column with name " + columnName
1513:                        + " found");
1514:            }
1515:
1516:            public void updateObject(int columnIndex, Object value)
1517:                    throws SQLException {
1518:                checkColumnBounds(columnIndex);
1519:                if (!isCursorInInsertRow) {
1520:                    checkRowBounds();
1521:                    if (rowDeleted())
1522:                        throw new SQLException("row was deleted");
1523:                }
1524:                String columnName = (String) columnNameList
1525:                        .get(columnIndex - 1);
1526:                updateObject(columnName, value);
1527:            }
1528:
1529:            public void updateObject(int columnIndex, Object value, int scale)
1530:                    throws SQLException {
1531:                updateObject(columnIndex, value);
1532:            }
1533:
1534:            public void updateObject(String columnName, Object value, int scale)
1535:                    throws SQLException {
1536:                updateObject(columnName, value);
1537:            }
1538:
1539:            public void updateObject(String columnName, Object value)
1540:                    throws SQLException {
1541:                checkColumnName(columnName);
1542:                checkResultSetConcurrency();
1543:                if (!isCursorInInsertRow) {
1544:                    checkRowBounds();
1545:                    if (rowDeleted())
1546:                        throw new SQLException("row was deleted");
1547:                }
1548:                if (isCursorInInsertRow) {
1549:                    List column = (List) insertRow.get(columnName);
1550:                    column.set(0, value);
1551:                } else {
1552:                    List column = (List) columnMapCopy.get(columnName);
1553:                    column.set(cursor, value);
1554:                }
1555:            }
1556:
1557:            public void updateString(int columnIndex, String value)
1558:                    throws SQLException {
1559:                updateObject(columnIndex, value);
1560:            }
1561:
1562:            public void updateString(String columnName, String value)
1563:                    throws SQLException {
1564:                updateObject(columnName, value);
1565:            }
1566:
1567:            public void updateNString(int columnIndex, String value)
1568:                    throws SQLException {
1569:                updateObject(columnIndex, value);
1570:            }
1571:
1572:            public void updateNString(String columnLabel, String value)
1573:                    throws SQLException {
1574:                updateObject(columnLabel, value);
1575:            }
1576:
1577:            public void updateNull(int columnIndex) throws SQLException {
1578:                updateObject(columnIndex, null);
1579:            }
1580:
1581:            public void updateNull(String columnName) throws SQLException {
1582:                updateObject(columnName, null);
1583:            }
1584:
1585:            public void updateBoolean(int columnIndex, boolean booleanValue)
1586:                    throws SQLException {
1587:                updateObject(columnIndex, new Boolean(booleanValue));
1588:            }
1589:
1590:            public void updateBoolean(String columnName, boolean booleanValue)
1591:                    throws SQLException {
1592:                updateObject(columnName, new Boolean(booleanValue));
1593:            }
1594:
1595:            public void updateByte(int columnIndex, byte byteValue)
1596:                    throws SQLException {
1597:                updateObject(columnIndex, new Byte(byteValue));
1598:            }
1599:
1600:            public void updateByte(String columnName, byte byteValue)
1601:                    throws SQLException {
1602:                updateObject(columnName, new Byte(byteValue));
1603:            }
1604:
1605:            public void updateShort(int columnIndex, short shortValue)
1606:                    throws SQLException {
1607:                updateObject(columnIndex, new Short(shortValue));
1608:            }
1609:
1610:            public void updateShort(String columnName, short shortValue)
1611:                    throws SQLException {
1612:                updateObject(columnName, new Short(shortValue));
1613:            }
1614:
1615:            public void updateInt(int columnIndex, int intValue)
1616:                    throws SQLException {
1617:                updateObject(columnIndex, new Integer(intValue));
1618:            }
1619:
1620:            public void updateInt(String columnName, int intValue)
1621:                    throws SQLException {
1622:                updateObject(columnName, new Integer(intValue));
1623:            }
1624:
1625:            public void updateLong(int columnIndex, long longValue)
1626:                    throws SQLException {
1627:                updateObject(columnIndex, new Long(longValue));
1628:            }
1629:
1630:            public void updateLong(String columnName, long longValue)
1631:                    throws SQLException {
1632:                updateObject(columnName, new Long(longValue));
1633:            }
1634:
1635:            public void updateFloat(int columnIndex, float floatValue)
1636:                    throws SQLException {
1637:                updateObject(columnIndex, new Float(floatValue));
1638:            }
1639:
1640:            public void updateFloat(String columnName, float floatValue)
1641:                    throws SQLException {
1642:                updateObject(columnName, new Float(floatValue));
1643:            }
1644:
1645:            public void updateDouble(int columnIndex, double doubleValue)
1646:                    throws SQLException {
1647:                updateObject(columnIndex, new Double(doubleValue));
1648:            }
1649:
1650:            public void updateDouble(String columnName, double doubleValue)
1651:                    throws SQLException {
1652:                updateObject(columnName, new Double(doubleValue));
1653:            }
1654:
1655:            public void updateBigDecimal(int columnIndex, BigDecimal bigDecimal)
1656:                    throws SQLException {
1657:                updateObject(columnIndex, bigDecimal);
1658:            }
1659:
1660:            public void updateBigDecimal(String columnName,
1661:                    BigDecimal bigDecimal) throws SQLException {
1662:                updateObject(columnName, bigDecimal);
1663:            }
1664:
1665:            public void updateBytes(int columnIndex, byte[] byteArray)
1666:                    throws SQLException {
1667:                updateObject(columnIndex, byteArray);
1668:            }
1669:
1670:            public void updateBytes(String columnName, byte[] byteArray)
1671:                    throws SQLException {
1672:                updateObject(columnName, byteArray);
1673:            }
1674:
1675:            public void updateDate(int columnIndex, Date date)
1676:                    throws SQLException {
1677:                updateObject(columnIndex, date);
1678:            }
1679:
1680:            public void updateDate(String columnName, Date date)
1681:                    throws SQLException {
1682:                updateObject(columnName, date);
1683:            }
1684:
1685:            public void updateTime(int columnIndex, Time time)
1686:                    throws SQLException {
1687:                updateObject(columnIndex, time);
1688:            }
1689:
1690:            public void updateTime(String columnName, Time time)
1691:                    throws SQLException {
1692:                updateObject(columnName, time);
1693:            }
1694:
1695:            public void updateTimestamp(int columnIndex, Timestamp timeStamp)
1696:                    throws SQLException {
1697:                updateObject(columnIndex, timeStamp);
1698:            }
1699:
1700:            public void updateTimestamp(String columnName, Timestamp timeStamp)
1701:                    throws SQLException {
1702:                updateObject(columnName, timeStamp);
1703:            }
1704:
1705:            public void updateAsciiStream(int columnIndex, InputStream stream,
1706:                    int length) throws SQLException {
1707:                updateBinaryStream(columnIndex, stream, length);
1708:            }
1709:
1710:            public void updateAsciiStream(String columnName,
1711:                    InputStream stream, int length) throws SQLException {
1712:                updateBinaryStream(columnName, stream, length);
1713:            }
1714:
1715:            public void updateAsciiStream(int columnIndex, InputStream stream,
1716:                    long length) throws SQLException {
1717:                updateBinaryStream(columnIndex, stream, length);
1718:            }
1719:
1720:            public void updateAsciiStream(String columnName,
1721:                    InputStream stream, long length) throws SQLException {
1722:                updateBinaryStream(columnName, stream, length);
1723:            }
1724:
1725:            public void updateAsciiStream(int columnIndex, InputStream stream)
1726:                    throws SQLException {
1727:                updateBinaryStream(columnIndex, stream);
1728:            }
1729:
1730:            public void updateAsciiStream(String columnName, InputStream stream)
1731:                    throws SQLException {
1732:                updateBinaryStream(columnName, stream);
1733:            }
1734:
1735:            public void updateBinaryStream(int columnIndex, InputStream stream,
1736:                    int length) throws SQLException {
1737:                byte[] data = StreamUtil.getStreamAsByteArray(stream, length);
1738:                updateObject(columnIndex, new ByteArrayInputStream(data));
1739:            }
1740:
1741:            public void updateBinaryStream(String columnName,
1742:                    InputStream stream, int length) throws SQLException {
1743:                byte[] data = StreamUtil.getStreamAsByteArray(stream, length);
1744:                updateObject(columnName, new ByteArrayInputStream(data));
1745:            }
1746:
1747:            public void updateBinaryStream(int columnIndex, InputStream stream,
1748:                    long length) throws SQLException {
1749:                updateBinaryStream(columnIndex, stream, (int) length);
1750:            }
1751:
1752:            public void updateBinaryStream(String columnName,
1753:                    InputStream stream, long length) throws SQLException {
1754:                updateBinaryStream(columnName, stream, (int) length);
1755:            }
1756:
1757:            public void updateBinaryStream(int columnIndex, InputStream stream)
1758:                    throws SQLException {
1759:                byte[] data = StreamUtil.getStreamAsByteArray(stream);
1760:                updateObject(columnIndex, new ByteArrayInputStream(data));
1761:            }
1762:
1763:            public void updateBinaryStream(String columnName, InputStream stream)
1764:                    throws SQLException {
1765:                byte[] data = StreamUtil.getStreamAsByteArray(stream);
1766:                updateObject(columnName, new ByteArrayInputStream(data));
1767:            }
1768:
1769:            public void updateCharacterStream(int columnIndex, Reader reader,
1770:                    int length) throws SQLException {
1771:                String data = StreamUtil.getReaderAsString(reader, length);
1772:                updateObject(columnIndex, new StringReader(data));
1773:            }
1774:
1775:            public void updateCharacterStream(String columnName, Reader reader,
1776:                    int length) throws SQLException {
1777:                String data = StreamUtil.getReaderAsString(reader, length);
1778:                updateObject(columnName, new StringReader(data));
1779:            }
1780:
1781:            public void updateCharacterStream(int columnIndex, Reader reader,
1782:                    long length) throws SQLException {
1783:                updateCharacterStream(columnIndex, reader, (int) length);
1784:            }
1785:
1786:            public void updateCharacterStream(String columnName, Reader reader,
1787:                    long length) throws SQLException {
1788:                updateCharacterStream(columnName, reader, (int) length);
1789:            }
1790:
1791:            public void updateCharacterStream(int columnIndex, Reader reader)
1792:                    throws SQLException {
1793:                String data = StreamUtil.getReaderAsString(reader);
1794:                updateObject(columnIndex, new StringReader(data));
1795:            }
1796:
1797:            public void updateCharacterStream(String columnName, Reader reader)
1798:                    throws SQLException {
1799:                String data = StreamUtil.getReaderAsString(reader);
1800:                updateObject(columnName, new StringReader(data));
1801:            }
1802:
1803:            public void updateNCharacterStream(int columnIndex, Reader reader)
1804:                    throws SQLException {
1805:                updateCharacterStream(columnIndex, reader);
1806:            }
1807:
1808:            public void updateNCharacterStream(String columnLabel, Reader reader)
1809:                    throws SQLException {
1810:                updateCharacterStream(columnLabel, reader);
1811:            }
1812:
1813:            public void updateNCharacterStream(int columnIndex, Reader reader,
1814:                    long length) throws SQLException {
1815:                updateCharacterStream(columnIndex, reader, length);
1816:            }
1817:
1818:            public void updateNCharacterStream(String columnLabel,
1819:                    Reader reader, long length) throws SQLException {
1820:                updateCharacterStream(columnLabel, reader, length);
1821:            }
1822:
1823:            public void updateRef(int columnIndex, Ref ref) throws SQLException {
1824:                updateObject(columnIndex, ref);
1825:            }
1826:
1827:            public void updateRef(String columnName, Ref ref)
1828:                    throws SQLException {
1829:                updateObject(columnName, ref);
1830:            }
1831:
1832:            /*public void updateRowId(int columnIndex, RowId rowId) throws SQLException
1833:            {
1834:                updateObject(columnIndex, rowId);
1835:            }*/
1836:
1837:            /*public void updateRowId(String columnName, RowId rowId) throws SQLException
1838:            {
1839:                updateObject(columnName, rowId);
1840:            }*/
1841:
1842:            public void updateBlob(int columnIndex, Blob blob)
1843:                    throws SQLException {
1844:                updateObject(columnIndex, blob);
1845:            }
1846:
1847:            public void updateBlob(String columnName, Blob blob)
1848:                    throws SQLException {
1849:                updateObject(columnName, blob);
1850:            }
1851:
1852:            public void updateBlob(int columnIndex, InputStream stream,
1853:                    long length) throws SQLException {
1854:                byte[] data = StreamUtil.getStreamAsByteArray(stream,
1855:                        (int) length);
1856:                updateBlob(columnIndex, new MockBlob(data));
1857:            }
1858:
1859:            public void updateBlob(String columnName, InputStream stream,
1860:                    long length) throws SQLException {
1861:                byte[] data = StreamUtil.getStreamAsByteArray(stream,
1862:                        (int) length);
1863:                updateBlob(columnName, new MockBlob(data));
1864:            }
1865:
1866:            public void updateBlob(int columnIndex, InputStream stream)
1867:                    throws SQLException {
1868:                byte[] data = StreamUtil.getStreamAsByteArray(stream);
1869:                updateBlob(columnIndex, new MockBlob(data));
1870:            }
1871:
1872:            public void updateBlob(String columnName, InputStream stream)
1873:                    throws SQLException {
1874:                byte[] data = StreamUtil.getStreamAsByteArray(stream);
1875:                updateBlob(columnName, new MockBlob(data));
1876:            }
1877:
1878:            public void updateClob(int columnIndex, Clob clob)
1879:                    throws SQLException {
1880:                updateObject(columnIndex, clob);
1881:            }
1882:
1883:            public void updateClob(String columnName, Clob clob)
1884:                    throws SQLException {
1885:                updateObject(columnName, clob);
1886:            }
1887:
1888:            public void updateClob(int columnIndex, Reader reader, long length)
1889:                    throws SQLException {
1890:                String data = StreamUtil
1891:                        .getReaderAsString(reader, (int) length);
1892:                updateClob(columnIndex, new MockClob(data));
1893:            }
1894:
1895:            public void updateClob(String columnName, Reader reader, long length)
1896:                    throws SQLException {
1897:                String data = StreamUtil
1898:                        .getReaderAsString(reader, (int) length);
1899:                updateClob(columnName, new MockClob(data));
1900:            }
1901:
1902:            public void updateClob(int columnIndex, Reader reader)
1903:                    throws SQLException {
1904:                String data = StreamUtil.getReaderAsString(reader);
1905:                updateClob(columnIndex, new MockClob(data));
1906:            }
1907:
1908:            public void updateClob(String columnName, Reader reader)
1909:                    throws SQLException {
1910:                String data = StreamUtil.getReaderAsString(reader);
1911:                updateClob(columnName, new MockClob(data));
1912:            }
1913:
1914:            /*public void updateNClob(int columnIndex, NClob nClob) throws SQLException
1915:            {
1916:                updateObject(columnIndex, nClob);
1917:            }*/
1918:
1919:            /*public void updateNClob(String columnName, NClob nClob) throws SQLException
1920:            {
1921:                updateObject(columnName, nClob);
1922:            }*/
1923:
1924:            /*public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException
1925:            {
1926:                String data = StreamUtil.getReaderAsString(reader, (int)length);
1927:                updateNClob(columnIndex, new MockNClob(data));
1928:            }*/
1929:
1930:            /*public void updateNClob(String columnName, Reader reader, long length) throws SQLException
1931:            {
1932:                String data = StreamUtil.getReaderAsString(reader, (int)length);
1933:                updateNClob(columnName, new MockNClob(data));
1934:            }*/
1935:
1936:            /*public void updateNClob(int columnIndex, Reader reader) throws SQLException
1937:            {
1938:                String data = StreamUtil.getReaderAsString(reader);
1939:                updateNClob(columnIndex, new MockNClob(data));
1940:            }*/
1941:
1942:            /*public void updateNClob(String columnName, Reader reader) throws SQLException
1943:            {
1944:                String data = StreamUtil.getReaderAsString(reader);
1945:                updateNClob(columnName, new MockNClob(data));
1946:            }*/
1947:
1948:            /*public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException
1949:            {
1950:                updateObject(columnIndex, xmlObject);
1951:            }*/
1952:
1953:            /*public void updateSQLXML(String columnName, SQLXML xmlObject) throws SQLException
1954:            {
1955:                updateObject(columnName, xmlObject);
1956:            }*/
1957:
1958:            public void updateArray(int columnIndex, Array array)
1959:                    throws SQLException {
1960:                updateObject(columnIndex, array);
1961:            }
1962:
1963:            public void updateArray(String columnName, Array array)
1964:                    throws SQLException {
1965:                updateObject(columnName, array);
1966:            }
1967:
1968:            public boolean rowUpdated() throws SQLException {
1969:                checkRowBounds();
1970:                return ((Boolean) updatedRows.get(cursor)).booleanValue();
1971:            }
1972:
1973:            public boolean rowInserted() throws SQLException {
1974:                checkRowBounds();
1975:                return ((Boolean) insertedRows.get(cursor)).booleanValue();
1976:            }
1977:
1978:            public boolean rowDeleted() throws SQLException {
1979:                checkRowBounds();
1980:                return ((Boolean) deletedRows.get(cursor)).booleanValue();
1981:            }
1982:
1983:            public void insertRow() throws SQLException {
1984:                if (!isCursorInInsertRow)
1985:                    throw new SQLException("cursor is not in insert row");
1986:                checkResultSetConcurrency();
1987:                insertRow(cursor);
1988:            }
1989:
1990:            public void updateRow() throws SQLException {
1991:                if (isCursorInInsertRow)
1992:                    throw new SQLException("cursor is in insert row");
1993:                if (rowDeleted())
1994:                    throw new SQLException("row was deleted");
1995:                checkResultSetConcurrency();
1996:                checkRowBounds();
1997:                updateRow(cursor, true);
1998:                updatedRows.set(cursor, new Boolean(true));
1999:            }
2000:
2001:            public void deleteRow() throws SQLException {
2002:                if (isCursorInInsertRow)
2003:                    throw new SQLException("cursor is in insert row");
2004:                checkResultSetConcurrency();
2005:                checkRowBounds();
2006:                deleteRow(cursor);
2007:                deletedRows.set(cursor, new Boolean(true));
2008:            }
2009:
2010:            public void refreshRow() throws SQLException {
2011:                cancelRowUpdates();
2012:            }
2013:
2014:            public void cancelRowUpdates() throws SQLException {
2015:                if (isCursorInInsertRow)
2016:                    throw new SQLException("cursor is in insert row");
2017:                if (rowDeleted())
2018:                    throw new SQLException("row was deleted");
2019:                checkRowBounds();
2020:                updateRow(cursor, false);
2021:                updatedRows.set(cursor, new Boolean(false));
2022:            }
2023:
2024:            public void moveToInsertRow() throws SQLException {
2025:                adjustCursorForInsert();
2026:                isCursorInInsertRow = true;
2027:            }
2028:
2029:            public void moveToCurrentRow() throws SQLException {
2030:                isCursorInInsertRow = false;
2031:            }
2032:
2033:            public boolean isWrapperFor(Class iface) throws SQLException {
2034:                return false;
2035:            }
2036:
2037:            public Object unwrap(Class iface) throws SQLException {
2038:                throw new SQLException("No object found for " + iface);
2039:            }
2040:
2041:            private void checkColumnName(String columnName) throws SQLException {
2042:                if (!columnMap.containsKey(columnName)) {
2043:                    throw new SQLException("No column " + columnName);
2044:                }
2045:            }
2046:
2047:            private void checkColumnBounds(int columnIndex) throws SQLException {
2048:                if (!(columnIndex - 1 < columnNameList.size())) {
2049:                    throw new SQLException("Index " + columnIndex
2050:                            + " out of bounds");
2051:                }
2052:            }
2053:
2054:            private void checkRowBounds() throws SQLException {
2055:                if (!isCurrentRowValid()) {
2056:                    throw new SQLException("Current row invalid");
2057:                }
2058:            }
2059:
2060:            private boolean isCurrentRowValid() {
2061:                return (cursor < getRowCount()) && (-1 != cursor);
2062:            }
2063:
2064:            private void checkResultSetType() throws SQLException {
2065:                if (resultSetType == ResultSet.TYPE_FORWARD_ONLY) {
2066:                    throw new SQLException("ResultSet is TYPE_FORWARD_ONLY");
2067:                }
2068:            }
2069:
2070:            private void checkResultSetConcurrency() throws SQLException {
2071:                if (resultSetConcurrency == ResultSet.CONCUR_READ_ONLY) {
2072:                    throw new SQLException("ResultSet is CONCUR_READ_ONLY");
2073:                }
2074:            }
2075:
2076:            private void checkFetchDirectionArguments(int fetchDirection)
2077:                    throws SQLException {
2078:                SQLUtil.checkFetchDirection(fetchDirection);
2079:                if (resultSetType == ResultSet.TYPE_FORWARD_ONLY
2080:                        && fetchDirection != ResultSet.FETCH_FORWARD) {
2081:                    throw new SQLException(
2082:                            "resultSetType is TYPE_FORWARD_ONLY, only FETCH_FORWARD allowed");
2083:                }
2084:            }
2085:
2086:            private void insertRow(int index) {
2087:                Iterator columnNames = columnMapCopy.keySet().iterator();
2088:                while (columnNames.hasNext()) {
2089:                    String currentColumnName = (String) columnNames.next();
2090:                    List copyColumn = (List) columnMapCopy
2091:                            .get(currentColumnName);
2092:                    List databaseColumn = (List) columnMap
2093:                            .get(currentColumnName);
2094:                    List sourceColumn = (List) insertRow.get(currentColumnName);
2095:                    copyColumn.add(index, ParameterUtil
2096:                            .copyParameter(sourceColumn.get(0)));
2097:                    databaseColumn.add(index, ParameterUtil
2098:                            .copyParameter(sourceColumn.get(0)));
2099:                }
2100:                updatedRows.add(index, new Boolean(false));
2101:                deletedRows.add(index, new Boolean(false));
2102:                insertedRows.add(index, new Boolean(true));
2103:            }
2104:
2105:            private void deleteRow(int index) {
2106:                Iterator columnNames = columnMapCopy.keySet().iterator();
2107:                while (columnNames.hasNext()) {
2108:                    String currentColumnName = (String) columnNames.next();
2109:                    List copyColumn = (List) columnMapCopy
2110:                            .get(currentColumnName);
2111:                    List databaseColumn = (List) columnMap
2112:                            .get(currentColumnName);
2113:                    copyColumn.set(index, null);
2114:                    databaseColumn.set(index, null);
2115:                }
2116:            }
2117:
2118:            private void updateRow(int index, boolean toDatabase) {
2119:                Iterator columnNames = columnMapCopy.keySet().iterator();
2120:                while (columnNames.hasNext()) {
2121:                    String currentColumnName = (String) columnNames.next();
2122:                    List sourceColumn;
2123:                    List targetColumn;
2124:                    if (toDatabase) {
2125:                        sourceColumn = (List) columnMapCopy
2126:                                .get(currentColumnName);
2127:                        targetColumn = (List) columnMap.get(currentColumnName);
2128:                    } else {
2129:                        sourceColumn = (List) columnMap.get(currentColumnName);
2130:                        targetColumn = (List) columnMapCopy
2131:                                .get(currentColumnName);
2132:                    }
2133:                    targetColumn.set(index, ParameterUtil
2134:                            .copyParameter(sourceColumn.get(index)));
2135:                }
2136:            }
2137:
2138:            private void adjustCursorForInsert() {
2139:                if (cursor >= getRowCount())
2140:                    cursor = getRowCount() - 1;
2141:                if (cursor < 0)
2142:                    cursor = 0;
2143:            }
2144:
2145:            private void adjustCursor() {
2146:                if (cursor < 0)
2147:                    cursor = -1;
2148:                if (cursor >= getRowCount())
2149:                    cursor = getRowCount();
2150:            }
2151:
2152:            private void adjustColumns() {
2153:                int rowCount = 0;
2154:                Iterator columns = columnMap.values().iterator();
2155:                while (columns.hasNext()) {
2156:                    List nextColumn = (List) columns.next();
2157:                    rowCount = Math.max(rowCount, nextColumn.size());
2158:                }
2159:                columns = columnMap.values().iterator();
2160:                while (columns.hasNext()) {
2161:                    List nextColumn = (List) columns.next();
2162:                    CollectionUtil.fillList(nextColumn, rowCount);
2163:                }
2164:            }
2165:
2166:            private void adjustFlags() {
2167:                for (int ii = updatedRows.size(); ii < getRowCount(); ii++) {
2168:                    updatedRows.add(new Boolean(false));
2169:                }
2170:                for (int ii = deletedRows.size(); ii < getRowCount(); ii++) {
2171:                    deletedRows.add(new Boolean(false));
2172:                }
2173:                for (int ii = insertedRows.size(); ii < getRowCount(); ii++) {
2174:                    insertedRows.add(new Boolean(false));
2175:                }
2176:            }
2177:
2178:            private void adjustInsertRow() {
2179:                insertRow = createCaseAwareMap();
2180:                Iterator columns = columnMap.keySet().iterator();
2181:                while (columns.hasNext()) {
2182:                    ArrayList list = new ArrayList(1);
2183:                    list.add(null);
2184:                    insertRow.put((String) columns.next(), list);
2185:                }
2186:            }
2187:
2188:            private void copyColumnMap() {
2189:                columnMapCopy = copyColumnDataMap(columnMap);
2190:            }
2191:
2192:            private String determineValidColumnName() {
2193:                String name = "Column";
2194:                int count = columnNameList.size() + 1;
2195:                while (columnMap.containsKey(name + count)) {
2196:                    count++;
2197:                }
2198:                return name + count;
2199:            }
2200:
2201:            private Map copyColumnDataMap(Map columnMap) {
2202:                Map copy = createCaseAwareMap();
2203:                Iterator columns = columnMap.keySet().iterator();
2204:                while (columns.hasNext()) {
2205:                    List copyList = new ArrayList();
2206:                    String nextKey = (String) columns.next();
2207:                    List nextColumnList = (List) columnMap.get(nextKey);
2208:                    for (int ii = 0; ii < nextColumnList.size(); ii++) {
2209:                        Object copyParameter = ParameterUtil
2210:                                .copyParameter(nextColumnList.get(ii));
2211:                        copyList.add(copyParameter);
2212:                    }
2213:                    copy.put(nextKey, copyList);
2214:                }
2215:                return copy;
2216:            }
2217:
2218:            private Map createCaseAwareMap() {
2219:                return new CaseAwareMap(columnsCaseSensitive);
2220:            }
2221:
2222:            /*private NClob getNClobFromClob(Clob clobValue) throws SQLException
2223:            {
2224:                return new MockNClob(clobValue.getSubString(1, (int)clobValue.length()));
2225:            }*/
2226:
2227:            public String toString() {
2228:                StringBuffer buffer = new StringBuffer("ResultSet " + id
2229:                        + ":\n");
2230:                buffer.append("Number of rows: " + getRowCount() + "\n");
2231:                buffer.append("Number of columns: " + getColumnCount() + "\n");
2232:                buffer.append("Column names:\n");
2233:                StringUtil.appendObjectsAsString(buffer, columnNameList);
2234:                buffer.append("Data:\n");
2235:                for (int ii = 1; ii <= getRowCount(); ii++) {
2236:                    buffer.append("Row number " + ii + ":\n");
2237:                    StringUtil.appendObjectsAsString(buffer, getRow(ii));
2238:                }
2239:                return buffer.toString();
2240:            }
2241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.