Ejemplo n.º 1
0
  protected List<TableMeta> getMetadata(CubeManager cubeMgr, String project, boolean cubedOnly)
      throws SQLException {

    Connection conn = null;
    ResultSet columnMeta = null;
    List<TableMeta> tableMetas = null;

    try {
      DataSource dataSource = getOLAPDataSource(project);
      conn = dataSource.getConnection();
      DatabaseMetaData metaData = conn.getMetaData();

      logger.debug("getting table metas");
      ResultSet JDBCTableMeta = metaData.getTables(null, null, null, null);

      tableMetas = new LinkedList<TableMeta>();
      Map<String, TableMeta> tableMap = new HashMap<String, TableMeta>();
      while (JDBCTableMeta.next()) {
        String catalogName = JDBCTableMeta.getString(1);
        String schemaName = JDBCTableMeta.getString(2);

        // Not every JDBC data provider offers full 10 columns, e.g., PostgreSQL has only 5
        TableMeta tblMeta =
            new TableMeta(
                catalogName == null ? Constant.FakeCatalogName : catalogName,
                schemaName == null ? Constant.FakeSchemaName : schemaName,
                JDBCTableMeta.getString(3),
                JDBCTableMeta.getString(4),
                JDBCTableMeta.getString(5),
                null,
                null,
                null,
                null,
                null);

        if (!cubedOnly
            || getProjectManager()
                .isExposedTable(project, schemaName + "." + tblMeta.getTABLE_NAME())) {
          tableMetas.add(tblMeta);
          tableMap.put(tblMeta.getTABLE_SCHEM() + "#" + tblMeta.getTABLE_NAME(), tblMeta);
        }
      }

      logger.debug("getting column metas");
      columnMeta = metaData.getColumns(null, null, null, null);

      while (columnMeta.next()) {
        String catalogName = columnMeta.getString(1);
        String schemaName = columnMeta.getString(2);

        // kylin(optiq) is not strictly following JDBC specification
        ColumnMeta colmnMeta =
            new ColumnMeta(
                catalogName == null ? Constant.FakeCatalogName : catalogName,
                schemaName == null ? Constant.FakeSchemaName : schemaName,
                columnMeta.getString(3),
                columnMeta.getString(4),
                columnMeta.getInt(5),
                columnMeta.getString(6),
                columnMeta.getInt(7),
                getInt(columnMeta.getString(8)),
                columnMeta.getInt(9),
                columnMeta.getInt(10),
                columnMeta.getInt(11),
                columnMeta.getString(12),
                columnMeta.getString(13),
                getInt(columnMeta.getString(14)),
                getInt(columnMeta.getString(15)),
                columnMeta.getInt(16),
                columnMeta.getInt(17),
                columnMeta.getString(18),
                columnMeta.getString(19),
                columnMeta.getString(20),
                columnMeta.getString(21),
                getShort(columnMeta.getString(22)),
                columnMeta.getString(23));

        if (!cubedOnly
            || getProjectManager()
                .isExposedColumn(
                    project,
                    schemaName + "." + colmnMeta.getTABLE_NAME(),
                    colmnMeta.getCOLUMN_NAME())) {
          tableMap
              .get(colmnMeta.getTABLE_SCHEM() + "#" + colmnMeta.getTABLE_NAME())
              .addColumn(colmnMeta);
        }
      }
      logger.debug("done column metas");
    } finally {
      close(columnMeta, null, conn);
    }

    return tableMetas;
  }