Java Code Examples for java.sql.Driver#getPropertyInfo()

The following examples show how to use java.sql.Driver#getPropertyInfo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CloudSpannerDriverTest.java    From spanner-jdbc with MIT License 6 votes vote down vote up
@Test
public void driverPropertyInfoWithoutValues() throws SQLException {
  Driver driver = getDriver();
  DriverPropertyInfo[] properties =
      driver.getPropertyInfo("jdbc:cloudspanner://localhost", null);
  assertEquals(ConnectionProperties.NUMBER_OF_PROPERTIES, properties.length);
  for (DriverPropertyInfo property : properties) {
    if (property.name.equals("AllowExtendedMode") || property.name.equals("AsyncDdlOperations")
        || property.name.equals("AutoBatchDdlOperations")
        || property.name.equals("BatchReadOnlyMode") || property.name.equals("UseCustomHost"))
      assertEquals("false", property.value);
    else if (property.name.equals("ReportDefaultSchemaAsNull"))
      assertEquals("true", property.value);
    else
      assertNull(property.value);
  }
}
 
Example 2
Source File: CloudSpannerDriverTest.java    From spanner-jdbc with MIT License 5 votes vote down vote up
@Test
public void driverPropertyInfoWithURLValues() throws SQLException {
  Driver driver = getDriver();
  DriverPropertyInfo[] properties = driver.getPropertyInfo(
      "jdbc:cloudspanner://localhost;Project=adroit-hall-xxx;Instance=test-instance;Database=testdb;PvtKeyPath=C:\\Users\\MyUserName\\Documents\\CloudSpannerKeys\\cloudspanner3.json;SimulateProductName=PostgreSQL",
      null);
  assertEquals(ConnectionProperties.NUMBER_OF_PROPERTIES, properties.length);
  assertEquals("adroit-hall-xxx", properties[0].value);
  assertEquals("test-instance", properties[1].value);
  assertEquals("testdb", properties[2].value);
  assertEquals("C:\\Users\\MyUserName\\Documents\\CloudSpannerKeys\\cloudspanner3.json",
      properties[3].value);
  assertNull(properties[4].value);
  assertEquals("PostgreSQL", properties[5].value);
}
 
Example 3
Source File: HiveDriver.java    From pentaho-hadoop-shims with Apache License 2.0 5 votes vote down vote up
@Override public DriverPropertyInfo[] getPropertyInfo( String url, Properties info ) throws SQLException {
  Driver driverDelegate = this.delegate;
  if ( driverDelegate == null ) {
    return null;
  }
  return driverDelegate.getPropertyInfo( url, info );
}
 
Example 4
Source File: ConnectionStringHolder.java    From beakerx with Apache License 2.0 5 votes vote down vote up
protected static String getProperty(String property, String connectionString, Driver dbDriver){
  String ret = null;
  if(property != null && !property.isEmpty() && dbDriver != null && connectionString != null && !connectionString.isEmpty()){
    try {
      for (DriverPropertyInfo dpi : dbDriver.getPropertyInfo(connectionString, new Properties())) {
        if(property.equalsIgnoreCase(dpi.name.trim())){
          ret = dpi.value;
          break;
        }
      }
    } catch (SQLException e) {}
  }
  return ret;
}
 
Example 5
Source File: BootAllTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * DERBY-1296 - Setting property db.system.bootAll causes an Exception
 *
 * Check that setting the system property "derby.system.bootAll" will not
 * cause an exception when used in combination with the system property
 * "derby.system.home".
 *
 * The property "derby.system.home" is set by default for all tests and does
 * not need to be explicitly set in this test.
 */
public void testSettingBootAllPropertyWithHomePropertySet() 
        throws Exception 
{
    JDBCClient embedded = getTestConfiguration().getJDBCClient();

    String driverName = embedded.getJDBCDriverName();
    String url = embedded.getUrlBase();
    
    // Ensure the engine is not booted.
    try {
        DriverManager.getDriver(url);
        fail("Derby is booted!");
    } catch (SQLException e) {
   }

    Class.forName(driverName).newInstance();

    Driver driver = DriverManager.getDriver(url);

    DriverPropertyInfo[] attributes = driver.getPropertyInfo(url, null);
    
    String returnedDatabases[] = null;
    for (int i = 0; i < attributes.length; i++) {
        if (attributes[i].name.equalsIgnoreCase("databaseName")) {
            returnedDatabases = attributes[i].choices;
        }
    }
    
    // We expect at least four databases to be booted,
    // but it could be more if other tests have left databases
    // around.
    // DERBY-2069 the single use databases are not
    // booted automatically, once DERBY-2069 is fixed
    // the length can be compared to four.
    assertNotNull(returnedDatabases);
    assertTrue("Fewer databases booted than expected",
            returnedDatabases.length >= 1);
}
 
Example 6
Source File: BootAllTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * DERBY-1296 - Setting property gemfirexd.system.bootAll causes an Exception
 *
 * Check that setting the system property "gemfirexd.system.bootAll" will not 
 * cause an exception when used in combination with the system property
 * "gemfirexd.system.home".
 *
 * The property "gemfirexd.system.home" is set by default for all tests and does
 * not need to be explicitly set in this test.
 */
