1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
|
/*
* $Id$
*
* This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
* project.
*
* Copyright (C) 1998-2012 OpenLink Software
*
* This project is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; only version 2 of the License, dated June 1991.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
package virtuoso.javax;
import javax.sql.RowSetMetaData;
import java.sql.*;
import java.io.Serializable;
/**
* <P>The RowSetMetaData interface extends ResultSetMetaData with
* methods that allow a metadata object to be initialized.
*/
public class OPLRowSetMetaData implements RowSetMetaData, Serializable {
private static final long serialVersionUID = 4491018005954285242L;
private Coldesc[] desc;
public OPLRowSetMetaData(ResultSetMetaData rsmd) throws SQLException {
int count = rsmd.getColumnCount();
setColumnCount(count);
for(int i = 0; i < count; i++){
int col = i + 1;
String v;
desc[i].columnLabel = rsmd.getColumnLabel(col);
desc[i].columnName = rsmd.getColumnName(col);
v = rsmd.getSchemaName(col);
desc[i].schemaName = ( v != null ? v : "");
v = rsmd.getTableName(col);
desc[i].tableName = ( v != null ? v : "");
v = rsmd.getCatalogName(col);
desc[i].catalogName = ( v != null ? v : "");
desc[i].typeName = rsmd.getColumnTypeName(col);
desc[i].type = rsmd.getColumnType(col);
desc[i].precision = rsmd.getPrecision(col);
desc[i].scale = rsmd.getScale(col);
desc[i].displaySize = rsmd.getColumnDisplaySize(col);
desc[i].isAutoIncrement = rsmd.isAutoIncrement(col);
desc[i].isCaseSensitive = rsmd.isCaseSensitive(col);
desc[i].isCurrency = rsmd.isCurrency(col);
desc[i].nullable = rsmd.isNullable(col);
desc[i].isSigned = rsmd.isSigned(col);
desc[i].isSearchable = rsmd.isSearchable(col);
desc[i].isDefinitelyWritable = rsmd.isDefinitelyWritable(col);
desc[i].isReadOnly = rsmd.isReadOnly(col);
desc[i].isWritable = rsmd.isWritable(col);
}
}
/**
* Specify whether the is column automatically numbered, thus read-only.
*
* @param column the first column is 1, the second is 2, ...
* @param property is either true or false (default is false).
*
* @exception SQLException if a database-access error occurs.
*/
public void setAutoIncrement(int column, boolean property) throws java.sql.SQLException {
check_index(column).isAutoIncrement = property;
}
/**
* Specify whether the column is case sensitive.
*
* @param column the first column is 1, the second is 2, ...
* @param property is either true or false (default is false).
*
* @exception SQLException if a database-access error occurs.
*/
public void setCaseSensitive(int column, boolean property) throws java.sql.SQLException {
check_index(column).isCaseSensitive = property;
}
/**
* Specify the column's table's catalog name, if any.
*
* @param column the first column is 1, the second is 2, ...
* @param catalogName column's catalog name.
*
* @exception SQLException if a database-access error occurs.
*/
public void setCatalogName(int column, String catalogName) throws java.sql.SQLException {
if (catalogName != null)
check_index(column).catalogName = catalogName;
else
check_index(column).catalogName = "";
}
/**
* Set the number of columns in the RowSet.
*
* @param columnCount number of columns.
* @exception SQLException if a database-access error occurs.
*/
public void setColumnCount(int columnCount) throws SQLException {
if (columnCount <= 0)
throw OPLMessage_x.makeException(OPLMessage_x.errx_Invalid_column_count);
desc = new Coldesc[columnCount];
for(int i = 0; i < columnCount; i++)
desc[i] = new Coldesc();
}
/**
* Specify the column's normal max width in chars.
*
* @param column the first column is 1, the second is 2, ...
* @param size size of the column
*
* @exception SQLException if a database-access error occurs.
*/
public void setColumnDisplaySize(int column, int size) throws java.sql.SQLException {
check_index(column).displaySize = size;
}
/**
* Specify the suggested column title for use in printouts and
* displays, if any.
*
* @param column the first column is 1, the second is 2, ...
* @param label the column title
* @exception SQLException if a database-access error occurs.
*/
public void setColumnLabel(int column, String label) throws java.sql.SQLException {
check_index(column).columnLabel = label;
}
/**
* Specify the column name.
*
* @param column the first column is 1, the second is 2, ...
* @param columnName the column name
* @exception SQLException if a database-access error occurs.
*/
public void setColumnName(int column, String columnName) throws java.sql.SQLException {
check_index(column).columnName = columnName;
}
/**
* Specify the column's SQL type.
*
* @param column the first column is 1, the second is 2, ...
* @param SQLType column's SQL type.
* @exception SQLException if a database-access error occurs.
* @see Types
*/
public void setColumnType(int column, int SQLType) throws java.sql.SQLException {
check_index(column).type = SQLType;
}
/**
* Specify the column's data source specific type name, if any.
*
* @param column the first column is 1, the second is 2, ...
* @param typeName data source specific type name.
* @exception SQLException if a database-access error occurs.
*/
public void setColumnTypeName(int column, String typeName) throws java.sql.SQLException {
check_index(column).typeName = typeName;
}
/**
* Specify whether the column is a cash value.
*
* @param column the first column is 1, the second is 2, ...
* @param property is either true or false (default is false).
*
* @exception SQLException if a database-access error occurs.
*/
public void setCurrency(int column, boolean property) throws java.sql.SQLException {
check_index(column).isCurrency = property;
}
/**
* Specify whether the column's value can be set to NULL.
*
* @param column the first column is 1, the second is 2, ...
* @param property is either one of columnNoNulls, columnNullable
* or columnNullableUnknown (default is columnNullableUnknown).
*
* @exception SQLException if a database-access error occurs.
*/
public void setNullable(int column, int property) throws java.sql.SQLException {
check_index(column).nullable = property;
}
/**
* Specify the column's number of decimal digits.
*
* @param column the first column is 1, the second is 2, ...
* @param precision number of decimal digits.
* @exception SQLException if a database-access error occurs.
*/
public void setPrecision(int column, int precision) throws java.sql.SQLException {
check_index(column).precision = precision;
}
/**
* Specify the column's number of digits to right of the decimal point.
*
* @param column the first column is 1, the second is 2, ...
* @param scale number of digits to right of decimal point.
* @exception SQLException if a database-access error occurs.
*/
public void setScale(int column, int scale) throws java.sql.SQLException {
check_index(column).scale = scale;
}
/**
* Specify the column's table's schema, if any.
*
* @param column the first column is 1, the second is 2, ...
* @param schemaName the schema name
* @exception SQLException if a database-access error occurs.
*/
public void setSchemaName(int column, String schemaName) throws java.sql.SQLException {
if (schemaName != null)
check_index(column).schemaName = schemaName;
else
check_index(column).schemaName = "";
}
/**
* Specify whether the column can be used in a where clause.
*
* @param column the first column is 1, the second is 2, ...
* @param property is either true or false (default is false).
*
* @exception SQLException if a database-access error occurs.
*/
public void setSearchable(int column, boolean property) throws java.sql.SQLException {
check_index(column).isSearchable = property;
}
/**
* Speicfy whether the column is a signed number.
*
* @param column the first column is 1, the second is 2, ...
* @param property is either true or false (default is false).
*
* @exception SQLException if a database-access error occurs.
*/
public void setSigned(int column, boolean property) throws java.sql.SQLException {
check_index(column).isSigned = property;
}
/**
* Specify the column's table name, if any.
*
* @param column the first column is 1, the second is 2, ...
* @param tableName column's table name.
* @exception SQLException if a database-access error occurs.
*/
public void setTableName(int column, String tableName) throws java.sql.SQLException {
if (tableName != null)
check_index(column).tableName = tableName;
else
check_index(column).tableName = "";
}
/**
* Returns the number of columns in this RowSet
*
* @return the number of columns
* @exception SQLException if a database access error occurs
*/
public int getColumnCount() throws SQLException {
return (desc != null ? desc.length : 0);
}
/**
* Indicates whether the column is automatically numbered, thus read-only.
*
* @param column the first column is 1, the second is 2, ...
* @return true if so
* @exception SQLException if a database access error occurs
*/
public boolean isAutoIncrement(int column) throws SQLException {
return check_index(column).isAutoIncrement;
}
/**
* Indicates whether a column's case matters.
*
* @param column the first column is 1, the second is 2, ...
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
public boolean isCaseSensitive(int column) throws SQLException {
return check_index(column).isCaseSensitive;
}
/**
* Indicates whether the designated column can be used in a where clause.
*
* @param column the first column is 1, the second is 2, ...
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
public boolean isSearchable(int column) throws SQLException {
return check_index(column).isSearchable;
}
/**
* Indicates whether the designated column is a cash value.
*
* @param column the first column is 1, the second is 2, ...
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
public boolean isCurrency(int column) throws SQLException {
return check_index(column).isCurrency;
}
/**
* Indicates the nullability of values in the designated column.
*
* @param column the first column is 1, the second is 2, ...
* @return the nullability status of the given column; one of <code>columnNoNulls</code>,
* <code>columnNullable</code> or <code>columnNullableUnknown</code>
* @exception SQLException if a database access error occurs
*/
public int isNullable(int column) throws SQLException {
return check_index(column).nullable;
}
/**
* Indicates whether values in the designated column are signed numbers.
*
* @param column the first column is 1, the second is 2, ...
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
public boolean isSigned(int column) throws SQLException {
return check_index(column).isSigned;
}
/**
* Indicates the designated column's normal maximum width in characters.
*
* @param column the first column is 1, the second is 2, ...
* @return the normal maximum number of characters allowed as the width
* of the designated column
* @exception SQLException if a database access error occurs
*/
public int getColumnDisplaySize(int column) throws SQLException {
return check_index(column).displaySize;
}
/**
* Gets the designated column's suggested title for use in printouts and
* displays.
*
* @param column the first column is 1, the second is 2, ...
* @return the suggested column title
* @exception SQLException if a database access error occurs
*/
public String getColumnLabel(int column) throws SQLException {
return check_index(column).columnLabel;
}
/**
* Get the designated column's name.
*
* @param column the first column is 1, the second is 2, ...
* @return column name
* @exception SQLException if a database access error occurs
*/
public String getColumnName(int column) throws SQLException {
return check_index(column).columnName;
}
/**
* Get the designated column's table's schema.
*
* @param column the first column is 1, the second is 2, ...
* @return schema name or "" if not applicable
* @exception SQLException if a database access error occurs
*/
public String getSchemaName(int column) throws SQLException {
return check_index(column).schemaName;
}
/**
* Get the designated column's number of decimal digits.
*
* @param column the first column is 1, the second is 2, ...
* @return precision
* @exception SQLException if a database access error occurs
*/
public int getPrecision(int column) throws SQLException {
return check_index(column).precision;
}
/**
* Gets the designated column's number of digits to right of the decimal point.
*
* @param column the first column is 1, the second is 2, ...
* @return scale
* @exception SQLException if a database access error occurs
*/
public int getScale(int column) throws SQLException {
return check_index(column).scale;
}
/**
* Gets the designated column's table name.
*
* @param column the first column is 1, the second is 2, ...
* @return table name or "" if not applicable
* @exception SQLException if a database access error occurs
*/
public String getTableName(int column) throws SQLException {
return check_index(column).tableName;
}
/**
* Gets the designated column's table's catalog name.
*
* @param column the first column is 1, the second is 2, ...
* @return column name or "" if not applicable
* @exception SQLException if a database access error occurs
*/
public String getCatalogName(int column) throws SQLException {
return check_index(column).catalogName;
}
/**
* Retrieves the designated column's SQL type.
*
* @param column the first column is 1, the second is 2, ...
* @return SQL type from java.sql.Types
* @exception SQLException if a database access error occurs
* @see Types
*/
public int getColumnType(int column) throws SQLException {
return check_index(column).type;
}
/**
* Retrieves the designated column's database-specific type name.
*
* @param column the first column is 1, the second is 2, ...
* @return type name used by the database. If the column type is
* a user-defined type, then a fully-qualified type name is returned.
* @exception SQLException if a database access error occurs
*/
public String getColumnTypeName(int column) throws SQLException {
return check_index(column).typeName;
}
/**
* Indicates whether the designated column is definitely not writable.
*
* @param column the first column is 1, the second is 2, ...
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
public boolean isReadOnly(int column) throws SQLException {
return check_index(column).isReadOnly;
}
/**
* Indicates whether it is possible for a write on the designated column to succeed.
*
* @param column the first column is 1, the second is 2, ...
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
public boolean isWritable(int column) throws SQLException {
return check_index(column).isWritable;
}
/**
* Indicates whether a write on the designated column will definitely succeed.
*
* @param column the first column is 1, the second is 2, ...
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
public boolean isDefinitelyWritable(int column) throws SQLException {
return check_index(column).isDefinitelyWritable;
}
/**
* <p>Returns the fully-qualified name of the Java class whose instances
* are manufactured if the method <code>ResultSet.getObject</code>
* is called to retrieve a value
* from the column. <code>ResultSet.getObject</code> may return a subclass of the
* class returned by this method.
*
* @return the fully-qualified name of the class in the Java programming
* language that would be used by the method
* <code>ResultSet.getObject</code> to retrieve the value in the specified
* column. This is the class name used for custom mapping.
* @exception SQLException if a database access error occurs
* @since 1.2
* @see <a href="package-summary.html#2.0 API">What Is in the JDBC
* 2.0 API</a>
*/
public String getColumnClassName(int column) throws SQLException {
return null;
}
#if JDK_VER >= 16
/**
* Returns an object that implements the given interface to allow access to
* non-standard methods, or standard methods not exposed by the proxy.
*
* If the receiver implements the interface then the result is the receiver
* or a proxy for the receiver. If the receiver is a wrapper
* and the wrapped object implements the interface then the result is the
* wrapped object or a proxy for the wrapped object. Otherwise return the
* the result of calling <code>unwrap</code> recursively on the wrapped object
* or a proxy for that result. If the receiver is not a
* wrapper and does not implement the interface, then an <code>SQLException</code> is thrown.
*
* @param iface A Class defining an interface that the result must implement.
* @return an object that implements the interface. May be a proxy for the actual implementing object.
* @throws java.sql.SQLException If no object found that implements the interface
* @since 1.6
*/
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
{
try {
// This works for classes that aren't actually wrapping anything
return iface.cast(this);
} catch (ClassCastException cce) {
throw OPLMessage_x.makeExceptionV(OPLMessage_x.errx_Unable_to_unwrap_to_XX, iface.toString());
}
}
/**
* Returns true if this either implements the interface argument or is directly or indirectly a wrapper
* for an object that does. Returns false otherwise. If this implements the interface then return true,
* else if this is a wrapper then return the result of recursively calling <code>isWrapperFor</code> on the wrapped
* object. If this does not implement the interface and is not a wrapper, return false.
* This method should be implemented as a low-cost operation compared to <code>unwrap</code> so that
* callers can use this method to avoid expensive <code>unwrap</code> calls that may fail. If this method
* returns true then calling <code>unwrap</code> with the same argument should succeed.
*
* @param iface a Class defining an interface.
* @return true if this implements the interface or directly or indirectly wraps an object that does.
* @throws java.sql.SQLException if an error occurs while determining whether this is a wrapper
* for an object with the given interface.
* @since 1.6
*/
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException
{
// This works for classes that aren't actually wrapping anything
return iface.isInstance(this);
}
#endif
private Coldesc check_index(int column) throws SQLException
{
if (desc==null || column < 1 || column > desc.length)
throw OPLMessage_x.makeException(OPLMessage_x.errx_Column_Index_out_of_range);
return desc[column - 1];
}
/////////// Inner class ///////
private class Coldesc implements Serializable {
private String columnLabel;
private String columnName;
private String schemaName;
private String tableName;
private String catalogName;
private String typeName;
private int type;
private int precision;
private int scale;
private int displaySize;
private int nullable;
private boolean isAutoIncrement;
private boolean isCaseSensitive;
private boolean isCurrency;
private boolean isSigned;
private boolean isSearchable;
private boolean isDefinitelyWritable;
private boolean isReadOnly;
private boolean isWritable;
}
}
|