Repository navigation
Expand file tree
/
Copy pathCreateMultipleAddressFrontEnd.java
More file actions
69 lines (64 loc) · 2.93 KB
/
Copy pathCreateMultipleAddressFrontEnd.java
File metadata and controls
69 lines (64 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package demo;
import org.jooq.impl.DSL;
/**
* Handles the {@code /multiple} UI action by inserting five fixed sample addresses.
*
* <p>All inserts share one transaction to demonstrate how asynchronous database-trigger
* invocations can begin before their source rows become visible to another connection.
* The inherited handler redirects only after the transaction call returns.
*/
public class CreateMultipleAddressFrontEnd extends AbstractActionFrontEnd {
/**
* Creates the batch-address action; the transaction starts only when the action is invoked.
*/
public CreateMultipleAddressFrontEnd() {
}
/**
* Inserts the Microsoft, Tesla, SpaceX, State Farm, and Delta sample addresses in
* one transaction, with numbered notes identifying the five rows in the UI.
*
* <p>A failed insert rolls back the transaction. Lambda invocations initiated by the
* database triggers are external effects and are not undone by that database rollback.
*
* @throws org.jooq.exception.DataAccessException if database access or the transaction
* fails; the inherited handler converts the failure to an HTTP 500 response
*/
@Override
protected void performAction() {
// Insert 5 addresses in one transaction so they all hit at once
var dsl = PostgresDataSource.getDSL();
dsl.transaction((configuration) -> {
var dslT = configuration.dsl();
dslT.insertInto(ADDRESS_TABLE)
.set(DSL.field("address_1"), "One Microsoft Way")
.set(DSL.field("city"), "Redmond")
.set(DSL.field("district"), "WA")
.set(DSL.field("address_notes"), "Batch Address #1")
.execute();
dslT.insertInto(ADDRESS_TABLE)
.set(DSL.field("address_1"), "1 Tesla Road")
.set(DSL.field("city"), "Austin")
.set(DSL.field("district"), "TX")
.set(DSL.field("address_notes"), "Batch Address #2")
.execute();
dslT.insertInto(ADDRESS_TABLE)
.set(DSL.field("address_1"), "1 Rocket Road")
.set(DSL.field("city"), "Hawthorne")
.set(DSL.field("district"), "CA")
.set(DSL.field("address_notes"), "Batch Address #3")
.execute();
dslT.insertInto(ADDRESS_TABLE)
.set(DSL.field("address_1"), "1 State Farm Plaza")
.set(DSL.field("city"), "Bloomington")
.set(DSL.field("district"), "IL")
.set(DSL.field("address_notes"), "Batch Address #4")
.execute();
dslT.insertInto(ADDRESS_TABLE)
.set(DSL.field("address_1"), "1030 Delta Blvd")
.set(DSL.field("city"), "Atlanta")
.set(DSL.field("district"), "GA")
.set(DSL.field("address_notes"), "Batch Address #5")
.execute();
});
}
}