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 com.sun.star.comp.sdbc; 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 JavaSQLResultSetMetaData extends WeakBase implements XResultSetMetaData { 28 private final JavaSQLConnection connection; 29 private final java.sql.ResultSetMetaData jdbcResultSetMetaData; 30 private int columnCount; 31 JavaSQLResultSetMetaData(JavaSQLConnection connection, java.sql.ResultSetMetaData jdbcResultSetMetaData)32 public JavaSQLResultSetMetaData(JavaSQLConnection connection, java.sql.ResultSetMetaData jdbcResultSetMetaData) { 33 this.connection = connection; 34 this.jdbcResultSetMetaData = jdbcResultSetMetaData; 35 columnCount = -1; 36 } 37 38 @Override getColumnDisplaySize(int column)39 public int getColumnDisplaySize(int column) throws SQLException { 40 try { 41 return jdbcResultSetMetaData.getColumnDisplaySize(column); 42 } catch (java.sql.SQLException jdbcSQLException) { 43 throw Tools.toUnoException(this, jdbcSQLException); 44 } 45 } 46 47 @Override getColumnType(int column)48 public int getColumnType(int column) throws SQLException { 49 try { 50 return jdbcResultSetMetaData.getColumnType(column); 51 } catch (java.sql.SQLException jdbcSQLException) { 52 throw Tools.toUnoException(this, jdbcSQLException); 53 } 54 } 55 56 @Override getColumnCount()57 public int getColumnCount() throws SQLException { 58 try { 59 if (columnCount == -1) { 60 columnCount = jdbcResultSetMetaData.getColumnCount(); 61 } 62 return columnCount; 63 } catch (java.sql.SQLException jdbcSQLException) { 64 throw Tools.toUnoException(this, jdbcSQLException); 65 } 66 } 67 68 @Override isCaseSensitive(int column)69 public boolean isCaseSensitive(int column) throws SQLException { 70 try { 71 return jdbcResultSetMetaData.isCaseSensitive(column); 72 } catch (java.sql.SQLException jdbcSQLException) { 73 throw Tools.toUnoException(this, jdbcSQLException); 74 } 75 } 76 77 @Override getSchemaName(int column)78 public String getSchemaName(int column) throws SQLException { 79 try { 80 String schemaName = jdbcResultSetMetaData.getSchemaName(column); 81 if (schemaName == null) { 82 schemaName = ""; 83 } 84 return schemaName; 85 } catch (java.sql.SQLException jdbcSQLException) { 86 throw Tools.toUnoException(this, jdbcSQLException); 87 } 88 } 89 90 @Override getColumnName(int column)91 public String getColumnName(int column) throws SQLException { 92 try { 93 String columnName = jdbcResultSetMetaData.getColumnName(column); 94 if (columnName == null) { 95 columnName = ""; 96 } 97 return columnName; 98 } catch (java.sql.SQLException jdbcSQLException) { 99 throw Tools.toUnoException(this, jdbcSQLException); 100 } 101 } 102 103 @Override getTableName(int column)104 public String getTableName(int column) throws SQLException { 105 try { 106 String tableName = jdbcResultSetMetaData.getTableName(column); 107 if (tableName == null) { 108 tableName = ""; 109 } 110 return tableName; 111 } catch (java.sql.SQLException jdbcSQLException) { 112 throw Tools.toUnoException(this, jdbcSQLException); 113 } 114 } 115 116 @Override getCatalogName(int column)117 public String getCatalogName(int column) throws SQLException { 118 try { 119 String catalogName = jdbcResultSetMetaData.getCatalogName(column); 120 if (catalogName == null) { 121 catalogName = ""; 122 } 123 return catalogName; 124 } catch (java.sql.SQLException jdbcSQLException) { 125 throw Tools.toUnoException(this, jdbcSQLException); 126 } 127 } 128 129 @Override getColumnTypeName(int column)130 public String getColumnTypeName(int column) throws SQLException { 131 try { 132 String columnTypeName = jdbcResultSetMetaData.getColumnTypeName(column); 133 if (columnTypeName == null) { 134 columnTypeName = ""; 135 } 136 return columnTypeName; 137 } catch (java.sql.SQLException jdbcSQLException) { 138 throw Tools.toUnoException(this, jdbcSQLException); 139 } 140 } 141 142 @Override getColumnLabel(int column)143 public String getColumnLabel(int column) throws SQLException { 144 try { 145 String columnLabel = jdbcResultSetMetaData.getColumnLabel(column); 146 if (columnLabel == null) { 147 columnLabel = ""; 148 } 149 return columnLabel; 150 } catch (java.sql.SQLException jdbcSQLException) { 151 throw Tools.toUnoException(this, jdbcSQLException); 152 } 153 } 154 155 @Override getColumnServiceName(int column)156 public String getColumnServiceName(int column) throws SQLException { 157 try { 158 String columnServiceName = jdbcResultSetMetaData.getColumnClassName(column); 159 if (columnServiceName == null) { 160 columnServiceName = ""; 161 } 162 return columnServiceName; 163 } catch (java.sql.SQLException jdbcSQLException) { 164 throw Tools.toUnoException(this, jdbcSQLException); 165 } 166 } 167 168 @Override isCurrency(int column)169 public boolean isCurrency(int column) throws SQLException { 170 try { 171 if (connection.isIgnoreCurrencyEnabled()) { 172 return false; 173 } 174 return jdbcResultSetMetaData.isCurrency(column); 175 } catch (java.sql.SQLException jdbcSQLException) { 176 throw Tools.toUnoException(this, jdbcSQLException); 177 } 178 } 179 180 @Override isAutoIncrement(int column)181 public boolean isAutoIncrement(int column) throws SQLException { 182 try { 183 return jdbcResultSetMetaData.isAutoIncrement(column); 184 } catch (java.sql.SQLException jdbcSQLException) { 185 throw Tools.toUnoException(this, jdbcSQLException); 186 } 187 } 188 189 @Override isSigned(int column)190 public boolean isSigned(int column) throws SQLException { 191 try { 192 return jdbcResultSetMetaData.isSigned(column); 193 } catch (java.sql.SQLException jdbcSQLException) { 194 throw Tools.toUnoException(this, jdbcSQLException); 195 } 196 } 197 198 @Override getPrecision(int column)199 public int getPrecision(int column) throws SQLException { 200 try { 201 return jdbcResultSetMetaData.getPrecision(column); 202 } catch (java.sql.SQLException jdbcSQLException) { 203 throw Tools.toUnoException(this, jdbcSQLException); 204 } 205 } 206 207 @Override getScale(int column)208 public int getScale(int column) throws SQLException { 209 try { 210 return jdbcResultSetMetaData.getScale(column); 211 } catch (java.sql.SQLException jdbcSQLException) { 212 throw Tools.toUnoException(this, jdbcSQLException); 213 } 214 } 215 216 @Override isNullable(int column)217 public int isNullable(int column) throws SQLException { 218 try { 219 return jdbcResultSetMetaData.isNullable(column); 220 } catch (java.sql.SQLException jdbcSQLException) { 221 throw Tools.toUnoException(this, jdbcSQLException); 222 } 223 } 224 225 @Override isSearchable(int column)226 public boolean isSearchable(int column) throws SQLException { 227 try { 228 return jdbcResultSetMetaData.isSearchable(column); 229 } catch (java.sql.SQLException jdbcSQLException) { 230 throw Tools.toUnoException(this, jdbcSQLException); 231 } 232 } 233 234 @Override isReadOnly(int column)235 public boolean isReadOnly(int column) throws SQLException { 236 try { 237 return jdbcResultSetMetaData.isReadOnly(column); 238 } catch (java.sql.SQLException jdbcSQLException) { 239 throw Tools.toUnoException(this, jdbcSQLException); 240 } 241 } 242 243 @Override isDefinitelyWritable(int column)244 public boolean isDefinitelyWritable(int column) throws SQLException { 245 try { 246 return jdbcResultSetMetaData.isDefinitelyWritable(column); 247 } catch (java.sql.SQLException jdbcSQLException) { 248 throw Tools.toUnoException(this, jdbcSQLException); 249 } 250 } 251 252 @Override isWritable(int column)253 public boolean isWritable(int column) throws SQLException { 254 try { 255 return jdbcResultSetMetaData.isWritable(column); 256 } catch (java.sql.SQLException jdbcSQLException) { 257 throw Tools.toUnoException(this, jdbcSQLException); 258 } 259 } 260 } 261