private BasicDataSource commonsDbcp() { return (BasicDataSource) dbClient.getDatabase().getDataSource(); }
private BasicDataSource commonsDbcp() { return (BasicDataSource) dbClient.getDatabase().getDataSource(); } }
private String createTruncateSql(String table) { if (dbClient.getDatabase().getDialect().getId().equals(Oracle.ID)) { // truncate operation is needs to lock the table on Oracle. Unfortunately // it fails sometimes in our QA environment because table is locked. // We never found the root cause (no locks found when displaying them just after // receiving the error). // Workaround is to use "delete" operation. It does not require lock on table. return "DELETE FROM " + table; } return "TRUNCATE TABLE " + table; }
private String getDbVendor() { return dbClient.getDatabase().getDialect().getId(); } }
private void writeDatabaseProduction(JsonWriter json) { json.prop("productionDatabase", !dbClient.getDatabase().getDialect().getId().equals(H2.ID)); }
private void mockDialect(Dialect dialect) { when(dbClient.getDatabase().getDialect()).thenReturn(dialect); }
private void prepareDb(String dbVendor) { when(dbClient.getDatabase().getDialect().getId()).thenReturn(dbVendor); }
@VisibleForTesting void installH2() { Connection connection = null; try (DbSession session = dbClient.openSession(false)) { connection = session.getConnection(); createH2Schema(connection, dbClient.getDatabase().getDialect().getId()); } finally { DbUtils.closeQuietly(connection); } }
@Override public void start() { if (serverUpgradeStatus.isFreshInstall()) { Loggers.get(getClass()).info("Automatically perform DB migration on fresh install"); Dialect dialect = dbClient.getDatabase().getDialect(); if (H2.ID.equals(dialect.getId())) { installH2(); } else { migrationEngine.execute(); } } else if (serverUpgradeStatus.isUpgraded() && serverUpgradeStatus.isBlueGreen()) { Loggers.get(getClass()).info("Automatically perform DB migration on blue/green deployment"); migrationEngine.execute(); } }
@Override public void execute(ComputationStep.Context context) { boolean supportUpsert = dbClient.getDatabase().getDialect().supportsUpsert(); try (DbSession dbSession = dbClient.openSession(supportUpsert)) { Component root = treeRootHolder.getRoot(); MeasureVisitor visitor = new MeasureVisitor(dbSession, supportUpsert); new DepthTraversalTypeAwareCrawler(visitor).visit(root); context.getStatistics().add("insertsOrUpdates", visitor.insertsOrUpdates); } }
@Test public void return_if_production_database_or_not() { init(); when(dbClient.getDatabase().getDialect()).thenReturn(new MySql()); assertJson(call()).isSimilarTo("{" + " \"productionDatabase\": true" + "}"); }
private void init(org.sonar.api.web.page.Page[] pages, ResourceTypeTree[] resourceTypeTrees) { when(dbClient.getDatabase().getDialect()).thenReturn(new H2()); when(server.getVersion()).thenReturn("6.42"); PluginRepository pluginRepository = mock(PluginRepository.class); when(pluginRepository.hasPlugin(any())).thenReturn(true); when(pluginRepository.getPluginInfo(any())).thenReturn(new PluginInfo("unused").setVersion(Version.create("1.0"))); CoreExtensionRepository coreExtensionRepository = mock(CoreExtensionRepository.class); when(coreExtensionRepository.isInstalled(any())).thenReturn(false); PageRepository pageRepository = new PageRepository(pluginRepository, coreExtensionRepository, new PageDefinition[] {context -> { for (Page page : pages) { context.addPage(page); } }}); pageRepository.start(); GlobalAction wsAction = new GlobalAction(pageRepository, settings.asConfig(), new ResourceTypes(resourceTypeTrees), server, webServer, dbClient, organizationFlags, defaultOrganizationProvider, branchFeature, userSession, editionProvider); ws = new WsActionTester(wsAction); wsAction.start(); }
@Test public void upsert_does_not_update_row_if_values_are_not_changed() { if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) { return; } LiveMeasureDto dto = newLiveMeasure(); underTest.upsert(db.getSession(), dto); // update int count = underTest.upsert(db.getSession(), dto); assertThat(count).isEqualTo(0); verifyPersisted(dto); verifyTableSize(1); }
@Test public void upsert_updates_row_if_value_is_added() { if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) { return; } LiveMeasureDto dto = newLiveMeasure().setValue(null); underTest.upsert(db.getSession(), dto); // update dto.setValue(40.0); int count = underTest.upsert(db.getSession(), dto); assertThat(count).isEqualTo(1); verifyPersisted(dto); verifyTableSize(1); }
@Test public void upsert_updates_row_if_variation_is_removed() { if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) { return; } LiveMeasureDto dto = newLiveMeasure().setVariation(40.0); underTest.upsert(db.getSession(), dto); // update dto.setVariation(null); int count = underTest.upsert(db.getSession(), dto); assertThat(count).isEqualTo(1); verifyPersisted(dto); verifyTableSize(1); }
@Test public void upsert_updates_row_if_variation_is_added() { if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) { return; } LiveMeasureDto dto = newLiveMeasure().setVariation(null); underTest.upsert(db.getSession(), dto); // update dto.setVariation(40.0); int count = underTest.upsert(db.getSession(), dto); assertThat(count).isEqualTo(1); verifyPersisted(dto); verifyTableSize(1); }
@Test public void upsert_updates_row_if_variation_is_changed() { if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) { return; } LiveMeasureDto dto = newLiveMeasure().setVariation(40.0); underTest.upsert(db.getSession(), dto); // update dto.setVariation(50.0); int count = underTest.upsert(db.getSession(), dto); assertThat(count).isEqualTo(1); verifyPersisted(dto); verifyTableSize(1); }
@Test public void upsert_updates_row_if_value_is_removed() { if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) { return; } LiveMeasureDto dto = newLiveMeasure().setValue(40.0); underTest.upsert(db.getSession(), dto); // update dto.setValue(null); int count = underTest.upsert(db.getSession(), dto); assertThat(count).isEqualTo(1); verifyPersisted(dto); verifyTableSize(1); }
@Test public void upsert_updates_row_if_value_is_changed() { if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) { return; } LiveMeasureDto dto = newLiveMeasure().setValue(40.0); underTest.upsert(db.getSession(), dto); // update dto.setValue(50.0); int count = underTest.upsert(db.getSession(), dto); assertThat(count).isEqualTo(1); verifyPersisted(dto); verifyTableSize(1); }
@Test public void upsert_inserts_or_updates_row() { if (!db.getDbClient().getDatabase().getDialect().supportsUpsert()) { return; } // insert LiveMeasureDto dto = newLiveMeasure(); int count = underTest.upsert(db.getSession(), dto); verifyPersisted(dto); verifyTableSize(1); assertThat(count).isEqualTo(1); // update dto.setValue(dto.getValue() + 1); dto.setVariation(dto.getVariation() + 10); dto.setData(dto.getDataAsString() + "_new"); count = underTest.upsert(db.getSession(), dto); assertThat(count).isEqualTo(1); verifyPersisted(dto); verifyTableSize(1); }