org.sonar.db.dialect.Dialect.getId()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(137)

本文整理了Java中org.sonar.db.dialect.Dialect.getId()方法的一些代码示例,展示了Dialect.getId()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dialect.getId()方法的具体详情如下:
包路径:org.sonar.db.dialect.Dialect
类名称:Dialect
方法名:getId

Dialect.getId介绍

暂无

代码示例

代码示例来源:origin: SonarSource/sonarqube

private static void appendCollationClause(StringBuilder res, Dialect dialect) {
 if (MySql.ID.equals(dialect.getId())) {
  res.append(" ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin");
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Override
public String generateSqlType(Dialect dialect) {
 switch (dialect.getId()) {
  case MsSql.ID:
   return format("NVARCHAR (%d)", columnSize);
  case Oracle.ID:
   return format("VARCHAR2 (%d%s)", columnSize, ignoreOracleUnit ? "" : " CHAR");
  default:
   return format("VARCHAR (%d)", columnSize);
 }
}

代码示例来源:origin: SonarSource/sonarqube

private String buildDeleteFromQuery(String tableName, String alias, String whereClause) {
 String dialectId = getDialect().getId();
 if ("mssql".equals(dialectId) || "mysql".equals(dialectId)) {
  return "delete " + alias + " from " + tableName + " as " + alias + " where " + whereClause;
 }
 return "delete from " + tableName + " " + alias + " where " + whereClause;
}

代码示例来源:origin: SonarSource/sonarqube

public UpdatePermissionTooLongTemplateKeys(Database db, UuidFactory uuidFactory) {
 super(db);
 this.uuidFactory = uuidFactory;
 if (db.getDialect().getId().equals(MsSql.ID)) {
  lengthFunction = "len";
 } else {
  lengthFunction = "length";
 }
}

代码示例来源:origin: SonarSource/sonarqube

public FixMissingQualityProfilesOnOrganizations(Database db, System2 system2, UuidFactory uuidFactory, Configuration configuration) {
 super(db);
 this.system2 = system2;
 this.uuidFactory = uuidFactory;
 this.configuration = configuration;
 if (db.getDialect().getId().equals(MySql.ID) || db.getDialect().getId().equals(MsSql.ID)) {
  as = " AS ";
 } else {
  as = "";
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Override
public void start() {
 if (MySql.ID.equals(database.getDialect().getId())) {
  throw new IllegalStateException("MySQL is not supported for Data Center Edition. Please connect to a supported database: Oracle, PostgreSQL, Microsoft SQL Server.");
 }
}

代码示例来源:origin: SonarSource/sonarqube

private Stream<String> createOracleAutoIncrementStatements() {
 if (!Oracle.ID.equals(dialect.getId())) {
  return Stream.empty();
 }
 return pkColumnDefs.stream()
  .filter(this::isAutoIncrement)
  .flatMap(columnDef -> of(createSequenceFor(tableName), createOracleTriggerForTable(tableName)));
}

代码示例来源:origin: SonarSource/sonarqube

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;
}

代码示例来源:origin: SonarSource/sonarqube

public static DatabaseCommands forDialect(Dialect dialect) {
 DatabaseCommands command = ImmutableMap.of(
  org.sonar.db.dialect.H2.ID, H2,
  MsSql.ID, MSSQL,
  MySql.ID, MYSQL,
  Oracle.ID, ORACLE,
  PostgreSql.ID, POSTGRESQL).get(dialect.getId());
 return Preconditions.checkNotNull(command, "Unknown database: " + dialect);
}

代码示例来源:origin: SonarSource/sonarqube

private Object toBool(boolean guarded) {
 Dialect dialect = db.database().getDialect();
 if (dialect.getId().equals(Oracle.ID)) {
  return guarded ? 1L : 0L;
 }
 return guarded;
}

代码示例来源:origin: SonarSource/sonarqube

private String selectDual() {
 String sql = "SELECT 1";
 if (Oracle.ID.equals(dbTester.database().getDialect().getId())) {
  sql = "SELECT 1 FROM DUAL";
 }
 return sql;
}

代码示例来源:origin: SonarSource/sonarqube

@Override
public void execute(Context context) throws SQLException {
 if (getDialect().getId().equals(MsSql.ID)) {
  // this should be handled automatically by DropColumnsBuilder
  dropMssqlConstraints();
 }
 context.execute(new DropColumnsBuilder(getDialect(), TABLE_NAME, COLUMN_NAME).build());
}

代码示例来源:origin: SonarSource/sonarqube

public void start() {
 if (!isDefault && !H2.ID.equals(db.getDialect().getId())) {
  throw new AssumptionViolatedException("Test disabled because it supports only H2");
 }
}

代码示例来源:origin: SonarSource/sonarqube

@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);
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void generateSqlType_thows_IAE_for_unknown_dialect() {
 Dialect dialect = mock(Dialect.class);
 when(dialect.getId()).thenReturn("AAA");
 expectedException.expect(IllegalArgumentException.class);
 expectedException.expectMessage("Unsupported dialect id AAA");
 underTest.generateSqlType(dialect);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
 public void getHandler_throws_IAE_if_unsupported_db() {
  Dialect unsupportedDialect = mock(Dialect.class);
  when(unsupportedDialect.getId()).thenReturn("foo");

  expectedException.expect(IllegalArgumentException.class);
  expectedException.expectMessage("Database not supported: foo");
  underTest.getHandler(unsupportedDialect);
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
 public void generateSqlType_thows_IAE_for_unknown_dialect() {
  Dialect dialect = mock(Dialect.class);
  when(dialect.getId()).thenReturn("AAA");

  expectedException.expect(IllegalArgumentException.class);
  expectedException.expectMessage("Unsupported dialect id AAA");

  underTest.generateSqlType(dialect);
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Before
public void disableIfNotH2() {
 // TODO dbTester.selectFirst() returns keys with different case
 // depending on target db (lower-case for MySQL but upper-case for H2).
 // It has to be fixed in order to reactive this test for all dbs.
 assumeTrue(dbTester.database().getDialect().getId().equals(H2.ID));
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void shouldGuessDialectFromUrl() {
 Settings settings = new MapSettings();
 settings.setProperty("sonar.jdbc.url", "jdbc:postgresql://localhost/sonar");
 DefaultDatabase database = new DefaultDatabase(logbackHelper, settings);
 database.initSettings();
 assertThat(database.getDialect().getId()).isEqualTo(PostgreSql.ID);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
 public void fail_with_UOE_to_generate_sql_type_when_unknown_dialect() {
  thrown.expect(UnsupportedOperationException.class);
  thrown.expectMessage("Unknown dialect 'unknown'");

  TinyIntColumnDef def = new TinyIntColumnDef.Builder()
   .setColumnName("foo")
   .setIsNullable(true)
   .build();

  Dialect dialect = mock(Dialect.class);
  when(dialect.getId()).thenReturn("unknown");
  def.generateSqlType(dialect);
 }
}

相关文章