diff options
author | David Gageot <david@gageot.net> | 2012-11-05 09:30:39 +0100 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-11-05 09:30:46 +0100 |
commit | 1eccecabf42f415582426bf1800afd66fb005878 (patch) | |
tree | ac1a3d10c2ccb870d724493b8d4888e8c8aba5e9 /sonar-core | |
parent | 0935f7db60ce855eff8f6f52313f96392ea10577 (diff) | |
download | sonarqube-1eccecabf42f415582426bf1800afd66fb005878.tar.gz sonarqube-1eccecabf42f415582426bf1800afd66fb005878.zip |
SONAR-3895 Fix table name case
Diffstat (limited to 'sonar-core')
3 files changed, 29 insertions, 17 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DbTemplate.java b/sonar-core/src/main/java/org/sonar/core/persistence/DbTemplate.java index bca98d80f8e..e83bf0c0cb3 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DbTemplate.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DbTemplate.java @@ -19,6 +19,8 @@ */ package org.sonar.core.persistence; +import com.google.common.base.Joiner; +import com.google.common.collect.Lists; import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; @@ -33,13 +35,24 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.List; public class DbTemplate implements ServerComponent { private static final Logger LOG = LoggerFactory.getLogger(DbTemplate.class); - public DbTemplate copyTable(DataSource source, DataSource dest, String table, String query) { + public DbTemplate copyTable(DataSource source, DataSource dest, String table, String... whereClauses) { LOG.info("Copy table " + table); + String selectQuery = "select * from " + table; + if (whereClauses.length > 0) { + List<String> clauses = Lists.newArrayList(); + for (String whereClause : whereClauses) { + clauses.add('(' + whereClause + ')'); + } + + selectQuery += " WHERE " + Joiner.on(" AND ").join(clauses); + } + truncate(dest, table); Connection sourceConnection = null; @@ -51,7 +64,7 @@ public class DbTemplate implements ServerComponent { try { sourceConnection = source.getConnection(); sourceStatement = sourceConnection.createStatement(); - sourceResultSet = sourceStatement.executeQuery(query); + sourceResultSet = sourceStatement.executeQuery(selectQuery); if (sourceResultSet.next()) { int colCount = sourceResultSet.getMetaData().getColumnCount(); diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DefaultDatabase.java b/sonar-core/src/main/java/org/sonar/core/persistence/DefaultDatabase.java index 4812f7c8b18..82d3736f629 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DefaultDatabase.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DefaultDatabase.java @@ -136,7 +136,6 @@ public class DefaultDatabase implements Database { } } - public final DefaultDatabase stop() { if (datasource != null) { try { diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java b/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java index 6b3c7c6e065..9c8b5252482 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java @@ -63,22 +63,22 @@ public class DryRunDatabaseFactory implements ServerComponent { } private void copy(DataSource source, DataSource dest, Integer resourceId) { - String notSecured = "NOT (PROP_KEY LIKE '%.secured')"; - String defaultProperty = "((USER_ID IS NULL) AND (RESOURCE_ID IS NULL))"; - String projectProperty = (null == resourceId) ? "" : " OR (RESOURCE_ID='" + resourceId + "')"; + String notSecured = "NOT (prop_key LIKE '%.secured')"; + String defaultProperty = "((user_id IS NULL) AND (resource_id IS NULL))"; + String projectProperty = (null == resourceId) ? "" : " OR (resource_id='" + resourceId + "')"; new DbTemplate() - .copyTable(source, dest, "ACTIVE_RULES", "SELECT * FROM ACTIVE_RULES") - .copyTable(source, dest, "ACTIVE_RULE_PARAMETERS", "SELECT * FROM ACTIVE_RULE_PARAMETERS") - .copyTable(source, dest, "CHARACTERISTICS", "SELECT * FROM CHARACTERISTICS") - .copyTable(source, dest, "CHARACTERISTIC_EDGES", "SELECT * FROM CHARACTERISTIC_EDGES") - .copyTable(source, dest, "CHARACTERISTIC_PROPERTIES", "SELECT * FROM CHARACTERISTIC_PROPERTIES") - .copyTable(source, dest, "METRICS", "SELECT * FROM METRICS") - .copyTable(source, dest, "PROPERTIES", "SELECT * FROM PROPERTIES WHERE " + notSecured + " AND (" + defaultProperty + projectProperty + ")") - .copyTable(source, dest, "QUALITY_MODELS", "SELECT * FROM QUALITY_MODELS") - .copyTable(source, dest, "RULES", "SELECT * FROM RULES") - .copyTable(source, dest, "RULES_PARAMETERS", "SELECT * FROM RULES_PARAMETERS") - .copyTable(source, dest, "RULES_PROFILES", "SELECT * FROM RULES_PROFILES"); + .copyTable(source, dest, "active_rules") + .copyTable(source, dest, "active_rule_parameters") + .copyTable(source, dest, "characteristics") + .copyTable(source, dest, "characteristic_edges") + .copyTable(source, dest, "characteristic_properties") + .copyTable(source, dest, "metrics") + .copyTable(source, dest, "properties", notSecured, defaultProperty + projectProperty) + .copyTable(source, dest, "quality_models") + .copyTable(source, dest, "rules") + .copyTable(source, dest, "rules_parameters") + .copyTable(source, dest, "rules_profiles"); } private BasicDataSource create(String dialect, String driver, String user, String password, String url) { |