org.sonar.db.dialect.Dialect类的使用及代码示例

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

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

Dialect介绍

暂无

代码示例

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

@Override
public String generateSqlType(Dialect dialect) {
 switch (dialect.getId()) {
  case PostgreSql.ID:
  case MySql.ID:
  case H2.ID:
   return "INTEGER";
  case MsSql.ID:
   return "INT";
  case Oracle.ID:
   return "NUMBER(38,0)";
  default:
   throw new IllegalArgumentException("Unsupported dialect id " + dialect.getId());
 }
}

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

MyBatisConfBuilder(Database database) {
 this.conf = new Configuration();
 this.conf.setEnvironment(new Environment("production", createTransactionFactory(), database.getDataSource()));
 this.conf.setUseGeneratedKeys(true);
 this.conf.setLazyLoadingEnabled(false);
 this.conf.setJdbcTypeForNull(JdbcType.NULL);
 Dialect dialect = database.getDialect();
 this.conf.setDatabaseId(dialect.getId());
 this.conf.getVariables().setProperty("_true", dialect.getTrueSqlValue());
 this.conf.getVariables().setProperty("_false", dialect.getFalseSqlValue());
 this.conf.getVariables().setProperty("_from_dual", dialect.getSqlFromDual());
 this.conf.getVariables().setProperty("_scrollFetchSize", String.valueOf(dialect.getScrollDefaultFetchSize()));
 this.conf.setLocalCacheScope(LocalCacheScope.STATEMENT);
}

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

@VisibleForTesting
void initSettings() {
 properties = new Properties();
 completeProperties(settings, properties, SONAR_JDBC);
 completeDefaultProperty(properties, JDBC_URL.getKey(), DEFAULT_URL);
 doCompleteProperties(properties);
 dialect = DialectUtils.find(properties.getProperty(SONAR_JDBC_DIALECT), properties.getProperty(JDBC_URL.getKey()));
 properties.setProperty(SONAR_JDBC_DRIVER, dialect.getDefaultDriverClassName());
}

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

private void appendDefaultValue(StringBuilder sql, ColumnDef columnDef) {
 Object defaultValue = columnDef.getDefaultValue();
 if (defaultValue != null) {
  sql.append(" DEFAULT ");
  if (defaultValue instanceof String) {
   sql.append(format("'%s'", defaultValue));
  } else if (defaultValue instanceof Boolean) {
   sql.append((boolean) defaultValue ? dialect.getTrueSqlValue() : dialect.getFalseSqlValue());
  } else {
   sql.append(defaultValue);
  }
 }
}

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

private void initDataSource() throws Exception {
 // but it's correctly caught by start()
 LOG.info("Create JDBC data source for {}", properties.getProperty(JDBC_URL.getKey()), DEFAULT_URL);
 BasicDataSource basicDataSource = BasicDataSourceFactory.createDataSource(extractCommonsDbcpProperties(properties));
 datasource = new ProfiledDataSource(basicDataSource, NullConnectionInterceptor.INSTANCE);
 datasource.setConnectionInitSqls(dialect.getConnectionInitStatements());
 datasource.setValidationQuery(dialect.getValidationQuery());
 enableSqlLogging(datasource, logbackHelper.getLoggerLevel("sql") == Level.TRACE);
}

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

public static SelectImpl create(Database db, Connection connection, String sql) throws SQLException {
  // TODO use DbClient#newScrollingSelectStatement()
  PreparedStatement pstmt = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
  pstmt.setFetchSize(db.getDialect().getScrollDefaultFetchSize());
  return new SelectImpl(pstmt);
 }
}

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

public CleanupDisabledUsers(Database db, System2 system2) {
 super(db);
 this.falseValue = db.getDialect().getFalseSqlValue();
 this.system2 = system2;
}

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

