public SuccessMessage testDatabase(String project, String type, JDBCSchemaConfig options) { SupportedCustomDatabase optionalFunction = SupportedCustomDatabase.getAdapter(type); Optional<String> test = optionalFunction.getDataSource().test(options); if (test.isPresent()) { throw new RakamException(test.get(), BAD_REQUEST); } return SuccessMessage.success(); }
private QueryExecution getSingleQueryExecution(String query, List<CustomDataSource> type) { char seperator = dbSeparator(type.get(0).type); StringBuilder builder = new StringBuilder(); Statement statement = sqlParser.createStatement(query, new ParsingOptions()); try { new RakamSqlFormatter.Formatter(builder, qualifiedName -> { String schema = qualifiedName.getPrefix().get().toString(); CustomDataSource customDataSource1 = type.stream() .filter(e -> e.schemaName.equals(schema)).findAny() .orElseThrow(() -> new RakamException("Cross database operations are not supported.", BAD_REQUEST)); return SupportedCustomDatabase.getAdapter(customDataSource1.type).getTableMapper() .apply(customDataSource1.options, qualifiedName.getSuffix()); }, seperator) { }.process(statement, 1); } catch (UnsupportedOperationException e) { return null; } String sqlQuery = builder.toString(); return new JDBCQueryExecution(() -> SupportedCustomDatabase.getAdapter(type.get(0).type).getDataSource().openConnection(type.get(0).options), sqlQuery, false, Optional.empty(), false); }
List<String> builder = new ArrayList<>(); SupportedCustomDatabase source = SupportedCustomDatabase.getAdapter(customDataSource.type); try (Connection conn = source.getDataSource().openConnection(customDataSource.options)) { ResultSet dbColumns = conn.getMetaData().getTables(null, customDataSource.options.getSchema(), null, null);
public CompletableFuture<List<SchemaField>> schemaTable(String project, String schema, String table) { CustomDataSource customDataSource = getDatabase(project, schema); List<SchemaField> builder = new ArrayList<>(); return CompletableFuture.supplyAsync(() -> { SupportedCustomDatabase source = SupportedCustomDatabase.getAdapter(customDataSource.type); try (Connection conn = source.getDataSource().openConnection(customDataSource.options)) { ResultSet dbColumns = conn.getMetaData().getColumns(null, customDataSource.options.getSchema(), table, null); while (dbColumns.next()) { String columnName = dbColumns.getString("COLUMN_NAME"); FieldType fieldType; try { fieldType = fromSql(dbColumns.getInt("DATA_TYPE"), dbColumns.getString("TYPE_NAME")); } catch (UnsupportedOperationException e) { continue; } builder.add(new SchemaField(columnName, fieldType)); } return builder; } catch (SQLException e) { throw Throwables.propagate(e); } }, executor); }
source = SupportedCustomDatabase.getAdapter(type.type); } catch (IllegalArgumentException e) { return null; return new JDBCQueryExecution(() -> source.getDataSource().openConnection(convert), builder.toString(), false, Optional.empty(), false);