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

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

本文整理了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

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

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

  1. /**
  2. * Returns a connection to the named database
  3. *
  4. * @param instance the name of the database
  5. * @return a connection to that database
  6. * @throws SQLException if there is a problem with the underlying database
  7. * @throws ClassNotFoundException if the class that the instance uses cannot be found
  8. */
  9. public static Database getDatabase(String instance)
  10. throws SQLException, ClassNotFoundException {
  11. Database database;
  12. // Only one thread to configure or test for a DataSource
  13. synchronized (databases) {
  14. // If we have this DataSource already configured
  15. if (databases.containsKey(instance)) {
  16. database = databases.get(instance);
  17. } else {
  18. Properties props = PropertiesUtil.getPropertiesStartingWith(instance);
  19. try {
  20. database = new Database(PropertiesUtil.stripStart(instance, props));
  21. } catch (Exception e) {
  22. throw new RuntimeException("Failed to initialise " + instance, e);
  23. }
  24. }
  25. }
  26. databases.put(instance, database);
  27. return database;
  28. }
  29. }

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

  1. /**
  2. * Returns a connection to the named database
  3. *
  4. * @param instance the name of the database
  5. * @return a connection to that database
  6. * @throws SQLException if there is a problem with the underlying database
  7. * @throws ClassNotFoundException if the class that the instance uses cannot be found
  8. */
  9. public static Database getDatabase(String instance)
  10. throws SQLException, ClassNotFoundException {
  11. Database database;
  12. // Only one thread to configure or test for a DataSource
  13. synchronized (databases) {
  14. // If we have this DataSource already configured
  15. if (databases.containsKey(instance)) {
  16. database = databases.get(instance);
  17. } else {
  18. Properties props = PropertiesUtil.getPropertiesStartingWith(instance);
  19. try {
  20. database = new Database(PropertiesUtil.stripStart(instance, props));
  21. } catch (Exception e) {
  22. throw new RuntimeException("Failed to initialise " + instance, e);
  23. }
  24. }
  25. }
  26. databases.put(instance, database);
  27. return database;
  28. }
  29. }

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

  1. public void testInvalidDataSourceClass() throws Exception {
  2. Properties invalidProps = new Properties();
  3. invalidProps.put("datasource.class", "org.class.that.cannot.be.Found");
  4. try {
  5. Database db = new Database(invalidProps);
  6. fail("Expected: ClassNotFoundException");
  7. } catch (ClassNotFoundException e) {
  8. }
  9. }

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

  1. public void testNullProperties() throws Exception {
  2. try {
  3. Database db = new Database(null);
  4. fail("Expected: NullPointerException");
  5. } catch (NullPointerException e) {
  6. }
  7. }

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

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

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

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

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

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

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

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

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

  1. public void testVersionIsAtLeast() throws Exception {
  2. Database db = new Database(props);
  3. db.version = "9.3";
  4. assertTrue(db.isVersionAtLeast("9.2"));
  5. assertTrue(db.isVersionAtLeast("9.1.7"));
  6. assertTrue(db.isVersionAtLeast("8"));
  7. assertTrue(db.isVersionAtLeast("9.3"));
  8. assertTrue(db.isVersionAtLeast("9.3.0"));
  9. assertFalse(db.isVersionAtLeast("10"));
  10. assertFalse(db.isVersionAtLeast("9.4"));
  11. assertFalse(db.isVersionAtLeast("9.3.1"));
  12. db.version = "9.2.1";
  13. assertTrue(db.isVersionAtLeast("9.2"));
  14. assertTrue(db.isVersionAtLeast("9.2.0"));
  15. assertTrue(db.isVersionAtLeast("9.2.1.0"));
  16. assertFalse(db.isVersionAtLeast("9.2.1.1"));
  17. assertFalse(db.isVersionAtLeast("9.2.2"));
  18. db.version = "9.4beta3";
  19. assertTrue(db.isVersionAtLeast("9.2"));
  20. assertTrue(db.isVersionAtLeast("9.4.0"));
  21. assertFalse(db.isVersionAtLeast("9.5"));
  22. }

相关文章