修复修改分组名称可能出现的空指针异常

This commit is contained in:
mxd
2021-07-07 08:11:50 +08:00
parent fe92a201e8
commit 3315704efd
2 changed files with 5 additions and 6 deletions

View File

@@ -61,7 +61,6 @@ public class DatabaseResource extends KeyValueResource {
@Override
public void readAll() {
this.cachedContent.clear();
String sql = String.format("select file_path, file_content from %s where file_path like '%s%%'", tableName, this.path);
SqlRowSet sqlRowSet = template.queryForRowSet(sql);
while (sqlRowSet.next()) {
@@ -93,7 +92,7 @@ public class DatabaseResource extends KeyValueResource {
@Override
public boolean exists() {
if (this.cachedContent.containsKey(this.path)) {
if (this.cachedContent.get(this.path) != null) {
return true;
}
String sql = String.format("select count(*) from %s where file_path = ?", tableName);
@@ -137,9 +136,10 @@ public class DatabaseResource extends KeyValueResource {
@Override
public boolean delete() {
String sql = String.format("delete from %s where file_path = ? or file_path like '%s%%'", tableName, isDirectory() ? this.path : this.path + separator);
String path = isDirectory() ? this.path : this.path + separator;
String sql = String.format("delete from %s where file_path = ? or file_path like '%s%%'", tableName, path);
if (template.update(sql, this.path) > 0) {
this.cachedContent.remove(this.path);
this.cachedContent.entrySet().removeIf(entry -> entry.getKey().startsWith(path));
return true;
}
return false;

View File

@@ -31,7 +31,6 @@ public class RedisResource extends KeyValueResource {
@Override
public void readAll() {
this.cachedContent.clear();
List<String> keys = new ArrayList<>(keys());
List<String> values = redisTemplate.opsForValue().multiGet(keys);
if (values != null) {
@@ -66,7 +65,7 @@ public class RedisResource extends KeyValueResource {
@Override
public boolean exists() {
if (this.cachedContent.containsKey(this.path)) {
if (this.cachedContent.get(this.path) != null) {
return true;
}
return Boolean.TRUE.equals(this.redisTemplate.hasKey(this.path));