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

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

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

Database介绍

暂无

代码示例

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

  1. private static Connection createDdlConnection(Database database) throws SQLException {
  2. Connection res = database.getDataSource().getConnection();
  3. res.setAutoCommit(false);
  4. return res;
  5. }

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

  1. public FixMissingQualityProfilesOnOrganizations(Database db, System2 system2, UuidFactory uuidFactory, Configuration configuration) {
  2. super(db);
  3. this.system2 = system2;
  4. this.uuidFactory = uuidFactory;
  5. this.configuration = configuration;
  6. if (db.getDialect().getId().equals(MySql.ID) || db.getDialect().getId().equals(MsSql.ID)) {
  7. as = " AS ";
  8. } else {
  9. as = "";
  10. }
  11. }

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

  1. public void changeLevel(LoggerLevel level) {
  2. Level logbackLevel = Level.toLevel(level.name());
  3. database.enableSqlLogging(level == TRACE);
  4. helper.changeRoot(serverProcessLogging.getLogLevelConfig(), logbackLevel);
  5. LoggerFactory.getLogger(ServerLogging.class).info("Level of logs changed to {}", level);
  6. }

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

  1. public void check(State state) {
  2. try (Connection connection = db.getDataSource().getConnection()) {
  3. CharsetHandler handler = getHandler(db.getDialect());
  4. if (handler != null) {
  5. handler.handle(connection, state);
  6. }
  7. } catch (SQLException e) {
  8. throw new IllegalStateException(e);
  9. }
  10. }

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

  1. db = new H2Database("h2Tests" + DigestUtils.md5Hex(StringUtils.defaultString(schemaPath)), schemaPath == null);
  2. db.start();
  3. if (schemaPath != null) {
  4. if (db.getDialect().getId().equals("h2")) {
  5. ((H2Database) db).executeScript(schemaPath);
  6. } else {
  7. db.stop();
  8. LOG.debug("Test Database: " + db);
  9. commands = DatabaseCommands.forDialect(db.getDialect());
  10. tester = new DataSourceDatabaseTester(db.getDataSource(), commands.useLoginAsSchema() ? login : null);

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

  1. MyBatisConfBuilder(Database database) {
  2. this.conf = new Configuration();
  3. this.conf.setEnvironment(new Environment("production", createTransactionFactory(), database.getDataSource()));
  4. this.conf.setUseGeneratedKeys(true);
  5. this.conf.setLazyLoadingEnabled(false);
  6. this.conf.setJdbcTypeForNull(JdbcType.NULL);
  7. Dialect dialect = database.getDialect();
  8. this.conf.setDatabaseId(dialect.getId());
  9. this.conf.getVariables().setProperty("_true", dialect.getTrueSqlValue());
  10. this.conf.getVariables().setProperty("_false", dialect.getFalseSqlValue());
  11. this.conf.getVariables().setProperty("_from_dual", dialect.getSqlFromDual());
  12. this.conf.getVariables().setProperty("_scrollFetchSize", String.valueOf(dialect.getScrollDefaultFetchSize()));
  13. this.conf.setLocalCacheScope(LocalCacheScope.STATEMENT);
  14. }

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

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

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

  1. private Connection createDdlConnection() throws SQLException {
  2. Connection res = db.getDataSource().getConnection();
  3. res.setAutoCommit(false);
  4. return res;
  5. }

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

  1. public void check(State state) {
  2. try (Connection connection = db.getDataSource().getConnection()) {
  3. CharsetHandler handler = getHandler(db.getDialect());
  4. if (handler != null) {
  5. handler.handle(connection, state);
  6. }
  7. } catch (SQLException e) {
  8. throw new IllegalStateException(e);
  9. }
  10. }

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

  1. @Test
  2. public void changeLevel_to_trace_enables_db_logging() {
  3. LogLevelConfig logLevelConfig = LogLevelConfig.newBuilder(rootLoggerName).build();
  4. when(serverProcessLogging.getLogLevelConfig()).thenReturn(logLevelConfig);
  5. reset(database);
  6. underTest.changeLevel(INFO);
  7. verify(database).enableSqlLogging(false);
  8. reset(database);
  9. underTest.changeLevel(DEBUG);
  10. verify(database).enableSqlLogging(false);
  11. reset(database);
  12. underTest.changeLevel(TRACE);
  13. verify(database).enableSqlLogging(true);
  14. }

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

  1. public CleanupDisabledUsers(Database db, System2 system2) {
  2. super(db);
  3. this.falseValue = db.getDialect().getFalseSqlValue();
  4. this.system2 = system2;
  5. }

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

  1. private Connection createDdlConnection() throws SQLException {
  2. Connection writeConnection = db.getDataSource().getConnection();
  3. writeConnection.setAutoCommit(false);
  4. return writeConnection;
  5. }

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

  1. public UpdatePermissionTooLongTemplateKeys(Database db, UuidFactory uuidFactory) {
  2. super(db);
  3. this.uuidFactory = uuidFactory;
  4. if (db.getDialect().getId().equals(MsSql.ID)) {
  5. lengthFunction = "len";
  6. } else {
  7. lengthFunction = "length";
  8. }
  9. }

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

  1. private Connection createReadUncommittedConnection() throws SQLException {
  2. Connection connection = db.getDataSource().getConnection();
  3. connection.setAutoCommit(false);
  4. if (connection.getMetaData().supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED)) {
  5. connection.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
  6. }
  7. return connection;
  8. }

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

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

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

  1. @Override
  2. public void start() {
  3. try (Connection connection = database.getDataSource().getConnection()) {
  4. checkState(DatabaseUtils.tableExists(MigrationHistoryTable.NAME, connection), "Migration history table is missing");
  5. } catch (SQLException e) {
  6. Throwables.propagate(e);
  7. }
  8. }

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

  1. private String createTruncateSql(String table) {
  2. if (dbClient.getDatabase().getDialect().getId().equals(Oracle.ID)) {
  3. // truncate operation is needs to lock the table on Oracle. Unfortunately
  4. // it fails sometimes in our QA environment because table is locked.
  5. // We never found the root cause (no locks found when displaying them just after
  6. // receiving the error).
  7. // Workaround is to use "delete" operation. It does not require lock on table.
  8. return "DELETE FROM " + table;
  9. }
  10. return "TRUNCATE TABLE " + table;
  11. }

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

  1. public boolean tableExists(Database database) throws SQLException {
  2. try (Connection connection = database.getDataSource().getConnection()) {
  3. return DatabaseUtils.tableExists(tableName, connection);
  4. }
  5. }

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

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

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

  1. private boolean tableExists() throws SQLException {
  2. try (Connection connection = db.getDataSource().getConnection()) {
  3. return DatabaseUtils.tableExists(ORG_QUALITY_GATES, connection);
  4. }
  5. }
  6. }

相关文章