default Named getNamed() { return new NamedImpl(getIdentifier()); } }
@Provides @Singleton public RawStatisticsRepository get(Injector injector, Platform platform) { return injector.getInstance(Key.get(RawStatisticsRepository.class, platform.getNamed())); } }
@Test public void h2() { Platform platform = new H2Platform(); Assert.assertTrue(platform.detect("H2")); Assert.assertFalse(platform.detect("MySQL")); Assert.assertEquals(platform.getIdentifier(), H2Platform.IDENTIFIER); Assert.assertEquals(platform.getNamed().value(), H2Platform.IDENTIFIER); }
@Test public void mssql() { Platform platform = new MsSQLPlatform(); Assert.assertFalse(platform.detect("H2")); Assert.assertTrue(platform.detect("Microsoft")); Assert.assertEquals(platform.getIdentifier(), MsSQLPlatform.IDENTIFIER); }
@Override public Platform get() { try { String productName = jdbcTxManager.getConnection().getMetaData().getDatabaseProductName(); for (Platform platform : platforms) if (platform.detect(productName)) return platform; throw new OxalisLoadingException(String.format("Unable to load platform for '%s'.", productName)); } catch (SQLException e) { throw new OxalisLoadingException("Unable to detect database platform.", e); } } }
@Test public void hsqldb() { Platform platform = new HSQLDBPlatform(); Assert.assertTrue(platform.detect("HSqlDB")); Assert.assertFalse(platform.detect("MySQL")); Assert.assertEquals(platform.getIdentifier(), HSQLDBPlatform.IDENTIFIER); }
@Override public Platform get() { try { String productName = jdbcTxManager.getConnection().getMetaData().getDatabaseProductName(); for (Platform platform : platforms) if (platform.detect(productName)) return platform; throw new OxalisLoadingException(String.format("Unable to load platform for '%s'.", productName)); } catch (SQLException e) { throw new OxalisLoadingException("Unable to detect database platform.", e); } } }
@Test public void mysql() { Platform platform = new MySQLPlatform(); Assert.assertFalse(platform.detect("H2")); Assert.assertTrue(platform.detect("MySQL")); Assert.assertEquals(platform.getIdentifier(), MySQLPlatform.IDENTIFIER); }
@Provides @Singleton public RawStatisticsRepository get(Injector injector, Platform platform) { return injector.getInstance(Key.get(RawStatisticsRepository.class, platform.getNamed())); } }
default Named getNamed() { return new NamedImpl(getIdentifier()); } }
@Test public void oracle() { Platform platform = new OraclePlatform(); Assert.assertFalse(platform.detect("H2")); Assert.assertTrue(platform.detect("Oracle")); Assert.assertEquals(platform.getIdentifier(), OraclePlatform.IDENTIFIER); } }