Search in sources :

Example 1 with Dialect

use of org.sonar.db.dialect.Dialect in project sonarqube by SonarSource.

the class PurgeCommandsTest method countAnalysesOfRoot.

private int countAnalysesOfRoot(ComponentDto projectOrView, String status, boolean isLast) {
    Dialect dialect = dbTester.getDbClient().getDatabase().getDialect();
    String bool = isLast ? dialect.getTrueSqlValue() : dialect.getFalseSqlValue();
    return dbTester.countSql("select count(1) from snapshots where component_uuid='" + projectOrView.uuid() + "' and status='" + status + "' and islast=" + bool);
}
Also used : Dialect(org.sonar.db.dialect.Dialect)

Example 2 with Dialect

use of org.sonar.db.dialect.Dialect in project sonarqube by SonarSource.

the class DbPrimaryKeyConstraintFinder method getDbVendorSpecificQuery.

String getDbVendorSpecificQuery(String tableName) {
    Dialect dialect = db.getDialect();
    String constraintQuery;
    switch(dialect.getId()) {
        case PostgreSql.ID:
            constraintQuery = getPostgresSqlConstraintQuery(tableName);
            break;
        case MsSql.ID:
            constraintQuery = getMssqlConstraintQuery(tableName);
            break;
        case Oracle.ID:
            constraintQuery = getOracleConstraintQuery(tableName);
            break;
        case H2.ID:
            constraintQuery = getH2ConstraintQuery(tableName);
            break;
        default:
            throw new IllegalStateException(format("Unsupported database '%s'", dialect.getId()));
    }
    return constraintQuery;
}
Also used : Dialect(org.sonar.db.dialect.Dialect)

Example 3 with Dialect

use of org.sonar.db.dialect.Dialect in project sonarqube by SonarSource.

the class DropPrimaryKeySqlGenerator method generate.

public List<String> generate(String tableName, Collection<String> columnNames, boolean isAutoGenerated) throws SQLException {
    Dialect dialect = db.getDialect();
    Optional<String> constraintName = dbConstraintFinder.findConstraintName(tableName);
    if (!constraintName.isPresent()) {
        return Collections.emptyList();
    }
    switch(dialect.getId()) {
        case PostgreSql.ID:
            return generateForPostgresSql(tableName, columnNames, constraintName.get());
        case MsSql.ID:
            return generateForMsSql(tableName, constraintName.get());
        case Oracle.ID:
            return generateForOracle(tableName, constraintName.get(), isAutoGenerated);
        case H2.ID:
            return generateForH2(tableName, constraintName.get());
        default:
            throw new IllegalStateException(format("Unsupported database '%s'", dialect.getId()));
    }
}
Also used : Dialect(org.sonar.db.dialect.Dialect)

Example 4 with Dialect

use of org.sonar.db.dialect.Dialect in project sonarqube by SonarSource.

the class DropPrimaryKeySqlGeneratorTest method generate_unknown_dialect.

@Test
public void generate_unknown_dialect() throws SQLException {
    Dialect mockDialect = mock(Dialect.class);
    when(mockDialect.getId()).thenReturn("unknown-db-vendor");
    when(db.getDialect()).thenReturn(mockDialect);
    when(dbConstraintFinder.findConstraintName(TABLE_NAME)).thenReturn(Optional.of(CONSTRAINT));
    assertThatThrownBy(() -> underTest.generate(TABLE_NAME, PK_COLUMN, true)).isInstanceOf(IllegalStateException.class);
}
Also used : Dialect(org.sonar.db.dialect.Dialect) Test(org.junit.Test)

Example 5 with Dialect

use of org.sonar.db.dialect.Dialect in project sonarqube by SonarSource.

the class DatabaseCharsetCheckerTest method getHandler_throws_IAE_if_unsupported_db.

@Test
public void getHandler_throws_IAE_if_unsupported_db() {
    Dialect unsupportedDialect = mock(Dialect.class);
    when(unsupportedDialect.getId()).thenReturn("foo");
    assertThatThrownBy(() -> underTest.getHandler(unsupportedDialect)).isInstanceOf(IllegalArgumentException.class).hasMessage("Database not supported: foo");
}
Also used : Dialect(org.sonar.db.dialect.Dialect) Test(org.junit.Test)

Aggregations

Dialect (org.sonar.db.dialect.Dialect)10 Test (org.junit.Test)6