在JIRA数据库上使用Apache Calcite和H2时的NPE

时间:2017-09-28 12:00:49

标签: java jira apache-calcite

使用方解石时,我收到了NPE。我的代码如下

@Autowired
public CalciteBootstrap(DatasourceProvider datasourceProvider) throws SQLException {
    this.datasource = datasourceProvider.fetchDatasource();
    log.debug("Datasource fetched - {}", datasource);
    this.connection = createRootSchema();
    this.schema = JdbcSchema.create(connection.getRootSchema(), "PUBLIC", datasource, null, null);

    connection.getRootSchema().add("jira", schema);
    connection.createStatement().executeQuery("select * from jira.PROJECT_KEY");
}

private CalciteConnection createRootSchema() {
    try {
        Class.forName("org.apache.calcite.jdbc.Driver");
        Properties info = new Properties();
        info.setProperty("lex", "JAVA");
        Connection connection = DriverManager.getConnection("jdbc:calcite:", info);
        CalciteConnection calciteConnection
                  = connection.unwrap(CalciteConnection.class);
        return calciteConnection;
    } catch (SQLException | ClassNotFoundException ex) {
        throw new RuntimeException(ex);
    }
}

和NPE:

[INFO] [talledLocalContainer] java.sql.SQLException: Error while executing SQL "select * from jira.PROJECT_KEY": null
[INFO] [talledLocalContainer]   at org.apache.calcite.avatica.Helper.createException(Helper.java:56)
[INFO] [talledLocalContainer]   at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
[INFO] [talledLocalContainer]   at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:156)
[INFO] [talledLocalContainer]   at org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:218)
[INFO] [talledLocalContainer]   at com.codedoers.jira.smartql.QueryController.request(QueryController.java:23)
...
[INFO] [talledLocalContainer] Caused by: java.lang.NullPointerException
[INFO] [talledLocalContainer]   at Baz.bind(Unknown Source)
[INFO] [talledLocalContainer]   at org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:335)
[INFO] [talledLocalContainer]   at org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:294)
[INFO] [talledLocalContainer]   at org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:559)
[INFO] [talledLocalContainer]   at org.apache.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:550)
[INFO] [talledLocalContainer]   at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:67)
[INFO] [talledLocalContainer]   at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:44)
[INFO] [talledLocalContainer]   at org.apache.calcite.avatica.AvaticaConnection$1.execute(AvaticaConnection.java:630)
[INFO] [talledLocalContainer]   at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:607)
[INFO] [talledLocalContainer]   at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:638)
[INFO] [talledLocalContainer]   at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:149)
[INFO] [talledLocalContainer]   ... 240 more

我正在为JIRA开发一个插件,因此容器是JIRA。 DB是H2。我正在为Calcite借用JIRAs数据源。

有人看到这样的方解石NPE吗?

1 个答案:

答案 0 :(得分:0)

在弄乱代码之后,我发现以下代码段工作

this.schema = JdbcSchema.create(connection.getRootSchema(), "JIRA", datasource, null, null);
connection.getRootSchema().add("JIRA", schema);