diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-12-06 21:00:39 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-12-12 13:05:19 +0100 |
commit | 1b16981bab6f9309b80fa08dde67aef9a2b3dc1d (patch) | |
tree | bbfd2027488b8f151aedd07ecea183fe09c7c7c1 /sonar-db/src/main | |
parent | cb07ea331a5e4e7bc650d59dd2e7583e82658ad8 (diff) | |
download | sonarqube-1b16981bab6f9309b80fa08dde67aef9a2b3dc1d.tar.gz sonarqube-1b16981bab6f9309b80fa08dde67aef9a2b3dc1d.zip |
SONAR-5471 add DropIndexBuilder
Diffstat (limited to 'sonar-db/src/main')
-rw-r--r-- | sonar-db/src/main/java/org/sonar/db/version/DropIndexBuilder.java | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/version/DropIndexBuilder.java b/sonar-db/src/main/java/org/sonar/db/version/DropIndexBuilder.java new file mode 100644 index 00000000000..091a5085532 --- /dev/null +++ b/sonar-db/src/main/java/org/sonar/db/version/DropIndexBuilder.java @@ -0,0 +1,75 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.db.version; + +import java.util.List; +import org.sonar.db.dialect.Dialect; +import org.sonar.db.dialect.H2; +import org.sonar.db.dialect.MsSql; +import org.sonar.db.dialect.MySql; +import org.sonar.db.dialect.Oracle; +import org.sonar.db.dialect.PostgreSql; + +import static java.util.Collections.singletonList; +import static org.sonar.db.version.Validations.validateIndexName; +import static org.sonar.db.version.Validations.validateTableName; + +public class DropIndexBuilder { + + private final Dialect dialect; + private String tableName; + private String indexName; + + public DropIndexBuilder(Dialect dialect) { + this.dialect = dialect; + } + + public DropIndexBuilder setTable(String s) { + this.tableName = s; + return this; + } + + public DropIndexBuilder setName(String s) { + this.indexName = s; + return this; + } + + public List<String> build() { + validateTableName(tableName); + validateIndexName(indexName); + return singletonList(createSqlStatement()); + } + + private String createSqlStatement() { + switch (dialect.getId()) { + case MsSql.ID: + case MySql.ID: + return "DROP INDEX " + indexName + " ON " + tableName; + case Oracle.ID: + return "DROP INDEX " + indexName; + case H2.ID: + case PostgreSql.ID: + return "DROP INDEX IF EXISTS " + indexName; + default: + throw new IllegalStateException("Unsupported dialect for drop of index: " + dialect); + } + } + +} |