use of io.syndesis.connector.sql.common.SqlStatementParser in project syndesis by syndesisio.
the class SqlConnectorMetaDataExtension method meta.
@Override
public Optional<MetaData> meta(final Map<String, Object> properties) {
final String sqlStatement = (String) properties.get("query");
MetaData metaData = EMPTY_METADATA;
if (sqlStatement != null) {
try (Connection connection = SqlSupport.createConnection(properties)) {
final DatabaseMetaData meta = connection.getMetaData();
final String defaultSchema = DatabaseMetaDataHelper.getDefaultSchema(meta.getDatabaseProductName(), String.valueOf(properties.get("user")));
final String schemaPattern = (String) properties.getOrDefault("schema-pattern", defaultSchema);
final SqlStatementParser parser = new SqlStatementParser(connection, schemaPattern, sqlStatement);
final SqlStatementMetaData sqlStatementMetaData = parseStatement(parser);
metaData = new DefaultMetaData(null, null, sqlStatementMetaData);
} catch (final SQLException e) {
throw new SyndesisServerException(e.getMessage(), e);
}
}
return Optional.of(metaData);
}
use of io.syndesis.connector.sql.common.SqlStatementParser in project syndesis by syndesisio.
the class SqlConnectorInputParamTest method sqlConnectorTest.
// **************************
// Tests
// **************************
@Test
public void sqlConnectorTest() throws Exception {
SqlStatementParser parser = new SqlStatementParser(db.connection, null, STATEMENT);
parser.parse();
Map<String, Object> values = new HashMap<>();
values.put("CHARVALUE", SqlParam.SqlSampleValue.CHAR_VALUE);
values.put("VARCHARVALUE", SqlParam.SqlSampleValue.STRING_VALUE);
values.put("NUMERICVALUE", SqlParam.SqlSampleValue.DECIMAL_VALUE);
values.put("DECIMALVALUE", SqlParam.SqlSampleValue.DECIMAL_VALUE);
values.put("SMALLINTVALUE", SqlParam.SqlSampleValue.INTEGER_VALUE);
String result = template.requestBody("direct:start", JSONBeanUtil.toJSONBean(values), String.class);
Assertions.assertThat(result).isNotNull();
try (Statement stmt = db.connection.createStatement()) {
stmt.execute("SELECT * FROM ALLTYPES");
ResultSet resultSet = stmt.getResultSet();
resultSet.next();
for (int i = 1; i < 6; i++) {
System.out.print(resultSet.getString(i) + " ");
}
System.out.println(resultSet.getString(1));
Assertions.assertThat(resultSet.getString(1)).isEqualTo(SqlParam.SqlSampleValue.CHAR_VALUE.toString());
Assertions.assertThat(resultSet.getString(2)).isEqualTo(SqlParam.SqlSampleValue.STRING_VALUE);
Assertions.assertThat(resultSet.getString(3)).isEqualTo(SqlParam.SqlSampleValue.DECIMAL_VALUE.toString());
Assertions.assertThat(resultSet.getString(4)).isEqualTo(SqlParam.SqlSampleValue.DECIMAL_VALUE.toString());
Assertions.assertThat(resultSet.getString(5)).isEqualTo(SqlParam.SqlSampleValue.INTEGER_VALUE.toString());
}
}
use of io.syndesis.connector.sql.common.SqlStatementParser in project syndesis by syndesisio.
the class SqlConnectorCustomizer method initJdbcMap.
private void initJdbcMap() {
final String sql = String.valueOf(options.get("query"));
final DataSource dataSource = (DataSource) options.get("dataSource");
final Map<String, Integer> tmpMap = new HashMap<>();
try (Connection connection = dataSource.getConnection()) {
SqlStatementMetaData md = new SqlStatementParser(connection, null, sql).parse();
for (SqlParam sqlParam : md.getInParams()) {
tmpMap.put(sqlParam.getName(), sqlParam.getJdbcType().getVendorTypeNumber());
}
} catch (SQLException e) {
LOGGER.error(e.getMessage(), e);
}
jdbcTypeMap = tmpMap;
}
Aggregations