org.apache.calcite.avatica.remote.LocalJsonService Java Examples

The following examples show how to use org.apache.calcite.avatica.remote.LocalJsonService. 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: RemoteDriverTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Override public Cache<Integer, Object>
getRemoteStatementMap(AvaticaConnection connection) throws Exception {
  Field metaF = AvaticaConnection.class.getDeclaredField("meta");
  metaF.setAccessible(true);
  Meta clientMeta = (Meta) metaF.get(connection);
  Field remoteMetaServiceF = clientMeta.getClass().getDeclaredField("service");
  remoteMetaServiceF.setAccessible(true);
  LocalJsonService remoteMetaService = (LocalJsonService) remoteMetaServiceF.get(clientMeta);
  // Use the explicitly class to avoid issues with LoggingLocalJsonService
  Field remoteMetaServiceServiceF = LocalJsonService.class.getDeclaredField("service");
  remoteMetaServiceServiceF.setAccessible(true);
  LocalService remoteMetaServiceService =
      (LocalService) remoteMetaServiceServiceF.get(remoteMetaService);
  Field remoteMetaServiceServiceMetaF =
      remoteMetaServiceService.getClass().getDeclaredField("meta");
  remoteMetaServiceServiceMetaF.setAccessible(true);
  JdbcMeta serverMeta = (JdbcMeta) remoteMetaServiceServiceMetaF.get(remoteMetaServiceService);
  Field jdbcMetaStatementMapF = JdbcMeta.class.getDeclaredField("statementCache");
  jdbcMetaStatementMapF.setAccessible(true);
  //noinspection unchecked
  @SuppressWarnings("unchecked")
  Cache<Integer, Object> cache = (Cache<Integer, Object>) jdbcMetaStatementMapF.get(serverMeta);
  return cache;
}
 
Example #2
Source File: RemoteDriverTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Override public Cache<String, Connection>
getRemoteConnectionMap(AvaticaConnection connection) throws Exception {
  Field metaF = AvaticaConnection.class.getDeclaredField("meta");
  metaF.setAccessible(true);
  Meta clientMeta = (Meta) metaF.get(connection);
  Field remoteMetaServiceF = clientMeta.getClass().getDeclaredField("service");
  remoteMetaServiceF.setAccessible(true);
  LocalJsonService remoteMetaService = (LocalJsonService) remoteMetaServiceF.get(clientMeta);
  // Get the field explicitly off the correct class to avoid LocalLoggingJsonService.class
  Field remoteMetaServiceServiceF = LocalJsonService.class.getDeclaredField("service");
  remoteMetaServiceServiceF.setAccessible(true);
  LocalService remoteMetaServiceService =
      (LocalService) remoteMetaServiceServiceF.get(remoteMetaService);
  Field remoteMetaServiceServiceMetaF =
      remoteMetaServiceService.getClass().getDeclaredField("meta");
  remoteMetaServiceServiceMetaF.setAccessible(true);
  JdbcMeta serverMeta = (JdbcMeta) remoteMetaServiceServiceMetaF.get(remoteMetaServiceService);
  Field jdbcMetaConnectionCacheF = JdbcMeta.class.getDeclaredField("connectionCache");
  jdbcMetaConnectionCacheF.setAccessible(true);
  //noinspection unchecked
  @SuppressWarnings("unchecked")
  Cache<String, Connection> cache =
      (Cache<String, Connection>) jdbcMetaConnectionCacheF.get(serverMeta);
  return cache;
}
 
Example #3
Source File: JsonHandlerTest.java    From calcite-avatica with Apache License 2.0 6 votes vote down vote up
@Test public void testExecuteRequestWithNumberParameter() {
  final List<TypedValue> expectedParameterValues = new ArrayList<>();
  final Service service = new ParameterValuesCheckingService(expectedParameterValues);
  final JsonService jsonService = new LocalJsonService(service);
  final JsonHandler jsonHandler = new JsonHandler(jsonService, NoopMetricsSystem.getInstance());

  final List<TypedValue> parameterValues = Arrays.asList(
      TypedValue.create("NUMBER", new BigDecimal("123")),
      TypedValue.create("STRING", "calcite"));

  jsonHandler.apply(
      "{'request':'execute',"
      + "'parameterValues':[{'type':'NUMBER','value':123},"
      + "{'type':'STRING','value':'calcite'}]}");
  assertThat(expectedParameterValues.size(), is(2));
  assertThat(expectedParameterValues.get(0), is(parameterValues.get(0)));
  assertThat(expectedParameterValues.get(1), is(parameterValues.get(1)));
}
 
Example #4
Source File: CalciteRemoteDriverTest.java    From Quicksql with MIT License 5 votes vote down vote up
public Service create(AvaticaConnection connection) {
  try {
    Connection localConnection = CalciteAssert.hr().connect();
    final Meta meta = CalciteConnectionImpl.TROJAN
        .getMeta((CalciteConnectionImpl) localConnection);
    return new LocalJsonService(new LocalService(meta));
  } catch (Exception e) {
    throw TestUtil.rethrow(e);
  }
}
 
Example #5
Source File: CalciteRemoteDriverTest.java    From calcite with Apache License 2.0 5 votes vote down vote up
public Service create(AvaticaConnection connection) {
  try {
    Connection localConnection = CalciteAssert.hr().connect();
    final Meta meta = CalciteConnectionImpl.TROJAN
        .getMeta((CalciteConnectionImpl) localConnection);
    return new LocalJsonService(new LocalService(meta));
  } catch (Exception e) {
    throw TestUtil.rethrow(e);
  }
}