Source Code Cross Referenced for ResultSetPropertyResolver.java in  » IDE-Netbeans » visualweb.api.designer » com » sun » rave » web » ui » faces » 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 » IDE Netbeans » visualweb.api.designer » com.sun.rave.web.ui.faces 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:        package com.sun.rave.web.ui.faces;
042:
043:        import java.sql.ResultSet;
044:        import java.sql.ResultSetMetaData;
045:        import java.sql.SQLException;
046:        import java.util.ArrayList;
047:        import java.util.List;
048:        import javax.faces.FacesException;
049:        import javax.faces.el.EvaluationException;
050:        import javax.faces.el.PropertyNotFoundException;
051:        import javax.faces.el.PropertyResolver;
052:        import javax.faces.model.SelectItem;
053:        import javax.sql.RowSet;
054:        import com.sun.rave.web.ui.model.Option;
055:
056:        /**
057:         * This custom Property Resolver handles the special case of resolving ResultSet columns into editable
058:         * data values.  This also enables binding to a SelectItem array from a ResultSet for filling lists
059:         * and dropdowns.
060:         *
061:         * These expressions are supported:
062:         *
063:         * #{...myResultSet.currentRow['COLUMN_NAME']}
064:         * --> binds to the 'COLUMN_NAME' column of the current row of the ResultSet
065:         *
066:         * #(...myResultSet.selectItems['COLUMN_NAME'])
067:         * #(...myResultSet.selectItems['VALUE_COLUMN_NAME,LABEL_COLUMN_NAME'])
068:         * #(...myResultSet.selectItems['VALUE_COLUMN_NAME,LABEL_COLUMN_NAME,DESC_COLUMN_NAME'])
069:         * --> binds to an array of SelectItem generated by iterating through the ResultSet
070:         *
071:         * #(...myResultSet.options['COLUMN_NAME'])
072:         * #(...myResultSet.options['VALUE_COLUMN_NAME,LABEL_COLUMN_NAME'])
073:         * #(...myResultSet.options['VALUE_COLUMN_NAME,LABEL_COLUMN_NAME,DESC_COLUMN_NAME'])
074:         * --> binds to an array of Options generated by iterating through the ResultSet
075:         */
076:        public class ResultSetPropertyResolver extends PropertyResolver {
077:
078:            public static final String CURRENT_ROW_KEY = "currentRow"; // NOI18N
079:            public static final String SELECT_ITEMS_KEY = "selectItems"; // NOI18N
080:            public static final String OPTIONS_KEY = "options"; // NOI18N
081:
082:            protected PropertyResolver nested;
083:
084:            public ResultSetPropertyResolver(PropertyResolver nested) {
085:                this .nested = nested;
086:            }
087:
088:            public Object getValue(Object base, Object property)
089:                    throws EvaluationException, PropertyNotFoundException {
090:                if (base instanceof  ResultSet) {
091:                    if (CURRENT_ROW_KEY.equals(property)) {
092:                        return new RowData((ResultSet) base);
093:                    }
094:                    if (SELECT_ITEMS_KEY.equals(property)) {
095:                        return new SelectItemsData((ResultSet) base);
096:                    }
097:                    if (OPTIONS_KEY.equals(property)) {
098:                        return new OptionsData((ResultSet) base);
099:                    }
100:                } else if (base instanceof  RowData) {
101:                    return ((RowData) base).getData(property.toString());
102:                } else if (base instanceof  SelectItemsData) {
103:                    return ((SelectItemsData) base).getSelectItems(property
104:                            .toString());
105:                } else if (base instanceof  OptionsData) {
106:                    return ((OptionsData) base).getOptions(property.toString());
107:                }
108:                Object o = nested.getValue(base, property);
109:                if (o instanceof  ResultSet) {
110:                    initResultSet((ResultSet) o);
111:                }
112:                return o;
113:            }
114:
115:            public Object getValue(Object base, int index)
116:                    throws EvaluationException, PropertyNotFoundException {
117:                Object o = nested.getValue(base, index);
118:                if (o instanceof  ResultSet) {
119:                    initResultSet((ResultSet) o);
120:                }
121:                return o;
122:            }
123:
124:            public void setValue(Object base, Object property, Object value)
125:                    throws EvaluationException, PropertyNotFoundException {
126:                if (base instanceof  RowData) {
127:                    ((RowData) base).setData(property.toString(), value);
128:                    return;
129:                }
130:                nested.setValue(base, property, value);
131:            }
132:
133:            public void setValue(Object base, int index, Object value)
134:                    throws EvaluationException, PropertyNotFoundException {
135:                nested.setValue(base, index, value);
136:            }
137:
138:            public boolean isReadOnly(Object base, Object property)
139:                    throws EvaluationException, PropertyNotFoundException {
140:                if (base instanceof  ResultSet
141:                        && (CURRENT_ROW_KEY.equals(property)
142:                                || SELECT_ITEMS_KEY.equals(property) || OPTIONS_KEY
143:                                .equals(property))) {
144:                    return true;
145:                } else if (base instanceof  RowData) {
146:                    return false;
147:                } else if (base instanceof  SelectItemsData) {
148:                    return true;
149:                } else if (base instanceof  OptionsData) {
150:                    return true;
151:                }
152:                return nested.isReadOnly(base, property);
153:            }
154:
155:            public boolean isReadOnly(Object base, int index)
156:                    throws EvaluationException, PropertyNotFoundException {
157:                return nested.isReadOnly(base, index);
158:            }
159:
160:            public Class getType(Object base, Object property)
161:                    throws EvaluationException, PropertyNotFoundException {
162:                if (base instanceof  ResultSet) {
163:                    if (CURRENT_ROW_KEY.equals(property)) {
164:                        return RowData.class;
165:                    }
166:                    if (SELECT_ITEMS_KEY.equals(property)) {
167:                        return SelectItemsData.class;
168:                    }
169:                    if (OPTIONS_KEY.equals(property)) {
170:                        return OptionsData.class;
171:                    }
172:                } else if (base instanceof  RowData) {
173:                    return ((RowData) base).getDataType(property.toString());
174:                } else if (base instanceof  SelectItemsData) {
175:                    return ArrayList.class;
176:                } else if (base instanceof  OptionsData) {
177:                    return ArrayList.class;
178:                }
179:                return nested.getType(base, property);
180:            }
181:
182:            public Class getType(Object base, int index)
183:                    throws EvaluationException, PropertyNotFoundException {
184:                return nested.getType(base, index);
185:            }
186:
187:            ////////////////////////////////////////////////////////////////////////////////////////////////
188:            ////////////////////////////////////////////////////////////////////////////////////////////////
189:
190:            public class RowData {
191:
192:                protected ResultSet resultSet;
193:                protected ResultSetMetaData metadata;
194:                protected ArrayList columnNameList;
195:
196:                public RowData(ResultSet resultSet) {
197:                    this .resultSet = resultSet;
198:                    try {
199:                        metadata = resultSet.getMetaData();
200:                        columnNameList = new ArrayList();
201:                        int cols = metadata.getColumnCount();
202:                        for (int i = 1; i <= cols; i++) {
203:                            columnNameList.add(metadata.getColumnName(i));
204:                        }
205:                    } catch (SQLException x) {
206:                        throw new FacesException(x);
207:                    }
208:                }
209:
210:                public Class getDataType(String column)
211:                        throws PropertyNotFoundException {
212:                    if (!columnNameList.contains(column)) {
213:                        throw new PropertyNotFoundException(
214:                                "Invalid column name: " + column); //NOI18N
215:                    }
216:                    try {
217:                        return Class.forName(metadata
218:                                .getColumnClassName(columnNameList
219:                                        .indexOf(column) + 1));
220:                    } catch (Exception x) {
221:                        return null;
222:                    }
223:                }
224:
225:                public Object getData(String column)
226:                        throws PropertyNotFoundException {
227:                    if (!columnNameList.contains(column)) {
228:                        throw new PropertyNotFoundException(
229:                                "Invalid column name: " + column);
230:                    }
231:                    try {
232:                        //                if (Beans.isDesignTime()) {
233:                        //                    return getFakeData(metadata, column);
234:                        //                } else {
235:                        initResultSet(resultSet);
236:                        return resultSet.getObject(column);
237:                        //                }
238:                    } catch (SQLException e) {
239:                        throw new FacesException(e);
240:                    }
241:                }
242:
243:                public Object setData(String column, Object value)
244:                        throws PropertyNotFoundException {
245:                    if (!columnNameList.contains(column)) {
246:                        throw new PropertyNotFoundException(
247:                                "Invalid column name: " + column);
248:                    }
249:                    try {
250:                        Object previous;
251:                        //                if (!Beans.isDesignTime()) {
252:                        initResultSet(resultSet);
253:                        previous = resultSet.getObject(column);
254:                        if ((previous == null) && (value == null)) {
255:                            return previous;
256:                        } else if ((previous != null) && (value != null)
257:                                && previous.equals(value)) {
258:                            return previous;
259:                        }
260:                        resultSet.updateObject(column, value);
261:                        return previous;
262:                        //                } else {
263:                        //                    previous = getFakeData(metadata, column);
264:                        //                    return previous;
265:                        //                }
266:                    } catch (SQLException e) {
267:                        throw new FacesException(e);
268:                    }
269:                }
270:            }
271:
272:            ////////////////////////////////////////////////////////////////////////////////////////////////
273:            ////////////////////////////////////////////////////////////////////////////////////////////////
274:
275:            public class SelectItemsData {
276:                protected ResultSet resultSet;
277:                protected ResultSetMetaData metadata;
278:
279:                public SelectItemsData(ResultSet resultSet) {
280:                    this .resultSet = resultSet;
281:                    try {
282:                        this .metadata = resultSet.getMetaData();
283:                    } catch (SQLException x) {
284:                        throw new FacesException(x);
285:                    }
286:                }
287:
288:                public Object getSelectItems(String columns) {
289:                    /*
290:                     * returns a List of SelectItem(s)
291:                     *
292:                     * (examples based on PERSON database table):
293:                     *
294:                     *  "NAME" -->
295:                     *  returns a List filled with SelectItem objects,
296:                     *  with the 'itemValue' set to NAME's values
297:                     *
298:                     *  "PERSONID,NAME" -->
299:                     *  returns a List filled with SelectItem objects,
300:                     *  with the 'itemValue' set to PERSONID's values,
301:                     *  and the 'itemLabel' set to NAME's values
302:                     *
303:                     *  "PERSONID,NAME,JOBTITLE" -->
304:                     *  returns a List filled with SelectItem objects,
305:                     *  with the 'itemValue' set to PERSONID's values,
306:                     *  the 'itemLabel' set to NAME's values,
307:                     *  and the 'itemDescription' set to JOBTITLE's values
308:                     *
309:                     * Any cases that are out-of-scope throw IllegalArgumentException
310:                     */
311:                    String itemValueName = null;
312:                    String itemLabelName = null;
313:                    String itemDescriptionName = null;
314:
315:                    //MBOHM fix 5086833
316:                    //could have internal commas, in say, selectItems['employee.employeeid, employee.firstname || \' , \' || employee.lastname']
317:                    List cols = new ArrayList();
318:                    String col;
319:                    boolean quoteOpen = false;
320:                    int currStart = 0;
321:                    for (int i = 0; i < columns.length(); i++) {
322:                        char c = columns.charAt(i);
323:                        if (c == '\'') {
324:                            quoteOpen = !quoteOpen;
325:                        } else if (c == ',' && !quoteOpen) {
326:                            col = columns.substring(currStart, i);
327:                            if (col.length() > 0) {
328:                                cols.add(col);
329:                            }
330:                            currStart = i + 1;
331:                        }
332:                    }
333:                    //get the remaining stuff after the last period
334:                    if (currStart < columns.length()) {
335:                        col = columns.substring(currStart);
336:                        cols.add(col);
337:                    }
338:
339:                    //String[] args = columns.split(","); //NOI18N
340:                    String[] args = (String[]) cols.toArray(new String[cols
341:                            .size()]);
342:                    if (args.length < 1) {
343:                        throw new IllegalArgumentException();
344:                    }
345:                    itemValueName = args[0];
346:                    if (args.length > 1) {
347:                        itemLabelName = args[1];
348:                    }
349:                    if (args.length > 2) {
350:                        itemDescriptionName = args[2];
351:                    }
352:
353:                    ArrayList list = new ArrayList();
354:                    //            if (!Beans.isDesignTime()) {
355:                    try {
356:                        initResultSet(resultSet);
357:                        int resultSetIndexSave = resultSet.getRow();
358:                        resultSet.first();
359:                        while (!resultSet.isAfterLast()) {
360:                            if (itemLabelName == null) {
361:                                list.add(new SelectItem(resultSet
362:                                        .getObject(itemValueName)));
363:                            } else if (itemDescriptionName == null) {
364:                                list.add(new SelectItem(resultSet
365:                                        .getObject(itemValueName), resultSet
366:                                        .getObject(itemLabelName).toString()));
367:                            } else {
368:                                list.add(new SelectItem(resultSet
369:                                        .getObject(itemValueName), resultSet
370:                                        .getObject(itemLabelName).toString(),
371:                                        resultSet
372:                                                .getObject(itemDescriptionName)
373:                                                .toString()));
374:                            }
375:                            resultSet.next();
376:                        }
377:                        if (resultSetIndexSave > 0) {
378:                            resultSet.absolute(resultSetIndexSave);
379:                        } else {
380:                            resultSet.first();
381:                        }
382:                    } catch (SQLException x) {
383:                        x.printStackTrace();
384:                    }
385:                    //            } else {
386:                    //                for (int i = 0; i < 3; i++) {
387:                    //                    try {
388:                    //                        if (itemLabelName == null) {
389:                    //                            list.add(new SelectItem(
390:                    //                                getFakeData(metadata, itemValueName)
391:                    //                                ));
392:                    //                        } else if (itemDescriptionName == null) {
393:                    //                            list.add(new SelectItem(
394:                    //                                getFakeData(metadata, itemValueName),
395:                    //                                getFakeData(metadata, itemLabelName).toString()
396:                    //                                ));
397:                    //                        } else {
398:                    //                            list.add(new SelectItem(
399:                    //                                getFakeData(metadata, itemValueName),
400:                    //                                getFakeData(metadata, itemLabelName).toString(),
401:                    //                                getFakeData(metadata, itemDescriptionName).toString()
402:                    //                                ));
403:                    //                        }
404:                    //                    } catch (SQLException x) {
405:                    //                    }
406:                    //                }
407:                    //            }
408:
409:                    return list;
410:                }
411:
412:            }
413:
414:            ////////////////////////////////////////////////////////////////////////////////////////////////
415:            ////////////////////////////////////////////////////////////////////////////////////////////////
416:
417:            public class OptionsData {
418:                protected ResultSet resultSet;
419:                protected ResultSetMetaData metadata;
420:
421:                public OptionsData(ResultSet resultSet) {
422:                    this .resultSet = resultSet;
423:                    try {
424:                        this .metadata = resultSet.getMetaData();
425:                    } catch (SQLException x) {
426:                        throw new FacesException(x);
427:                    }
428:                }
429:
430:                public Object getOptions(String columns) {
431:                    /*
432:                     * returns a List of Option(s)
433:                     *
434:                     * (examples based on PERSON database table):
435:                     *
436:                     *  "NAME" -->
437:                     *  returns a List filled with Option objects,
438:                     *  with the 'itemValue' set to NAME's values
439:                     *
440:                     *  "PERSONID,NAME" -->
441:                     *  returns a List filled with Option objects,
442:                     *  with the 'itemValue' set to PERSONID's values,
443:                     *  and the 'itemLabel' set to NAME's values
444:                     *
445:                     *  "PERSONID,NAME,JOBTITLE" -->
446:                     *  returns a List filled with Option objects,
447:                     *  with the 'itemValue' set to PERSONID's values,
448:                     *  the 'itemLabel' set to NAME's values,
449:                     *  and the 'itemDescription' set to JOBTITLE's values
450:                     *
451:                     * Any cases that are out-of-scope throw IllegalArgumentException
452:                     */
453:                    String itemValueName = null;
454:                    String itemLabelName = null;
455:                    String itemDescriptionName = null;
456:
457:                    //MBOHM fix 5086833
458:                    //could have internal commas, in say, selectItems['employee.employeeid, employee.firstname || \' , \' || employee.lastname']
459:                    List cols = new ArrayList();
460:                    String col;
461:                    boolean quoteOpen = false;
462:                    int currStart = 0;
463:                    for (int i = 0; i < columns.length(); i++) {
464:                        char c = columns.charAt(i);
465:                        if (c == '\'') {
466:                            quoteOpen = !quoteOpen;
467:                        } else if (c == ',' && !quoteOpen) {
468:                            col = columns.substring(currStart, i);
469:                            if (col.length() > 0) {
470:                                cols.add(col);
471:                            }
472:                            currStart = i + 1;
473:                        }
474:                    }
475:                    //get the remaining stuff after the last period
476:                    if (currStart < columns.length()) {
477:                        col = columns.substring(currStart);
478:                        cols.add(col);
479:                    }
480:
481:                    //String[] args = columns.split(","); //NOI18N
482:                    String[] args = (String[]) cols.toArray(new String[cols
483:                            .size()]);
484:                    if (args.length < 1) {
485:                        throw new IllegalArgumentException();
486:                    }
487:                    itemValueName = args[0];
488:                    if (args.length > 1) {
489:                        itemLabelName = args[1];
490:                    }
491:                    if (args.length > 2) {
492:                        itemDescriptionName = args[2];
493:                    }
494:
495:                    ArrayList list = new ArrayList();
496:                    //            if (!Beans.isDesignTime()) {
497:                    try {
498:                        initResultSet(resultSet);
499:                        int resultSetIndexSave = resultSet.getRow();
500:                        resultSet.first();
501:                        while (!resultSet.isAfterLast()) {
502:                            if (itemLabelName == null) {
503:                                list.add(new Option(resultSet
504:                                        .getObject(itemValueName)));
505:                            } else if (itemDescriptionName == null) {
506:                                list.add(new Option(resultSet
507:                                        .getObject(itemValueName), resultSet
508:                                        .getObject(itemLabelName).toString()));
509:                            } else {
510:                                list.add(new Option(resultSet
511:                                        .getObject(itemValueName), resultSet
512:                                        .getObject(itemLabelName).toString(),
513:                                        resultSet
514:                                                .getObject(itemDescriptionName)
515:                                                .toString()));
516:                            }
517:                            resultSet.next();
518:                        }
519:                        if (resultSetIndexSave > 0) {
520:                            resultSet.absolute(resultSetIndexSave);
521:                        } else {
522:                            resultSet.first();
523:                        }
524:                    } catch (SQLException x) {
525:                        x.printStackTrace();
526:                    }
527:                    //            } else {
528:                    //                for (int i = 0; i < 3; i++) {
529:                    //                    try {
530:                    //                        if (itemLabelName == null) {
531:                    //                            list.add(new Option(
532:                    //                                getFakeData(metadata, itemValueName)
533:                    //                                ));
534:                    //                        } else if (itemDescriptionName == null) {
535:                    //                            list.add(new Option(
536:                    //                                getFakeData(metadata, itemValueName),
537:                    //                                getFakeData(metadata, itemLabelName).toString()
538:                    //                                ));
539:                    //                        } else {
540:                    //                            list.add(new Option(
541:                    //                                getFakeData(metadata, itemValueName),
542:                    //                                getFakeData(metadata, itemLabelName).toString(),
543:                    //                                getFakeData(metadata, itemDescriptionName).toString()
544:                    //                                ));
545:                    //                        }
546:                    //                    } catch (SQLException x) {
547:                    //                    }
548:                    //                }
549:                    //            }
550:
551:                    return list;
552:                }
553:
554:            }
555:
556:            ////////////////////////////////////////////////////////////////////////////////////////////////
557:            ////////////////////////////////////////////////////////////////////////////////////////////////
558:
559:            public static void initResultSet(ResultSet resultSet) {
560:                try {
561:                    if (resultSet.isBeforeFirst()) {
562:                        try {
563:                            resultSet.first();
564:                        } catch (SQLException x) {
565:                        }
566:                    }
567:                } catch (SQLException x) {
568:                    if (resultSet instanceof  RowSet) {
569:                        try {
570:                            ((RowSet) resultSet).execute();
571:                            resultSet.first();
572:                        } catch (SQLException x2) {
573:                        }
574:                    }
575:                }
576:            }
577:
578:            //    ////////////////////////////////////////////////////////////////////////////////////////////////
579:            //    ////////////////////////////////////////////////////////////////////////////////////////////////
580:            //
581:            //    private static Object getFakeData(ResultSetMetaData rsmd, String colName) throws SQLException {
582:            //
583:            //        int colIndex = -1;
584:            //        for (int i = 1; i <= rsmd.getColumnCount(); i++) {
585:            //            if (rsmd.getColumnName(i).equals(colName)) {
586:            //                colIndex = i;
587:            //                break;
588:            //            }
589:            //        }
590:            //        switch (rsmd.getColumnType(colIndex)) {
591:            //            case Types.ARRAY:
592:            //                return new java.sql.Array() {
593:            //                    public Object getArray() {
594:            //                        return null;
595:            //                    }
596:            //
597:            //                    public Object getArray(long index, int count) {
598:            //                        return null;
599:            //                    }
600:            //
601:            //                    public Object getArray(long index, int count, Map map) {
602:            //                        return null;
603:            //                    }
604:            //
605:            //                    public Object getArray(Map map) {
606:            //                        return null;
607:            //                    }
608:            //
609:            //                    public int getBaseType() {
610:            //                        return Types.CHAR;
611:            //                    }
612:            //
613:            //                    public String getBaseTypeName() {
614:            //                        return "CHAR"; //NOI18N
615:            //                    }
616:            //
617:            //                    public ResultSet getResultSet() {
618:            //                        return null;
619:            //                    }
620:            //
621:            //                    public ResultSet getResultSet(long index, int count) {
622:            //                        return null;
623:            //                    }
624:            //
625:            //                    public ResultSet getResultSet(long index, int count, Map map) {
626:            //                        return null;
627:            //                    }
628:            //
629:            //                    public ResultSet getResultSet(Map map) {
630:            //                        return null;
631:            //                    }
632:            //                }
633:            //                ;
634:            //            case Types.BIGINT:
635:            //
636:            //                //return new Long(rowIndex);
637:            //                return new Long(123);
638:            //            case Types.BINARY:
639:            //                return new byte[] {
640:            //                    1, 2, 3, 4, 5};
641:            //            case Types.BIT:
642:            //                return new Boolean(true);
643:            //            case Types.BLOB:
644:            //                return new javax.sql.rowset.serial.SerialBlob(new byte[] {
645:            //                    1, 2, 3, 4, 5});
646:            //            case Types.BOOLEAN:
647:            //                return new Boolean(true);
648:            //            case Types.CHAR:
649:            //
650:            //                //return new String(colName + rowIndex);
651:            //                return new String("abc"); //NOI18N
652:            //            case Types.CLOB:
653:            //                return new javax.sql.rowset.serial.SerialClob(
654:            //                    "abcdefghijklmnopqrstuvwxyz".toCharArray());
655:            //            case Types.DATALINK:
656:            //                try {
657:            //                    return new java.net.URL("http://www.sun.com"); //NOI18N
658:            //                } catch (java.net.MalformedURLException e) {
659:            //                    return null;
660:            //                }
661:            //                case Types.DATE:
662:            //                    return new java.sql.Date(new java.util.Date().getTime());
663:            //            case Types.DECIMAL:
664:            //                return new java.math.BigDecimal(java.math.BigInteger.ONE);
665:            //            case Types.DISTINCT:
666:            //                return null;
667:            //            case Types.DOUBLE:
668:            //
669:            //                //return new Double(rowIndex);
670:            //                return new Double(123);
671:            //            case Types.FLOAT:
672:            //
673:            //                //return new Double(rowIndex);
674:            //                return new Double(123);
675:            //            case Types.INTEGER:
676:            //
677:            //                //return new Integer(rowIndex);
678:            //                return new Integer(123);
679:            //            case Types.JAVA_OBJECT:
680:            //
681:            //                //return new String(colName + "_" + rowIndex);  //NOI18N
682:            //                return new String("abc"); //NOI18N
683:            //            case Types.LONGVARBINARY:
684:            //                return new byte[] {
685:            //                    1, 2, 3, 4, 5};
686:            //            case Types.LONGVARCHAR:
687:            //
688:            //                //return new String(colName + "_" + rowIndex); //NOI18N
689:            //                return new String("abc"); //NOI18N
690:            //            case Types.NULL:
691:            //                return null;
692:            //            case Types.NUMERIC:
693:            //                return new java.math.BigDecimal(java.math.BigInteger.ONE);
694:            //            case Types.OTHER:
695:            //                return null;
696:            //            case Types.REAL:
697:            //
698:            //                //return new Float(rowIndex);
699:            //                return new Float(123);
700:            //            case Types.REF:
701:            //                return new java.sql.Ref() {
702:            //                    private Object data = new String("abc"); //NOI18N
703:            //                    public String getBaseTypeName() {
704:            //                        return "CHAR"; //NOI18N
705:            //                    }
706:            //
707:            //                    public Object getObject() {
708:            //                        return data;
709:            //                    }
710:            //
711:            //                    public Object getObject(Map map) {
712:            //                        return data;
713:            //                    }
714:            //
715:            //                    public void setObject(Object value) {
716:            //                        data = value;
717:            //                    }
718:            //                }
719:            //                ;
720:            //            case Types.SMALLINT:
721:            //
722:            //                //return new Short((short)rowIndex);
723:            //                return new Short((short)123);
724:            //            case Types.STRUCT:
725:            //                return new java.sql.Struct() {
726:            //                    private String[] data = {
727:            //                        "abc", "def", "ghi"}; //NOI18N
728:            //                    public Object[] getAttributes() {
729:            //                        return data;
730:            //                    }
731:            //
732:            //                    public Object[] getAttributes(Map map) {
733:            //                        return data;
734:            //                    }
735:            //
736:            //                    public String getSQLTypeName() {
737:            //                        return "CHAR"; //NOI18N
738:            //                    }
739:            //                }
740:            //                ;
741:            //            case Types.TIME:
742:            //                return new java.sql.Time(new java.util.Date().getTime());
743:            //            case Types.TIMESTAMP:
744:            //                return new java.sql.Timestamp(new java.util.Date().getTime());
745:            //            case Types.TINYINT:
746:            //
747:            //                //return new Byte((byte)rowIndex);
748:            //                return new Byte((byte)123);
749:            //            case Types.VARBINARY:
750:            //                return new byte[] {
751:            //                    1, 2, 3, 4, 5};
752:            //            case Types.VARCHAR:
753:            //
754:            //                //return new String(colName + "_" + rowIndex); //NOI18N
755:            //                return new String("abc"); //NOI18N
756:            //        }
757:            //        return null;
758:            //    }
759:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.