ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/jdbc/JdbcResultSetMetaData.java

Path
ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/jdbc/JdbcResultSetMetaData.java
Status
scanned
Type
file
Name
JdbcResultSetMetaData.java
Extension
.java
Programming language
Java
Mime type
text/x-java
File type
Java source, ASCII text
Tag

      
    
Rootfs path

      
    
Size
13753 (13.4 KB)
MD5
b8f93913e992ee891fd1bdffdd6cd3fb
SHA1
6001c3e8975661caa60ab0d3030ad4d5a06c3cb1
SHA256
5f256351af32e7b23047c248f6c2a0bf740e1fc8f06997424db4445ac6c5aece
SHA512

      
    
SHA1_git
a5fa2f8e23959c4be1ebe01e8393f6dd18f9fb42
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
JdbcResultSetMetaData.java | 13.4 KB |

/* * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (https://h2database.com/html/license.html). * Initial Developer: H2 Group */ package org.h2.jdbc; import java.sql.ResultSetMetaData; import java.sql.SQLException; import org.h2.message.DbException; import org.h2.message.Trace; import org.h2.message.TraceObject; import org.h2.result.ResultInterface; import org.h2.util.MathUtils; import org.h2.value.DataType; import org.h2.value.ValueToObjectConverter; /** * Represents the meta data for a ResultSet. */ public final class JdbcResultSetMetaData extends TraceObject implements ResultSetMetaData { private final String catalog; private final JdbcResultSet rs; private final JdbcPreparedStatement prep; private final ResultInterface result; private final int columnCount; JdbcResultSetMetaData(JdbcResultSet rs, JdbcPreparedStatement prep, ResultInterface result, String catalog, Trace trace, int id) { setTrace(trace, TraceObject.RESULT_SET_META_DATA, id); this.catalog = catalog; this.rs = rs; this.prep = prep; this.result = result; this.columnCount = result.getVisibleColumnCount(); } /** * Returns the number of columns. * * @return the number of columns * @throws SQLException if the result set is closed or invalid */ @Override public int getColumnCount() throws SQLException { try { debugCodeCall("getColumnCount"); checkClosed(); return columnCount; } catch (Exception e) { throw logAndConvert(e); } } /** * Returns the column label. * * @param column the column index (1,2,...) * @return the column label * @throws SQLException if the result set is closed or invalid */ @Override public String getColumnLabel(int column) throws SQLException { try { return result.getAlias(getColumn("getColumnLabel", column)); } catch (Exception e) { throw logAndConvert(e); } } /** * Returns the column name. * * @param column the column index (1,2,...) * @return the column name * @throws SQLException if the result set is closed or invalid */ @Override public String getColumnName(int column) throws SQLException { try { return result.getColumnName(getColumn("getColumnName", column)); } catch (Exception e) { throw logAndConvert(e); } } /** * Returns the data type of a column. * See also java.sql.Type. * * @param column the column index (1,2,...) * @return the data type * @throws SQLException if the result set is closed or invalid */ @Override public int getColumnType(int column) throws SQLException { try { return DataType.convertTypeToSQLType(result.getColumnType(getColumn("getColumnType", column))); } catch (Exception e) { throw logAndConvert(e); } } /** * Returns the data type name of a column. * * @param column the column index (1,2,...) * @return the data type name * @throws SQLException if the result set is closed or invalid */ @Override public String getColumnTypeName(int column) throws SQLException { try { return result.getColumnType(getColumn("getColumnTypeName", column)).getDeclaredTypeName(); } catch (Exception e) { throw logAndConvert(e); } } /** * Returns the schema name. * * @param column the column index (1,2,...) * @return the schema name, or "" (an empty string) if not applicable * @throws SQLException if the result set is closed or invalid */ @Override public String getSchemaName(int column) throws SQLException { try { String schema = result.getSchemaName(getColumn("getSchemaName", column)); return schema == null ? "" : schema; } catch (Exception e) { throw logAndConvert(e); } } /** * Returns the table name. * * @param column the column index (1,2,...) * @return the table name * @throws SQLException if the result set is closed or invalid */ @Override public String getTableName(int column) throws SQLException { try { String table = result.getTableName(getColumn("getTableName", column)); return table == null ? "" : table; } catch (Exception e) { throw logAndConvert(e); } } /** * Returns the catalog name. * * @param column the column index (1,2,...) * @return the catalog name * @throws SQLException if the result set is closed or invalid */ @Override public String getCatalogName(int column) throws SQLException { try { getColumn("getCatalogName", column); return catalog == null ? "" : catalog; } catch (Exception e) { throw logAndConvert(e); } } /** * Checks if this an autoincrement column. * * @param column the column index (1,2,...) * @return false * @throws SQLException if the result set is closed or invalid */ @Override public boolean isAutoIncrement(int column) throws SQLException { try { return result.isIdentity(getColumn("isAutoIncrement", column)); } catch (Exception e) { throw logAndConvert(e); } } /** * Checks if this column is case sensitive. * It always returns true. * * @param column the column index (1,2,...) * @return true * @throws SQLException if the result set is closed or invalid */ @Override public boolean isCaseSensitive(int column) throws SQLException { try { getColumn("isCaseSensitive", column); return true; } catch (Exception e) { throw logAndConvert(e); } } /** * Checks if this column is searchable. * It always returns true. * * @param column the column index (1,2,...) * @return true * @throws SQLException if the result set is closed or invalid */ @Override public boolean isSearchable(int column) throws SQLException { try { getColumn("isSearchable", column); return true; } catch (Exception e) { throw logAndConvert(e); } } /** * Checks if this is a currency column. * It always returns false. * * @param column the column index (1,2,...) * @return false * @throws SQLException if the result set is closed or invalid */ @Override public boolean isCurrency(int column) throws SQLException { try { getColumn("isCurrency", column); return false; } catch (Exception e) { throw logAndConvert(e); } } /** * Checks if this is nullable column. Returns * ResultSetMetaData.columnNullableUnknown if this is not a column of a * table. Otherwise, it returns ResultSetMetaData.columnNoNulls if the * column is not nullable, and ResultSetMetaData.columnNullable if it is * nullable. * * @param column the column index (1,2,...) * @return ResultSetMetaData.column* * @throws SQLException if the result set is closed or invalid */ @Override public int isNullable(int column) throws SQLException { try { return result.getNullable(getColumn("isNullable", column)); } catch (Exception e) { throw logAndConvert(e); } } /** * Checks if this column is signed. * Returns true for numeric columns. * * @param column the column index (1,2,...) * @return true for numeric columns * @throws SQLException if the result set is closed or invalid */ @Override public boolean isSigned(int column) throws SQLException { try { return DataType.isNumericType(result.getColumnType(getColumn("isSigned", column)).getValueType()); } catch (Exception e) { throw logAndConvert(e); } } /** * Checks if this column is read only. * It always returns false. * * @param column the column index (1,2,...) * @return false * @throws SQLException if the result set is closed or invalid */ @Override public boolean isReadOnly(int column) throws SQLException { try { getColumn("isReadOnly", column); return false; } catch (Exception e) { throw logAndConvert(e); } } /** * Checks whether it is possible for a write on this column to succeed. * It always returns true. * * @param column the column index (1,2,...) * @return true * @throws SQLException if the result set is closed or invalid */ @Override public boolean isWritable(int column) throws SQLException { try { getColumn("isWritable", column); return true; } catch (Exception e) { throw logAndConvert(e); } } /** * Checks whether a write on this column will definitely succeed. * It always returns false. * * @param column the column index (1,2,...) * @return false * @throws SQLException if the result set is closed or invalid */ @Override public boolean isDefinitelyWritable(int column) throws SQLException { try { getColumn("isDefinitelyWritable", column); return false; } catch (Exception e) { throw logAndConvert(e); } } /** * Gets the Java class name of the object that will be returned * if ResultSet.getObject is called. * * @param column the column index (1,2,...) * @return the Java class name * @throws SQLException if the result set is closed or invalid */ @Override public String getColumnClassName(int column) throws SQLException { try { int type = result.getColumnType(getColumn("getColumnClassName", column)).getValueType(); return ValueToObjectConverter.getDefaultClass(type, true).getName(); } catch (Exception e) { throw logAndConvert(e); } } /** * Gets the precision for this column. * * @param column the column index (1,2,...) * @return the precision * @throws SQLException if the result set is closed or invalid */ @Override public int getPrecision(int column) throws SQLException { try { return MathUtils.convertLongToInt(result.getColumnType(getColumn("getPrecision", column)).getPrecision()); } catch (Exception e) { throw logAndConvert(e); } } /** * Gets the scale for this column. * * @param column the column index (1,2,...) * @return the scale * @throws SQLException if the result set is closed or invalid */ @Override public int getScale(int column) throws SQLException { try { return result.getColumnType(getColumn("getScale", column)).getScale(); } catch (Exception e) { throw logAndConvert(e); } } /** * Gets the maximum display size for this column. * * @param column the column index (1,2,...) * @return the display size * @throws SQLException if the result set is closed or invalid */ @Override public int getColumnDisplaySize(int column) throws SQLException { try { return result.getColumnType(getColumn("getColumnDisplaySize", column)).getDisplaySize(); } catch (Exception e) { throw logAndConvert(e); } } private void checkClosed() { if (rs != null) { rs.checkClosed(); } if (prep != null) { prep.checkClosed(); } } /** * Writes trace information and checks validity of this object and * parameter. * * @param methodName * the called method name * @param columnIndex * 1-based column index * @return 0-based column index */ private int getColumn(String methodName, int columnIndex) { debugCodeCall(methodName, columnIndex); checkClosed(); if (columnIndex < 1 || columnIndex > columnCount) { throw DbException.getInvalidValueException("columnIndex", columnIndex); } return columnIndex - 1; } /** * Return an object of this class if possible. * * @param iface the class * @return this */ @Override @SuppressWarnings("unchecked") public <T> T unwrap(Class<T> iface) throws SQLException { try { if (isWrapperFor(iface)) { return (T) this; } throw DbException.getInvalidValueException("iface", iface); } catch (Exception e) { throw logAndConvert(e); } } /** * Checks if unwrap can return an object of this class. * * @param iface the class * @return whether or not the interface is assignable from this class */ @Override public boolean isWrapperFor(Class<?> iface) throws SQLException { return iface != null && iface.isAssignableFrom(getClass()); } /** * INTERNAL */ @Override public String toString() { return getTraceObjectName() + ": columns=" + columnCount; } }
Detected license expression
mpl-2.0 AND epl-1.0
Detected license expression (SPDX)
MPL-2.0 AND EPL-1.0
Percentage of license text
0.66
Copyrights
- end_line: 2
  copyright: Copyright 2004-2023 H2 Group. Multiple-Licensed
  start_line: 2
Holders
- holder: H2 Group. Multiple-Licensed
  end_line: 2
  start_line: 2
Authors

      
    
License detections License expression License expression SPDX
mpl_2_0_and_epl_1_0-796bf8d7-f485-3520-923d-e6a4b1ecd2f3 mpl-2.0 AND epl-1.0 MPL-2.0 AND EPL-1.0
URL Start line End line
https://h2database.com/html/license.html 3 3
Package URL License Primary language
pkg:osgi/com.h2database.source@2.2.220