Source Code Cross Referenced for MockCallableStatement.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) 


001:        package com.mockrunner.mock.jdbc;
002:
003:        import java.io.ByteArrayInputStream;
004:        import java.io.InputStream;
005:        import java.io.Reader;
006:        import java.io.StringReader;
007:        import java.io.UnsupportedEncodingException;
008:        import java.math.BigDecimal;
009:        import java.net.MalformedURLException;
010:        import java.net.URL;
011:        import java.sql.Array;
012:        import java.sql.Blob;
013:        import java.sql.CallableStatement;
014:        import java.sql.Clob;
015:        import java.sql.Connection;
016:        import java.sql.Date; //import java.sql.NClob;
017:        import java.sql.Ref;
018:        import java.sql.ResultSet; //import java.sql.RowId;
019:        import java.sql.SQLException; //import java.sql.SQLXML;
020:        import java.sql.Time;
021:        import java.sql.Timestamp;
022:        import java.util.ArrayList;
023:        import java.util.Calendar;
024:        import java.util.Collections;
025:        import java.util.HashMap;
026:        import java.util.HashSet;
027:        import java.util.Iterator;
028:        import java.util.List;
029:        import java.util.Map;
030:        import java.util.Set;
031:
032:        import com.mockrunner.base.NestedApplicationException;
033:        import com.mockrunner.jdbc.AbstractOutParameterResultSetHandler;
034:        import com.mockrunner.util.common.StreamUtil;
035:
036:        /**
037:         * Mock implementation of <code>CallableStatement</code>.
038:         */
039:        public class MockCallableStatement extends MockPreparedStatement
040:                implements  CallableStatement {
041:            private AbstractOutParameterResultSetHandler resultSetHandler;
042:            private Map paramObjects = new HashMap();
043:            private Set registeredOutParameterSetIndexed = new HashSet();
044:            private Set registeredOutParameterSetNamed = new HashSet();
045:            private List batchParameters = new ArrayList();
046:            private Map lastOutParameters = null;
047:            private boolean wasNull = false;
048:
049:            public MockCallableStatement(Connection connection, String sql) {
050:                super (connection, sql);
051:            }
052:
053:            public MockCallableStatement(Connection connection, String sql,
054:                    int resultSetType, int resultSetConcurrency) {
055:                super (connection, sql, resultSetType, resultSetConcurrency);
056:            }
057:
058:            public MockCallableStatement(Connection connection, String sql,
059:                    int resultSetType, int resultSetConcurrency,
060:                    int resultSetHoldability) {
061:                super (connection, sql, resultSetType, resultSetConcurrency,
062:                        resultSetHoldability);
063:            }
064:
065:            public void setCallableStatementResultSetHandler(
066:                    AbstractOutParameterResultSetHandler resultSetHandler) {
067:                super .setPreparedStatementResultSetHandler(resultSetHandler);
068:                this .resultSetHandler = resultSetHandler;
069:            }
070:
071:            public Map getNamedParameterMap() {
072:                return Collections.unmodifiableMap(paramObjects);
073:            }
074:
075:            public Map getParameterMap() {
076:                Map parameterMap = new HashMap(getIndexedParameterMap());
077:                parameterMap.putAll(getNamedParameterMap());
078:                return Collections.unmodifiableMap(parameterMap);
079:            }
080:
081:            public Object getParameter(String name) {
082:                return paramObjects.get(name);
083:            }
084:
085:            public void clearParameters() throws SQLException {
086:                super .clearParameters();
087:                paramObjects.clear();
088:            }
089:
090:            public Set getNamedRegisteredOutParameterSet() {
091:                return Collections
092:                        .unmodifiableSet(registeredOutParameterSetNamed);
093:            }
094:
095:            public boolean isOutParameterRegistered(int index) {
096:                return registeredOutParameterSetIndexed.contains(new Integer(
097:                        index));
098:            }
099:
100:            public Set getIndexedRegisteredOutParameterSet() {
101:                return Collections
102:                        .unmodifiableSet(registeredOutParameterSetIndexed);
103:            }
104:
105:            public boolean isOutParameterRegistered(String parameterName) {
106:                return registeredOutParameterSetNamed.contains(parameterName);
107:            }
108:
109:            public void clearRegisteredOutParameter() {
110:                registeredOutParameterSetIndexed.clear();
111:                registeredOutParameterSetNamed.clear();
112:            }
113:
114:            public ResultSet executeQuery() throws SQLException {
115:                ResultSet resultSet = executeQuery(getParameterMap());
116:                lastOutParameters = getOutParameterMap();
117:                return resultSet;
118:            }
119:
120:            public int executeUpdate() throws SQLException {
121:                int updateCount = executeUpdate(getParameterMap());
122:                lastOutParameters = getOutParameterMap();
123:                return updateCount;
124:            }
125:
126:            public void addBatch() throws SQLException {
127:                batchParameters.add(new HashMap(getParameterMap()));
128:            }
129:
130:            public int[] executeBatch() throws SQLException {
131:                return executeBatch(batchParameters);
132:            }
133:
134:            public void registerOutParameter(int parameterIndex, int sqlType)
135:                    throws SQLException {
136:                registeredOutParameterSetIndexed
137:                        .add(new Integer(parameterIndex));
138:            }
139:
140:            public void registerOutParameter(int parameterIndex, int sqlType,
141:                    int scale) throws SQLException {
142:                registerOutParameter(parameterIndex, sqlType);
143:            }
144:
145:            public void registerOutParameter(int parameterIndex, int sqlType,
146:                    String typeName) throws SQLException {
147:                registerOutParameter(parameterIndex, sqlType);
148:            }
149:
150:            public void registerOutParameter(String parameterName, int sqlType)
151:                    throws SQLException {
152:                registeredOutParameterSetNamed.add(parameterName);
153:            }
154:
155:            public void registerOutParameter(String parameterName, int sqlType,
156:                    int scale) throws SQLException {
157:                registerOutParameter(parameterName, sqlType);
158:            }
159:
160:            public void registerOutParameter(String parameterName, int sqlType,
161:                    String typeName) throws SQLException {
162:                registerOutParameter(parameterName, sqlType);
163:            }
164:
165:            public boolean wasNull() throws SQLException {
166:                return wasNull;
167:            }
168:
169:            public Object getObject(int parameterIndex) throws SQLException {
170:                wasNull = false;
171:                Object returnValue = null;
172:                if (null != lastOutParameters) {
173:                    returnValue = lastOutParameters.get(new Integer(
174:                            parameterIndex));
175:                }
176:                if (null == returnValue)
177:                    wasNull = true;
178:                return returnValue;
179:            }
180:
181:            public Object getObject(int parameterIndex, Map map)
182:                    throws SQLException {
183:                return getObject(parameterIndex);
184:            }
185:
186:            public byte getByte(int parameterIndex) throws SQLException {
187:                Object value = getObject(parameterIndex);
188:                if (null != value) {
189:                    if (value instanceof  Number)
190:                        return ((Number) value).byteValue();
191:                    return new Byte(value.toString()).byteValue();
192:                }
193:                return 0;
194:            }
195:
196:            public double getDouble(int parameterIndex) throws SQLException {
197:                Object value = getObject(parameterIndex);
198:                if (null != value) {
199:                    if (value instanceof  Number)
200:                        return ((Number) value).doubleValue();
201:                    return new Double(value.toString()).doubleValue();
202:                }
203:                return 0;
204:            }
205:
206:            public float getFloat(int parameterIndex) throws SQLException {
207:                Object value = getObject(parameterIndex);
208:                if (null != value) {
209:                    if (value instanceof  Number)
210:                        return ((Number) value).floatValue();
211:                    return new Float(value.toString()).floatValue();
212:                }
213:                return 0;
214:            }
215:
216:            public int getInt(int parameterIndex) throws SQLException {
217:                Object value = getObject(parameterIndex);
218:                if (null != value) {
219:                    if (value instanceof  Number)
220:                        return ((Number) value).intValue();
221:                    return new Integer(value.toString()).intValue();
222:                }
223:                return 0;
224:            }
225:
226:            public long getLong(int parameterIndex) throws SQLException {
227:                Object value = getObject(parameterIndex);
228:                if (null != value) {
229:                    if (value instanceof  Number)
230:                        return ((Number) value).longValue();
231:                    return new Long(value.toString()).longValue();
232:                }
233:                return 0;
234:            }
235:
236:            public short getShort(int parameterIndex) throws SQLException {
237:                Object value = getObject(parameterIndex);
238:                if (null != value) {
239:                    if (value instanceof  Number)
240:                        return ((Number) value).shortValue();
241:                    return new Short(value.toString()).shortValue();
242:                }
243:                return 0;
244:            }
245:
246:            public boolean getBoolean(int parameterIndex) throws SQLException {
247:                Object value = getObject(parameterIndex);
248:                if (null != value) {
249:                    if (value instanceof  Boolean)
250:                        return ((Boolean) value).booleanValue();
251:                    return new Boolean(value.toString()).booleanValue();
252:                }
253:                return false;
254:            }
255:
256:            public byte[] getBytes(int parameterIndex) throws SQLException {
257:                Object value = getObject(parameterIndex);
258:                if (null != value) {
259:                    if (value instanceof  byte[])
260:                        return (byte[]) value;
261:                    try {
262:                        return value.toString().getBytes("ISO-8859-1");
263:                    } catch (UnsupportedEncodingException exc) {
264:                        throw new NestedApplicationException(exc);
265:                    }
266:                }
267:                return null;
268:            }
269:
270:            public String getString(int parameterIndex) throws SQLException {
271:                Object value = getObject(parameterIndex);
272:                if (null != value)
273:                    return value.toString();
274:                return null;
275:            }
276:
277:            public String getNString(int parameterIndex) throws SQLException {
278:                return getString(parameterIndex);
279:            }
280:
281:            public BigDecimal getBigDecimal(int parameterIndex)
282:                    throws SQLException {
283:                Object value = getObject(parameterIndex);
284:                if (null != value) {
285:                    if (value instanceof  Number)
286:                        return new BigDecimal(((Number) value).doubleValue());
287:                    return new BigDecimal(value.toString());
288:                }
289:                return null;
290:            }
291:
292:            public BigDecimal getBigDecimal(int parameterIndex, int scale)
293:                    throws SQLException {
294:                return getBigDecimal(parameterIndex);
295:            }
296:
297:            public URL getURL(int parameterIndex) throws SQLException {
298:                Object value = getObject(parameterIndex);
299:                if (null != value) {
300:                    if (value instanceof  URL)
301:                        return (URL) value;
302:                    try {
303:                        return new URL(value.toString());
304:                    } catch (MalformedURLException exc) {
305:
306:                    }
307:                }
308:                return null;
309:            }
310:
311:            public Array getArray(int parameterIndex) throws SQLException {
312:                Object value = getObject(parameterIndex);
313:                if (null != value) {
314:                    if (value instanceof  Array)
315:                        return (Array) value;
316:                    return new MockArray(value);
317:                }
318:                return null;
319:            }
320:
321:            public Blob getBlob(int parameterIndex) throws SQLException {
322:                Object value = getObject(parameterIndex);
323:                if (null != value) {
324:                    if (value instanceof  Blob)
325:                        return (Blob) value;
326:                    return new MockBlob(getBytes(parameterIndex));
327:                }
328:                return null;
329:            }
330:
331:            public Clob getClob(int parameterIndex) throws SQLException {
332:                Object value = getObject(parameterIndex);
333:                if (null != value) {
334:                    if (value instanceof  Clob)
335:                        return (Clob) value;
336:                    return new MockClob(getString(parameterIndex));
337:                }
338:                return null;
339:            }
340:
341:            /*public NClob getNClob(int parameterIndex) throws SQLException
342:            {
343:                Object value = getObject(parameterIndex);
344:                if(null != value)
345:                {
346:                    if(value instanceof NClob) return (NClob)value;
347:                    if(value instanceof Clob) return getNClobFromClob((Clob)value);
348:                    return new MockNClob(getString(parameterIndex));
349:                }
350:                return null;
351:            }*/
352:
353:            /*public SQLXML getSQLXML(int parameterIndex) throws SQLException
354:            {
355:                Object value = getObject(parameterIndex);
356:                if(null != value)
357:                {
358:                    if(value instanceof SQLXML) return (SQLXML)value;
359:                    return new MockSQLXML(getString(parameterIndex));
360:                }
361:                return null;
362:            }*/
363:
364:            public Reader getCharacterStream(int parameterIndex)
365:                    throws SQLException {
366:                Object value = getObject(parameterIndex);
367:                if (null != value) {
368:                    if (value instanceof  Reader)
369:                        return (Reader) value;
370:                    return new StringReader(getString(parameterIndex));
371:                }
372:                return null;
373:            }
374:
375:            public Reader getNCharacterStream(int parameterIndex)
376:                    throws SQLException {
377:                return getCharacterStream(parameterIndex);
378:            }
379:
380:            public Date getDate(int parameterIndex) throws SQLException {
381:                Object value = getObject(parameterIndex);
382:                if (null != value) {
383:                    if (value instanceof  Date)
384:                        return (Date) value;
385:                    return Date.valueOf(value.toString());
386:                }
387:                return null;
388:            }
389:
390:            public Date getDate(int parameterIndex, Calendar calendar)
391:                    throws SQLException {
392:                return getDate(parameterIndex);
393:            }
394:
395:            public Ref getRef(int parameterIndex) throws SQLException {
396:                Object value = getObject(parameterIndex);
397:                if (null != value) {
398:                    if (value instanceof  Ref)
399:                        return (Ref) value;
400:                    return new MockRef(value);
401:                }
402:                return null;
403:            }
404:
405:            public Time getTime(int parameterIndex) throws SQLException {
406:                Object value = getObject(parameterIndex);
407:                if (null != value) {
408:                    if (value instanceof  Time)
409:                        return (Time) value;
410:                    return Time.valueOf(value.toString());
411:                }
412:                return null;
413:            }
414:
415:            public Time getTime(int parameterIndex, Calendar calendar)
416:                    throws SQLException {
417:                return getTime(parameterIndex);
418:            }
419:
420:            public Timestamp getTimestamp(int parameterIndex)
421:                    throws SQLException {
422:                Object value = getObject(parameterIndex);
423:                if (null != value) {
424:                    if (value instanceof  Timestamp)
425:                        return (Timestamp) value;
426:                    return Timestamp.valueOf(value.toString());
427:                }
428:                return null;
429:            }
430:
431:            public Timestamp getTimestamp(int parameterIndex, Calendar calendar)
432:                    throws SQLException {
433:                return getTimestamp(parameterIndex);
434:            }
435:
436:            /*public RowId getRowId(int parameterIndex) throws SQLException
437:            {
438:                Object value = getObject(parameterIndex);
439:                if(null != value)
440:                {
441:                    if(value instanceof RowId) return (RowId)value;
442:                    return new MockRowId(getBytes(parameterIndex));
443:                }
444:                return null;
445:            }*/
446:
447:            public Object getObject(String parameterName) throws SQLException {
448:                wasNull = false;
449:                Object returnValue = null;
450:                if (null != lastOutParameters) {
451:                    returnValue = lastOutParameters.get(parameterName);
452:                }
453:                if (null == returnValue)
454:                    wasNull = true;
455:                return returnValue;
456:            }
457:
458:            public Object getObject(String parameterName, Map map)
459:                    throws SQLException {
460:                return getObject(parameterName);
461:            }
462:
463:            public byte getByte(String parameterName) throws SQLException {
464:                Object value = getObject(parameterName);
465:                if (null != value) {
466:                    if (value instanceof  Number)
467:                        return ((Number) value).byteValue();
468:                    return new Byte(value.toString()).byteValue();
469:                }
470:                return 0;
471:            }
472:
473:            public double getDouble(String parameterName) throws SQLException {
474:                Object value = getObject(parameterName);
475:                if (null != value) {
476:                    if (value instanceof  Number)
477:                        return ((Number) value).doubleValue();
478:                    return new Double(value.toString()).doubleValue();
479:                }
480:                return 0;
481:            }
482:
483:            public float getFloat(String parameterName) throws SQLException {
484:                Object value = getObject(parameterName);
485:                if (null != value) {
486:                    if (value instanceof  Number)
487:                        return ((Number) value).floatValue();
488:                    return new Float(value.toString()).floatValue();
489:                }
490:                return 0;
491:            }
492:
493:            public int getInt(String parameterName) throws SQLException {
494:                Object value = getObject(parameterName);
495:                if (null != value) {
496:                    if (value instanceof  Number)
497:                        return ((Number) value).intValue();
498:                    return new Integer(value.toString()).intValue();
499:                }
500:                return 0;
501:            }
502:
503:            public long getLong(String parameterName) throws SQLException {
504:                Object value = getObject(parameterName);
505:                if (null != value) {
506:                    if (value instanceof  Number)
507:                        return ((Number) value).longValue();
508:                    return new Long(value.toString()).longValue();
509:                }
510:                return 0;
511:            }
512:
513:            public short getShort(String parameterName) throws SQLException {
514:                Object value = getObject(parameterName);
515:                if (null != value) {
516:                    if (value instanceof  Number)
517:                        return ((Number) value).shortValue();
518:                    return new Short(value.toString()).shortValue();
519:                }
520:                return 0;
521:            }
522:
523:            public boolean getBoolean(String parameterName) throws SQLException {
524:                Object value = getObject(parameterName);
525:                if (null != value) {
526:                    if (value instanceof  Boolean)
527:                        return ((Boolean) value).booleanValue();
528:                    return new Boolean(value.toString()).booleanValue();
529:                }
530:                return false;
531:            }
532:
533:            public byte[] getBytes(String parameterName) throws SQLException {
534:                Object value = getObject(parameterName);
535:                if (null != value) {
536:                    if (value instanceof  byte[])
537:                        return (byte[]) value;
538:                    try {
539:                        return value.toString().getBytes("ISO-8859-1");
540:                    } catch (UnsupportedEncodingException exc) {
541:                        throw new NestedApplicationException(exc);
542:                    }
543:                }
544:                return null;
545:            }
546:
547:            public String getString(String parameterName) throws SQLException {
548:                Object value = getObject(parameterName);
549:                if (null != value)
550:                    return value.toString();
551:                return null;
552:            }
553:
554:            public String getNString(String parameterName) throws SQLException {
555:                return getString(parameterName);
556:            }
557:
558:            public BigDecimal getBigDecimal(String parameterName)
559:                    throws SQLException {
560:                Object value = getObject(parameterName);
561:                if (null != value) {
562:                    if (value instanceof  Number)
563:                        return new BigDecimal(((Number) value).doubleValue());
564:                    return new BigDecimal(value.toString());
565:                }
566:                return null;
567:            }
568:
569:            public URL getURL(String parameterName) throws SQLException {
570:                Object value = getObject(parameterName);
571:                if (null != value) {
572:                    if (value instanceof  URL)
573:                        return (URL) value;
574:                    try {
575:                        return new URL(value.toString());
576:                    } catch (MalformedURLException exc) {
577:
578:                    }
579:                }
580:                return null;
581:            }
582:
583:            public Array getArray(String parameterName) throws SQLException {
584:                Object value = getObject(parameterName);
585:                if (null != value) {
586:                    if (value instanceof  Array)
587:                        return (Array) value;
588:                    return new MockArray(value);
589:                }
590:                return null;
591:            }
592:
593:            public Blob getBlob(String parameterName) throws SQLException {
594:                Object value = getObject(parameterName);
595:                if (null != value) {
596:                    if (value instanceof  Blob)
597:                        return (Blob) value;
598:                    return new MockBlob(getBytes(parameterName));
599:                }
600:                return null;
601:            }
602:
603:            public Clob getClob(String parameterName) throws SQLException {
604:                Object value = getObject(parameterName);
605:                if (null != value) {
606:                    if (value instanceof  Clob)
607:                        return (Clob) value;
608:                    return new MockClob(getString(parameterName));
609:                }
610:                return null;
611:            }
612:
613:            /*public NClob getNClob(String parameterName) throws SQLException
614:            {
615:                Object value = getObject(parameterName);
616:                if(null != value)
617:                {
618:                    if(value instanceof NClob) return (NClob)value;
619:                    if(value instanceof Clob) return getNClobFromClob((Clob)value);
620:                    return new MockNClob(getString(parameterName));
621:                }
622:                return null;
623:            }*/
624:
625:            /*public SQLXML getSQLXML(String parameterName) throws SQLException
626:            {
627:                Object value = getObject(parameterName);
628:                if(null != value)
629:                {
630:                    if(value instanceof SQLXML) return (SQLXML)value;
631:                    return new MockSQLXML(getString(parameterName));
632:                }
633:                return null;
634:            }*/
635:
636:            public Reader getCharacterStream(String parameterName)
637:                    throws SQLException {
638:                Object value = getObject(parameterName);
639:                if (null != value) {
640:                    if (value instanceof  Reader)
641:                        return (Reader) value;
642:                    return new StringReader(getString(parameterName));
643:                }
644:                return null;
645:            }
646:
647:            public Reader getNCharacterStream(String parameterName)
648:                    throws SQLException {
649:                return getCharacterStream(parameterName);
650:            }
651:
652:            public Date getDate(String parameterName) throws SQLException {
653:                Object value = getObject(parameterName);
654:                if (null != value) {
655:                    if (value instanceof  Date)
656:                        return (Date) value;
657:                    return Date.valueOf(value.toString());
658:                }
659:                return null;
660:            }
661:
662:            public Date getDate(String parameterName, Calendar calendar)
663:                    throws SQLException {
664:                return getDate(parameterName);
665:            }
666:
667:            public Ref getRef(String parameterName) throws SQLException {
668:                Object value = getObject(parameterName);
669:                if (null != value) {
670:                    if (value instanceof  Ref)
671:                        return (Ref) value;
672:                    return new MockRef(value);
673:                }
674:                return null;
675:            }
676:
677:            public Time getTime(String parameterName) throws SQLException {
678:                Object value = getObject(parameterName);
679:                if (null != value) {
680:                    if (value instanceof  Time)
681:                        return (Time) value;
682:                    return Time.valueOf(value.toString());
683:                }
684:                return null;
685:            }
686:
687:            public Time getTime(String parameterName, Calendar calendar)
688:                    throws SQLException {
689:                return getTime(parameterName);
690:            }
691:
692:            public Timestamp getTimestamp(String parameterName)
693:                    throws SQLException {
694:                Object value = getObject(parameterName);
695:                if (null != value) {
696:                    if (value instanceof  Timestamp)
697:                        return (Timestamp) value;
698:                    return Timestamp.valueOf(value.toString());
699:                }
700:                return null;
701:            }
702:
703:            public Timestamp getTimestamp(String parameterName,
704:                    Calendar calendar) throws SQLException {
705:                return getTimestamp(parameterName);
706:            }
707:
708:            /*public RowId getRowId(String parameterName) throws SQLException
709:            {
710:                Object value = getObject(parameterName);
711:                if(null != value)
712:                {
713:                    if(value instanceof RowId) return (RowId)value;
714:                    return new MockRowId(getBytes(parameterName));
715:                }
716:                return null;
717:            }*/
718:
719:            public void setByte(String parameterName, byte byteValue)
720:                    throws SQLException {
721:                setObject(parameterName, new Byte(byteValue));
722:            }
723:
724:            public void setDouble(String parameterName, double doubleValue)
725:                    throws SQLException {
726:                setObject(parameterName, new Double(doubleValue));
727:            }
728:
729:            public void setFloat(String parameterName, float floatValue)
730:                    throws SQLException {
731:                setObject(parameterName, new Float(floatValue));
732:            }
733:
734:            public void setInt(String parameterName, int intValue)
735:                    throws SQLException {
736:                setObject(parameterName, new Integer(intValue));
737:            }
738:
739:            public void setNull(String parameterName, int sqlType)
740:                    throws SQLException {
741:                setObject(parameterName, null);
742:            }
743:
744:            public void setNull(String parameterName, int sqlType,
745:                    String typeName) throws SQLException {
746:                setNull(parameterName, sqlType);
747:            }
748:
749:            public void setLong(String parameterName, long longValue)
750:                    throws SQLException {
751:                setObject(parameterName, new Long(longValue));
752:            }
753:
754:            public void setShort(String parameterName, short shortValue)
755:                    throws SQLException {
756:                setObject(parameterName, new Short(shortValue));
757:            }
758:
759:            public void setBoolean(String parameterName, boolean booleanValue)
760:                    throws SQLException {
761:                setObject(parameterName, new Boolean(booleanValue));
762:            }
763:
764:            public void setBytes(String parameterName, byte[] byteArray)
765:                    throws SQLException {
766:                setObject(parameterName, byteArray);
767:            }
768:
769:            public void setAsciiStream(String parameterName, InputStream stream)
770:                    throws SQLException {
771:                setBinaryStream(parameterName, stream);
772:            }
773:
774:            public void setAsciiStream(String parameterName,
775:                    InputStream stream, int length) throws SQLException {
776:                setBinaryStream(parameterName, stream, length);
777:            }
778:
779:            public void setAsciiStream(String parameterName,
780:                    InputStream stream, long length) throws SQLException {
781:                setBinaryStream(parameterName, stream, length);
782:            }
783:
784:            public void setBinaryStream(String parameterName, InputStream stream)
785:                    throws SQLException {
786:                byte[] data = StreamUtil.getStreamAsByteArray(stream);
787:                setObject(parameterName, new ByteArrayInputStream(data));
788:            }
789:
790:            public void setBinaryStream(String parameterName,
791:                    InputStream stream, int length) throws SQLException {
792:                byte[] data = StreamUtil.getStreamAsByteArray(stream, length);
793:                setObject(parameterName, new ByteArrayInputStream(data));
794:            }
795:
796:            public void setBinaryStream(String parameterName,
797:                    InputStream stream, long length) throws SQLException {
798:                setBinaryStream(parameterName, stream, (int) length);
799:            }
800:
801:            public void setCharacterStream(String parameterName, Reader reader)
802:                    throws SQLException {
803:                String data = StreamUtil.getReaderAsString(reader);
804:                setObject(parameterName, new StringReader(data));
805:            }
806:
807:            public void setCharacterStream(String parameterName, Reader reader,
808:                    int length) throws SQLException {
809:                String data = StreamUtil.getReaderAsString(reader, length);
810:                setObject(parameterName, new StringReader(data));
811:            }
812:
813:            public void setCharacterStream(String parameterName, Reader reader,
814:                    long length) throws SQLException {
815:                setCharacterStream(parameterName, reader, (int) length);
816:            }
817:
818:            public void setNCharacterStream(String parameterName, Reader reader)
819:                    throws SQLException {
820:                setCharacterStream(parameterName, reader);
821:            }
822:
823:            public void setNCharacterStream(String parameterName,
824:                    Reader reader, long length) throws SQLException {
825:                setCharacterStream(parameterName, reader, length);
826:            }
827:
828:            public void setBlob(String parameterName, Blob blob)
829:                    throws SQLException {
830:                setObject(parameterName, blob);
831:            }
832:
833:            public void setBlob(String parameterName, InputStream inputStream)
834:                    throws SQLException {
835:                byte[] data = StreamUtil.getStreamAsByteArray(inputStream);
836:                setBlob(parameterName, new MockBlob(data));
837:            }
838:
839:            public void setBlob(String parameterName, InputStream inputStream,
840:                    long length) throws SQLException {
841:                byte[] data = StreamUtil.getStreamAsByteArray(inputStream,
842:                        (int) length);
843:                setBlob(parameterName, new MockBlob(data));
844:            }
845:
846:            public void setClob(String parameterName, Clob clob)
847:                    throws SQLException {
848:                setObject(parameterName, clob);
849:            }
850:
851:            public void setClob(String parameterName, Reader reader)
852:                    throws SQLException {
853:                String data = StreamUtil.getReaderAsString(reader);
854:                setClob(parameterName, new MockClob(data));
855:            }
856:
857:            public void setClob(String parameterName, Reader reader, long length)
858:                    throws SQLException {
859:                String data = StreamUtil
860:                        .getReaderAsString(reader, (int) length);
861:                setClob(parameterName, new MockClob(data));
862:            }
863:
864:            /*public void setNClob(String parameterName, NClob nClob) throws SQLException
865:            {
866:                setObject(parameterName, nClob);
867:            }*/
868:
869:            /*public void setNClob(String parameterName, Reader reader) throws SQLException
870:            {
871:                String data = StreamUtil.getReaderAsString(reader);
872:                setNClob(parameterName, new MockNClob(data));
873:            }*/
874:
875:            /*public void setNClob(String parameterName, Reader reader, long length) throws SQLException
876:            {
877:                String data = StreamUtil.getReaderAsString(reader, (int)length);
878:                setNClob(parameterName, new MockNClob(data));
879:            }*/
880:
881:            /*public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException
882:            {
883:                setObject(parameterName, xmlObject);
884:            }*/
885:
886:            public void setString(String parameterName, String string)
887:                    throws SQLException {
888:                setObject(parameterName, string);
889:            }
890:
891:            public void setNString(String parameterName, String string)
892:                    throws SQLException {
893:                setObject(parameterName, string);
894:            }
895:
896:            public void setBigDecimal(String parameterName,
897:                    BigDecimal bigDecimal) throws SQLException {
898:                setObject(parameterName, bigDecimal);
899:            }
900:
901:            public void setURL(String parameterName, URL url)
902:                    throws SQLException {
903:                setObject(parameterName, url);
904:            }
905:
906:            public void setDate(String parameterName, Date date)
907:                    throws SQLException {
908:                setObject(parameterName, date);
909:            }
910:
911:            public void setTime(String parameterName, Time time)
912:                    throws SQLException {
913:                setObject(parameterName, time);
914:            }
915:
916:            public void setTimestamp(String parameterName, Timestamp timestamp)
917:                    throws SQLException {
918:                setObject(parameterName, timestamp);
919:            }
920:
921:            public void setDate(String parameterName, Date date,
922:                    Calendar calendar) throws SQLException {
923:                setDate(parameterName, date);
924:            }
925:
926:            public void setTime(String parameterName, Time time,
927:                    Calendar calendar) throws SQLException {
928:                setTime(parameterName, time);
929:            }
930:
931:            public void setTimestamp(String parameterName, Timestamp timestamp,
932:                    Calendar calendar) throws SQLException {
933:                setTimestamp(parameterName, timestamp);
934:            }
935:
936:            /*public void setRowId(String parameterName, RowId rowId) throws SQLException
937:            {
938:                setObject(parameterName, rowId);
939:            }*/
940:
941:            public void setObject(String parameterName, Object object)
942:                    throws SQLException {
943:                paramObjects.put(parameterName, object);
944:            }
945:
946:            public void setObject(String parameterName, Object object,
947:                    int targetSqlType) throws SQLException {
948:                setObject(parameterName, object);
949:            }
950:
951:            public void setObject(String parameterName, Object object,
952:                    int targetSqlType, int scale) throws SQLException {
953:                setObject(parameterName, object);
954:            }
955:
956:            private Map getOutParameterMap() {
957:                Map outParameter = resultSetHandler.getOutParameter(getSQL(),
958:                        getParameterMap());
959:                if (null == outParameter) {
960:                    outParameter = resultSetHandler.getOutParameter(getSQL());
961:                }
962:                if (null == outParameter) {
963:                    outParameter = resultSetHandler.getGlobalOutParameter();
964:                }
965:                if (resultSetHandler.getMustRegisterOutParameters()) {
966:                    return filterNotRegisteredParameters(outParameter);
967:                }
968:                return outParameter;
969:            }
970:
971:            private Map filterNotRegisteredParameters(Map outParameter) {
972:                Map filteredMap = new HashMap();
973:                Iterator keys = outParameter.keySet().iterator();
974:                while (keys.hasNext()) {
975:                    Object nextKey = keys.next();
976:                    if (registeredOutParameterSetIndexed.contains(nextKey)
977:                            || registeredOutParameterSetNamed.contains(nextKey)) {
978:                        filteredMap.put(nextKey, outParameter.get(nextKey));
979:                    }
980:                }
981:                return Collections.unmodifiableMap(filteredMap);
982:            }
983:
984:            /*private NClob getNClobFromClob(Clob clobValue) throws SQLException
985:            {
986:                return new MockNClob(clobValue.getSubString(1, (int)clobValue.length()));
987:            }*/
988:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.