@Test
 public void testGetJdbcCompliant() throws SQLException {
   when(driver.jdbcCompliant()).thenReturn(true).thenReturn(false);
   assertTrue(lazyDelegatingDriver.acceptsURL(testUrl));
   assertTrue(lazyDelegatingDriver.jdbcCompliant());
   assertFalse(lazyDelegatingDriver.jdbcCompliant());
 }
Пример #2
0
  /** {@inheritDoc} */
  @Override
  public void deploy(final DeploymentPhaseContext phaseContext)
      throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    final ServicesAttachment servicesAttachment =
        deploymentUnit.getAttachment(Attachments.SERVICES);
    if (module != null && servicesAttachment != null) {
      final ModuleClassLoader classLoader = module.getClassLoader();
      final List<String> driverNames =
          servicesAttachment.getServiceImplementations(Driver.class.getName());
      for (String driverClassName : driverNames) {
        try {
          final Class<? extends Driver> driverClass =
              classLoader.loadClass(driverClassName).asSubclass(Driver.class);
          final Constructor<? extends Driver> constructor = driverClass.getConstructor();
          final Driver driver = constructor.newInstance();
          final int majorVersion = driver.getMajorVersion();
          final int minorVersion = driver.getMinorVersion();
          final boolean compliant = driver.jdbcCompliant();
          if (compliant) {
            log.infof(
                "Deploying JDBC-compliant driver %s (version %d.%d)",
                driverClass, Integer.valueOf(majorVersion), Integer.valueOf(minorVersion));
          } else {
            log.infof(
                "Deploying non-JDBC-compliant driver %s (version %d.%d)",
                driverClass, Integer.valueOf(majorVersion), Integer.valueOf(minorVersion));
          }
          String driverName = deploymentUnit.getName();
          InstalledDriver driverMetadata =
              new InstalledDriver(
                  driverName, driverClass.getName(), null, majorVersion, minorVersion, compliant);
          DriverService driverService = new DriverService(driverMetadata, driver);
          phaseContext
              .getServiceTarget()
              .addService(
                  ServiceName.JBOSS.append("jdbc-driver", driverName.replaceAll(".", "_")),
                  driverService)
              .addDependency(
                  ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE,
                  DriverRegistry.class,
                  driverService.getDriverRegistryServiceInjector())
              .setInitialMode(Mode.ACTIVE)
              .install();

        } catch (Exception e) {
          log.warnf("Unable to instantiate driver class \"%s\": %s", driverClassName, e);
        }
      }
    }
  }
Пример #3
0
 /**
  * Report whether the underlying driver is JDBC compliant. If there is no underlying driver, false
  * will be returned, because the driver cannot actually do any work without an underlying driver.
  *
  * @return <code>true</code> if the underlying driver is JDBC Compliant; <code>false</code>
  *     otherwise.
  */
 public boolean jdbcCompliant() {
   return lastUnderlyingDriverRequested != null && lastUnderlyingDriverRequested.jdbcCompliant();
 }
Пример #4
0
 /** �����������Ƿ���һ������� JDBC CompliantTM ����� */
 public boolean jdbcCompliant() {
   return driver.jdbcCompliant();
 }
Пример #5
0
 @Test
 public void testJdbcCompliant() {
   when(delegate.jdbcCompliant()).thenReturn(true).thenReturn(false);
   assertTrue(hiveDriver.jdbcCompliant());
   assertFalse(hiveDriver.jdbcCompliant());
 }
Пример #6
0
 @Test
 public void testJdbcCompliantException() {
   when(delegate.jdbcCompliant()).thenThrow(new RuntimeException());
   assertFalse(hiveDriver.jdbcCompliant());
 }
Пример #7
0
 @Override
 public boolean jdbcCompliant() {
   return delegate.jdbcCompliant();
 }