Skip to content

Commit fd7064f

Browse files
committed
update docs
1 parent ff40c72 commit fd7064f

File tree

2 files changed

+99
-14
lines changed

2 files changed

+99
-14
lines changed

xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/FeatureProviderSql.java

Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@
172172
* <p>### Dataset Changes
173173
* <p>{@docVar:datasetChanges}
174174
* <p>{@docTable:datasetChanges}
175+
* <p>### Query Generation
176+
* <p>Options for query generation.
177+
* <p>{@docTable:queryGeneration}
175178
* <p>### Source Path Defaults
176179
* <p>Defaults for the path expressions in `sourcePath`, also see [Source Path
177180
* Syntax](#path-syntax).
@@ -202,13 +205,50 @@
202205
* <p>Additional columns for CRUD inserts can be set by adding `{inserts=columnName=value}`
203206
* after the table name. The value may be a constant or a function, for example
204207
* `{inserts=id=gen_random_uuid()&featuretype='type1'}`.
208+
* <p>Also regarding CRUD, if a property with `role: ID` does match the primary key of the main
209+
* table, but it should not be automatically generated on insert, add `{generated=false}` to the
210+
* `sourcePath` of that property.
205211
* <p>All table and column names must be unquoted identifiers.
206212
* <p>Arbitrary SQL expressions for values are supported, for example to apply function calls.
207213
* As an example, this `[EXPRESSION]{sql=$T$.length+55.5}` (instead of just `length`) would add
208214
* a fixed amount to the length column. The prefix `$T$` will be replaced with the table alias.
209-
* <p>### Query Generation
210-
* <p>Options for query generation.
211-
* <p>{@docTable:queryGeneration}
215+
* <p>### CRUD
216+
* <p>If the features of this provider should be mutated via the API, `datasetChanges.mode` has
217+
* to be set to `CRUD`. Also consider the following paragraphs to understand which adjustments
218+
* to the mapping might be necessary for your use case.
219+
* <p>#### Table types
220+
* <p><code>
221+
* - `main` Main tables represent the instances of a feature type. They are defined in the
222+
* upper-most `sourcePath` of a type.
223+
* - `secondary` Secondary tables are connected to main tables via joins, either directly or
224+
* through a chain of secondary and/or junction tables.
225+
* - `junction` Junction tables usually represent m:n relations. They only contain two foreign keys
226+
* of main and/or secondary tables.
227+
* </code>
228+
* <p>#### Primary keys
229+
* <p>It is expected that every main and secondary table has a primary key, and that the value
230+
* for the primary key is automatically generated on insert. Usually
231+
* `sourcePathDefaults.primaryKey` should match the primary key name from the database. If not
232+
* every table has the same primary key, it can be overridden, see [Source Path
233+
* Syntax](#source-path-syntax).
234+
* <p>In rare cases, when another column than the primary key is used in join conditions, the
235+
* `primaryKey` in the mapping needs to match that column and differ from the actual primary
236+
* key. An example would be a junction table that connects feature instances by id.
237+
* <p>#### Feature ids
238+
* <p>There are four variants for creating new feature ids on insert:
239+
* <p><code>
240+
* - **Primary key, auto-generated** The `sourcePath` of the property with `role: ID` matches
241+
* the `primaryKey` and new values are automatically generated on insert by the database.
242+
* - **Primary key, user-defined** The `sourcePath` of the property with `role: ID` matches the
243+
* `primaryKey` and has the flag `{generated=false}`, the value from the payload given by the
244+
* user is inserted.
245+
* - **Other column, auto-generated** The `sourcePath` of the property with `role: ID` does not
246+
* match the `primaryKey`, and the `sourcePath` of the main table has a matching `inserts` flag
247+
* with a generation function, e.g. `{inserts=id=gen_random_uuid()'}` (see [Source Path Syntax](#source-path-syntax)).
248+
* - **Other column, user-defined** The `sourcePath` of the property with `role: ID` does not match
249+
* the `primaryKey`, and the `sourcePath` of the main table does not have a matching `inserts`
250+
* flag, the value from the payload given by the user is inserted.
251+
* </code>
212252
* @cfgPropertiesAdditionalDe ### Connection Info
213253
* <p>Das Connection-Info-Objekt für SQL-Datenbanken wird wie folgt beschrieben:
214254
* <p>{@docTable:connectionInfo}
@@ -218,6 +258,9 @@
218258
* <p>### Datensatzänderungen
219259
* <p>{@docVar:datasetChanges}
220260
* <p>{@docTable:datasetChanges}
261+
* <p>### Query-Generierung
262+
* <p>Optionen für die Query-Generierung in `queryGeneration`.
263+
* <p>{@docTable:queryGeneration}
221264
* <p>### SQL-Pfad-Defaults
222265
* <p>Defaults für die Pfad-Ausdrücke in `sourcePath`, siehe auch
223266
* [SQL-Pfad-Syntax](#path-syntax).
@@ -254,14 +297,55 @@
254297
* <p>Zusätzliche Spalten für CRUD Inserts können durch den Zusatz `{inserts=Spaltenname=Wert}`
255298
* nach dem Tabellennamen angegeben werden. Der Wert kann eine Konstante oder eine Funktion
256299
* sein, z.B. `{inserts=id=gen_random_uuid()&featuretype='type1'}`.
300+
* <p>Auch im Hinblick auf CRUD: wenn eine Eigenschaft mit `role: ID` dem Primärschlüssel der
301+
* Haupttabelle entspricht, aber der Wert beim Einfügen nicht automatisch generiert werden soll,
302+
* dann ist für diese Eigenschaft in `sourcePath` das Flag `{generated=false}` anzugeben.
257303
* <p>Alle Tabellen- und Spaltennamen müssen "unquoted Identifier" sein.
258304
* <p>Beliebige SQL-Ausdrücke für Werte sind möglich, z.B. um Funktionsaufrufe anzuwenden. So
259305
* würde z.B. dieser Ausdruck `[EXPRESSION]{sql=$T$.length+55.5}` (anstatt nur `length`) einen
260306
* fixen Wert zur Längen-Spalte addieren. Der Präfix `$T$` wird durch den Tabellen-Alias
261307
* ersetzt.
262-
* <p>### Query-Generierung
263-
* <p>Optionen für die Query-Generierung in `queryGeneration`.
264-
* <p>{@docTable:queryGeneration}
308+
* <p>### CRUD
309+
* <p>Wenn die Features dieses Providers über die API verändert werden sollen, muss
310+
* `datasetChanges.mode` auf `CRUD` gesetzt werden. Außerdem sind die folgenden Absätze zu
311+
* beachten, um zu verstehen, welche Anpassungen am Mapping für den eigenen Anwendungsfall
312+
* notwendig sind.
313+
* <p>#### Tabellentypen
314+
* <p><code>
315+
* - `main` Haupttabellen repräsentieren die Instanzen einer Objektart. Sie sind im
316+
* obersten `sourcePath` einer Objektart definiert.
317+
* - `secondary` Sekundärtabellen sind über Joins mit Haupttabellen verbunden, entweder direkt
318+
* oder über eine Kette von Sekundär- und/oder Junction-Tabellen.
319+
* - `junction` Junction-Tabellen repräsentieren in der Regel m:n-Beziehungen. Sie enthalten
320+
* ausschließlich zwei Fremdschlüssel von Haupt- und/oder Sekundärtabellen.
321+
* </code>
322+
* <p>#### Primärschlüssel
323+
* <p>Es wird erwartet, dass jede Haupt- und Sekundärtabelle einen Primärschlüssel hat und dass
324+
* der Wert für den Primärschlüssel beim Einfügen automatisch generiert wird. In der Regel
325+
* sollte `sourcePathDefaults.primaryKey` dem Primärschlüssel aus der Datenbank entsprechen.
326+
* Wenn nicht jede Tabelle denselben Primärschlüssel hat, kann dieser überschrieben werden,
327+
* siehe [SQL-Pfad-Syntax](#sql-pfad-syntax).
328+
* <p>In seltenen Fällen, wenn in Join-Bedingungen eine andere Spalte als der Primärschlüssel
329+
* verwendet wird, muss der `primaryKey` im Mapping dieser Spalte entsprechen und sich vom
330+
* tatsächlichen Primärschlüssel unterscheiden. Ein Beispiel wäre eine Junction-Tabelle, die
331+
* Feature-Instanzen über deren Ids verbindet.
332+
* <p>#### Feature-Ids
333+
* <p>Es gibt vier Varianten, um bei Inserts neue Feature-Ids zu erzeugen:
334+
* <p><code>
335+
* - **Primärschlüssel, automatisch generiert** Der `sourcePath` der Eigenschaft mit `role: ID`
336+
* entspricht dem `primaryKey` und neue Werte werden beim Einfügen automatisch von der
337+
* Datenbank generiert.
338+
* - **Primärschlüssel, benutzerdefiniert** Der `sourcePath` der Eigenschaft mit `role: ID`
339+
* entspricht dem `primaryKey` und hat das Flag `{generated=false}`, der Wert aus dem
340+
* Payload wird eingefügt.
341+
* - **Andere Spalte, automatisch generiert** Der `sourcePath` der Eigenschaft mit `role: ID`
342+
* entspricht nicht dem `primaryKey`, und der `sourcePath` der Haupttabelle hat ein
343+
* entsprechendes `inserts`-Flag mit einer Generierungsfunktion, z.B.
344+
* `{inserts=id=gen_random_uuid()'}` (siehe [SQL-Pfad-Syntax](#sql-pfad-syntax)).
345+
* - **Andere Spalte, benutzerdefiniert** Der `sourcePath` der Eigenschaft mit `role: ID`
346+
* entspricht nicht dem `primaryKey`, und der `sourcePath` der Haupttabelle hat kein
347+
* entsprechendes `inserts`-Flag, der Wert aus der Nutzlast wird eingefügt.
348+
* </code>
265349
* @ref:cfgProperties {@link de.ii.xtraplatform.features.sql.domain.ImmutableFeatureProviderSqlData}
266350
* @ref:connectionInfo {@link de.ii.xtraplatform.features.sql.domain.ImmutableConnectionInfoSql}
267351
* @ref:pool {@link de.ii.xtraplatform.features.sql.domain.ImmutablePoolSettings}

xtraplatform-features-sql/src/main/java/de/ii/xtraplatform/features/sql/domain/SqlPathDefaults.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public interface SqlPathDefaults {
2323

2424
/**
2525
* @langEn The default column that is used for join analysis if no differing primary key is set in
26-
* the [sourcePath](#path-syntax). Only relevant for CRUD.
26+
* the [sourcePath](#source-path-syntax). Only relevant for CRUD.
2727
* @langDe Die Standard-Spalte die zur Analyse von Joins verwendet wird, wenn keine abweichende
28-
* Spalte in `sourcePath` gesetzt wird. Nur relevant für CRUD.
28+
* Spalte in [sourcePath](#sql-pfad-syntax) gesetzt wird. Nur relevant für CRUD.
2929
* @default `id`
3030
*/
3131
@Value.Default
@@ -35,10 +35,10 @@ default String getPrimaryKey() {
3535

3636
/**
3737
* @langEn The default column that is used to sort rows if no differing sort key is set in the
38-
* [sourcePath](#path-syntax).
39-
* @langDe Die Standard-Spalte die zur Sortierung von Reihen verwendet wird, wenn keine
40-
* abweichende Spalte in `sourcePath` gesetzt wird. Es wird empfohlen, dass als Datentyp eine
41-
* Ganzzahl verwendet wird.
38+
* [sourcePath](#source-path-syntax).
39+
* @langDe Die Standard-Spalte die zur Sortierung von Rows verwendet wird, wenn keine abweichende
40+
* Spalte in [sourcePath](#sql-pfad-syntax) gesetzt wird. Es wird empfohlen, dass als Datentyp
41+
* eine Ganzzahl verwendet wird.
4242
* @default `id`
4343
*/
4444
@Value.Default
@@ -49,8 +49,9 @@ default String getSortKey() {
4949
/**
5050
* @since v3.3
5151
* @langEn The default schema that is applied to tables without prefix in
52-
* [sourcePaths](#path-syntax).
53-
* @langDe Das Standard-Schema das Tabellen ohne Präfix in `sourcePath` vorangestellt wird.
52+
* [sourcePaths](#source-path-syntax).
53+
* @langDe Das Standard-Schema das Tabellen ohne Präfix in [sourcePaths](#sql-pfad-syntax)
54+
* vorangestellt wird.
5455
* @default null
5556
*/
5657
Optional<String> getSchema();

0 commit comments

Comments
 (0)