Search in sources :

Example 6 with JdbcColumnMeta

use of org.apache.ignite.client.proto.query.event.JdbcColumnMeta in project ignite-3 by apache.

the class JdbcDatabaseMetadata method getPrimaryKeys.

/**
 * {@inheritDoc}
 */
@Override
public ResultSet getPrimaryKeys(String catalog, String schema, String tbl) throws SQLException {
    conn.ensureNotClosed();
    final List<JdbcColumnMeta> meta = asList(new JdbcColumnMeta("TABLE_CAT", String.class), new JdbcColumnMeta("TABLE_SCHEM", String.class), new JdbcColumnMeta("TABLE_NAME", String.class), new JdbcColumnMeta("COLUMN_NAME", String.class), new JdbcColumnMeta("KEY_SEQ", Short.class), new JdbcColumnMeta("PK_NAME", String.class));
    if (!isValidCatalog(catalog)) {
        return new JdbcResultSet(Collections.emptyList(), meta);
    }
    JdbcMetaPrimaryKeysResult res = conn.handler().primaryKeysMetaAsync(new JdbcMetaPrimaryKeysRequest(schema, tbl)).join();
    if (!res.hasResults()) {
        throw IgniteQueryErrorCode.createJdbcSqlException(res.err(), res.status());
    }
    List<List<Object>> rows = new LinkedList<>();
    for (JdbcPrimaryKeyMeta pkMeta : res.meta()) {
        rows.addAll(primaryKeyRows(pkMeta));
    }
    return new JdbcResultSet(rows, meta);
}
Also used : JdbcColumnMeta(org.apache.ignite.client.proto.query.event.JdbcColumnMeta) JdbcMetaPrimaryKeysRequest(org.apache.ignite.client.proto.query.event.JdbcMetaPrimaryKeysRequest) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) LinkedList(java.util.LinkedList) List(java.util.List) JdbcPrimaryKeyMeta(org.apache.ignite.client.proto.query.event.JdbcPrimaryKeyMeta) JdbcMetaPrimaryKeysResult(org.apache.ignite.client.proto.query.event.JdbcMetaPrimaryKeysResult) LinkedList(java.util.LinkedList)

Example 7 with JdbcColumnMeta

use of org.apache.ignite.client.proto.query.event.JdbcColumnMeta in project ignite-3 by apache.

the class JdbcDatabaseMetadata method getColumns.

/**
 * {@inheritDoc}
 */
@Override
public ResultSet getColumns(String catalog, String schemaPtrn, String tblNamePtrn, String colNamePtrn) throws SQLException {
    conn.ensureNotClosed();
    final List<JdbcColumnMeta> meta = asList(// 1
    new JdbcColumnMeta("TABLE_CAT", String.class), // 2
    new JdbcColumnMeta("TABLE_SCHEM", String.class), // 3
    new JdbcColumnMeta("TABLE_NAME", String.class), // 4
    new JdbcColumnMeta("COLUMN_NAME", String.class), // 5
    new JdbcColumnMeta("DATA_TYPE", Short.class), // 6
    new JdbcColumnMeta("TYPE_NAME", String.class), // 7
    new JdbcColumnMeta("COLUMN_SIZE", Integer.class), // 8
    new JdbcColumnMeta("BUFFER_LENGTH", Integer.class), // 9
    new JdbcColumnMeta("DECIMAL_DIGITS", Integer.class), // 10
    new JdbcColumnMeta("NUM_PREC_RADIX", Short.class), // 11
    new JdbcColumnMeta("NULLABLE", Short.class), // 12
    new JdbcColumnMeta("REMARKS", String.class), // 13
    new JdbcColumnMeta("COLUMN_DEF", String.class), // 14
    new JdbcColumnMeta("SQL_DATA_TYPE", Integer.class), // 15
    new JdbcColumnMeta("SQL_DATETIME_SUB", Integer.class), // 16
    new JdbcColumnMeta("CHAR_OCTET_LENGTH", Integer.class), // 17
    new JdbcColumnMeta("ORDINAL_POSITION", Integer.class), // 18
    new JdbcColumnMeta("IS_NULLABLE", String.class), // 19
    new JdbcColumnMeta("SCOPE_CATLOG", String.class), // 20
    new JdbcColumnMeta("SCOPE_SCHEMA", String.class), // 21
    new JdbcColumnMeta("SCOPE_TABLE", String.class), // 22
    new JdbcColumnMeta("SOURCE_DATA_TYPE", Short.class), // 23
    new JdbcColumnMeta("IS_AUTOINCREMENT", String.class), // 24
    new JdbcColumnMeta("IS_GENERATEDCOLUMN", String.class));
    if (!isValidCatalog(catalog)) {
        return new JdbcResultSet(Collections.emptyList(), meta);
    }
    JdbcMetaColumnsResult res = conn.handler().columnsMetaAsync(new JdbcMetaColumnsRequest(schemaPtrn, tblNamePtrn, colNamePtrn)).join();
    if (!res.hasResults()) {
        throw IgniteQueryErrorCode.createJdbcSqlException(res.err(), res.status());
    }
    List<List<Object>> rows = new LinkedList<>();
    for (int i = 0; i < res.meta().size(); ++i) {
        rows.add(columnRow(res.meta().get(i), i + 1));
    }
    return new JdbcResultSet(rows, meta);
}
Also used : JdbcMetaColumnsResult(org.apache.ignite.client.proto.query.event.JdbcMetaColumnsResult) JdbcColumnMeta(org.apache.ignite.client.proto.query.event.JdbcColumnMeta) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) LinkedList(java.util.LinkedList) List(java.util.List) JdbcMetaColumnsRequest(org.apache.ignite.client.proto.query.event.JdbcMetaColumnsRequest) LinkedList(java.util.LinkedList)

Aggregations

JdbcColumnMeta (org.apache.ignite.client.proto.query.event.JdbcColumnMeta)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Arrays.asList (java.util.Arrays.asList)4 Collections.singletonList (java.util.Collections.singletonList)4 LinkedList (java.util.LinkedList)4 JdbcMetaColumnsResult (org.apache.ignite.client.proto.query.event.JdbcMetaColumnsResult)2 JdbcPrimaryKeyMeta (org.apache.ignite.client.proto.query.event.JdbcPrimaryKeyMeta)2 JdbcTableMeta (org.apache.ignite.client.proto.query.event.JdbcTableMeta)2 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)1 IntList (it.unimi.dsi.fastutil.ints.IntList)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 LinkedHashSet (java.util.LinkedHashSet)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Function (java.util.function.Function)1