01: /*
02: * Copyright 2006 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
07: * BI Platform. The Initial Developer is Pentaho Corporation.
08: *
09: * 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;
20: import java.sql.SQLException;
21:
22: import org.pentaho.commons.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 nativeMetaData = null;
32:
33: private Object[][] columnHeaders;
34:
35: public SQLMetaData(ResultSetMetaData nativeMetaData) {
36: this .nativeMetaData = nativeMetaData;
37: }
38:
39: /*
40: * (non-Javadoc)
41: *
42: * @see org.pentaho.connection.IPentahoMetaData#getColumnHeaders()
43: *
44: * In the case of SQL data there is only 1 row
45: */
46: public Object[][] getColumnHeaders() {
47: if (columnHeaders == null) {
48: try {
49: int rowCount = 1;
50: int columnCount = nativeMetaData.getColumnCount();
51: Object[][] result = new Object[rowCount][columnCount];
52: for (int column = 0; column < columnCount; column++) {
53: result[0][column] = nativeMetaData
54: .getColumnLabel(column + 1);
55: }
56: this .columnHeaders = result;
57: } catch (SQLException e) {
58: // TODO Auto-generated catch block
59: e.printStackTrace();
60: }
61: }
62: return columnHeaders;
63: }
64:
65: public int getColumnCount() {
66: try {
67: return nativeMetaData.getColumnCount();
68: } catch (SQLException ex) {
69: ex.printStackTrace();
70: }
71: // TODO: Ripple the exception out of this package
72: return -1;
73: }
74:
75: public Object[][] getRowHeaders() {
76: return null;
77: }
78: }
|