-
Notifications
You must be signed in to change notification settings - Fork 999
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[improve] support multiple receivers. (#1731)
- Loading branch information
Showing
12 changed files
with
196 additions
and
119 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
.../main/java/org/apache/hertzbeat/common/entity/manager/JsonLongListAttributeConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.apache.hertzbeat.common.entity.manager; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import jakarta.persistence.AttributeConverter; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.hertzbeat.common.util.JsonUtil; | ||
import java.util.List; | ||
|
||
|
||
/** | ||
* json str to id list | ||
*/ | ||
|
||
public class JsonLongListAttributeConverter implements AttributeConverter<List<Long>, String> { | ||
@Override | ||
public String convertToDatabaseColumn(List<Long> attribute) { | ||
return JsonUtil.toJson(attribute); | ||
|
||
} | ||
|
||
@Override | ||
public List<Long> convertToEntityAttribute(String dbData) { | ||
TypeReference<List<Long>> typeReference = new TypeReference<>() {}; | ||
List<Long> longList = JsonUtil.fromJson(dbData, typeReference); | ||
if (longList == null && !dbData.isEmpty()) { | ||
if (StringUtils.isNumeric(dbData)){ | ||
return List.of(Long.parseLong(dbData)); | ||
} | ||
else throw new NumberFormatException("String convert to Long error"); | ||
}else return longList; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ain/java/org/apache/hertzbeat/common/entity/manager/JsonStringListAttributeConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.apache.hertzbeat.common.entity.manager; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import jakarta.persistence.AttributeConverter; | ||
import org.apache.hertzbeat.common.util.JsonUtil; | ||
|
||
import java.util.List; | ||
|
||
|
||
/** | ||
* Convert the list of strings to a JSON string | ||
*/ | ||
public class JsonStringListAttributeConverter implements AttributeConverter<List<String>, String> { | ||
@Override | ||
public String convertToDatabaseColumn(List<String> attribute) { | ||
return JsonUtil.toJson(attribute); | ||
|
||
} | ||
|
||
@Override | ||
public List<String> convertToEntityAttribute(String dbData) { | ||
TypeReference<List<String>> typeReference = new TypeReference<>() {}; | ||
List<String> stringList = JsonUtil.fromJson(dbData, typeReference); | ||
if (stringList == null && !dbData.isEmpty()) { | ||
return List.of(dbData); | ||
}else return stringList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.