private void addColumn(StringBuilder sql, ColumnDef columnDef) {
 sql.append(columnDef.getName()).append(" ").append(columnDef.generateSqlType(dialect));
 Object defaultValue = columnDef.getDefaultValue();
 if (defaultValue != null) {
  sql.append(" DEFAULT ");
  // TODO remove duplication with CreateTableBuilder
  if (defaultValue instanceof String) {
   sql.append(format("'%s'", defaultValue));
  } else if (defaultValue instanceof Boolean) {
   sql.append((boolean) defaultValue ? dialect.getTrueSqlValue() : dialect.getFalseSqlValue());
  } else {
   sql.append(defaultValue);
  }
 }
 sql.append(columnDef.isNullable() ? " NULL" : " NOT NULL");
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-db

private void initDataSource() throws Exception {
 // but it's correctly caught by start()
 LOG.info("Create JDBC data source for {}", properties.getProperty(DatabaseProperties.PROP_URL, DEFAULT_URL));
 BasicDataSource basicDataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(extractCommonsDbcpProperties(properties));
 datasource = new ProfiledDataSource(basicDataSource, NullConnectionInterceptor.INSTANCE);
 datasource.setConnectionInitSqls(dialect.getConnectionInitStatements());
 datasource.setValidationQuery(dialect.getValidationQuery());
 enableSqlLogging(datasource, logbackHelper.getLoggerLevel("sql") == Level.TRACE);
}

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

/**
 * Create a PreparedStatement for SELECT requests with scrolling of results
 */
public PreparedStatement newScrollingSelectStatement(DbSession session, String sql) {
 int fetchSize = database.getDialect().getScrollDefaultFetchSize();
 return newScrollingSelectStatement(session, sql, fetchSize);
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-db-migration

public CleanupDisabledUsers(Database db, System2 system2) {
 super(db);
 this.falseValue = db.getDialect().getFalseSqlValue();
 this.system2 = system2;
}

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

@Override
public String generateSqlType(Dialect dialect) {
 switch (dialect.getId()) {
  case MsSql.ID:
  case MySql.ID:
   return "DATETIME";
  case Oracle.ID:
   return "TIMESTAMP (6)";
  case H2.ID:
  case PostgreSql.ID:
   return "TIMESTAMP";
  default:
   throw new IllegalArgumentException("Unsupported dialect id " + dialect.getId());
 }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-db

public MyBatisConfBuilder(Database database) {
 this.conf = new Configuration();
 this.conf.setEnvironment(new Environment("production", createTransactionFactory(), database.getDataSource()));
 this.conf.setUseGeneratedKeys(true);
 this.conf.setLazyLoadingEnabled(false);
 this.conf.setJdbcTypeForNull(JdbcType.NULL);
 Dialect dialect = database.getDialect();
 this.conf.setDatabaseId(dialect.getId());
 this.conf.getVariables().setProperty("_true", dialect.getTrueSqlValue());
 this.conf.getVariables().setProperty("_false", dialect.getFalseSqlValue());
 this.conf.getVariables().setProperty("_scrollFetchSize", String.valueOf(dialect.getScrollDefaultFetchSize()));
 this.conf.setLocalCacheScope(LocalCacheScope.STATEMENT);
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-db-migration

private void appendDefaultValue(StringBuilder sql, ColumnDef columnDef) {
 Object defaultValue = columnDef.getDefaultValue();
 if (defaultValue != null) {
  sql.append(" DEFAULT ");
  if (defaultValue instanceof String) {
   sql.append(format("'%s'", defaultValue));
  } else if (defaultValue instanceof Boolean) {
   sql.append((boolean) defaultValue ? dialect.getTrueSqlValue() : dialect.getFalseSqlValue());
  } else {
   sql.append(defaultValue);
  }
 }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-db-core

private void initDataSource() throws Exception {
 // but it's correctly caught by start()
 LOG.info("Create JDBC data source for {}", properties.getProperty(JDBC_URL.getKey()), DEFAULT_URL);
 BasicDataSource basicDataSource = BasicDataSourceFactory.createDataSource(extractCommonsDbcpProperties(properties));
 datasource = new ProfiledDataSource(basicDataSource, NullConnectionInterceptor.INSTANCE);
 datasource.setConnectionInitSqls(dialect.getConnectionInitStatements());
 datasource.setValidationQuery(dialect.getValidationQuery());
 enableSqlLogging(datasource, logbackHelper.getLoggerLevel("sql") == Level.TRACE);
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-db-migration

public static SelectImpl create(Database db, Connection connection, String sql) throws SQLException {
  // TODO use DbClient#newScrollingSelectStatement()
  PreparedStatement pstmt = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
  pstmt.setFetchSize(db.getDialect().getScrollDefaultFetchSize());
  return new SelectImpl(pstmt);
 }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-db

@VisibleForTesting
void initSettings() {
 properties = new Properties();
 completeProperties(settings, properties, SONAR_JDBC);
 completeDefaultProperty(properties, DatabaseProperties.PROP_URL, DEFAULT_URL);
 doCompleteProperties(properties);
 dialect = DialectUtils.find(properties.getProperty(SONAR_JDBC_DIALECT), properties.getProperty(SONAR_JDBC_URL));
 properties.setProperty(DatabaseProperties.PROP_DRIVER, dialect.getDefaultDriverClassName());
}

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

@Override
public String generateSqlType(Dialect dialect) {
 return dialect.getId().equals(Oracle.ID) ? "NUMBER (38)" : "BIGINT";
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-db-migration

private void addColumn(StringBuilder sql, ColumnDef columnDef) {
 sql.append(columnDef.getName()).append(" ").append(columnDef.generateSqlType(dialect));
 Object defaultValue = columnDef.getDefaultValue();
 if (defaultValue != null) {
  sql.append(" DEFAULT ");
  // TODO remove duplication with CreateTableBuilder
  if (defaultValue instanceof String) {
   sql.append(format("'%s'", defaultValue));
  } else if (defaultValue instanceof Boolean) {
   sql.append((boolean) defaultValue ? dialect.getTrueSqlValue() : dialect.getFalseSqlValue());
  } else {
   sql.append(defaultValue);
  }
 }
 sql.append(columnDef.isNullable() ? " NULL" : " NOT NULL");
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-db

/**
 * Create a PreparedStatement for SELECT requests with scrolling of results
 */
public PreparedStatement newScrollingSelectStatement(DbSession session, String sql) {
 int fetchSize = database.getDialect().getScrollDefaultFetchSize();
 return newScrollingSelectStatement(session, sql, fetchSize);
}

相关文章