forked from ebean-orm/ebean-orm.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraftable.html
More file actions
325 lines (276 loc) · 16.1 KB
/
draftable.html
File metadata and controls
325 lines (276 loc) · 16.1 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta id="layout-head" />
<title>Features</title>
<link rel="shortcut icon" href="/images/favicon.ico" >
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
<link rel="stylesheet" href="/css/pygments.css" type="text/css" />
<link rel="stylesheet" href="/css/site.css">
</head>
<body>
<div id="wrap">
<div id="header">
<div class="navbar" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".mobile-nav">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">
<img src="/images/lg5-21x100.png" height="35">
</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav pull-right nav-btn-rhs">
<li ><a href="/"><span class="fas fa-home"></span> Home</a></li>
<li ><a href="/docs">Docs</a></li>
<li ><a href="/docs/getting-started">Get Started</a></li>
<li ><a href="/support">Help</a></li>
<li ><a href="/videos">Videos</a></li>
<li ><a target="_blank" href="/apidoc/11">ApiDocs</a></li>
<li ><a href="/releases">Releases</a></li>
<li><a target="_blank" href="https://github.com/ebean-orm/ebean"> <i class="fab fa-github"></i></a></li>
</ul>
</div>
<div class="mobile-nav">
<ul class="nav navbar-nav pull-right nav-btn-rhs">
<li ><a href="/"><span class="fas fa-home"></span> Home</a></li>
<li ><a href="/docs">Docs</a></li>
<li ><a href="/docs/getting-started">Get Started</a></li>
<li ><a href="/support">Help</a></li>
<li ><a href="/videos">Videos</a></li>
<li ><a target="_blank" href="/apidoc/11">ApiDocs</a></li>
<li ><a href="/releases">Releases</a></li>
<li><a target="_blank" href="https://github.com/ebean-orm/ebean"> <i class="fab fa-github"></i></a></li>
</ul>
</div>
</div>
</div>
</div>
<div id="main">
<div class="jumbotron mini">
<div class="container">
<h1><a href="/docs/">Documentation</a> / <a href="/docs/features/">Features</a> / Draftable</h1>
</div>
</div>
<div class="container doc-index bs-docs-container">
<div class="row">
<div class="col-md-9" role="main">
<form action="https://www.google.com/search" method="get">
<div class="page-inline-search" style="margin-bottom:8px;">
<div class="input-group">
<input name="q" id="searchinput" type="text" class="form-control" placeholder="Search... (press 's' to focus)" data-placeholder-focus="Search... (use '↑', '↓' and '⏎' to select results)" data-placeholder-blur="Search... (press 's' to focus)" autocomplete="off">
<input type="hidden" name="as_sitesearch" value="ebean.io">
<div class="input-group-btn">
<button class="btn btn-default form-control" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
<div class="search-results-inline-container" style="display: none;">
<ul id="search-results-container" class="search-results"><li class=" active"><a href="/docs" title="Docs"><span style="color:#777;">Docs</span> Documentation </a></li><li class=""><small style="color:#999;">And 101 more...</small></li></ul>
</div>
</div>
</form>
<div class="bs-docs-section">
<h2 id="overview">Overview</h2>
<p>
Draftable is a feature that uses a second set of tables to hold a 'draft' version of the
object graph separately from the 'live'. Typically the draft objects are edited and go
through an approval process before being published.
</p>
<p>
To implement this feature all @Draftable and @DraftElement beans have a second draft table
that closely resembles the live table but commonly will have additional columns to support
an approval workflow for publishing.
</p>
<p>
Publishing is a function that takes underlying rows from the draft tables and copies them
to the matching live table. In this way the application can easily maintain a 'draft' version
and 'live' version of the entities.
</p>
<h2 id="mapping">Mapping</h2>
<hr/>
<h4>ENTITY MAPPING</h4>
<h4 id="draftable">@Draftable</h4>
<p>
<code>@Draftable</code> is an annotation put on entity beans that should support draftable
features.
</p>
<p>
The @Draftable annotation put on 'top level' (or root level) entity beans and @DraftableElement
is put on related child entity beans which are considered part of the same graph.
</p>
<p>
Publishing a <code>@Draftable</code> bean will publish the 'top level' @Draftable entity beans
along with any of its related child @DraftableElement beans.
</p>
<h4 id="draftable-element">@DraftableElement</h4>
<p>
<code>@DraftableElement</code> is an annotation put on entity beans that are part of a draftable
object graph but not 'top level' beans. The publish() and draftRestore() functions act on a draftable
bean and all it's associated draftableElement beans as a single unit (published/restored as a unit).
</p>
<hr/>
<h4>PROPERTY MAPPING</h4>
<h4 id="draft-only">@DraftOnly</h4>
<p>
<code>@DraftOnly</code> is an annotation put on properties that exist on the draft table only
- these properties do not exist on the associated live table. For example, annotation properties
that are on the draft to support approval workflow (workflow status, when publish timestamp etc).
</p>
<h4 id="draft-dirty">@DraftDirty</h4>
<p>
<code>@DraftDirty</code> is an annotation that can be put on a boolean property of a @Draftable entity bean.
This property only exists on the draft table and it's value is automatically set to true when the draft
bean is saved and automatically set to false when the draft bean is published. The property is expected
to be used to identify (query) draft beans that should be published.
</p>
<p>
Currently a change to a @DraftableElement does not set the dirty flag on the 'owning' @Draftable bean and
instead this would need to be done manually in this case if required.
</p>
<h4 id="draft-reset">@DraftReset</h4>
<p>
<code>@DraftReset</code> is an annotation that can be put on a property of a @Draftable entity bean.
The value of this property is automatically set to null on the draft bean after it has been published.
For example, the property is could contain comments or timestamp values related to the approval workflow
(and after a bean is publish these are 'reset' to null on the draft bean).
</p>
<h2 id="query-as-draft">Query As Draft</h2>
<p>
A normal Query builds the object graph from the 'live' tables. You can specify the query to run
<code>asDraft()</code> and then it will build the object graph using the draft tables. This can be
used to <code>PREVIEW</code> the currently editing state of the object graphs.
</p>
<div class="syntax java"><div class="highlight"><pre><span></span><span class="c1">// Get the 'draft' object graph</span>
<span class="n">Document</span> <span class="n">documentDraft</span> <span class="o">=</span>
<span class="n">Ebean</span><span class="o">.</span><span class="na">find</span><span class="o">(</span><span class="n">Document</span><span class="o">.</span><span class="na">class</span><span class="o">)</span>
<span class="o">.</span><span class="na">setId</span><span class="o">(</span><span class="n">docId</span><span class="o">)</span>
<span class="o">.</span><span class="na">asDraft</span><span class="o">()</span>
<span class="o">.</span><span class="na">findOne</span><span class="o">();</span>
<span class="c1">// Get the 'draft' documents</span>
<span class="n">List</span><span class="o"><</span><span class="n">Document</span><span class="o">></span> <span class="n">draftDocuments</span> <span class="o">=</span>
<span class="n">Ebean</span><span class="o">.</span><span class="na">find</span><span class="o">(</span><span class="n">Document</span><span class="o">.</span><span class="na">class</span><span class="o">)</span>
<span class="o">.</span><span class="na">where</span><span class="o">()</span>
<span class="o">.</span><span class="na">eq</span><span class="o">(</span><span class="s">"dirty"</span><span class="o">,</span> <span class="kc">true</span><span class="o">)</span>
<span class="o">.</span><span class="na">ge</span><span class="o">(</span><span class="s">"whenPublish"</span><span class="o">,</span> <span class="n">now</span><span class="o">)</span>
<span class="o">.</span><span class="na">asDraft</span><span class="o">()</span>
<span class="o">.</span><span class="na">findList</span><span class="o">();</span>
</pre></div>
</div>
<p>
Note: The <code>asDraft</code> query state is propagated to any lazy loading or query joins.
</p>
<p>
Note: Any <code>asDraft</code> query does not use the L2 cache (Only queries for live beans can use L2 cache).
</p>
<h2 id="publish">Publish</h2>
<p>
<code>Publish</code> is the function that takes the values from draft object graph and applies them
to the matching live object graph. The publish function cascades from a top level @Draftable entity bean
to any related @DraftableElement entity beans.
</p>
<h4>@OneToMany</h4>
<p>
A <code>@OneToMany</code> relationship to a @DraftableElement effectively has save and delete cascade
turned on automatically. The cascade save/delete is used internally to publish the object graph.
</p>
<h4>@ManyToMany</h4>
<p>
A <code>@ManyToMany</code> relationship to a @Draftable bean effectively has save and delete cascade
turned on automatically to maintain the relationship.
</p>
<div class="syntax java"><div class="highlight"><pre><span></span><span class="n">EbeanServer</span> <span class="n">server</span> <span class="o">=</span> <span class="n">Ebean</span><span class="o">.</span><span class="na">getDefaultServer</span><span class="o">();</span>
<span class="c1">// publish a single bean (from draft to live)</span>
<span class="c1">// returning the 'live' bean</span>
<span class="n">Document</span> <span class="n">liveDoc</span> <span class="o">=</span> <span class="n">server</span><span class="o">.</span><span class="na">publish</span><span class="o">(</span><span class="n">Document</span><span class="o">.</span><span class="na">class</span><span class="o">,</span> <span class="n">docId</span><span class="o">);</span>
<span class="c1">// publish using a query</span>
<span class="n">Query</span><span class="o"><</span><span class="n">Link</span><span class="o">></span> <span class="n">pubQuery</span> <span class="o">=</span> <span class="n">server</span><span class="o">.</span><span class="na">find</span><span class="o">(</span><span class="n">Link</span><span class="o">.</span><span class="na">class</span><span class="o">)</span>
<span class="o">.</span><span class="na">where</span><span class="o">().</span><span class="na">idIn</span><span class="o">(</span><span class="n">ids</span><span class="o">)</span>
<span class="o">.</span><span class="na">order</span><span class="o">().</span><span class="na">asc</span><span class="o">(</span><span class="s">"id"</span><span class="o">);</span>
<span class="c1">// publish returning the resulting 'live' beans</span>
<span class="n">List</span><span class="o"><</span><span class="n">Link</span><span class="o">></span> <span class="n">pubList</span> <span class="o">=</span> <span class="n">server</span><span class="o">.</span><span class="na">publish</span><span class="o">(</span><span class="n">pubQuery</span><span class="o">);</span>
</pre></div>
</div>
<h2 id="draft-restore">Draft Restore</h2>
<p>
<code>DraftRestore</code> is the function that takes the values from the live object graph and applies them
back to the matching draft object graph. You can consider it the opposite of a publish().
</p>
<div class="syntax java"><div class="highlight"><pre><span></span><span class="n">EbeanServer</span> <span class="n">server</span> <span class="o">=</span> <span class="n">Ebean</span><span class="o">.</span><span class="na">getDefaultServer</span><span class="o">();</span>
<span class="c1">// Restore a single draft bean</span>
<span class="n">server</span><span class="o">.</span><span class="na">draftRestore</span><span class="o">(</span><span class="n">Document</span><span class="o">.</span><span class="na">class</span><span class="o">,</span> <span class="n">docId</span><span class="o">);</span>
<span class="n">Query</span><span class="o"><</span><span class="n">Document</span><span class="o">></span> <span class="n">restoreQuery</span> <span class="o">=</span> <span class="n">server</span><span class="o">.</span><span class="na">find</span><span class="o">(</span><span class="n">Document</span><span class="o">.</span><span class="na">class</span><span class="o">)</span>
<span class="o">.</span><span class="na">where</span><span class="o">().</span><span class="na">idIn</span><span class="o">(</span><span class="n">ids</span><span class="o">)</span>
<span class="o">.</span><span class="na">order</span><span class="o">().</span><span class="na">asc</span><span class="o">(</span><span class="s">"id"</span><span class="o">);</span>
<span class="c1">// Restore all the beans matching a query</span>
<span class="n">server</span><span class="o">.</span><span class="na">draftRestore</span><span class="o">(</span><span class="n">restoreQuery</span><span class="o">);</span>
</pre></div>
</div>
<h2 id="example-app">Example Application</h2>
<p>
An example application is available at <a href="https://github.com/ebean-orm/example-draftable">example-draftable</a> .
</p>
<h2>L2 Cache</h2>
<p>
Only live beans and queries can use the L2 cache. Similarly only save/delete of live beans invalidate parts
of the L2 cache. All queries for draft beans do not use the L2 cache and save/delete of draft beans do not
invalidate any part of the L2 cache.
</p>
</div>
</div>
<div class="col-md-3" role="complementary">
<nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm">
<ul class="nav bs-docs-sidenav">
<li class="active">
<a href="/docs/features/draftable">Draftable</a>
<ul class="nav">
<li><a href="#overview">Overview</a></li>
<li><a href="#mapping">Mapping</a></li>
<li><a href="#query-as-draft">Query As Draft</a></li>
<li><a href="#publish">Publish</a></li>
<li><a href="#draft-restore">Draft Restore</a></li>
</ul>
</li>
</ul>
</nav>
</div>
</div>
</div>
</div>
</div>
<footer id="footer">
<div class="doc-footer">
<ul class="doc-footer-links">
<li><a href="/">Ebean ORM</a></li>
<li> | </li>
<li><a href="http://avaje-metric.github.io">Metrics</a></li>
</ul>
</div>
</footer>
<script type="text/javascript">
var categoryNames = {};
</script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/js/jquery.easing.min.js"></script>
<script src="/js/jquery.storageapi.min.js"></script>
<script src="/js/ebean-site.js"></script>
<script src="/js/extra.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-75181644-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>