java.sql.DriverPropertyInfo Java Examples

The following examples show how to use java.sql.DriverPropertyInfo. 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: MetaDataRegressionTest.java    From r-course with MIT License 6 votes vote down vote up
/**
 * Fix for BUG#22628 - Driver.getPropertyInfo() throws NullPointerException
 * for URL that only specifies host and/or port.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug22628() throws Exception {
    DriverPropertyInfo[] dpi = new NonRegisteringDriver().getPropertyInfo("jdbc:mysql://bogus:9999", new Properties());

    boolean foundHost = false;
    boolean foundPort = false;

    for (int i = 0; i < dpi.length; i++) {
        if ("bogus".equals(dpi[i].value)) {
            foundHost = true;
        }

        if ("9999".equals(dpi[i].value)) {
            foundPort = true;
        }
    }

    assertTrue(foundHost && foundPort);
}
 
Example #2
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 #3
Source File: UnregisteredDriver.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
public DriverPropertyInfo[] getPropertyInfo(
    String url, Properties info) throws SQLException {
  List<DriverPropertyInfo> list = new ArrayList<DriverPropertyInfo>();

  // First, add the contents of info
  for (Map.Entry<Object, Object> entry : info.entrySet()) {
    list.add(
        new DriverPropertyInfo(
            (String) entry.getKey(),
            (String) entry.getValue()));
  }
  // Next, add property definitions not mentioned in info
  for (ConnectionProperty p : getConnectionProperties()) {
    if (info.containsKey(p.name())) {
      continue;
    }
    list.add(new DriverPropertyInfo(p.name(), null));
  }
  return list.toArray(new DriverPropertyInfo[list.size()]);
}
 
Example #4
Source File: CloudSpannerDriver.java    From spanner-jdbc with MIT License 5 votes vote down vote up
@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
  if (!acceptsURL(url))
    return new DriverPropertyInfo[0];
  ConnectionProperties properties = ConnectionProperties.parse(url);
  properties.setAdditionalConnectionProperties(info);

  return properties.getPropertyInfo();
}
 
Example #5
Source File: ConnectionPropertiesImpl.java    From r-course with MIT License 5 votes vote down vote up
DriverPropertyInfo getAsDriverPropertyInfo() {
    DriverPropertyInfo dpi = new DriverPropertyInfo(this.propertyName, null);
    dpi.choices = getAllowableValues();
    dpi.value = (this.valueAsObject != null) ? this.valueAsObject.toString() : null;
    dpi.required = this.required;
    dpi.description = this.description;

    return dpi;
}
 
Example #6
Source File: ConnectionPropertiesImpl.java    From r-course with MIT License 5 votes vote down vote up
protected DriverPropertyInfo[] exposeAsDriverPropertyInfoInternal(Properties info, int slotsToReserve) throws SQLException {
    initializeProperties(info);

    int numProperties = PROPERTY_LIST.size();

    int listSize = numProperties + slotsToReserve;

    DriverPropertyInfo[] driverProperties = new DriverPropertyInfo[listSize];

    for (int i = slotsToReserve; i < listSize; i++) {
        java.lang.reflect.Field propertyField = PROPERTY_LIST.get(i - slotsToReserve);

        try {
            ConnectionProperty propToExpose = (ConnectionProperty) propertyField.get(this);

            if (info != null) {
                propToExpose.initializeFrom(info, getExceptionInterceptor());
            }

            driverProperties[i] = propToExpose.getAsDriverPropertyInfo();
        } catch (IllegalAccessException iae) {
            throw SQLError.createSQLException(Messages.getString("ConnectionProperties.InternalPropertiesFailure"), SQLError.SQL_STATE_GENERAL_ERROR,
                    getExceptionInterceptor());
        }
    }

    return driverProperties;
}
 
Example #7
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 #8
Source File: DriverPropertyInfoHelper.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
private void addPropInfo(final ArrayList<DriverPropertyInfo> propInfos, final String propName,
	final String defaultVal, final String description, final String[] choices)
{
	DriverPropertyInfo newProp = new DriverPropertyInfo(propName, defaultVal);
	newProp.description = description;
	if (choices != null)
	{
		newProp.choices = choices;
	}
	propInfos.add(newProp);
}
 
Example #9
Source File: DriverPropertyInfoHelper.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
public DriverPropertyInfo[] getPropertyInfo()
{
	ArrayList<DriverPropertyInfo> propInfos = new ArrayList<DriverPropertyInfo>();

	addPropInfo(
		propInfos,
		AUTO_CONNECT_RETRY,
		"false",
		"If true, the driver will keep trying to connect to the same server in case that the socket "
			+ "cannot be established. There is maximum amount of time to keep retrying, which is 15s by "
			+ "default.", null);

	addPropInfo(propInfos, CONNECTIONS_PER_HOST, "10", "The maximum number of connections allowed per "
		+ "host for this Mongo instance. Those connections will be kept in a pool when idle.", null);

	addPropInfo(propInfos, CONNECT_TIMEOUT, "10000", "The connection timeout in milliseconds. ", null);

	addPropInfo(propInfos, CURSOR_FINALIZER_ENABLED, "true", "Sets whether there is a a finalize "
		+ "method created that cleans up instances of DBCursor that the client does not close.",
		null);

	addPropInfo(propInfos, MAX_AUTO_CONNECT_RETRY_TIME, "0",
		"The maximum amount of time in MS to spend retrying to open connection to the same server."
			+ "Default is 0, which means to use the default 15s if autoConnectRetry is on.", null);

	addPropInfo(propInfos, READ_PREFERENCE, "primary",
		"represents preferred replica set members to which a query or command can be sent", new String[] {
				"primary", "primary preferred", "secondary", "secondary preferred", "nearest" });

	addPropInfo(propInfos, SOCKET_TIMEOUT, "0", "The socket timeout in milliseconds It is used for "
		+ "I/O socket read and write operations "
		+ "Socket.setSoTimeout(int) Default is 0 and means no timeout.", null);

	return propInfos.toArray(new DriverPropertyInfo[propInfos.size()]);
}
 
Example #10
Source File: DriverPropertyInfoHelper.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
private void addPropInfo(final ArrayList<DriverPropertyInfo> propInfos, final String propName,
	final String defaultVal, final String description, final String[] choices)
{
	DriverPropertyInfo newProp = new DriverPropertyInfo(propName, defaultVal);
	newProp.description = description;
	if (choices != null)
	{
		newProp.choices = choices;
	}
	propInfos.add(newProp);
}
 
Example #11
Source File: OlapServerDriver.java    From olaper with MIT License 5 votes vote down vote up
@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
		throws SQLException {
       List<DriverPropertyInfo> list = new ArrayList<DriverPropertyInfo>();
       for (Map.Entry<Object, Object> entry : info.entrySet()) {
           list.add(
               new DriverPropertyInfo(
                   (String) entry.getKey(),
                   (String) entry.getValue()));
       }
       return list.toArray(new DriverPropertyInfo[list.size()]);

}
 
Example #12
Source File: DriverPropertyInfoHelper.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
public DriverPropertyInfo[] getPropertyInfo()
{
	ArrayList<DriverPropertyInfo> propInfos = new ArrayList<DriverPropertyInfo>();

	addPropInfo(
		propInfos,
		AUTO_CONNECT_RETRY,
		"false",
		"If true, the driver will keep trying to connect to the same server in case that the socket "
			+ "cannot be established. There is maximum amount of time to keep retrying, which is 15s by "
			+ "default.", null);

	addPropInfo(propInfos, CONNECTIONS_PER_HOST, "10", "The maximum number of connections allowed per "
		+ "host for this Mongo instance. Those connections will be kept in a pool when idle.", null);

	addPropInfo(propInfos, CONNECT_TIMEOUT, "10000", "The connection timeout in milliseconds. ", null);

	addPropInfo(propInfos, CURSOR_FINALIZER_ENABLED, "true", "Sets whether there is a a finalize "
		+ "method created that cleans up instances of DBCursor that the client does not close.",
		null);

	addPropInfo(propInfos, MAX_AUTO_CONNECT_RETRY_TIME, "0",
		"The maximum amount of time in MS to spend retrying to open connection to the same server."
			+ "Default is 0, which means to use the default 15s if autoConnectRetry is on.", null);

	addPropInfo(propInfos, READ_PREFERENCE, "primary",
		"represents preferred replica set members to which a query or command can be sent", new String[] {
				"primary", "primary preferred", "secondary", "secondary preferred", "nearest" });

	addPropInfo(propInfos, SOCKET_TIMEOUT, "0", "The socket timeout in milliseconds It is used for "
		+ "I/O socket read and write operations "
		+ "Socket.setSoTimeout(int) Default is 0 and means no timeout.", null);

	return propInfos.toArray(new DriverPropertyInfo[propInfos.size()]);
}
 
Example #13
Source File: AbstractConnectionProperty.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public DriverPropertyInfo getDriverPropertyInfo(Properties mergedProperties)
{
    String currentValue = mergedProperties.getProperty(key);
    DriverPropertyInfo result = new DriverPropertyInfo(key, currentValue);
    result.required = isRequired.test(mergedProperties);
    return result;
}
 
Example #14
Source File: InvocationReporterImpl.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private String formatDriverPropertyInfo( final DriverPropertyInfo info ) {
  return
      "[ "
      + "name = " + formatValue( info.name )
      + ", value = " + formatValue( info.value )
      + ", required = " + info.required
      + ", choices = " + formatValue( info.choices )
      + ", description = " + formatValue( info.description )
      + " ]";
}
 
Example #15
Source File: PrestoDriver.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
        throws SQLException
{
    Properties properties = new PrestoDriverUri(url, info).getProperties();

    return ConnectionProperties.allProperties().stream()
            .map(property -> property.getDriverPropertyInfo(properties))
            .toArray(DriverPropertyInfo[]::new);
}
 
Example #16
Source File: JdbcPropertySetImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private DriverPropertyInfo getAsDriverPropertyInfo(ReadableProperty<?> pr) {
    PropertyDefinition<?> pdef = pr.getPropertyDefinition();

    DriverPropertyInfo dpi = new DriverPropertyInfo(pdef.getName(), null);
    dpi.choices = pdef.getAllowableValues();
    dpi.value = (pr.getStringValue() != null) ? pr.getStringValue() : null;
    dpi.required = false;
    dpi.description = pdef.getDescription();

    return dpi;
}
 
Example #17
Source File: ESDriver.java    From sql4es with Apache License 2.0 5 votes vote down vote up
@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
	Properties props = (Properties)parseURL(url, info)[3];
	DriverPropertyInfo[] result = new DriverPropertyInfo[props.size()];
	int index = 0;
	for(Map.Entry<Object,Object> entry : props.entrySet()){
		result[index] = new DriverPropertyInfo((String)entry.getKey(), entry.getValue().toString());
		index++;
	}
	return result;
}
 
Example #18
Source File: ConnectionPropertiesImpl.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
DriverPropertyInfo getAsDriverPropertyInfo() {
    DriverPropertyInfo dpi = new DriverPropertyInfo(this.propertyName, null);
    dpi.choices = getAllowableValues();
    dpi.value = (this.valueAsObject != null) ? this.valueAsObject.toString() : null;
    dpi.required = this.required;
    dpi.description = this.description;

    return dpi;
}
 
Example #19
Source File: ConnectionPropertiesImpl.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
protected DriverPropertyInfo[] exposeAsDriverPropertyInfoInternal(Properties info, int slotsToReserve) throws SQLException {
    initializeProperties(info);

    int numProperties = PROPERTY_LIST.size();

    int listSize = numProperties + slotsToReserve;

    DriverPropertyInfo[] driverProperties = new DriverPropertyInfo[listSize];

    for (int i = slotsToReserve; i < listSize; i++) {
        java.lang.reflect.Field propertyField = PROPERTY_LIST.get(i - slotsToReserve);

        try {
            ConnectionProperty propToExpose = (ConnectionProperty) propertyField.get(this);

            if (info != null) {
                propToExpose.initializeFrom(info, getExceptionInterceptor());
            }

            driverProperties[i] = propToExpose.getAsDriverPropertyInfo();
        } catch (IllegalAccessException iae) {
            throw SQLError.createSQLException(Messages.getString("ConnectionProperties.InternalPropertiesFailure"), SQLError.SQL_STATE_GENERAL_ERROR,
                    getExceptionInterceptor());
        }
    }

    return driverProperties;
}
 
Example #20
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 #21
Source File: NashornSQLDriver.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DriverPropertyInfo[] getPropertyInfo(final String url, final Properties info) {
    return new DriverPropertyInfo[0];
}
 
Example #22
Source File: AvaticaNoopDriver.java    From calcite-avatica with Apache License 2.0 4 votes vote down vote up
@Override public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
    throws SQLException {
  return new DriverPropertyInfo[0];
}
 
Example #23
Source File: StubDriver.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
Example #24
Source File: LuckyDogDriver.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
Example #25
Source File: AutoloadedDriver.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
  * Returns an array of DriverPropertyInfo objects describing possible properties.
   @exception SQLException if a database-access error occurs.
   @see java.sql.Driver
  */
