Przeglądaj źródła

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

mxd 4 lat temu
rodzic
commit
3315704efd

+ 4 - 4
magic-api/src/main/java/org/ssssssss/magicapi/adapter/resource/DatabaseResource.java

@@ -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;

+ 1 - 2
magic-api/src/main/java/org/ssssssss/magicapi/adapter/resource/RedisResource.java

@@ -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));