| /* |
| * Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0, |
| * or the Eclipse Distribution License v. 1.0 which is available at |
| * http://www.eclipse.org/org/documents/edl-v10.php. |
| * |
| * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause |
| */ |
| |
| // Contributors: |
| // Oracle - initial API and implementation from Oracle TopLink |
| package org.eclipse.persistence.testing.tests.performance.emulateddb; |
| |
| import java.sql.*; |
| import org.eclipse.persistence.internal.helper.DatabaseField; |
| import org.eclipse.persistence.sessions.DatabaseRecord; |
| |
| /** |
| * Emulated database result set meta data. |
| * This extracts columns from a list of DatabaseRows. |
| */ |
| public class EmulatedResultSetMetaData implements ResultSetMetaData { |
| |
| protected EmulatedResultSet resultSet; |
| |
| public EmulatedResultSetMetaData(EmulatedResultSet resultSet) { |
| this.resultSet = resultSet; |
| } |
| |
| /** |
| * Returns the number of columns in this <code>ResultSet</code> object. |
| * |
| * @return the number of columns |
| * @exception SQLException if a database access error occurs |
| */ |
| @Override |
| public int getColumnCount() throws SQLException { |
| if (resultSet.getRows().isEmpty()) { |
| return 1; |
| } |
| return ((DatabaseRecord)resultSet.getRows().get(0)).getFields().size(); |
| } |
| |
| /** |
| * Indicates whether the designated column is automatically numbered, thus read-only. |
| * |
| * @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 |
| */ |
| @Override |
| public boolean isAutoIncrement(int column) throws SQLException { |
| return false; |
| } |
| |
| /** |
| * 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 |
| */ |
| @Override |
| public boolean isCaseSensitive(int column) throws SQLException { |
| return true; |
| } |
| |
| /** |
| * 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 |
| */ |
| @Override |
| public boolean isSearchable(int column) throws SQLException { |
| return true; |
| } |
| |
| /** |
| * 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 |
| */ |
| @Override |
| public boolean isCurrency(int column) throws SQLException { |
| return false; |
| } |
| |
| /** |
| * 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 |
| */ |
| @Override |
| public int isNullable(int column) throws SQLException { |
| return 0; |
| } |
| |
| /** |
| * 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 |
| */ |
| @Override |
| public boolean isSigned(int column) throws SQLException { |
| return true; |
| } |
| |
| /** |
| * 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 |
| */ |
| @Override |
| public int getColumnDisplaySize(int column) throws SQLException { |
| return 0; |
| } |
| |
| /** |
| * 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 |
| */ |
| @Override |
| public String getColumnLabel(int column) throws SQLException { |
| return ""; |
| } |
| |
| /** |
| * 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 |
| */ |
| @Override |
| public String getColumnName(int column) throws SQLException { |
| return ((DatabaseRecord)resultSet.getRows().get(0)).getFields().get(column - 1).getName(); |
| } |
| |
| /** |
| * 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 |
| */ |
| @Override |
| public String getSchemaName(int column) throws SQLException { |
| return ""; |
| } |
| |
| /** |
| * 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 |
| */ |
| @Override |
| public int getPrecision(int column) throws SQLException { |
| return 0; |
| } |
| |
| /** |
| * 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 |
| */ |
| @Override |
| public int getScale(int column) throws SQLException { |
| return 0; |
| } |
| |
| /** |
| * 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 |
| */ |
| @Override |
| public String getTableName(int column) throws SQLException { |
| return ""; |
| } |
| |
| /** |
| * Gets the designated column's table's catalog name. |
| * |
| * @param column the first column is 1, the second is 2, ... |
| * @return the name of the catalog for the table in which the given column |
| * appears or "" if not applicable |
| * @exception SQLException if a database access error occurs |
| */ |
| @Override |
| public String getCatalogName(int column) throws SQLException { |
| return ""; |
| } |
| |
| /** |
| * 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 |
| */ |
| @Override |
| public int getColumnType(int column) throws SQLException { |
| return 0; |
| } |
| |
| /** |
| * 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 |
| */ |
| @Override |
| public String getColumnTypeName(int column) throws SQLException { |
| return ""; |
| } |
| |
| /** |
| * 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 |
| */ |
| @Override |
| public boolean isReadOnly(int column) throws SQLException { |
| return false; |
| } |
| |
| /** |
| * 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 |
| */ |
| @Override |
| public boolean isWritable(int column) throws SQLException { |
| return true; |
| } |
| |
| /** |
| * 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 |
| */ |
| @Override |
| public boolean isDefinitelyWritable(int column) throws SQLException { |
| return true; |
| } |
| |
| //--------------------------JDBC 2.0----------------------------------- |
| |
| /** |
| * <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. |
| * |
| * @param column the first column is 1, the second is 2, ... |
| * @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 |
| */ |
| @Override |
| public String getColumnClassName(int column) throws SQLException { |
| return ""; |
| } |
| |
| @Override |
| public boolean isWrapperFor(Class<?> iFace) throws SQLException{ |
| return false; |
| } |
| |
| @Override |
| public <T>T unwrap(Class<T> iFace) throws SQLException { |
| return iFace.cast(this); |
| } |
| |
| } |