...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
@Converter(autoApply = true) public final class StringToMapConverter implements AttributeConverter<Map<String, ? extends Object>, String> { private static final Coder coder = new StandardCoder(); @Override public String convertToDatabaseColumn(Map<String, ? extends Object> map) { try { return map == null ? null : coder.encode(map); } catch (CoderException e) { throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e); } } @Override public Map<String, ? extends Object> convertToEntityAttribute(String dbData) { if (dbData == null) { return Map.of(); } try { return coder.decode(dbData, Map.class); } catch (CoderException e) { throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e); } } } |
Table of comparison
Type | DataStore | Validation | Support Query | Index | Preserve Order |
---|---|---|---|---|---|
longtext | MariaDB | SELECT | Yes | No | Yes |
longtext | PostgreSQL | No | No | No | Yes |
json | PostgreSQL | INSERT / UPDATE | Yes | No | Yes |
jsonb | PostgreSQL | INSERT / UPDATE | Yes | Yes | No |
Conclusion
My propose options are shown below:
- replace all ElementCollections with Converters (Minimum change with Minimum improvement):
- A lot of small Jsons
- Using longtext, we are be able to maintain compatibility with MariaDB
- Minimum Java code impact
- 50% of tables (with postfix as _ATTRIBUTES, _PROPERTIES, _METADATA, _OCCURRENCES, _CONSTRAINTS, _TARGETS, _TRIGGERS and _INPUTS) will be removed
- Unit tests not need to change
- Unique Json String:
- One big Json for each model (e.g. saving the whole ToscaServiceTemplace as Json)
- Using jsonb, only PostgreSQL will be supported
- Medium Java code impact: all persistence classes could be removed or have to be as Json Document
- 90% of tables will be removed
- Unit tests need PostgreSQLContainer
- Cassandra
- Document oriented approach full supported by SpringBoot (not needs Converters)
- Huge Java code impact: All repositories and all persistence classes have to change to a Json Document
- No support for MariaDB and PostgreSQL anymore
- Unit tests need an Embedded Cassandra Server (EmbeddedCassandraServerHelper or CassandraContainer)
Benchmark Performance
Using Jmeter to make calls and Prometheus to trace
Current version
Eclipse-Link/Mariadb. Tosca Service template is saved as a schema entity relation.
Unique Json
Hibernate/Mariadb. Tosca Service Template is saved into a longtext as Json.