Search in sources :

Example 1 with SplunkConnectionImpl

use of org.apache.calcite.adapter.splunk.search.SplunkConnectionImpl in project calcite by apache.

the class SplunkDriver method connect.

@Override
public Connection connect(String url, Properties info) throws SQLException {
    Connection connection = super.connect(url, info);
    CalciteConnection calciteConnection = (CalciteConnection) connection;
    SplunkConnection splunkConnection;
    try {
        String url1 = info.getProperty("url");
        if (url1 == null) {
            throw new IllegalArgumentException("Must specify 'url' property");
        }
        if (url1.equals("mock")) {
            splunkConnection = new MockSplunkConnection();
        } else {
            String user = info.getProperty("user");
            if (user == null) {
                throw new IllegalArgumentException("Must specify 'user' property");
            }
            String password = info.getProperty("password");
            if (password == null) {
                throw new IllegalArgumentException("Must specify 'password' property");
            }
            URL url2 = new URL(url1);
            splunkConnection = new SplunkConnectionImpl(url2, user, password);
        }
    } catch (Exception e) {
        throw new SQLException("Cannot connect", e);
    }
    final SchemaPlus rootSchema = calciteConnection.getRootSchema();
    rootSchema.add("splunk", new SplunkSchema(splunkConnection));
    return connection;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) SplunkConnection(org.apache.calcite.adapter.splunk.search.SplunkConnection) CalciteConnection(org.apache.calcite.jdbc.CalciteConnection) SchemaPlus(org.apache.calcite.schema.SchemaPlus) SplunkConnectionImpl(org.apache.calcite.adapter.splunk.search.SplunkConnectionImpl) CalciteConnection(org.apache.calcite.jdbc.CalciteConnection) URL(java.net.URL) SQLException(java.sql.SQLException) SplunkConnection(org.apache.calcite.adapter.splunk.search.SplunkConnection)

Aggregations

URL (java.net.URL)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 SplunkConnection (org.apache.calcite.adapter.splunk.search.SplunkConnection)1 SplunkConnectionImpl (org.apache.calcite.adapter.splunk.search.SplunkConnectionImpl)1 CalciteConnection (org.apache.calcite.jdbc.CalciteConnection)1 SchemaPlus (org.apache.calcite.schema.SchemaPlus)1