public void testSettingBootAllPropertyWithHomePropertySet() 
        throws Exception 
{
    JDBCClient embedded = getTestConfiguration().getJDBCClient();

    String driverName = embedded.getJDBCDriverName();
    String url = embedded.getUrlBase();
    
    // Ensure the engine is not booted.
    try {
        DriverManager.getDriver(url);
        fail("Derby is booted!");
    } catch (SQLException e) {
   }

    Class.forName(driverName).newInstance();

    Driver driver = DriverManager.getDriver(url);

    DriverPropertyInfo[] attributes = driver.getPropertyInfo(url, null);
    
    String returnedDatabases[] = null;
    for (int i = 0; i < attributes.length; i++) {
        if (attributes[i].name.equalsIgnoreCase("databaseName")) {
            returnedDatabases = attributes[i].choices;
        }
    }
    
    // We expect at least four databases to be booted,
    // but it could be more if other tests have left databases
    // around.
    // DERBY-2069 the single use databases are not
    // booted automatically, once DERBY-2069 is fixed
    // the length can be compared to four.
    assertNotNull(returnedDatabases);
    // GemStone changes BEGIN
    // in gemfirexd, there are no databaseNames
    /*
     assertTrue("Fewer databases booted than expected",
             returnedDatabases.length >= 1);
     */
    assertEquals("Did not expect any databaseName",
                 0,
                 returnedDatabases.length);
    // GemStone changes END
}
 
Example 7
Source File: SnowflakeDriverIT.java    From snowflake-jdbc with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetPropertyInfo() throws SQLException
{
  // Test with blank URL and no properties. ServerURL is needed.
  String url = "";
  Properties props = new Properties();
  Driver driver = DriverManager.getDriver("jdbc:snowflake://snowflake.reg.local:8082");
  DriverPropertyInfo[] info = driver.getPropertyInfo(url, props);
  assertEquals(1, info.length);
  assertEquals("serverURL", info[0].name);
  assertEquals("server URL in form of <protocol>://<host or domain>:<port number>/<path of resource>",
               info[0].description);

  // Test with URL that requires username and password.
  url = "jdbc:snowflake://snowflake.reg.local:8082";
  info = driver.getPropertyInfo(url, props);
  assertEquals(2, info.length);
  assertEquals("user", info[0].name);
  assertEquals("username for account",
               info[0].description);
  assertEquals("password", info[1].name);
  assertEquals("password for account", info[1].description);

  // Add username and try again; get password requirement back
  props.put("user", "snowman");
  props.put("password", "test");
  info = driver.getPropertyInfo(url, props);
  assertEquals(0, info.length);

  props.put("useProxy", "true");
  info = driver.getPropertyInfo(url, props);
  assertEquals(2, info.length);
  assertEquals("proxyHost", info[0].name);
  assertEquals("proxy host name", info[0].description);
  assertEquals("proxyPort", info[1].name);
  assertEquals("proxy port; should be an integer", info[1].description);

  props.put("proxyHost", "dummyHost");
  props.put("proxyPort", "dummyPort");
  info = driver.getPropertyInfo(url, props);
  assertEquals(0, info.length);

  // invalid URL still throws SQLException
  try
  {
    url = "snowflake.reg.local:8082";
    driver.getPropertyInfo(url, props);
  }
  catch (SQLException e)
  {
    assertEquals((int) ErrorCode.INVALID_CONNECT_STRING.getMessageCode(), e.getErrorCode());
  }
}
 
Example 8
Source File: BootAllTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * DERBY-1296 - Setting property gemfirexd.system.bootAll causes an Exception
 *
 * Check that setting the system property "gemfirexd.system.bootAll" will not 
 * cause an exception when used in combination with the system property
 * "gemfirexd.system.home".
 *
 * The property "gemfirexd.system.home" is set by default for all tests and does
 * not need to be explicitly set in this test.
 */
public void testSettingBootAllPropertyWithHomePropertySet() 
        throws Exception 
{
    JDBCClient embedded = getTestConfiguration().getJDBCClient();

    String driverName = embedded.getJDBCDriverName();
    String url = embedded.getUrlBase();
    
    // Ensure the engine is not booted.
    try {
        DriverManager.getDriver(url);
        fail("Derby is booted!");
    } catch (SQLException e) {
   }

    Class.forName(driverName).newInstance();

    Driver driver = DriverManager.getDriver(url);

    DriverPropertyInfo[] attributes = driver.getPropertyInfo(url, null);
    
    String returnedDatabases[] = null;
    for (int i = 0; i < attributes.length; i++) {
        if (attributes[i].name.equalsIgnoreCase("databaseName")) {
            returnedDatabases = attributes[i].choices;
        }
    }
    
    // We expect at least four databases to be booted,
    // but it could be more if other tests have left databases
    // around.
    // DERBY-2069 the single use databases are not
    // booted automatically, once DERBY-2069 is fixed
    // the length can be compared to four.
    assertNotNull(returnedDatabases);
    // GemStone changes BEGIN
    // in gemfirexd, there are no databaseNames
    /*
     assertTrue("Fewer databases booted than expected",
             returnedDatabases.length >= 1);
     */
    assertEquals("Did not expect any databaseName",
                 0,
                 returnedDatabases.length);
    // GemStone changes END
}