public Table convertToTable(final String schemaName, final String tableName) { final Schema schema; if (schemaName == null) { schema = getDefaultSchema(); } else { schema = getSchemaByName(schemaName); } if (schema == null) { throw new IllegalArgumentException( "Schema " + schemaName + " not found. Available schema names are: " + dataContext.getSchemaNames()); } final Table table; if (tableName == null) { if (schema.getTables().stream().filter(t -> t.getType() == TableType.TABLE).count() == 1) { table = schema.getTables().stream().filter(t -> t.getType() == TableType.TABLE).findFirst().get(); } else { throw new IllegalArgumentException( "No table name specified, and multiple options exist. Available table names are: " + schema.getTableNames()); } } else { table = schema.getTableByName(tableName); } if (table == null) { throw new IllegalArgumentException( "Table not found. Available table names are: " + schema.getTableNames()); } return table; }
private JButton createQueryButton(final Datastore datastore) { final JButton queryButton = WidgetFactory.createDefaultButton("Query", IconUtils.MODEL_QUERY); queryButton.setToolTipText("Query datastore"); queryButton.addActionListener(e -> { final String queryString; try (DatastoreConnection connection = datastore.openConnection()) { final List<Table> tables = connection.getSchemaNavigator().getDefaultSchema().getTables(); if (tables.size() > 0) { queryString = "SELECT *\nFROM " + tables.get(0).getQualifiedLabel(); } else { queryString = "SELECT *\nFROM ?"; } } final QueryWindow queryWindow = new QueryWindow(_windowContext, datastore, queryString); queryWindow.open(); }); return queryButton; }
private void setSchemaTree(final Datastore datastore, final boolean expandTree, final DatastoreConnection con) { if (con != null) { final Schema defaultSchema = con.getSchemaNavigator().getDefaultSchema(); final int datastoreSize = defaultSchema.getTableCount(); if (datastoreSize == 1) { _schemaTreePanel.setDatastore(datastore, true); } else { _schemaTreePanel.setDatastore(datastore, expandTree); } } }
private void addTableToSource(final DatastoreConnection con) { if (con != null) { final Schema defaultSchema = con.getSchemaNavigator().getDefaultSchema(); final int datastoreSize = defaultSchema.getTableCount(); if (datastoreSize == 1) { final List<Column> columns = defaultSchema.getTable(0).getColumns(); _analysisJobBuilder.addSourceColumns(columns); } } }
public void setDatastore(final Datastore datastore) { final String previousValue = getValue(); _datastoreRef.set(datastore); if (datastore == null) { _comboBox.setModel(new DefaultComboBoxModel<>(new Schema[1])); } else { try (DatastoreConnection con = datastore.openConnection()) { Schema[] schemas = con.getSchemaNavigator().getSchemas(); schemas = CollectionUtils.array(new Schema[1], schemas); _comboBox.setModel(new DefaultComboBoxModel<>(schemas)); Schema newValue = null; if (previousValue != null) { newValue = con.getSchemaNavigator().getSchemaByName(previousValue); } if (newValue == null) { newValue = con.getSchemaNavigator().getDefaultSchema(); } _comboBox.setSelectedItem(newValue); } } }
@Override protected void setValue(String value) { final Datastore datastore = _datastoreRef.get(); if (value == null && datastore != null) { try (DatastoreConnection con = datastore.openConnection()) { value = con.getSchemaNavigator().getDefaultSchema().getName(); } } if (getValue() == value) { return; } final Schema schema; if (value == null) { schema = null; } else if (datastore == null) { schema = new MutableSchema(value); } else { try (DatastoreConnection con = datastore.openConnection()) { schema = con.getSchemaNavigator().getSchemaByName(value); } } _comboBox.setEditable(true); _comboBox.setSelectedItem(schema); _comboBox.setEditable(false); }