org.apache.kylin.jdbc.Driver Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kylin.jdbc;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.apache.calcite.avatica.AvaticaConnection;
import org.apache.calcite.avatica.DriverVersion;
import org.apache.calcite.avatica.Meta;
import org.apache.calcite.avatica.UnregisteredDriver;
/**
*
* Kylin JDBC Driver based on Calcite Avatica and Kylin restful API.
* Supported versions:
*
*
* - jdbc 4.0
* - jdbc 4.1
*
*
*
* Supported Statements:
*
*
* - {@link KylinStatementImpl}
* - {@link KylinPrepareStatementImpl}
*
*
*
* Supported properties:
*
* - user: username
* - password: password
* - ssl: true/false
*
*
*
*
* Driver init code sample:
*
*
* Driver driver = (Driver) Class.forName("org.apache.kylin.kylin.jdbc.Driver").newInstance();
* Properties info = new Properties();
* info.put("user", "user");
* info.put("password", "password");
* info.put("ssl", true);
* Connection conn = driver.connect("jdbc:kylin://{domain}/{project}", info);
*
*
*
*/
public class Driver extends UnregisteredDriver {
public static final String CONNECT_STRING_PREFIX = "jdbc:kylin:";
static {
try {
DriverManager.registerDriver(new Driver());
} catch (SQLException e) {
throw new RuntimeException("Error occurred while registering JDBC driver " + Driver.class.getName() + ": " + e.toString());
}
}
@Override
protected String getConnectStringPrefix() {
return CONNECT_STRING_PREFIX;
}
@Override
protected DriverVersion createDriverVersion() {
return DriverVersion.load(Driver.class, "kylin-jdbc.properties", "Kylin JDBC Driver", "unknown version", "Kylin", "unknown version");
}
@Override
protected String getFactoryClassName(JdbcVersion jdbcVersion) {
switch (jdbcVersion) {
case JDBC_30:
throw new UnsupportedOperationException();
case JDBC_40:
return KylinJdbcFactory.Version40.class.getName();
case JDBC_41:
default:
return KylinJdbcFactory.Version41.class.getName();
}
}
@Override
public Meta createMeta(AvaticaConnection connection) {
return new KylinMeta((KylinConnection) connection);
}
// @Override
// protected Handler createHandler() {
// return new HandlerImpl() {
// @Override
// public void onConnectionInit(AvaticaConnection connection) throws SQLException {
// KylinConnection conn = (KylinConnection) connection;
// RemoteClient runner = ((KylinJdbcFactory) factory).newRemoteClient(conn);
// try {
// runner.connect();
// conn.setMetaProject(runner.getMetadata(conn.getProject()));
// logger.debug("Connection inited.");
// } catch (ConnectionException e) {
// logger.error(e.getLocalizedMessage(), e);
// throw new SQLException(e.getLocalizedMessage());
// }
// }
//
// public void onConnectionClose(AvaticaConnection connection) {
// logger.debug("Connection closed.");
// }
//
// public void onStatementExecute(AvaticaStatement statement, ResultSink resultSink) {
// logger.debug("statement executed.");
// }
//
// public void onStatementClose(AvaticaStatement statement) {
// logger.debug("statement closed.");
// }
// };
// }
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy