Java Code Examples for java.sql.Connection#getClientInfo()

The following examples show how to use java.sql.Connection#getClientInfo() . 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: ConnectionIT.java    From snowflake-jdbc with Apache License 2.0 6 votes vote down vote up
/**
 * Verify the passed heartbeat frequency, which is too small, is changed to
 * the smallest valid value.
 */
@Test
public void testHeartbeatFrequencyTooSmall() throws Exception
{
  Properties paramProperties = new Properties();
  paramProperties.put(CLIENT_SESSION_KEEP_ALIVE_HEARTBEAT_FREQUENCY, 2);
  Connection connection = getConnection(paramProperties);

  connection.getClientInfo(CLIENT_SESSION_KEEP_ALIVE_HEARTBEAT_FREQUENCY);

  for (Enumeration<?> enums = paramProperties.propertyNames();
       enums.hasMoreElements(); )
  {
    String key = (String) enums.nextElement();
    ResultSet rs = connection.createStatement().executeQuery(
        String.format("show parameters like '%s'", key));
    rs.next();
    String value = rs.getString("value");

    assertThat(key, value, equalTo("900"));
  }
}
 
Example 2
Source File: ConnectionIT.java    From snowflake-jdbc with Apache License 2.0 6 votes vote down vote up
/**
 * Verify the passed heartbeat frequency, which is too large, is changed to
 * the maximum valid value.
 */
@Test
public void testHeartbeatFrequencyTooLarge() throws Exception
{
  Properties paramProperties = new Properties();
  paramProperties.put(CLIENT_SESSION_KEEP_ALIVE_HEARTBEAT_FREQUENCY, 4000);
  Connection connection = getConnection(paramProperties);

  connection.getClientInfo(CLIENT_SESSION_KEEP_ALIVE_HEARTBEAT_FREQUENCY);

  for (Enumeration<?> enums = paramProperties.propertyNames();
       enums.hasMoreElements(); )
  {
    String key = (String) enums.nextElement();
    ResultSet rs = connection.createStatement().executeQuery(
        String.format("show parameters like '%s'", key));
    rs.next();
    String value = rs.getString("value");

    assertThat(key, value, equalTo("3600"));
  }
}
 
Example 3
Source File: ConnectionIT.java    From snowflake-jdbc with Apache License 2.0 6 votes vote down vote up
/**
 * Verify the passed heartbeat frequency matches the output value if the
 * input is valid (between 900 and 3600).
 */
@Test
public void testHeartbeatFrequencyValidValue() throws Exception
{
  Properties paramProperties = new Properties();
  paramProperties.put(CLIENT_SESSION_KEEP_ALIVE_HEARTBEAT_FREQUENCY, 1800);
  Connection connection = getConnection(paramProperties);

  connection.getClientInfo(CLIENT_SESSION_KEEP_ALIVE_HEARTBEAT_FREQUENCY);

  for (Enumeration<?> enums = paramProperties.propertyNames();
       enums.hasMoreElements(); )
  {
    String key = (String) enums.nextElement();
    ResultSet rs = connection.createStatement().executeQuery(
        String.format("show parameters like '%s'", key));
    rs.next();
    String value = rs.getString("value");

    assertThat(key, value, equalTo(paramProperties.get(key).toString()));
  }
}
 
Example 4
Source File: BaseTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private static void deletePriorSequences(long ts, Connection globalConn) throws Exception {
    // TODO: drop tenant-specific sequences too
    ResultSet rs = globalConn.createStatement().executeQuery("SELECT " 
            + PhoenixDatabaseMetaData.TENANT_ID + ","
            + PhoenixDatabaseMetaData.SEQUENCE_SCHEMA + "," 
            + PhoenixDatabaseMetaData.SEQUENCE_NAME 
            + " FROM " + PhoenixDatabaseMetaData.SEQUENCE_FULLNAME_ESCAPED);
    String lastTenantId = null;
    Connection conn = globalConn;
    while (rs.next()) {
        String tenantId = rs.getString(1);
        if (tenantId != null && !tenantId.equals(lastTenantId))  {
            if (lastTenantId != null) {
                conn.close();
            }
            // Open tenant-specific connection when we find a new one
            Properties props = new Properties(globalConn.getClientInfo());
            props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
            conn = DriverManager.getConnection(url, props);
            lastTenantId = tenantId;
        }

        logger.info("DROP SEQUENCE STATEMENT: DROP SEQUENCE " + SchemaUtil.getEscapedTableName(rs.getString(2), rs.getString(3)));
        conn.createStatement().execute("DROP SEQUENCE " + SchemaUtil.getEscapedTableName(rs.getString(2), rs.getString(3)));
    }
}
 
Example 5
Source File: ConnectionRegressionTest.java    From r-course with MIT License 5 votes vote down vote up
/**
 * Tests fix for Bug#56122 - JDBC4 functionality failure when using replication connections.
 */
public void testBug56122() throws Exception {
    for (final Connection testConn : new Connection[] { this.conn, getFailoverConnection(), getLoadBalancedConnection(),
            getMasterSlaveReplicationConnection() }) {
        testConn.createClob();
        testConn.createBlob();
        testConn.createNClob();
        testConn.createSQLXML();
        testConn.isValid(12345);
        testConn.setClientInfo(new Properties());
        testConn.setClientInfo("NAME", "VALUE");
        testConn.getClientInfo();
        testConn.getClientInfo("CLIENT");
        assertThrows(SQLFeatureNotSupportedException.class, new Callable<Void>() {
            public Void call() throws Exception {
                testConn.createArrayOf("A_TYPE", null);
                return null;
            }
        });
        assertThrows(SQLFeatureNotSupportedException.class, new Callable<Void>() {
            public Void call() throws Exception {
                testConn.createStruct("A_TYPE", null);
                return null;
            }
        });
    }
}
 
Example 6
Source File: ConnectionRegressionTest.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Tests fix for Bug#56122 - JDBC4 functionality failure when using replication connections.
 */
public void testBug56122() throws Exception {
    for (final Connection testConn : new Connection[] { this.conn, getFailoverConnection(), getLoadBalancedConnection(),
            getMasterSlaveReplicationConnection() }) {
        testConn.createClob();
        testConn.createBlob();
        testConn.createNClob();
        testConn.createSQLXML();
        testConn.isValid(12345);
        testConn.setClientInfo(new Properties());
        testConn.setClientInfo("NAME", "VALUE");
        testConn.getClientInfo();
        testConn.getClientInfo("CLIENT");
        assertThrows(SQLFeatureNotSupportedException.class, new Callable<Void>() {
            public Void call() throws Exception {
                testConn.createArrayOf("A_TYPE", null);
                return null;
            }
        });
        assertThrows(SQLFeatureNotSupportedException.class, new Callable<Void>() {
            public Void call() throws Exception {
                testConn.createStruct("A_TYPE", null);
                return null;
            }
        });
    }
}
 
