calcite-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From 勾王敏浩 <gwm...@mails.tsinghua.edu.cn>
Subject Re: calcite close connection
Date Tue, 28 May 2019 03:41:38 GMT
Hi,
  My sample code is like this:

package calcite;

import dwf3s.PGConnection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.calcite.adapter.jdbc.JdbcSchema;
import org.apache.calcite.jdbc.CalciteConnection;
import org.apache.calcite.schema.Schema;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.commons.dbcp2.BasicDataSource;

public class CalciteConnectionPGAllTest {

  public static void main(String[] args) throws ClassNotFoundException, SQLException {
    for (int i = 0; i < 10000; i++) {
      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);
      SchemaPlus rootSchema = calciteConnection.getRootSchema();

      // 本地Schema.
      // Schema schema = ReflectiveSchema.create(calciteConnection, rootSchema, "hr",
      // new HrSchema());

      /**
       * 此处为不同数据源的实际操作部分,BasicDataSource为Apache DBCP的连接池
       */
      Class.forName("org.postgresql.Driver");
      BasicDataSource dataSource = new BasicDataSource();
      dataSource.setUrl("jdbc:postgresql://192.168.130.7:5432/postgres");
      dataSource.setUsername("postgres");
      dataSource.setPassword("postgres");
      dataSource.addConnectionProperty("remarks", "true");
      dataSource.addConnectionProperty("useInformationSchema", "true");

      Schema schema = JdbcSchema.create(rootSchema, "hr", dataSource, null, "pgtest");
      rootSchema.add("hr", schema);
      Statement statement = calciteConnection.createStatement();
      ResultSet resultSet = statement.executeQuery("select * from hr.dwf3s");
      System.out.println(String.format("第%s个客户端", i));
      resultSet.close();
      statement.close();
      connection.close();
    }
  }
}

Best Regards,
Wangminhao Gou


> -----原始邮件-----
> 发件人: "勾王敏浩" <gwmh18@mails.tsinghua.edu.cn>
> 发送时间: 2019-05-28 10:39:21 (星期二)
> 收件人: dev@calcite.apache.org
> 抄送: 
> 主题: calcite close connection
> 
> Hi,
>     I found that when I close the calciteConnection,the subSchema connection is not auto-closed...
> 
> 
> Best Regards
> Wangminhao Gou
Mime
View raw message