public  DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
	throws SQLException
{
	return getDriverModule().getPropertyInfo(url, info);
}
 
Example #26
Source File: NashornSQLDriver.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DriverPropertyInfo[] getPropertyInfo(final String url, final Properties info) {
    return new DriverPropertyInfo[0];
}
 
Example #27
Source File: StubDriver.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
Example #28
Source File: DriverAdapter.java    From vanillacore with Apache License 2.0 4 votes vote down vote up
@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) {
	return null;
}
 
Example #29
Source File: JdbcPropertySetImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public DriverPropertyInfo[] exposeAsDriverPropertyInfo(Properties info, int slotsToReserve) throws SQLException {
    initializeProperties(info);

    int numProperties = PropertyDefinitions.PROPERTY_NAME_TO_PROPERTY_DEFINITION.size();

    int listSize = numProperties + slotsToReserve;

    DriverPropertyInfo[] driverProperties = new DriverPropertyInfo[listSize];

    int i = slotsToReserve;

    for (String propName : PropertyDefinitions.PROPERTY_NAME_TO_PROPERTY_DEFINITION.keySet()) {
        driverProperties[i++] = getAsDriverPropertyInfo(getReadableProperty(propName));
    }

    return driverProperties;
}
 
Example #30
Source File: StubDriver.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
}