org.intermine.sql.Database.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(120)

本文整理了Java中org.intermine.sql.Database.<init>()方法的一些代码示例,展示了Database.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Database.<init>()方法的具体详情如下:
包路径:org.intermine.sql.Database
类名称:Database
方法名:<init>

Database.<init>介绍

[英]No argument constructor for testing purposes
[中]没有用于测试目的的参数构造函数

代码示例

代码示例来源:origin: intermine/intermine

public void testInvalidMethod() throws Exception {
  Properties invalidProps = new Properties();
  invalidProps.put("datasource.class", "org.postgresql.ds.PGPoolingDataSource");
  invalidProps.put("datasource.someRubbish", "blahblahblah");
  Database db = new Database(invalidProps);
}

代码示例来源:origin: intermine/intermine

/**
   * Returns a connection to the named database
   *
   * @param instance the name of the database
   * @return a connection to that database
   * @throws SQLException if there is a problem with the underlying database
   * @throws ClassNotFoundException if the class that the instance uses cannot be found
   */
  public static Database getDatabase(String instance)
    throws SQLException, ClassNotFoundException {
    Database database;

    // Only one thread to configure or test for a DataSource
    synchronized (databases) {
      // If we have this DataSource already configured
      if (databases.containsKey(instance)) {
        database = databases.get(instance);
      } else {
        Properties props = PropertiesUtil.getPropertiesStartingWith(instance);
        try {
          database = new Database(PropertiesUtil.stripStart(instance, props));
        } catch (Exception e) {
          throw new RuntimeException("Failed to initialise " + instance, e);
        }
      }
    }
    databases.put(instance, database);
    return database;
  }
}

代码示例来源:origin: org.intermine/intermine-objectstore

/**
   * Returns a connection to the named database
   *
   * @param instance the name of the database
   * @return a connection to that database
   * @throws SQLException if there is a problem with the underlying database
   * @throws ClassNotFoundException if the class that the instance uses cannot be found
   */
  public static Database getDatabase(String instance)
    throws SQLException, ClassNotFoundException {
    Database database;

    // Only one thread to configure or test for a DataSource
    synchronized (databases) {
      // If we have this DataSource already configured
      if (databases.containsKey(instance)) {
        database = databases.get(instance);
      } else {
        Properties props = PropertiesUtil.getPropertiesStartingWith(instance);
        try {
          database = new Database(PropertiesUtil.stripStart(instance, props));
        } catch (Exception e) {
          throw new RuntimeException("Failed to initialise " + instance, e);
        }
      }
    }
    databases.put(instance, database);
    return database;
  }
}

代码示例来源:origin: intermine/intermine

public void testInvalidDataSourceClass() throws Exception {
  Properties invalidProps = new Properties();
  invalidProps.put("datasource.class", "org.class.that.cannot.be.Found");
  try {
    Database db = new Database(invalidProps);
    fail("Expected: ClassNotFoundException");
  } catch (ClassNotFoundException e) {
  }
}

代码示例来源:origin: intermine/intermine

public void testNullProperties() throws Exception {
  try {
    Database db = new Database(null);
    fail("Expected: NullPointerException");
  } catch (NullPointerException e) {
  }
}

代码示例来源:origin: intermine/intermine

public void testURL() throws Exception {
  Database db = new Database(props);
  assertEquals("jdbc:postgresql://dbserver.mydomain.org/test", db.getURL());
}

代码示例来源:origin: intermine/intermine

public void testUser() throws Exception {
  Database db = new Database(props);
  assertEquals("auser", db.getUser());
}

代码示例来源:origin: intermine/intermine

public void testPassword() throws Exception {
  Database db = new Database(props);
  assertEquals("secret", db.getPassword());
}

代码示例来源:origin: intermine/intermine

public void testConfigure() throws Exception {
  Database db = new Database();
  db.configure(props);
  assertTrue(db.getDataSource() != null);
  assertTrue(db.getDataSource() instanceof PGPoolingDataSource);
  assertEquals("PostgreSQL", db.getPlatform());
  assertEquals("dbserver.mydomain.org", ((PGPoolingDataSource) db.getDataSource()).getServerName());
  assertEquals("test", ((PGPoolingDataSource) db.getDataSource()).getDatabaseName());
  assertEquals(10, ((PGPoolingDataSource) db.getDataSource()).getMaxConnections());
}

代码示例来源:origin: intermine/intermine

public void testVersionIsAtLeast() throws Exception {
  Database db = new Database(props);
  db.version = "9.3";
  assertTrue(db.isVersionAtLeast("9.2"));
  assertTrue(db.isVersionAtLeast("9.1.7"));
  assertTrue(db.isVersionAtLeast("8"));
  assertTrue(db.isVersionAtLeast("9.3"));
  assertTrue(db.isVersionAtLeast("9.3.0"));
  assertFalse(db.isVersionAtLeast("10"));
  assertFalse(db.isVersionAtLeast("9.4"));
  assertFalse(db.isVersionAtLeast("9.3.1"));
  db.version = "9.2.1";
  assertTrue(db.isVersionAtLeast("9.2"));
  assertTrue(db.isVersionAtLeast("9.2.0"));
  assertTrue(db.isVersionAtLeast("9.2.1.0"));
  assertFalse(db.isVersionAtLeast("9.2.1.1"));
  assertFalse(db.isVersionAtLeast("9.2.2"));
  db.version = "9.4beta3";
  assertTrue(db.isVersionAtLeast("9.2"));
  assertTrue(db.isVersionAtLeast("9.4.0"));
  assertFalse(db.isVersionAtLeast("9.5"));
}

相关文章