Exemple #1
0
 private ImmutableMap<String, JdbcTable> computeTables() {
   Connection connection = null;
   ResultSet resultSet = null;
   try {
     connection = dataSource.getConnection();
     DatabaseMetaData metaData = connection.getMetaData();
     resultSet = metaData.getTables(catalog, schema, null, null);
     final ImmutableMap.Builder<String, JdbcTable> builder = ImmutableMap.builder();
     while (resultSet.next()) {
       final String tableName = resultSet.getString(3);
       final String catalogName = resultSet.getString(1);
       final String schemaName = resultSet.getString(2);
       final String tableTypeName = resultSet.getString(4);
       // Clean up table type. In particular, this ensures that 'SYSTEM TABLE',
       // returned by Phoenix among others, maps to TableType.SYSTEM_TABLE.
       // We know enum constants are upper-case without spaces, so we can't
       // make things worse.
       final String tableTypeName2 = tableTypeName.toUpperCase().replace(' ', '_');
       final TableType tableType = Util.enumVal(TableType.class, tableTypeName2);
       final JdbcTable table = new JdbcTable(this, catalogName, schemaName, tableName, tableType);
       builder.put(tableName, table);
     }
     return builder.build();
   } catch (SQLException e) {
     throw new RuntimeException("Exception while reading tables", e);
   } finally {
     close(connection, null, resultSet);
   }
 }
Exemple #2
0
 RelProtoDataType getRelDataType(String catalogName, String schemaName, String tableName)
     throws SQLException {
   Connection connection = null;
   try {
     connection = dataSource.getConnection();
     DatabaseMetaData metaData = connection.getMetaData();
     return getRelDataType(metaData, catalogName, schemaName, tableName);
   } finally {
     close(connection, null, null);
   }
 }
Exemple #3
0
  protected RelNode optimizeLoopbackLink(
      RelOptCluster cluster, RelOptConnection connection, String[] actualName) throws SQLException {
    if (directory == null) {
      return null;
    }
    if (directory.server == null) {
      return null;
    }
    if ((directory.server.schemaName != null)
        && !directory.server.useSchemaNameAsForeignQualifier) {
      // Schema name should never be specified for a connection to
      // Farrago; if it is, bail.
      return null;
    }

    Connection loopbackConnection = directory.server.getConnection();
    if (!(loopbackConnection instanceof FarragoJdbcEngineConnection)) {
      Connection conn = loopbackConnection;
      while ((conn != null) && (conn instanceof DelegatingConnection)) {
        conn = ((DelegatingConnection) conn).getDelegate();
      }
      if (!(conn instanceof FarragoJdbcEngineConnection)) {
        return null;
      }
    }

    String catalogName = directory.server.catalogName;
    if (catalogName == null) {
      // No catalog name specified, so try to query the connection for
      // it.
      catalogName = loopbackConnection.getCatalog();
      if (catalogName == null) {
        return null;
      }
    }

    if (actualName[0] == null) {
      actualName[0] = catalogName;
    }

    // REVIEW jvs 14-Aug-2006:  Security security security.
    RelOptTable realTable = getPreparingStmt().getTableForMember(actualName);
    if (realTable == null) {
      return null;
    }
    return realTable.toRel(cluster, connection);
  }
Exemple #4
0
 private static void close(Connection connection, Statement statement, ResultSet resultSet) {
   if (resultSet != null) {
     try {
       resultSet.close();
     } catch (SQLException e) {
       // ignore
     }
   }
   if (statement != null) {
     try {
       statement.close();
     } catch (SQLException e) {
       // ignore
     }
   }
   if (connection != null) {
     try {
       connection.close();
     } catch (SQLException e) {
       // ignore
     }
   }
 }
  // implement FarragoMedDataServer
  public FarragoMedColumnSet newColumnSet(
      String[] localName,
      Properties tableProps,
      FarragoTypeFactory typeFactory,
      RelDataType rowType,
      Map<String, Properties> columnPropMap)
      throws SQLException {
    if (rowType == null) {
      rowType = createMockRowType(typeFactory);
    }

    assert (rowType.getFieldList().size() == 1);
    RelDataType type = rowType.getFields()[0].getType();
    assert (!type.isNullable());
    assert (typeFactory.getClassForPrimitive(type) != null);

    // TODO jvs 5-Aug-2005:  clean up usage of server properties
    // as defaults

    long nRows = -1;
    String rowCountSql = tableProps.getProperty(PROP_ROW_COUNT_SQL);
    if (rowCountSql != null) {
      // Attempt to issue a loopback query into Farrago to
      // get the number of rows to produce.
      DataSource loopbackDataSource = getLoopbackDataSource();
      Connection connection = null;
      if (loopbackDataSource != null) {
        try {
          connection = loopbackDataSource.getConnection();
          Statement stmt = connection.createStatement();
          ResultSet resultSet = stmt.executeQuery(rowCountSql);
          if (resultSet.next()) {
            nRows = resultSet.getLong(1);
          }
        } finally {
          // It's OK not to clean up stmt and resultSet;
          // connection.close() will do that for us.
          if (connection != null) {
            connection.close();
          }
        }
      }
    }

    if (nRows == -1) {
      nRows =
          getLongProperty(
              tableProps, PROP_ROW_COUNT, getLongProperty(getProperties(), PROP_ROW_COUNT, 10));
    }

    String executorImpl =
        tableProps.getProperty(
            PROP_EXECUTOR_IMPL, getProperties().getProperty(PROP_EXECUTOR_IMPL, PROPVAL_JAVA));
    assert (executorImpl.equals(PROPVAL_JAVA) || executorImpl.equals(PROPVAL_FENNEL));

    String udxSpecificName = tableProps.getProperty(PROP_UDX_SPECIFIC_NAME);

    if (udxSpecificName != null) {
      assert (executorImpl.equals(PROPVAL_JAVA));
    }

    checkNameMatch(getForeignSchemaName(), tableProps.getProperty(PROP_SCHEMA_NAME));

    checkNameMatch(getForeignTableName(), tableProps.getProperty(PROP_TABLE_NAME));

    return new MedMockColumnSet(this, localName, rowType, nRows, executorImpl, udxSpecificName);
  }