Пример #1
0
 /**
  * Get the major version of the driver. This call will be delegated to the underlying driver that
  * is being spied upon (if there is no underlying driver found, then 1 will be returned.)
  *
  * @return the major version of the JDBC driver.
  */
 public int getMajorVersion() {
   if (lastUnderlyingDriverRequested == null) {
     return 1;
   } else {
     return lastUnderlyingDriverRequested.getMajorVersion();
   }
 }
 @Test
 public void testVersionConstructor() throws Throwable {
   int majorVersion = 22;
   int minorVersion = 33;
   when(driver.getMajorVersion()).thenReturn(majorVersion);
   when(driver.getMinorVersion()).thenReturn(minorVersion);
   assertTrue(impalaDatabaseMeta.isDriverVersion(majorVersion, minorVersion));
   assertFalse(impalaDatabaseMeta.isDriverVersion(majorVersion, minorVersion + 1));
   assertFalse(impalaDatabaseMeta.isDriverVersion(majorVersion + 1, minorVersion));
 }
Пример #3
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);
        }
      }
    }
  }
 @Before
 public void setup() throws SQLException {
   testUrl = "testUrl";
   majorVersion = 10;
   minorVersion = 11;
   lazyDelegatingDriver = new LazyDelegatingDriver(driverRegistry, hasRegisterDriver);
   drivers = new ArrayList<>();
   drivers.add(makeEntry(badDriverServiceReference, badDriver));
   drivers.add(makeEntry(goodDriverServiceReference, driver));
   when(driver.connect(testUrl, null)).thenReturn(connection);
   when(driver.acceptsURL(testUrl)).thenReturn(true);
   when(driver.getPropertyInfo(testUrl, null))
       .thenReturn(new DriverPropertyInfo[] {driverPropertyInfo});
   when(driver.getMajorVersion()).thenReturn(majorVersion);
   when(driver.getMinorVersion()).thenReturn(minorVersion);
   when(driver.getParentLogger()).thenReturn(logger);
   when(driverRegistry.getDrivers()).thenReturn(drivers.iterator());
 }
Пример #5
0
  public void testMajorVersion() {
    try {
      Properties props = P6TestUtil.loadProperties("P6Test.properties");
      String url = props.getProperty("url");

      Driver driver = DriverManager.getDriver(url);

      // make sure you have a p6 driver
      if (!(driver instanceof P6SpyDriverCore)) {
        fail("Expected to get back a p6spy driver, got back a " + driver);
      }

      // but make sure it's bound to something
      // these numbers will likely change over time :)
      assertEquals(1, driver.getMajorVersion());
      assertEquals(0, driver.getMinorVersion());

    } catch (Exception e) {
      e.printStackTrace(System.out);
      fail("unexpected exception: " + e);
    } finally {
    }
  }
Пример #6
0
 @Override
 public int getRawDriverMajorVersion() {
   return rawDriver.getMajorVersion();
 }
Пример #7
0
 /** ��ô������Ĵΰ汾�š� */
 public int getMinorVersion() {
   return driver.getMajorVersion();
 }
Пример #8
0
 @Test
 public void testGetMajorVersion() {
   int expected = 111;
   when(delegate.getMajorVersion()).thenReturn(expected);
   assertEquals(expected, hiveDriver.getMajorVersion());
 }
Пример #9
0
 @Override
 public int getMajorVersion() {
   return delegate.getMajorVersion();
 }
 @Test
 public void testGetFieldDefinitionDate() {
   when(driver.getMajorVersion()).thenReturn(0);
   when(driver.getMinorVersion()).thenReturn(8);
   assertGetFieldDefinition(new ValueMetaDate(), "dateName", "TIMESTAMP");
 }
 @Test(expected = IllegalArgumentException.class)
 public void testGetFieldDefinitionUnsupported() {
   when(driver.getMajorVersion()).thenReturn(0);
   when(driver.getMinorVersion()).thenReturn(7);
   assertGetFieldDefinition(new ValueMetaTimestamp(), "timestampName", "TIMESTAMP");
 }