Examples of BasicDataSource


Examples of org.apache.commons.dbcp.BasicDataSource

    }
    return convertedValue;
  }

  private BasicDataSource legacyDbcpConfiguration(Map map) {
    BasicDataSource basicDataSource = null;
    if (map.containsKey("JDBC.Driver")) {
      basicDataSource = new BasicDataSource();
      String driver = (String) map.get("JDBC.Driver");
      String url = (String) map.get("JDBC.ConnectionURL");
      String username = (String) map.get("JDBC.Username");
      String password = (String) map.get("JDBC.Password");
      String validationQuery = (String) map.get("Pool.ValidationQuery");
      String maxActive = (String) map.get("Pool.MaximumActiveConnections");
      String maxIdle = (String) map.get("Pool.MaximumIdleConnections");
      String maxWait = (String) map.get("Pool.MaximumWait");

      basicDataSource.setUrl(url);
      basicDataSource.setDriverClassName(driver);
      basicDataSource.setUsername(username);
      basicDataSource.setPassword(password);

      if (notEmpty(validationQuery)) {
        basicDataSource.setValidationQuery(validationQuery);
      }

      if (notEmpty(maxActive)) {
        basicDataSource.setMaxActive(Integer.parseInt(maxActive));
      }

      if (notEmpty(maxIdle)) {
        basicDataSource.setMaxIdle(Integer.parseInt(maxIdle));
      }

      if (notEmpty(maxWait)) {
        basicDataSource.setMaxWait(Integer.parseInt(maxWait));
      }

    }
    return basicDataSource;
  }
View Full Code Here