Example 7
Source File: CsvUpsertExecutor.java    From phoenix with Apache License 2.0 5 votes vote down vote up
SimpleDatatypeConversionFunction(PDataType dataType, Connection conn) {
    Properties props = null;
    try {
        props = conn.getClientInfo();
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
    this.dataType = dataType;
    if(dataType.isCoercibleTo(PTimestamp.INSTANCE)) {
        // TODO: move to DateUtil
        String dateFormat;
        int dateSqlType = dataType.getResultSetSqlType();
        if (dateSqlType == Types.DATE) {
            dateFormat = props.getProperty(QueryServices.DATE_FORMAT_ATTRIB,
                    DateUtil.DEFAULT_DATE_FORMAT);
        } else if (dateSqlType == Types.TIME) {
            dateFormat = props.getProperty(QueryServices.TIME_FORMAT_ATTRIB,
                    DateUtil.DEFAULT_TIME_FORMAT);
        } else {
            dateFormat = props.getProperty(QueryServices.TIMESTAMP_FORMAT_ATTRIB,
                    DateUtil.DEFAULT_TIMESTAMP_FORMAT);                    
        }
        String timeZoneId = props.getProperty(QueryServices.DATE_FORMAT_TIMEZONE_ATTRIB,
                QueryServicesOptions.DEFAULT_DATE_FORMAT_TIMEZONE);
        this.dateTimeParser = DateUtil.getDateTimeParser(dateFormat, dataType, timeZoneId);
    } else {
        this.dateTimeParser = null;
    }
}
 
Example 8
Source File: JsonUpsertExecutor.java    From phoenix with Apache License 2.0 5 votes vote down vote up
SimpleDatatypeConversionFunction(PDataType dataType, Connection conn) {
    Properties props;
    try {
        props = conn.getClientInfo();
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
    this.dataType = dataType;
    if (dataType.isCoercibleTo(PTimestamp.INSTANCE)) {
        // TODO: move to DateUtil
        String dateFormat;
        int dateSqlType = dataType.getResultSetSqlType();
        if (dateSqlType == Types.DATE) {
            dateFormat = props.getProperty(QueryServices.DATE_FORMAT_ATTRIB,
                    DateUtil.DEFAULT_DATE_FORMAT);
        } else if (dateSqlType == Types.TIME) {
            dateFormat = props.getProperty(QueryServices.TIME_FORMAT_ATTRIB,
                    DateUtil.DEFAULT_TIME_FORMAT);
        } else {
            dateFormat = props.getProperty(QueryServices.TIMESTAMP_FORMAT_ATTRIB,
                    DateUtil.DEFAULT_TIMESTAMP_FORMAT);
        }
        String timeZoneId = props.getProperty(QueryServices.DATE_FORMAT_TIMEZONE_ATTRIB,
                QueryServicesOptions.DEFAULT_DATE_FORMAT_TIMEZONE);
        this.dateTimeParser = DateUtil.getDateTimeParser(dateFormat, dataType, timeZoneId);
    } else {
        this.dateTimeParser = null;
    }
    this.binaryEncoding = props.getProperty(QueryServices.UPLOAD_BINARY_DATA_TYPE_ENCODING,
            QueryServicesOptions.DEFAULT_UPLOAD_BINARY_DATA_TYPE_ENCODING);
}
 
Example 9
Source File: BaseTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static void deletePriorSequences(long ts, Connection globalConn) throws Exception {
    // TODO: drop tenant-specific sequences too
    ResultSet rs = globalConn.createStatement().executeQuery("SELECT " 
            + PhoenixDatabaseMetaData.TENANT_ID + ","
            + PhoenixDatabaseMetaData.SEQUENCE_SCHEMA + "," 
            + PhoenixDatabaseMetaData.SEQUENCE_NAME 
            + " FROM " + PhoenixDatabaseMetaData.SYSTEM_SEQUENCE);
    String lastTenantId = null;
    Connection conn = globalConn;
    while (rs.next()) {
        String tenantId = rs.getString(1);
        if (tenantId != null && !tenantId.equals(lastTenantId))  {
            if (lastTenantId != null) {
                conn.close();
            }
            // Open tenant-specific connection when we find a new one
            Properties props = new Properties(globalConn.getClientInfo());
            props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
            conn = DriverManager.getConnection(url, props);
            lastTenantId = tenantId;
        }

        LOGGER.info("DROP SEQUENCE STATEMENT: DROP SEQUENCE " + SchemaUtil.getEscapedTableName(rs.getString(2), rs.getString(3)));
        conn.createStatement().execute("DROP SEQUENCE " + SchemaUtil.getEscapedTableName(rs.getString(2), rs.getString(3)));
    }
    rs.close();
}
 
Example 10
Source File: TraceReader.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public TraceReader(Connection conn, String statsTableName) throws SQLException {
    this.conn = conn;
    this.table = statsTableName;
    String ps = conn.getClientInfo(QueryServices.TRACING_PAGE_SIZE_ATTRIB);
    this.pageSize = ps == null ? QueryServicesOptions.DEFAULT_TRACING_PAGE_SIZE : Integer.parseInt(ps);
}
 
Example 11
Source File: TraceReader.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public TraceReader(Connection conn, String tracingTableName) throws SQLException {
    this.conn = conn;
    this.table = tracingTableName;
    String ps = conn.getClientInfo(QueryServices.TRACING_PAGE_SIZE_ATTRIB);
    this.pageSize = ps == null ? QueryServicesOptions.DEFAULT_TRACING_PAGE_SIZE : Integer.parseInt(ps);
}