Search in sources :

Example 1 with JdbcTableMeta

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

the class JdbcDatabaseMetadata method getTables.

/**
 * {@inheritDoc}
 */
@Override
public ResultSet getTables(String catalog, String schemaPtrn, String tblNamePtrn, String[] tblTypes) 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("TABLE_TYPE", String.class), new JdbcColumnMeta("REMARKS", String.class), new JdbcColumnMeta("TYPE_CAT", String.class), new JdbcColumnMeta("TYPE_SCHEM", String.class), new JdbcColumnMeta("TYPE_NAME", String.class), new JdbcColumnMeta("SELF_REFERENCING_COL_NAME", String.class), new JdbcColumnMeta("REF_GENERATION", String.class));
    boolean tblTypeMatch = false;
    if (tblTypes == null) {
        tblTypeMatch = true;
    } else {
        for (String type : tblTypes) {
            if (TYPE_TABLE.equals(type)) {
                tblTypeMatch = true;
                break;
            }
        }
    }
    if (!isValidCatalog(catalog) || !tblTypeMatch) {
        return new JdbcResultSet(Collections.emptyList(), meta);
    }
    JdbcMetaTablesResult res = conn.handler().tablesMetaAsync(new JdbcMetaTablesRequest(schemaPtrn, tblNamePtrn, tblTypes)).join();
    if (!res.hasResults()) {
        throw IgniteQueryErrorCode.createJdbcSqlException(res.err(), res.status());
    }
    List<List<Object>> rows = new LinkedList<>();
    for (JdbcTableMeta tblMeta : res.meta()) {
        rows.add(tableRow(tblMeta));
    }
    return new JdbcResultSet(rows, meta);
}
Also used : JdbcTableMeta(org.apache.ignite.client.proto.query.event.JdbcTableMeta) JdbcColumnMeta(org.apache.ignite.client.proto.query.event.JdbcColumnMeta) JdbcMetaTablesRequest(org.apache.ignite.client.proto.query.event.JdbcMetaTablesRequest) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) LinkedList(java.util.LinkedList) List(java.util.List) JdbcMetaTablesResult(org.apache.ignite.client.proto.query.event.JdbcMetaTablesResult) 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 JdbcMetaTablesRequest (org.apache.ignite.client.proto.query.event.JdbcMetaTablesRequest)1 JdbcMetaTablesResult (org.apache.ignite.client.proto.query.event.JdbcMetaTablesResult)1 JdbcTableMeta (org.apache.ignite.client.proto.query.event.JdbcTableMeta)1