Skip to content

Commit

Permalink
[ISSUE #6216] Unify SQL naming style. (#6239)
Browse files Browse the repository at this point in the history
* [ISSUE #6216] Unify SQL naming style.

* [ISSUE #6216] Unify SQL naming style.

* [ISSUE #6216] Unify SQL naming style.
  • Loading branch information
mask616 authored Jul 5, 2021
1 parent e25d415 commit 5aab426
Show file tree
Hide file tree
Showing 17 changed files with 412 additions and 403 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public class EmbeddedPermissionPersistServiceImpl implements PermissionPersistSe
public Page<PermissionInfo> getPermissions(String role, int pageNo, int pageSize) {
PaginationHelper<PermissionInfo> helper = persistService.createPaginationHelper();

String sqlCountRows = "SELECT COUNT(*) FROM permissions WHERE ";
String sqlCountRows = "SELECT count(*) FROM permissions WHERE ";

String sqlFetchRows = "SELECT role,resource,action FROM permissions WHERE ";

String where = " role= ? ";
Expand Down Expand Up @@ -84,7 +85,7 @@ public Page<PermissionInfo> getPermissions(String role, int pageNo, int pageSize
*/
@Override
public void addPermission(String role, String resource, String action) {
String sql = "INSERT into permissions (role, resource, action) VALUES (?, ?, ?)";
String sql = "INSERT INTO permissions (role, resource, action) VALUES (?, ?, ?)";
EmbeddedStorageContextUtils.addSqlContext(sql, role, resource, action);
databaseOperate.blockUpdate();
}
Expand All @@ -98,7 +99,7 @@ public void addPermission(String role, String resource, String action) {
*/
@Override
public void deletePermission(String role, String resource, String action) {
String sql = "DELETE from permissions WHERE role=? and resource=? and action=?";
String sql = "DELETE FROM permissions WHERE role=? AND resource=? AND action=?";
EmbeddedStorageContextUtils.addSqlContext(sql, role, resource, action);
databaseOperate.blockUpdate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ public class EmbeddedRolePersistServiceImpl implements RolePersistService {
public Page<RoleInfo> getRoles(int pageNo, int pageSize) {

PaginationHelper<RoleInfo> helper = persistService.createPaginationHelper();

String sqlCountRows = "SELECT COUNT(*) FROM (SELECT DISTINCT role FROM roles) roles WHERE ";

String sqlCountRows = "SELECT count(*) FROM (SELECT DISTINCT role FROM roles) roles WHERE ";

String sqlFetchRows = "SELECT role,username FROM roles WHERE ";

String where = " 1=1 ";
Expand All @@ -75,7 +76,8 @@ public Page<RoleInfo> getRolesByUserName(String username, int pageNo, int pageSi

PaginationHelper<RoleInfo> helper = persistService.createPaginationHelper();

String sqlCountRows = "SELECT COUNT(*) FROM roles WHERE ";
String sqlCountRows = "SELECT count(*) FROM roles WHERE ";

String sqlFetchRows = "SELECT role,username FROM roles WHERE ";

String where = " username= ? ";
Expand All @@ -100,7 +102,7 @@ public Page<RoleInfo> getRolesByUserName(String username, int pageNo, int pageSi
@Override
public void addRole(String role, String userName) {

String sql = "INSERT into roles (role, username) VALUES (?, ?)";
String sql = "INSERT INTO roles (role, username) VALUES (?, ?)";

try {
EmbeddedStorageContextUtils.addSqlContext(sql, role, userName);
Expand All @@ -117,7 +119,7 @@ public void addRole(String role, String userName) {
*/
@Override
public void deleteRole(String role) {
String sql = "DELETE from roles WHERE role=?";
String sql = "DELETE FROM roles WHERE role=?";
try {
EmbeddedStorageContextUtils.addSqlContext(sql, role);
databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
Expand All @@ -134,7 +136,7 @@ public void deleteRole(String role) {
*/
@Override
public void deleteRole(String role, String username) {
String sql = "DELETE from roles WHERE role=? and username=?";
String sql = "DELETE FROM roles WHERE role=? AND username=?";
try {
EmbeddedStorageContextUtils.addSqlContext(sql, role, username);
databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void createUser(String username, String password) {
*/
@Override
public void deleteUser(String username) {
String sql = "DELETE from users WHERE username=?";
String sql = "DELETE FROM users WHERE username=?";
try {
EmbeddedStorageContextUtils.addSqlContext(sql, username);
databaseOperate.blockUpdate();
Expand Down Expand Up @@ -109,7 +109,8 @@ public Page<User> getUsers(int pageNo, int pageSize) {

PaginationHelper<User> helper = persistService.createPaginationHelper();

String sqlCountRows = "SELECT COUNT(*) FROM users WHERE ";
String sqlCountRows = "SELECT count(*) FROM users WHERE ";

String sqlFetchRows = "SELECT username,password FROM users WHERE ";

String where = " 1=1 ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public Page<PermissionInfo> getPermissions(String role, int pageNo, int pageSize
@Override
public void addPermission(String role, String resource, String action) {

String sql = "INSERT into permissions (role, resource, action) VALUES (?, ?, ?)";
String sql = "INSERT INTO permissions (role, resource, action) VALUES (?, ?, ?)";

try {
jt.update(sql, role, resource, action);
Expand All @@ -118,7 +118,7 @@ public void addPermission(String role, String resource, String action) {
@Override
public void deletePermission(String role, String resource, String action) {

String sql = "DELETE from permissions WHERE role=? and resource=? and action=?";
String sql = "DELETE FROM permissions WHERE role=? AND resource=? AND action=?";
try {
jt.update(sql, role, resource, action);
} catch (CannotGetJdbcConnectionException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public Page<RoleInfo> getRoles(int pageNo, int pageSize) {

PaginationHelper<RoleInfo> helper = persistService.createPaginationHelper();

String sqlCountRows = "SELECT COUNT(*) from (SELECT DISTINCT role FROM roles) roles WHERE ";
String sqlCountRows = "SELECT count(*) FROM (SELECT DISTINCT role FROM roles) roles WHERE ";

String sqlFetchRows = "SELECT role,username FROM roles WHERE ";

String where = " 1=1 ";
Expand All @@ -87,8 +88,9 @@ public Page<RoleInfo> getRoles(int pageNo, int pageSize) {
public Page<RoleInfo> getRolesByUserName(String username, int pageNo, int pageSize) {

PaginationHelper<RoleInfo> helper = persistService.createPaginationHelper();

String sqlCountRows = "SELECT COUNT(*) FROM roles WHERE ";

String sqlCountRows = "SELECT count(*) FROM roles WHERE ";

String sqlFetchRows = "SELECT role,username FROM roles WHERE ";

String where = " username= ? ";
Expand Down Expand Up @@ -117,7 +119,7 @@ public Page<RoleInfo> getRolesByUserName(String username, int pageNo, int pageSi
@Override
public void addRole(String role, String userName) {

String sql = "INSERT into roles (role, username) VALUES (?, ?)";
String sql = "INSERT INTO roles (role, username) VALUES (?, ?)";

try {
jt.update(sql, role, userName);
Expand All @@ -134,7 +136,7 @@ public void addRole(String role, String userName) {
*/
@Override
public void deleteRole(String role) {
String sql = "DELETE from roles WHERE role=?";
String sql = "DELETE FROM roles WHERE role=?";
try {
jt.update(sql, role);
} catch (CannotGetJdbcConnectionException e) {
Expand All @@ -151,7 +153,7 @@ public void deleteRole(String role) {
*/
@Override
public void deleteRole(String role, String username) {
String sql = "DELETE from roles WHERE role=? and username=?";
String sql = "DELETE FROM roles WHERE role=? AND username=?";
try {
jt.update(sql, role, username);
} catch (CannotGetJdbcConnectionException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected void init() {
*/
@Override
public void createUser(String username, String password) {
String sql = "INSERT into users (username, password, enabled) VALUES (?, ?, ?)";
String sql = "INSERT INTO users (username, password, enabled) VALUES (?, ?, ?)";

try {
jt.update(sql, username, password, true);
Expand All @@ -79,7 +79,7 @@ public void createUser(String username, String password) {
*/
@Override
public void deleteUser(String username) {
String sql = "DELETE from users WHERE username=?";
String sql = "DELETE FROM users WHERE username=?";
try {
jt.update(sql, username);
} catch (CannotGetJdbcConnectionException e) {
Expand Down Expand Up @@ -131,7 +131,8 @@ public Page<User> getUsers(int pageNo, int pageSize) {

PaginationHelper<User> helper = persistService.createPaginationHelper();

String sqlCountRows = "SELECT COUNT(*) FROM users WHERE ";
String sqlCountRows = "SELECT count(*) FROM users WHERE ";

String sqlFetchRows = "SELECT username,password FROM users WHERE ";

String where = " 1=1 ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ public boolean insertGroupCapacity(final GroupCapacity capacity) {
String sql;
if (CLUSTER.equals(capacity.getGroup())) {
sql = "INSERT INTO group_capacity (group_id, quota, `usage`, `max_size`, max_aggr_count, max_aggr_size, "
+ "gmt_create, gmt_modified) SELECT ?, ?, COUNT(*), ?, ?, ?, ?, ? FROM config_info;";
+ "gmt_create, gmt_modified) SELECT ?, ?, count(*), ?, ?, ?, ?, ? FROM config_info;";
} else {
// Note: add "tenant_id = ''" condition.
sql = "INSERT INTO group_capacity (group_id, quota, `usage`, `max_size`, max_aggr_count, max_aggr_size, "
+ "gmt_create, gmt_modified) SELECT ?, ?, COUNT(*), ?, ?, ?, ?, ? FROM config_info WHERE "
+ "gmt_create, gmt_modified) SELECT ?, ?, count(*), ?, ?, ?, ?, ? FROM config_info WHERE "
+ "group_id=? AND tenant_id = '';";
}
return insertGroupCapacity(sql, capacity);
Expand Down Expand Up @@ -262,7 +262,7 @@ public boolean updateGroupCapacity(String group, Integer quota, Integer maxSize,
sql.append(" gmt_modified = ?");
argList.add(TimeUtils.getCurrentTime());

sql.append(" where group_id = ?");
sql.append(" WHERE group_id = ?");
argList.add(group);
try {
return jdbcTemplate.update(sql.toString(), argList.toArray()) == 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public boolean decrementUsage(TenantCapacity tenantCapacity) {
public boolean updateTenantCapacity(String tenant, Integer quota, Integer maxSize, Integer maxAggrCount,
Integer maxAggrSize) {
List<Object> argList = Lists.newArrayList();
StringBuilder sql = new StringBuilder("update tenant_capacity set");
StringBuilder sql = new StringBuilder("UPDATE tenant_capacity SET");
if (quota != null) {
sql.append(" quota = ?,");
argList.add(quota);
Expand All @@ -230,7 +230,7 @@ public boolean updateTenantCapacity(String tenant, Integer quota, Integer maxSiz
sql.append(" gmt_modified = ?");
argList.add(TimeUtils.getCurrentTime());

sql.append(" where tenant_id = ?");
sql.append(" WHERE tenant_id = ?");
argList.add(tenant);
try {
return jdbcTemplate.update(sql.toString(), argList.toArray()) == 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ public interface PersistService {
Object[] EMPTY_ARRAY = new Object[] {};
@SuppressWarnings("checkstyle:linelength")
String SQL_FIND_ALL_CONFIG_INFO = "SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_create,gmt_modified,src_user,src_ip,c_desc,c_use,effect,c_schema FROM config_info";
String SQL_TENANT_INFO_COUNT_BY_TENANT_ID = "SELECT COUNT(1) WHERE tenant_info WHERE tenant_id = ?";
String SQL_FIND_CONFIG_INFO_BY_IDS = "SELECT ID,data_id,group_id,tenant_id,app_name,content,md5 FROM config_info WHERE ";

String SQL_TENANT_INFO_COUNT_BY_TENANT_ID = "SELECT count(1) FROM tenant_info WHERE tenant_id = ?";
String SQL_FIND_CONFIG_INFO_BY_IDS = "SELECT id,data_id,group_id,tenant_id,app_name,content,md5 FROM config_info WHERE ";

String SQL_DELETE_CONFIG_INFO_BY_IDS = "DELETE FROM config_info WHERE ";
int QUERY_LIMIT_SIZE = 50;
String PATTERN_STR = "*";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public ConfigInfoWrapper mapRow(ResultSet rs, int rowNum) throws SQLException {
} catch (SQLException ignore) {
}
try {
info.setId(rs.getLong("ID"));
info.setId(rs.getLong("id"));
} catch (SQLException ignore) {
}
try {
Expand Down Expand Up @@ -238,7 +238,7 @@ public ConfigInfoBetaWrapper mapRow(ResultSet rs, int rowNum) throws SQLExceptio
} catch (SQLException ignore) {
}
try {
info.setId(rs.getLong("ID"));
info.setId(rs.getLong("id"));
} catch (SQLException ignore) {
}
try {
Expand Down Expand Up @@ -270,7 +270,7 @@ public ConfigInfoTagWrapper mapRow(ResultSet rs, int rowNum) throws SQLException
} catch (SQLException ignore) {
}
try {
info.setId(rs.getLong("ID"));
info.setId(rs.getLong("id"));
} catch (SQLException ignore) {
}
try {
Expand Down Expand Up @@ -305,7 +305,7 @@ public ConfigInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
} catch (SQLException ignore) {
}
try {
info.setId(rs.getLong("ID"));
info.setId(rs.getLong("id"));
} catch (SQLException ignore) {
}
try {
Expand Down Expand Up @@ -366,7 +366,7 @@ public ConfigAllInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
} catch (SQLException ignore) {
}
try {
info.setId(rs.getLong("ID"));
info.setId(rs.getLong("id"));
} catch (SQLException ignore) {
}
info.setCreateTime(rs.getTimestamp("gmt_modified").getTime());
Expand Down Expand Up @@ -399,7 +399,7 @@ public ConfigInfo4Beta mapRow(ResultSet rs, int rowNum) throws SQLException {
} catch (SQLException ignore) {
}
try {
info.setId(rs.getLong("ID"));
info.setId(rs.getLong("id"));
} catch (SQLException ignore) {
}
try {
Expand Down Expand Up @@ -427,7 +427,7 @@ public ConfigInfo4Tag mapRow(ResultSet rs, int rowNum) throws SQLException {
} catch (SQLException ignore) {
}
try {
info.setId(rs.getLong("ID"));
info.setId(rs.getLong("id"));
} catch (SQLException ignore) {
}
try {
Expand All @@ -452,7 +452,7 @@ public ConfigInfoBase mapRow(ResultSet rs, int rowNum) throws SQLException {
} catch (SQLException ignore) {
}
try {
info.setId(rs.getLong("ID"));
info.setId(rs.getLong("id"));
} catch (SQLException ignore) {
}
return info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public Page<E> fetchPageLimit(final String sqlFetchRows, final Object[] args, fi

@Override
public void updateLimit(final String sql, final Object[] args) {
String sqlUpdate = sql.replaceAll("limit \\?", "OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY");
String sqlUpdate = sql.replaceAll("LIMIT \\?", "OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY");

EmbeddedStorageContextUtils.addSqlContext(sqlUpdate, args);
try {
Expand Down
Loading

0 comments on commit 5aab426

Please sign in to comment.