Search in sources :

Example 1 with JdbcPrimaryKeyMeta

use of org.apache.ignite.client.proto.query.event.JdbcPrimaryKeyMeta 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 2 with JdbcPrimaryKeyMeta

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

the class JdbcMetadataCatalog method createPrimaryKeyMeta.

/**
 * Creates primary key metadata from table object.
 *
 * @param tbl Table.
 * @return Jdbc primary key metadata.
 */
private JdbcPrimaryKeyMeta createPrimaryKeyMeta(Table tbl) {
    String schemaName = getTblSchema(tbl.name());
    String tblName = getTblName(tbl.name());
    final String keyName = PK + tblName;
    SchemaRegistry registry = ((TableImpl) tbl).schemaView();
    List<String> keyColNames = Arrays.stream(registry.schema().keyColumns().columns()).map(Column::name).collect(Collectors.toList());
    return new JdbcPrimaryKeyMeta(schemaName, tblName, keyName, keyColNames);
}
Also used : TableImpl(org.apache.ignite.internal.table.TableImpl) JdbcPrimaryKeyMeta(org.apache.ignite.client.proto.query.event.JdbcPrimaryKeyMeta) SchemaRegistry(org.apache.ignite.internal.schema.SchemaRegistry)

Aggregations

JdbcPrimaryKeyMeta (org.apache.ignite.client.proto.query.event.JdbcPrimaryKeyMeta)2 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 SchemaRegistry (org.apache.ignite.internal.schema.SchemaRegistry)1 TableImpl (org.apache.ignite.internal.table.TableImpl)1