| 1 | # SQL-based `ContractNegotiationStore` - technical proposal |
| 2 | |
| 3 | **_Note that the SQL statements (DDL) are specific to and only tested with PostgreSQL. Using it with other RDBMS may |
| 4 | work but might have unexpected side effects!_** |
| 5 | |
| 6 | ## 1. Table schema |
| 7 | |
| 8 | see [schema.sql](src/main/resources/contract-negotiation-schema.sql). |
| 9 | |
| 10 | As an alternative to storing `ContractAgreement`s in a dedicated table, it could also be serialized and stored as column |
| 11 | in the `contract_negotiation` table. However, we will need to be able to list all contract agreements at some point, so |
| 12 | it seemed more future-proof to have it separate. |
| 13 | |
| 14 | ## 2. Translating the `ContractNegotiationStore` into SQL statements |
| 15 | |
| 16 | All SQL contants such as table names, column names, statement templates etc. are stored in an interface |
| 17 | called `ContractNegotiationStatements`. Column names are declared directly in that interface, as they likely won't |
| 18 | change between different DB technologies, but all statements are then implemented in the `PostgreStatements` class. |
| 19 | |
| 20 | ## Create a flexible query API to accommodate `QuerySpec` |
| 21 | |
| 22 | _For the first version, only the `limit` and `offset` arguments from the `QuerySpec` will be used._ |
| 23 | |
| 24 | For subsequent versions it is recommended to re-use the `Clause` interface and its implementors, that were originally |
| 25 | implemented for CosmosDB, and create an equivalent set of clauses for SQL. Thus, there would be a `Limit-`, `Offset-` |
| 26 | , `Order-` and `WhereClause` for SQL. |
| 27 | |
| 28 | That way, dialect-dependent variants can be implemented should the need arise, because the actual SQL statement is |
| 29 | encoded in those clauses, offering a fluent Java API. |