Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pax-jdbc-iotdb/osgi.bnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Bundle-SymbolicName:\
org.ops4j.pax.jdbc.iotdb

Bundle-Activator:\
org.ops4j.pax.jdbc.iotdb.impl.Activator

Provide-Capability:\
osgi.service;objectClass=org.osgi.service.jdbc.DataSourceFactory;osgi.jdbc.driver.class=org.apache.iotdb.jdbc.IoTDBDriver;osgi.jdbc.driver.name=iotdb

Private-Package:\
org.ops4j.pax.jdbc.common,\
org.ops4j.pax.jdbc.iotdb.impl

Import-Package:\
*
56 changes: 56 additions & 0 deletions pax-jdbc-iotdb/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

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.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.ops4j.pax</groupId>
<artifactId>jdbc</artifactId>
<version>1.4.6-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<groupId>org.ops4j.pax.jdbc</groupId>
<artifactId>pax-jdbc-iotdb</artifactId>
<packaging>bundle</packaging>

<name>OPS4J Pax JDBC IoTDB Driver Adapter</name>

<dependencies>
<!-- pax-jdbc own artifacts -->

<dependency>
<groupId>org.ops4j.pax.jdbc</groupId>
<artifactId>pax-jdbc-common</artifactId>
</dependency>

<!-- JDBC drivers -->

<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-jdbc</artifactId>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.ops4j.pax.jdbc.iotdb.impl;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.service.jdbc.DataSourceFactory;
import org.apache.iotdb.jdbc.IoTDBDriver;
import java.util.Dictionary;
import java.util.Hashtable;

public class Activator implements BundleActivator {

public void start(BundleContext context) {
IoTDbDataSourceFactory dsf = new IoTDbDataSourceFactory();
Dictionary<String, String> props = new Hashtable<String, String>();
props.put(DataSourceFactory.OSGI_JDBC_DRIVER_CLASS, IoTDBDriver.class.getName());
props.put(DataSourceFactory.OSGI_JDBC_DRIVER_NAME, "iotdb");
context.registerService(DataSourceFactory.class.getName(), dsf, props);
}

public void stop(BundleContext context) {
// EMPTY
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package org.ops4j.pax.jdbc.iotdb.impl;

import javax.sql.DataSource;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
import org.apache.iotdb.jdbc.*;
import org.apache.thrift.transport.TTransportException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class IoTDbDataSource implements DataSource {

private final Logger logger = LoggerFactory.getLogger(IoTDbDataSource.class);

private String url;
private String user;
private String password;
private Properties properties;
private Integer port = 6667;

public IoTDbDataSource() {
properties = new Properties(2);
}

public IoTDbDataSource(String url, String user, String password, Integer port) {
this.url = url;
this.properties = new Properties(5);
properties.setProperty("user",user);
properties.setProperty("password",password);
if(port!=0) {
this.port = port;
}
}

public String getUser() {
return user;
}

public void setUser(String user) {
this.user = user;
properties.setProperty("user",user);
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
properties.setProperty("password",password);
}

public Integer getPort() {
return port;
}

public void setPort(Integer port) {
this.port = port;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

@Override
public Connection getConnection() throws SQLException {
try {
return new IoTDBConnection(url, properties);
} catch (TTransportException e) {
e.printStackTrace();
}
return null;
}

@Override
public Connection getConnection(String username, String password) throws SQLException {
try {
Properties newProp = new Properties(2);
newProp.setProperty("user",username);
newProp.setProperty("password",password);
return new IoTDBConnection(url, newProp);
}
catch (Exception e){
e.printStackTrace();
}
return null;
}


@Override
public PrintWriter getLogWriter() throws SQLException {
return null;
}

@Override
public void setLogWriter(PrintWriter printWriter) throws SQLException {

}

@Override
public void setLoginTimeout(int i) throws SQLException {

}

@Override
public int getLoginTimeout() throws SQLException {
return 0;
}

@Override
public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {
return null;
}

@Override
public <T> T unwrap(Class<T> aClass) throws SQLException {
return null;
}

@Override
public boolean isWrapperFor(Class<?> aClass) throws SQLException {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.ops4j.pax.jdbc.iotdb.impl;

import org.apache.iotdb.jdbc.IoTDBDriver;
import org.ops4j.pax.jdbc.common.BeanConfig;
import org.osgi.service.jdbc.DataSourceFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.sql.ConnectionPoolDataSource;
import javax.sql.DataSource;
import javax.sql.XADataSource;
import java.sql.Driver;
import java.sql.SQLException;
import java.util.Properties;

public class IoTDbDataSourceFactory implements DataSourceFactory {
private final Logger logger = LoggerFactory.getLogger(IoTDbDataSourceFactory.class);
@Override
public DataSource createDataSource(Properties properties) throws SQLException {
IoTDbDataSource ds = new IoTDbDataSource();
setProperties(ds, properties);
return ds;
}
public void setProperties(IoTDbDataSource ds, Properties prop){
Properties properties = (Properties)prop.clone();
String url = (String)properties.remove(DataSourceFactory.JDBC_URL);
if(url!=null){
ds.setUrl(url);
logger.info("URL set {}",url);
}

String user = (String) properties.remove(DataSourceFactory.JDBC_USER);
ds.setUser(user);
logger.info("User set {}",user);


String password = (String) properties.remove(DataSourceFactory.JDBC_PASSWORD);
ds.setPassword(password);
logger.info("Password set {}",password);


logger.info("Remaining properties {}", properties.size());

if (!properties.isEmpty()) {
BeanConfig.configure(ds, properties);
}
}

@Override
public ConnectionPoolDataSource createConnectionPoolDataSource(Properties properties) throws SQLException {
return null;
}

@Override
public XADataSource createXADataSource(Properties properties) throws SQLException {
return null;
}

@Override
public Driver createDriver(Properties properties) throws SQLException {
org.apache.iotdb.jdbc.IoTDBDriver driver = new IoTDBDriver();
return driver;
}
}
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
<version.org.apache.derby>10.14.2.0</version.org.apache.derby>
<version.org.hsqldb>2.5.0</version.org.hsqldb>
<version.org.mariadb.jdbc>2.4.4</version.org.mariadb.jdbc>
<version.org.apache.iotdb>0.10.0-SNAPSHOT</version.org.apache.iotdb>
<version.org.postgresql>42.2.8</version.org.postgresql>
<version.org.xerial.sqlite>3.28.0</version.org.xerial.sqlite>

Expand Down Expand Up @@ -897,6 +898,12 @@
<artifactId>mariadb-java-client</artifactId>
<version>${version.org.mariadb.jdbc}</version>
</dependency>
<dependency>
<groupId>org.apache.iotdb</groupId>
<artifactId>iotdb-jdbc</artifactId>
<version>${version.org.apache.iotdb}</version>
</dependency>

<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
Expand Down Expand Up @@ -952,6 +959,7 @@
<module>pax-jdbc-checkstyle-rules</module>
<module>pax-jdbc</module>
<module>pax-jdbc-common</module>
<module>pax-jdbc-iotdb</module>
<module>pax-jdbc-db2</module>
<module>pax-jdbc-derby</module>
<module>pax-jdbc-derbyclient</module>
Expand Down