Examples of org.apache.commons.dbcp.BasicDataSource

                bindings = containerSystem.getJNDIContext().listBindings("java:openejb/Resource/");
                Set<String> dbnames = new TreeSet<String>();
                for (Binding binding : Collections.list(bindings)) {
                    Object value = binding.getObject();
                    if (value instanceof BasicDataSource) {
                        BasicDataSource jdbc = (BasicDataSource) value;
                        String path = getPath(jdbc);
                        if (path != null) {
                            if (dbnames.size() > 9) {
                                throw new ServiceException("Hsql Server can only host 10 database instances");
                            }
View Full Code Here

Examples of org.apache.commons.dbcp.BasicDataSource

    }

    @Test public void test() throws Exception {
        assertNotNull(bean.datasource());
        assertTrue(bean.datasource() instanceof BasicDataSource);
        BasicDataSource ds = (BasicDataSource) bean.datasource();
        assertEquals("org.hsqldb.jdbcDriver", ds.getDriverClassName());
        assertEquals("not:used:url", ds.getUrl());
        assertEquals("foo", ds.getUsername());
        assertEquals("bar", ds.getPassword());

        assertNotNull(bean.resource());
        assertEquals("ok", bean.resource().attr);
    }
View Full Code Here

Examples of org.apache.commons.dbcp.BasicDataSource

     * @return the data source
     * @throws Exception if an error occurs
     */
    private DataSource setUpDataSource() throws Exception
    {
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName(DATABASE_DRIVER);
        ds.setUrl(DATABASE_URL);
        ds.setUsername(DATABASE_USERNAME);
        ds.setPassword(DATABASE_PASSWORD);
        ds.setDefaultAutoCommit(isAutoCommit());

        // prepare the database
        Connection conn = ds.getConnection();
        IDatabaseConnection connection = new DatabaseConnection(conn);
        IDataSet dataSet = new XmlDataSet(new FileInputStream(
                "conf/dataset.xml"));

        try
View Full Code Here

Examples of org.apache.commons.dbcp.BasicDataSource

        if (hsqlDB == null)
        {
            hsqlDB = new HsqlDB(DATABASE_URL, DATABASE_DRIVER, "conf/testdb.script");
        }

        BasicDataSource datasource = new BasicDataSource();
        datasource.setDriverClassName(DATABASE_DRIVER);
        datasource.setUrl(DATABASE_URL);
        datasource.setUsername(DATABASE_USERNAME);
        datasource.setPassword(DATABASE_PASSWORD);

        this.datasource = datasource;
       

        // prepare the database
        IDatabaseConnection connection = new DatabaseConnection(datasource.getConnection());
        IDataSet dataSet = new XmlDataSet(new FileInputStream("conf/dataset.xml"));

        try
        {
            DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
View Full Code Here

Examples of org.apache.commons.dbcp.BasicDataSource

    params.put(PORT.key, port);
    params.put(USER.key, username);
    params.put(PASSWD.key, password);
    params.put(DATABASE.key, database);

    BasicDataSource dataSource = null;
    Connection connection = null;
    try {
      dataSource = factory.createDataSource(params);
      connection = dataSource.getConnection();

      Statement statement = connection.createStatement();

      if (!hasWritableTable(
          "SYSSPATIAL.spatial_ref_sys", "SRID", statement)) { //$NON-NLS-1$
        error = "The 'srid' table is either missing or not accessible; the Teradata datastore cannot work without the srid table.  Please talk to your database administrator.";
        return;
      }

      // Pair is schema, table name
      List<Pair<String, String>> tableNames = new ArrayList<Pair<String, String>>();

      ResultSet resultSet = statement
          .executeQuery("SELECT F_TABLE_NAME,f_geometry_column FROM SYSSPATIAL.GEOMETRY_COLUMNS ORDER BY F_TABLE_NAME;");
      while (resultSet.next()) {
        String schema = database; //$NON-NLS-1$
        String table = resultSet.getString(1); //$NON-NLS-1$
        if (hasWritableTable(database+"."+table, resultSet.getString(2), statement)) { //$NON-NLS-1$
          tableNames.add(Pair.create(schema, table));
        }
      }
      if(tableNames.size() > 0) {
        Collection<TableDescriptor> results = lookupGeometryColumn(
            tableNames, connection);
        tables.addAll(results);
      }
      statement.close();
    } catch (SQLException e) {
      error = "An error occurred when querying the database about the data it contains. Please talk to the administrator: "
          + e.getMessage();
    } catch (IOException io) {
      error = "An error occurred when querying the database about the data it contains. Please talk to the administrator: "
          + io.getMessage();
    } finally {
      if (connection != null) {
        connection.close();
      }
      if (dataSource != null) {
        dataSource.close();
      }
    }
  }
View Full Code Here

Examples of org.apache.commons.dbcp.BasicDataSource

      params.put(PORT.key, port);
      params.put(USER.key, username);
      params.put(PASSWD.key, password);
      params.put(DATABASE.key, "dbc");

      BasicDataSource source = TeradataServiceExtension.getFactory()
          .createDataSource(params);
      Connection connection = source.getConnection();
      try {

        Statement statement = connection.createStatement();
        if (statement
            .execute("SELECT F_TABLE_SCHEMA FROM SYSSPATIAL.GEOMETRY_COLUMNS")) {
          ResultSet resultSet = statement.getResultSet();
          while (resultSet.next()) {
            databaseNames.add(resultSet.getString(1).trim());
          }
        }
        statement.close();
      } finally {
        if (connection != null) {
          connection.close();
        }
        if (source != null) {
          source.close();
        }
      }
    } catch (SQLException e) {
      checkSqlException(e);
    } catch (Exception e) {
View Full Code Here

Examples of org.apache.commons.dbcp.BasicDataSource

        if (hsqlDB == null)
        {
            hsqlDB = new HsqlDB(DATABASE_URL, DATABASE_DRIVER, "conf/testdb.script");
        }

        BasicDataSource datasource = new BasicDataSource();
        datasource.setDriverClassName(DATABASE_DRIVER);
        datasource.setUrl(DATABASE_URL);
        datasource.setUsername(DATABASE_USERNAME);
        datasource.setPassword(DATABASE_PASSWORD);

        this.datasource = datasource;
       

        // prepare the database
        IDatabaseConnection connection = new DatabaseConnection(datasource.getConnection());
        IDataSet dataSet = new XmlDataSet(new FileInputStream("conf/dataset.xml"));

        try
        {
            DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
View Full Code Here

Examples of org.apache.commons.dbcp.BasicDataSource

                        && Context.class.isAssignableFrom(driverClass)) {
                    DataSource ds = getJndiDataSource((Class<Context>) driverClass, def.getUrl());
                    nameToDataSource.put(def.getLogicalName(), ds);
                    nameToDataSourceDef.put(def.getLogicalName(), def);
                } else {
                    BasicDataSource bds =
                        getDriverDataSource(driverClass, def.getUrl(), def.getUser(), def.getPassword());
                    if (def.getMaxPoolSize() > 0) {
                        bds.setMaxActive(def.getMaxPoolSize());
                    }
                    if (def.getValidationQuery() != null && !"".equals(def.getValidationQuery().trim())) {
                        bds.setValidationQuery(def.getValidationQuery());
                    }
                    nameToDataSource.put(def.getLogicalName(), bds);
                    nameToDataSourceDef.put(def.getLogicalName(), def);
                }
            }
View Full Code Here

Examples of org.apache.commons.dbcp.BasicDataSource

     * @param url the JDBC connection URL
     * @return pooling DataSource for accessing the specified database
     */
    private BasicDataSource getDriverDataSource(
            Class<?> driverClass, String url, String user, String password) {
        BasicDataSource ds = new BasicDataSource();
        created.add(ds);

        if (driverClass != null) {
            try {
                // Workaround for Apache Derby:
                // The JDBC specification recommends the Class.forName
                // method without the .newInstance() method call,
                // but it is required after a Derby 'shutdown'
                driverClass.newInstance();
            } catch (Throwable e) {
                // Ignore exceptions as there's no requirement for
                // a JDBC driver class to have a public default constructor
            }

            ds.setDriverClassName(driverClass.getName());
        }

        ds.setUrl(url);
        ds.setUsername(user);
        ds.setPassword(password);
        ds.setDefaultAutoCommit(true);
        ds.setTestOnBorrow(false);
        ds.setTestWhileIdle(true);
        ds.setTimeBetweenEvictionRunsMillis(1000);
        ds.setMaxActive(-1); // unlimited
        ds.setValidationQuery(guessValidationQuery(url));
        ds.setAccessToUnderlyingConnectionAllowed(true);
        ds.setPoolPreparedStatements(true);
        ds.setMaxOpenPreparedStatements(-1); // unlimited
        return ds;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.