Search in sources :

Example 1 with JdbcMetaPrimaryKeysResult

use of org.apache.ignite.client.proto.query.event.JdbcMetaPrimaryKeysResult 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)

Aggregations

ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collections.singletonList (java.util.Collections.singletonList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 JdbcColumnMeta (org.apache.ignite.client.proto.query.event.JdbcColumnMeta)1 JdbcMetaPrimaryKeysRequest (org.apache.ignite.client.proto.query.event.JdbcMetaPrimaryKeysRequest)1 JdbcMetaPrimaryKeysResult (org.apache.ignite.client.proto.query.event.JdbcMetaPrimaryKeysResult)1 JdbcPrimaryKeyMeta (org.apache.ignite.client.proto.query.event.JdbcPrimaryKeyMeta)1