Exemplo n.º 1
0
  /*
   * (non-Javadoc)
   *
   * @see javax.sql.CommonDataSource#setLogWriter(java.io.PrintWriter)
   */
  @Override
  public void setLogWriter(PrintWriter out) throws SQLException {
    if (datasource == null)
      throw new ConfigurationException("Logic DataSource in Oceanus, do not support this function");

    datasource.setLogWriter(out);
  }
Exemplo n.º 2
0
 public void setLogWriter(PrintWriter out) throws SQLException {
   realDataSource.setLogWriter(out);
 }
Exemplo n.º 3
0
 public void setLogWriter(PrintWriter out) throws SQLException {
   ds.setLogWriter(out);
 }
Exemplo n.º 4
0
 public void setLogWriter(PrintWriter arg0) throws SQLException {
   delegate.setLogWriter(arg0);
 }
Exemplo n.º 5
0
  /**
   * 创建数据源
   *
   * @return 创建好的数据源
   * @throws SQLException
   */
  protected DataSource createDataSource() throws SQLException {
    if (closed) throw new SQLException("The DataSource is closed.");

    if (dataSource != null) {
      return dataSource;
    }

    synchronized (this) {
      if (dataSource != null) return dataSource;

      Driver driverToUse = this.driver;
      if (driverToUse == null) {
        Class<?> driverFromCCL = null;
        if (driverClassName != null) {
          try {
            driverFromCCL = Class.forName(driverClassName);
          } catch (ClassNotFoundException e) {
            Log.e(e, tag, "Cannot load JDBC driver class " + driverClassName);
            throw new SQLException(e);
          }
        }

        try {
          if (driverFromCCL == null) {
            driverToUse = DriverManager.getDriver(url);
          } else {
            driverToUse = (Driver) driverFromCCL.newInstance();
            if (!driverToUse.acceptsURL(url)) {
              throw new SQLException("No suitable driver", "08001");
            }
          }
        } catch (Exception e) {
          Log.e(
              e,
              tag,
              "Cannot create JDBC driver of class %s for connection url %s",
              driverClassName != null ? driverClassName : "",
              url);
          throw new SQLException(e);
        }
        this.driver = driverToUse;
      }

      String user = userName;
      if (user != null) {
        props.put("user", user);
      } else {
        Log.w(tag, "DataSource configured without a 'username'");
      }

      String pwd = password;
      if (pwd != null) {
        props.put("password", pwd);
      } else {
        Log.w(tag, "DataSource configured without a 'password'");
      }

      try {
        connectionFactory = new JdbcConnectionFactory(driver, url, props);
        jdbcConnectionValidator = new JdbcConnectionValidator();
        pool =
            new BoundedBlockingPool<>(maxConnections, jdbcConnectionValidator, connectionFactory);
        dataSource = new PooledDataSource<>(pool);
        dataSource.setLogWriter(logWriter);
      } catch (SQLException e) {
        Log.e(e, tag, "Cannot create a datasource.");
        throw new SQLException(e);
      }
      return dataSource;
    }
  }