KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > data > connection > sql > SQLMetaData


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * Created Sep 7, 2005
14  * @author wseyler
15  */

16
17 package org.pentaho.data.connection.sql;
18
19 import java.sql.ResultSetMetaData JavaDoc;
20 import java.sql.SQLException JavaDoc;
21
22 import org.pentaho.core.connection.AbstractPentahoMetaData;
23
24 /**
25  * @author wseyler
26  *
27  * TODO To change the template for this generated type comment go to Window -
28  * Preferences - Java - Code Style - Code Templates
29  */

30 public class SQLMetaData extends AbstractPentahoMetaData {
31     ResultSetMetaData JavaDoc nativeMetaData = null;
32     private Object JavaDoc[][] columnHeaders;
33
34     public SQLMetaData(ResultSetMetaData JavaDoc nativeMetaData) {
35         this.nativeMetaData = nativeMetaData;
36     }
37
38     /*
39      * (non-Javadoc)
40      *
41      * @see org.pentaho.connection.IPentahoMetaData#getColumnHeaders()
42      *
43      * In the case of SQL data there is only 1 row
44      */

45     public Object JavaDoc[][] getColumnHeaders() {
46       if (columnHeaders == null) {
47         try {
48             int rowCount = 1;
49             int columnCount = nativeMetaData.getColumnCount();
50             Object JavaDoc[][] result = new Object JavaDoc[rowCount][columnCount];
51             for (int column = 0; column < columnCount; column++) {
52                 result[0][column] = nativeMetaData.getColumnLabel(column + 1);
53             }
54             this.columnHeaders = result;
55         } catch (SQLException JavaDoc e) {
56             // TODO Auto-generated catch block
57
e.printStackTrace();
58         }
59       }
60       return columnHeaders;
61     }
62
63     public int getColumnCount() {
64         try {
65             return nativeMetaData.getColumnCount();
66         } catch (SQLException JavaDoc ex) {
67             ex.printStackTrace();
68         }
69         // TODO: Ripple the exception out of this package
70
return -1;
71     }
72     
73     public Object JavaDoc[][] getRowHeaders() {
74       return null;
75     }
76 }
77
Popular Tags