diff --git a/pax-jdbc-iotdb/osgi.bnd b/pax-jdbc-iotdb/osgi.bnd new file mode 100644 index 00000000..318e1924 --- /dev/null +++ b/pax-jdbc-iotdb/osgi.bnd @@ -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:\ + * diff --git a/pax-jdbc-iotdb/pom.xml b/pax-jdbc-iotdb/pom.xml new file mode 100644 index 00000000..cf1d8f46 --- /dev/null +++ b/pax-jdbc-iotdb/pom.xml @@ -0,0 +1,56 @@ + + + + + 4.0.0 + + + org.ops4j.pax + jdbc + 1.4.6-SNAPSHOT + ../pom.xml + + + org.ops4j.pax.jdbc + pax-jdbc-iotdb + bundle + + OPS4J Pax JDBC IoTDB Driver Adapter + + + + + + org.ops4j.pax.jdbc + pax-jdbc-common + + + + + + org.apache.iotdb + iotdb-jdbc + + + + + diff --git a/pax-jdbc-iotdb/src/main/java/org/ops4j/pax/jdbc/iotdb/impl/Activator.java b/pax-jdbc-iotdb/src/main/java/org/ops4j/pax/jdbc/iotdb/impl/Activator.java new file mode 100644 index 00000000..4c887e37 --- /dev/null +++ b/pax-jdbc-iotdb/src/main/java/org/ops4j/pax/jdbc/iotdb/impl/Activator.java @@ -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 props = new Hashtable(); + 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 + } + +} \ No newline at end of file diff --git a/pax-jdbc-iotdb/src/main/java/org/ops4j/pax/jdbc/iotdb/impl/IoTDbDataSource.java b/pax-jdbc-iotdb/src/main/java/org/ops4j/pax/jdbc/iotdb/impl/IoTDbDataSource.java new file mode 100644 index 00000000..113989b2 --- /dev/null +++ b/pax-jdbc-iotdb/src/main/java/org/ops4j/pax/jdbc/iotdb/impl/IoTDbDataSource.java @@ -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 unwrap(Class aClass) throws SQLException { + return null; + } + + @Override + public boolean isWrapperFor(Class aClass) throws SQLException { + return false; + } +} diff --git a/pax-jdbc-iotdb/src/main/java/org/ops4j/pax/jdbc/iotdb/impl/IoTDbDataSourceFactory.java b/pax-jdbc-iotdb/src/main/java/org/ops4j/pax/jdbc/iotdb/impl/IoTDbDataSourceFactory.java new file mode 100644 index 00000000..de1bb424 --- /dev/null +++ b/pax-jdbc-iotdb/src/main/java/org/ops4j/pax/jdbc/iotdb/impl/IoTDbDataSourceFactory.java @@ -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; + } +} diff --git a/pom.xml b/pom.xml index 3dcbdc2d..36c54e5d 100644 --- a/pom.xml +++ b/pom.xml @@ -170,6 +170,7 @@ 10.14.2.0 2.5.0 2.4.4 + 0.10.0-SNAPSHOT 42.2.8 3.28.0 @@ -897,6 +898,12 @@ mariadb-java-client ${version.org.mariadb.jdbc} + + org.apache.iotdb + iotdb-jdbc + ${version.org.apache.iotdb} + + com.microsoft.sqlserver mssql-jdbc @@ -952,6 +959,7 @@ pax-jdbc-checkstyle-rules pax-jdbc pax-jdbc-common + pax-jdbc-iotdb pax-jdbc-db2 pax-jdbc-derby pax-jdbc-derbyclient