1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 package org.apache.openoffice.comp.sdbc.dbtools.util;
22 
23 import com.sun.star.lib.uno.helper.WeakBase;
24 import com.sun.star.sdbc.SQLException;
25 import com.sun.star.sdbc.XResultSetMetaData;
26 
27 public class CustomResultSetMetaData extends WeakBase implements XResultSetMetaData {
28     private CustomColumn[] columns;
29 
CustomResultSetMetaData(CustomColumn[] columns)30     public CustomResultSetMetaData(CustomColumn[] columns) {
31         this.columns = columns;
32     }
33 
getColumn(int i)34     private CustomColumn getColumn(int i) {
35         if (i < 1 || columns.length < i) {
36             return null;
37         }
38         return columns[i-1];
39     }
40 
41     @Override
getCatalogName(int column)42     public String getCatalogName(int column) throws SQLException {
43         CustomColumn customColumn = getColumn(column);
44         if (customColumn != null) {
45             return customColumn.getCatalogName();
46         }
47         return "";
48     }
49 
50     @Override
getColumnCount()51     public int getColumnCount() throws SQLException {
52         return columns.length;
53     }
54 
55     @Override
getColumnDisplaySize(int column)56     public int getColumnDisplaySize(int column) throws SQLException {
57         CustomColumn customColumn = getColumn(column);
58         if (customColumn != null) {
59             return customColumn.getColumnDisplaySize();
60         }
61         return 0;
62     }
63 
64     @Override
getColumnLabel(int column)65     public String getColumnLabel(int column) throws SQLException {
66         CustomColumn customColumn = getColumn(column);
67         if (customColumn != null) {
68             return customColumn.getColumnLabel();
69         }
70         return getColumnName(column);
71     }
72 
73     @Override
getColumnName(int column)74     public String getColumnName(int column) throws SQLException {
75         CustomColumn customColumn = getColumn(column);
76         if (customColumn != null) {
77             return customColumn.getColumnName();
78         }
79         return "";
80     }
81 
82     @Override
getColumnServiceName(int column)83     public String getColumnServiceName(int column) throws SQLException {
84         CustomColumn customColumn = getColumn(column);
85         if (customColumn != null) {
86             return customColumn.getColumnServiceName();
87         }
88         return "";
89     }
90 
91     @Override
getColumnType(int column)92     public int getColumnType(int column) throws SQLException {
93         CustomColumn customColumn = getColumn(column);
94         if (customColumn != null) {
95             return customColumn.getColumnType();
96         }
97         return 1;
98     }
99 
100     @Override
getColumnTypeName(int column)101     public String getColumnTypeName(int column) throws SQLException {
102         CustomColumn customColumn = getColumn(column);
103         if (customColumn != null) {
104             return customColumn.getColumnTypeName();
105         }
106         return "";
107     }
108 
109     @Override
getPrecision(int column)110     public int getPrecision(int column) throws SQLException {
111         CustomColumn customColumn = getColumn(column);
112         if (customColumn != null) {
113             return customColumn.getPrecision();
114         }
115         return 0;
116     }
117 
118     @Override
getScale(int column)119     public int getScale(int column) throws SQLException {
120         CustomColumn customColumn = getColumn(column);
121         if (customColumn != null) {
122             return customColumn.getScale();
123         }
124         return 0;
125     }
126 
127     @Override
getSchemaName(int column)128     public String getSchemaName(int column) throws SQLException {
129         CustomColumn customColumn = getColumn(column);
130         if (customColumn != null) {
131             return customColumn.getSchemaName();
132         }
133         return "";
134     }
135 
136     @Override
getTableName(int column)137     public String getTableName(int column) throws SQLException {
138         CustomColumn customColumn = getColumn(column);
139         if (customColumn != null) {
140             return customColumn.getTableName();
141         }
142         return "";
143     }
144 
145     @Override
isAutoIncrement(int column)146     public boolean isAutoIncrement(int column) throws SQLException {
147         CustomColumn customColumn = getColumn(column);
148         if (customColumn != null) {
149             return customColumn.isAutoIncrement();
150         }
151         return false;
152     }
153 
154     @Override
isCaseSensitive(int column)155     public boolean isCaseSensitive(int column) throws SQLException {
156         CustomColumn customColumn = getColumn(column);
157         if (customColumn != null) {
158             return customColumn.isCaseSensitive();
159         }
160         return true;
161     }
162 
163     @Override
isCurrency(int column)164     public boolean isCurrency(int column) throws SQLException {
165         CustomColumn customColumn = getColumn(column);
166         if (customColumn != null) {
167             return customColumn.isCurrency();
168         }
169         return false;
170     }
171 
172     @Override
isDefinitelyWritable(int column)173     public boolean isDefinitelyWritable(int column) throws SQLException {
174         CustomColumn customColumn = getColumn(column);
175         if (customColumn != null) {
176             return customColumn.isDefinitelyWritable();
177         }
178         return false;
179     }
180 
181     @Override
isNullable(int column)182     public int isNullable(int column) throws SQLException {
183         CustomColumn customColumn = getColumn(column);
184         if (customColumn != null) {
185             return customColumn.getNullable();
186         }
187         return 0;
188     }
189 
190     @Override
isReadOnly(int column)191     public boolean isReadOnly(int column) throws SQLException {
192         CustomColumn customColumn = getColumn(column);
193         if (customColumn != null) {
194             return customColumn.isReadOnly();
195         }
196         return true;
197     }
198 
199     @Override
isSearchable(int column)200     public boolean isSearchable(int column) throws SQLException {
201         CustomColumn customColumn = getColumn(column);
202         if (customColumn != null) {
203             return customColumn.isSearchable();
204         }
205         return true;
206     }
207 
208     @Override
isSigned(int column)209     public boolean isSigned(int column) throws SQLException {
210         CustomColumn customColumn = getColumn(column);
211         if (customColumn != null) {
212             return customColumn.isSigned();
213         }
214         return false;
215     }
216 
217     @Override
isWritable(int column)218     public boolean isWritable(int column) throws SQLException {
219         CustomColumn customColumn = getColumn(column);
220         if (customColumn != null) {
221             return customColumn.isWritable();
222         }
223         return false;
224     }
225 }
226