AMashenkov commented on a change in pull request #339: URL: https://github.com/apache/ignite-3/pull/339#discussion_r710121374
########## File path: modules/client/src/main/java/org/apache/ignite/internal/jdbc/JdbcDatabaseMetadata.java ########## @@ -0,0 +1,1529 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.jdbc; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.RowIdLifetime; +import java.sql.SQLException; +import java.sql.Types; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import org.apache.ignite.client.proto.query.IgniteQueryErrorCode; +import org.apache.ignite.client.proto.query.event.JdbcColumnMeta; +import org.apache.ignite.client.proto.query.event.JdbcMetaColumnsRequest; +import org.apache.ignite.client.proto.query.event.JdbcMetaColumnsResult; +import org.apache.ignite.client.proto.query.event.JdbcMetaPrimaryKeysRequest; +import org.apache.ignite.client.proto.query.event.JdbcMetaPrimaryKeysResult; +import org.apache.ignite.client.proto.query.event.JdbcMetaSchemasRequest; +import org.apache.ignite.client.proto.query.event.JdbcMetaSchemasResult; +import org.apache.ignite.client.proto.query.event.JdbcMetaTablesRequest; +import org.apache.ignite.client.proto.query.event.JdbcMetaTablesResult; +import org.apache.ignite.client.proto.query.event.JdbcPrimaryKeyMeta; +import org.apache.ignite.client.proto.query.event.JdbcTableMeta; +import org.apache.ignite.internal.client.proto.ProtocolVersion; + +import static java.sql.Connection.TRANSACTION_NONE; +import static java.sql.ResultSet.CONCUR_READ_ONLY; +import static java.sql.ResultSet.HOLD_CURSORS_OVER_COMMIT; +import static java.sql.ResultSet.TYPE_FORWARD_ONLY; +import static java.sql.RowIdLifetime.ROWID_UNSUPPORTED; +import static java.util.Arrays.asList; +import static java.util.Collections.singletonList; + +/** + * JDBC database metadata implementation. + */ +public class JdbcDatabaseMetadata implements DatabaseMetaData { + /** Driver name. */ + public static final String DRIVER_NAME = "Apache Ignite JDBC Driver"; + + /** The only possible name for catalog. */ + public static final String CATALOG_NAME = "IGNITE"; + + /** Name of TABLE type. */ + public static final String TYPE_TABLE = "TABLE"; + + /** Connection. */ + private final JdbcConnection conn; + + /** + * Constructor. + * + * @param conn Connection. + */ + JdbcDatabaseMetadata(JdbcConnection conn) { + this.conn = conn; + } + + /** {@inheritDoc} */ + @Override public boolean allProceduresAreCallable() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean allTablesAreSelectable() { + return true; + } + + /** {@inheritDoc} */ + @Override public String getURL() { + return conn.url(); + } + + /** {@inheritDoc} */ + @Override public String getUserName() { + return ""; + } + + /** {@inheritDoc} */ + @Override public boolean isReadOnly() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean nullsAreSortedHigh() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean nullsAreSortedLow() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean nullsAreSortedAtStart() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean nullsAreSortedAtEnd() { + return true; + } + + /** {@inheritDoc} */ + @Override public String getDatabaseProductName() { + return "Apache Ignite"; + } + + /** {@inheritDoc} */ + @Override public String getDatabaseProductVersion() { + return ProtocolVersion.LATEST_VER.toString(); + } + + /** {@inheritDoc} */ + @Override public String getDriverName() { + return DRIVER_NAME; + } + + /** {@inheritDoc} */ + @Override public String getDriverVersion() { + return ProtocolVersion.LATEST_VER.toString(); + } + + /** {@inheritDoc} */ + @Override public int getDriverMajorVersion() { + return ProtocolVersion.LATEST_VER.major(); + } + + /** {@inheritDoc} */ + @Override public int getDriverMinorVersion() { + return ProtocolVersion.LATEST_VER.minor(); + } + + /** {@inheritDoc} */ + @Override public boolean usesLocalFiles() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean usesLocalFilePerTable() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsMixedCaseIdentifiers() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean storesUpperCaseIdentifiers() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean storesLowerCaseIdentifiers() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean storesMixedCaseIdentifiers() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsMixedCaseQuotedIdentifiers() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean storesUpperCaseQuotedIdentifiers() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean storesLowerCaseQuotedIdentifiers() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean storesMixedCaseQuotedIdentifiers() { + return true; + } + + /** {@inheritDoc} */ + @Override public String getIdentifierQuoteString() { + return "\""; + } + + /** {@inheritDoc} */ + @Override public String getSQLKeywords() { + return ""; + } + + /** {@inheritDoc} */ + @Override public String getNumericFunctions() { + return ""; + } + + /** {@inheritDoc} */ + @Override public String getStringFunctions() { + return ""; + } + + /** {@inheritDoc} */ + @Override public String getSystemFunctions() { + return ""; + } + + /** {@inheritDoc} */ + @Override public String getTimeDateFunctions() { + return ""; + } + + /** {@inheritDoc} */ + @Override public String getSearchStringEscape() { + return "\\"; + } + + /** {@inheritDoc} */ + @Override public String getExtraNameCharacters() { + return ""; + } + + /** {@inheritDoc} */ + @Override public boolean supportsAlterTableWithAddColumn() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsAlterTableWithDropColumn() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsColumnAliasing() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean nullPlusNonNullIsNull() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsConvert() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsConvert(int fromType, int toType) { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsTableCorrelationNames() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsDifferentTableCorrelationNames() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsExpressionsInOrderBy() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsOrderByUnrelated() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsGroupBy() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsGroupByUnrelated() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsGroupByBeyondSelect() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsLikeEscapeClause() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsMultipleResultSets() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsMultipleTransactions() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsNonNullableColumns() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsMinimumSQLGrammar() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsCoreSQLGrammar() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsExtendedSQLGrammar() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsANSI92EntryLevelSQL() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsANSI92IntermediateSQL() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsANSI92FullSQL() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsIntegrityEnhancementFacility() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsOuterJoins() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsFullOuterJoins() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsLimitedOuterJoins() { + return true; + } + + /** {@inheritDoc} */ + @Override public String getSchemaTerm() { + return ""; + } + + /** {@inheritDoc} */ + @Override public String getProcedureTerm() { + return ""; + } + + /** {@inheritDoc} */ + @Override public String getCatalogTerm() { + return ""; + } + + /** {@inheritDoc} */ + @Override public boolean isCatalogAtStart() { + return false; + } + + /** {@inheritDoc} */ + @Override public String getCatalogSeparator() { + return ""; + } + + /** {@inheritDoc} */ + @Override public boolean supportsSchemasInDataManipulation() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsSchemasInProcedureCalls() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsSchemasInTableDefinitions() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsSchemasInIndexDefinitions() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsSchemasInPrivilegeDefinitions() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsCatalogsInDataManipulation() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsCatalogsInProcedureCalls() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsCatalogsInTableDefinitions() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsCatalogsInIndexDefinitions() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsCatalogsInPrivilegeDefinitions() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsPositionedDelete() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsPositionedUpdate() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsSelectForUpdate() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsStoredProcedures() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsSubqueriesInComparisons() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsSubqueriesInExists() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsSubqueriesInIns() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsSubqueriesInQuantifieds() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsCorrelatedSubqueries() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsUnion() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsUnionAll() { + return true; + } + + /** {@inheritDoc} */ + @Override public boolean supportsOpenCursorsAcrossCommit() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsOpenCursorsAcrossRollback() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsOpenStatementsAcrossCommit() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsOpenStatementsAcrossRollback() { + return false; + } + + /** {@inheritDoc} */ + @Override public int getMaxBinaryLiteralLength() { + return 0; + } + + /** {@inheritDoc} */ + @Override public int getMaxCharLiteralLength() { + return 0; + } + + /** {@inheritDoc} */ + @Override public int getMaxColumnNameLength() { + return 0; + } + + /** {@inheritDoc} */ + @Override public int getMaxColumnsInGroupBy() { + return 0; + } + + /** {@inheritDoc} */ + @Override public int getMaxColumnsInIndex() { + return 0; + } + + /** {@inheritDoc} */ + @Override public int getMaxColumnsInOrderBy() { + return 0; + } + + /** {@inheritDoc} */ + @Override public int getMaxColumnsInSelect() { + return 0; + } + + /** {@inheritDoc} */ + @Override public int getMaxColumnsInTable() { + return 0; + } + + /** {@inheritDoc} */ + @Override public int getMaxConnections() { + return 0; + } + + /** {@inheritDoc} */ + @Override public int getMaxCursorNameLength() { + return 0; + } + + /** {@inheritDoc} */ + @Override public int getMaxIndexLength() { + return 0; + } + + /** {@inheritDoc} */ + @Override public int getMaxSchemaNameLength() { + return 0; + } + + /** {@inheritDoc} */ + @Override public int getMaxProcedureNameLength() { + return 0; + } + + /** {@inheritDoc} */ + @Override public int getMaxCatalogNameLength() { + return 0; + } + + /** {@inheritDoc} */ + @Override public int getMaxRowSize() { + return 0; + } + + /** {@inheritDoc} */ + @Override public boolean doesMaxRowSizeIncludeBlobs() { + return false; + } + + /** {@inheritDoc} */ + @Override public int getMaxStatementLength() { + return 0; + } + + /** {@inheritDoc} */ + @Override public int getMaxStatements() { + return 0; + } + + /** {@inheritDoc} */ + @Override public int getMaxTableNameLength() { + return 0; + } + + /** {@inheritDoc} */ + @Override public int getMaxTablesInSelect() { + return 0; + } + + /** {@inheritDoc} */ + @Override public int getMaxUserNameLength() { + return 0; + } + + /** {@inheritDoc} */ + @Override public int getDefaultTransactionIsolation() { + return TRANSACTION_NONE; + } + + /** {@inheritDoc} */ + @Override public boolean supportsTransactions() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsTransactionIsolationLevel(int level) { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsDataDefinitionAndDataManipulationTransactions() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean supportsDataManipulationTransactionsOnly() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean dataDefinitionCausesTransactionCommit() { + return false; + } + + /** {@inheritDoc} */ + @Override public boolean dataDefinitionIgnoredInTransactions() { + return false; + } + + /** {@inheritDoc} */ + @Override public ResultSet getProcedures(String catalog, String schemaPtrn, + String procedureNamePtrn) { + return new JdbcResultSet(Collections.emptyList(), asList( + new JdbcColumnMeta(null, null, "PROCEDURE_CAT", String.class), + new JdbcColumnMeta(null, null, "PROCEDURE_SCHEM", String.class), + new JdbcColumnMeta(null, null, "PROCEDURE_NAME", String.class), + new JdbcColumnMeta(null, null, "REMARKS", String.class), + new JdbcColumnMeta(null, null, "PROCEDURE_TYPE", String.class), + new JdbcColumnMeta(null, null, "SPECIFIC_NAME", String.class) + )); Review comment: Should we throw SqlException(UnsupportedOperationException) here as log as supportsStoredProcedures() returns false? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
