diff options
author | Hugo Arès <hugo.ares@ericsson.com> | 2017-04-24 17:39:02 +0200 |
---|---|---|
committer | Hugo Arès <hugo.ares@ericsson.com> | 2017-04-25 11:07:26 +0200 |
commit | 336db37b9b80aa54f63bfdf4b3bdd982676b0bc7 (patch) | |
tree | 787011c292194a77f37b0333ceaea9770db6e12a | |
parent | 7de517712e58e145e1d51e8d15dc9a35837b2bb8 (diff) |
Use lower case table/column/constraint names in H2AccountPatchReviewStore
Some databases are case insensitive but some are not, like MySQL.
AccountPatchReviewStore is implemented with H2 but a follow up change
will add support for MySQL.
This change prepares the ground for supporting MySQL, i.e. make sure we
avoid case issues if MySQL is installed on a case sensitive operating
system.
Only table and trigger names are case sensitive but also lower case
column and constraint names for more consistent and nicer looking SQL
code.
Change-Id: I53e9f304e038276d2638a279fbe35a36f24a8d24
-rw-r--r-- | gerrit-server/src/main/java/com/google/gerrit/server/schema/H2AccountPatchReviewStore.java | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/schema/H2AccountPatchReviewStore.java b/gerrit-server/src/main/java/com/google/gerrit/server/schema/H2AccountPatchReviewStore.java index 9028e62dd5..797f10208f 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/schema/H2AccountPatchReviewStore.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/schema/H2AccountPatchReviewStore.java @@ -138,20 +138,20 @@ public class H2AccountPatchReviewStore private static void doCreateTable(Statement stmt) throws SQLException { stmt.executeUpdate( - "CREATE TABLE IF NOT EXISTS ACCOUNT_PATCH_REVIEWS (" - + "ACCOUNT_ID INTEGER DEFAULT 0 NOT NULL, " - + "CHANGE_ID INTEGER DEFAULT 0 NOT NULL, " - + "PATCH_SET_ID INTEGER DEFAULT 0 NOT NULL, " - + "FILE_NAME VARCHAR(255) DEFAULT '' NOT NULL, " - + "CONSTRAINT PRIMARY_KEY_ACCOUNT_PATCH_REVIEWS " - + "PRIMARY KEY (ACCOUNT_ID, CHANGE_ID, PATCH_SET_ID, FILE_NAME)" + "CREATE TABLE IF NOT EXISTS account_patch_reviews (" + + "account_id INTEGER DEFAULT 0 NOT NULL, " + + "change_id INTEGER DEFAULT 0 NOT NULL, " + + "patch_set_id INTEGER DEFAULT 0 NOT NULL, " + + "file_name VARCHAR(255) DEFAULT '' NOT NULL, " + + "CONSTRAINT primary_key_account_patch_reviews " + + "PRIMARY KEY (account_id, change_id, patch_set_id, file_name)" + ")"); } public static void dropTableIfExists(String url) throws OrmException { try (Connection con = DriverManager.getConnection(url); Statement stmt = con.createStatement()) { - stmt.executeUpdate("DROP TABLE IF EXISTS ACCOUNT_PATCH_REVIEWS"); + stmt.executeUpdate("DROP TABLE IF EXISTS account_patch_reviews"); } catch (SQLException e) { throw convertError("create", e); } @@ -166,8 +166,8 @@ public class H2AccountPatchReviewStore String path) throws OrmException { try (Connection con = ds.getConnection(); PreparedStatement stmt = - con.prepareStatement("INSERT INTO ACCOUNT_PATCH_REVIEWS " - + "(ACCOUNT_ID, CHANGE_ID, PATCH_SET_ID, FILE_NAME) VALUES " + con.prepareStatement("INSERT INTO account_patch_reviews " + + "(account_id, change_id, patch_set_id, file_name) VALUES " + "(?, ?, ?, ?)")) { stmt.setInt(1, accountId.get()); stmt.setInt(2, psId.getParentKey().get()); @@ -193,8 +193,8 @@ public class H2AccountPatchReviewStore try (Connection con = ds.getConnection(); PreparedStatement stmt = - con.prepareStatement("INSERT INTO ACCOUNT_PATCH_REVIEWS " - + "(ACCOUNT_ID, CHANGE_ID, PATCH_SET_ID, FILE_NAME) VALUES " + con.prepareStatement("INSERT INTO account_patch_reviews " + + "(account_id, change_id, patch_set_id, file_name) VALUES " + "(?, ?, ?, ?)")) { for (String path : paths) { stmt.setInt(1, accountId.get()); @@ -218,9 +218,9 @@ public class H2AccountPatchReviewStore throws OrmException { try (Connection con = ds.getConnection(); PreparedStatement stmt = - con.prepareStatement("DELETE FROM ACCOUNT_PATCH_REVIEWS " - + "WHERE ACCOUNT_ID = ? AND CHANGE_ID = ? AND " - + "PATCH_SET_ID = ? AND FILE_NAME = ?")) { + con.prepareStatement("DELETE FROM account_patch_reviews " + + "WHERE account_id = ? AND change_id = ? AND " + + "patch_set_id = ? AND file_name = ?")) { stmt.setInt(1, accountId.get()); stmt.setInt(2, psId.getParentKey().get()); stmt.setInt(3, psId.get()); @@ -235,8 +235,8 @@ public class H2AccountPatchReviewStore public void clearReviewed(PatchSet.Id psId) throws OrmException { try (Connection con = ds.getConnection(); PreparedStatement stmt = - con.prepareStatement("DELETE FROM ACCOUNT_PATCH_REVIEWS " - + "WHERE CHANGE_ID = ? AND PATCH_SET_ID = ?")) { + con.prepareStatement("DELETE FROM account_patch_reviews " + + "WHERE change_id = ? AND patch_set_id = ?")) { stmt.setInt(1, psId.getParentKey().get()); stmt.setInt(2, psId.get()); stmt.executeUpdate(); @@ -250,8 +250,8 @@ public class H2AccountPatchReviewStore throws OrmException { try (Connection con = ds.getConnection(); PreparedStatement stmt = - con.prepareStatement("SELECT FILE_NAME FROM ACCOUNT_PATCH_REVIEWS " - + "WHERE ACCOUNT_ID = ? AND CHANGE_ID = ? AND PATCH_SET_ID = ?")) { + con.prepareStatement("SELECT FILE_NAME FROM account_patch_reviews " + + "WHERE account_id = ? AND change_id = ? AND patch_set_id = ?")) { stmt.setInt(1, accountId.get()); stmt.setInt(2, psId.getParentKey().get()); stmt.setInt(3, psId.get()); @@ -271,13 +271,13 @@ public class H2AccountPatchReviewStore switch (getSQLStateInt(err)) { case 23001: // UNIQUE CONSTRAINT VIOLATION case 23505: // DUPLICATE_KEY_1 - return new OrmDuplicateKeyException("ACCOUNT_PATCH_REVIEWS", err); + return new OrmDuplicateKeyException("account_patch_reviews", err); default: if (err.getCause() == null && err.getNextException() != null) { err.initCause(err.getNextException()); } - return new OrmException(op + " failure on ACCOUNT_PATCH_REVIEWS", err); + return new OrmException(op + " failure on account_patch_reviews", err); } } |