-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquickstart.html
486 lines (412 loc) · 26.7 KB
/
quickstart.html
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
<!DOCTYPE html>
<!--
| Generated by Apache Maven Doxia Site Renderer 1.7.1 at 2017-03-19
| Rendered using Apache Maven Fluido Skin 1.5
-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="Date-Revision-yyyymmdd" content="20170319" />
<meta http-equiv="Content-Language" content="en" />
<title>RDFBeans – Quick Start Guide</title>
<link rel="stylesheet" href="./css/apache-maven-fluido-1.5.min.css" />
<link rel="stylesheet" href="./css/site.css" />
<link rel="stylesheet" href="./css/print.css" media="print" />
<script type="text/javascript" src="./js/apache-maven-fluido-1.5.min.js"></script>
</head>
<body class="topBarDisabled">
<div class="container-fluid">
<div id="banner">
<div class="pull-left">
<div id="bannerLeft">
<h2>RDFBeans</h2>
</div>
</div>
<div class="pull-right"> </div>
<div class="clear"><hr/></div>
</div>
<div id="breadcrumbs">
<ul class="breadcrumb">
<li id="publishDate">Last Published: 2017-03-19
<span class="divider">|</span>
</li>
<li id="projectVersion">Version: 2.2
</li>
</ul>
</div>
<div class="row-fluid">
<div id="leftColumn" class="span2">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">RDFBeans</li>
<li>
<a href="index.html" title="Overview">
<span class="none"></span>
Overview</a>
</li>
<li class="active">
<a href="#"><span class="none"></span>Quick Start Guide</a>
</li>
<li>
<a href="rdfbean.html" title="RDFBean format">
<span class="none"></span>
RDFBean format</a>
</li>
<li>
<a href="download.html" title="Download">
<span class="none"></span>
Download</a>
</li>
<li>
<a href="apidocs/index.html" title="JavaDoc">
<span class="none"></span>
JavaDoc</a>
</li>
<li>
<a href="http://github.com/cyberborean/rdfbeans" class="externalLink" title="GitHub project">
<span class="none"></span>
GitHub project</a>
</li>
<li class="nav-header">Project Documentation</li>
<li>
<a href="project-info.html" title="Project Information">
<span class="icon-chevron-right"></span>
Project Information</a>
</li>
<li>
<a href="project-reports.html" title="Project Reports">
<span class="icon-chevron-right"></span>
Project Reports</a>
</li>
</ul>
<hr />
<div id="poweredBy">
<div class="clear"></div>
<div class="clear"></div>
<div class="clear"></div>
<div class="clear"></div>
<a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
<img class="builtBy" alt="Built by Maven" src="./images/logos/maven-feather.png" />
</a>
</div>
</div>
</div>
<div id="bodyColumn" class="span10" >
<h1>Quick Start Guide</h1>
<ul class="toc">
<li><a href="#Getting_started">Getting started</a>
<ul>
<li><a href="#Classes_or_interfaces">Classes or interfaces?</a></li>
<li><a href="#Make_sure_that_your_Java_classes_andor_interfaces_are_RDFBeans-compliant">Make sure that your Java classes and/or interfaces are RDFBeans-compliant</a></li>
<li><a href="#Add_required_RDFBeans_annotations">Add required RDFBeans annotations</a></li>
<li><a href="#Prepare_your_RDF_storage">Prepare your RDF storage</a></li></ul></li>
<li><a href="#RDFBeanManager">RDFBeanManager</a>
<ul>
<li><a href="#A_note_on_multi-threading_access">A note on multi-threading access</a></li></ul></li>
<li><a href="#Working_with_RDFBean_classes">Working with RDFBean classes</a>
<ul>
<li><a href="#Adding_instances">Adding instances</a></li>
<li><a href="#Updating_instances">Updating instances</a></li>
<li><a href="#Retrieving_instances">Retrieving instances</a></li></ul></li>
<li><a href="#Working_with_RDFBean_interfaces">Working with RDFBean interfaces</a></li>
<li><a href="#Managing_RDFBeans_in_the_model">Managing RDFBeans in the model</a>
<ul>
<li><a href="#Resolving_RDFBean_identifiers">Resolving RDFBean identifiers</a></li>
<li><a href="#Deleting_RDFBeans">Deleting RDFBeans</a></li></ul></li>
<li><a href="#Advanced_topics">Advanced topics</a>
<ul>
<li><a href="#Cascade_databinding">Cascade databinding</a></li>
<li><a href="#Arrays_and_Collections">Arrays and Collections</a></li>
<li><a href="#Anonymous_RDFBeans">Anonymous RDFBeans</a></li>
<li><a href="#Transactions">Transactions</a></li></ul></li></ul>
<div class="section">
<h2><a name="Getting_started"></a>Getting started</h2>
<div class="section">
<h3><a name="Classes_or_interfaces"></a>Classes or interfaces?</h3>
<p>Before you start, it is good to know about two RDF databinding techniques provided by RDFBeans framework.</p>
<p>The first method is based on use of RDFBean classes and it is much more like a traditional JavaBeans persistence technique. Here you declare a Java class with <a href="rdfbean.html">RDFBeans annotations</a> and the no-argument constructor, instantiate it and manipulate with the object data. At any time, you can dump (marshal) or retrieve (unmarshal) the object state to/from the RDF model.</p>
<p>You can sub-class your RDFBean classes to create complex polymorphic object models, like you usually do in OOP. The RDFBeans-annotated properties will be inherited down through the levels of your class hierarchy. </p>
<p>You may also want to extract interfaces from your classes to separate method signatures from their implementations. In this case, all RDFBeans annotations can be moved to the interfaces so that the implementing classes would derive annotations implicitly. </p>
<p>This is where the second RDFBeans databinding method comes into play. If you have interfaces specifying RDFBean classes in your object model, you don’t need their actual implementation classes. Instead of this, the RDFBeans framework offers the special dynamic proxy mechanism for direct manipulation of RDF data via annotated RDFBean interfaces. Under the hood, the framework uses the special <a class="externalLink" href="http://docs.oracle.com/javase/8/docs/technotes/guides/reflection/proxy.html">proxy objects</a> which are created dynamically at runtime to access the RDF data through the interface methods. Setting of a RDFBean property causes immediate update of the RDF model and the getter methods return actual values, retrieved from the model, so you don’t have to bother about state synchronization between your objects in the Java heap and in the RDF model.</p>
<p>It is completely up to you which one method you should use in your application. Moreover, it is perfectly ok to use both methods at the same time and on the same RDF model.</p></div>
<div class="section">
<h3><a name="Make_sure_that_your_Java_classes_andor_interfaces_are_RDFBeans-compliant"></a>Make sure that your Java classes and/or interfaces are RDFBeans-compliant</h3>
<p>This basically means that every class or interface to use within RDFBeans framework must obey general <a class="externalLink" href="http://en.wikipedia.org/wiki/JavaBean">JavaBeans conventions</a>:</p>
<ul>
<li>
<p>The classes have a public no-argument constructor.</p></li>
<li>
<p>Classes and interfaces declare conventionally named getter and setter methods for the fields you plan to map to RDF properties.</p></li>
</ul></div>
<div class="section">
<h3><a name="Add_required_RDFBeans_annotations"></a>Add required RDFBeans annotations</h3>
<p><b>RDFBean type declaration</b> (<tt>@RDFBean</tt>) declares that the class or interface is an RDFBean mapped to specified RDF type (commonly, a reference to an RDF-Schema class):</p>
<div class="source">
<div class="source"><pre class="prettyprint">@RDFBean("http://xmlns.com/foaf/0.1/Person")
public class Person
{
// instances of this class will represent RDF resources of the foaf:Person type
...
</pre></div></div>
<p><b>Identifier property declaration</b> (<tt>@RDFSubject</tt>) is applied to a single getter method to specify that it returns an unique String value identifying the RDFBean instance. This value will be used to construct an URI of the RDF resource that will represent this instance in the RDF model (a subject part of all data statements). </p>
<p>This method may return a valid absolute URI string:</p>
<div class="source">
<div class="source"><pre class="prettyprint">@RDFSubject
public String getUri()
{
// must return absolute URI
return uri;
}
</pre></div></div>
<p>Alternatively, you can declare a namespace prefix to construct the URI from an arbitrary String, returned by this method:</p>
<div class="source">
<div class="source"><pre class="prettyprint">@RDFSubject(prefix="urn:some.uri.prefix/")
public String getId()
{
// resource URI will be constructed by concatenation of the prefix and returned value
return id;
}
</pre></div></div>
<p><b>Property declarations</b> (<tt>@RDF</tt>) are applied to the getter methods of the data properties to declare their RDF counterparts (predicates):</p>
<div class="source">
<div class="source"><pre class="prettyprint">@RDF("http://xmlns.com/foaf/0.1/name")
public String getName()
{
// this property will be represented as an RDF statement with the foaf:name predicate
return name;
}
</pre></div></div>
<p>For complete specification of RDFBeans annotation conventions and examples, please refer to <a href="rdfbean.html">RDFBeans classes and interfaces format specification</a>.</p></div>
<div class="section">
<h3><a name="Prepare_your_RDF_storage"></a>Prepare your RDF storage</h3>
<p>Use the RDF4J API to set up and initialize a repository that will be used to store RDF representations of your RDFBean objects. </p>
<p>For example, you can use the built-in RDF4J Native RDF repository:</p>
<div class="source">
<div class="source"><pre class="prettyprint">import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.sail.SailRepository;
import org.eclipse.rdf4j.sail.nativerdf.NativeStore;
...
File dataDir = new File("C:\\temp\\myRepository\\");
repo = new SailRepository(new NativeStore(dataDir));
repo.initialize();
</pre></div></div>
<p>For detailed information about configuration of different repository types, please refer to <a class="externalLink" href="http://docs.rdf4j.org/programming/#_the_repository_api">RDF4J documentation</a>.</p></div></div>
<div class="section">
<h2><a name="RDFBeanManager"></a>RDFBeanManager</h2>
<p>RDFBeans databinding functions are accessible as methods of a single <tt>RDFBeanManager</tt> class. An <tt>RDFBeanManager</tt> instance is created with an opened RDF4J <tt>RepositoryConnection</tt> that provides access to the unrelying RDF store.</p>
<div class="source">
<div class="source"><pre class="prettyprint">import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.cyberborean.rdfbeans.RDFBeanManager;
...
try (RepositoryConnection con = repo.getConnection()) {
RDFBeanManager manager = new RDFBeanManager(con);
// ... do something with RDFBeanManager
}
</pre></div></div>
<p>Note that you need to close the <tt>RepositoryConnection</tt> after the work is completed (or use “try-with-resource” block as in the above example). The <tt>Repository</tt> object may also need to be properly closed by calling the <tt>shutDown()</tt> method.</p>
<div class="section">
<h3><a name="A_note_on_multi-threading_access"></a>A note on multi-threading access</h3>
<p><tt>RDFBeanManager</tt> class, as well as RDF4J <tt>RepositoryConnection</tt> is not thread-safe. It is recommended that each thread obtain it’s own RepositoryConnection from a shared Repository object and create a separate RDFBeanManager instance on it.</p></div></div>
<div class="section">
<h2><a name="Working_with_RDFBean_classes"></a>Working with RDFBean classes</h2>
<div class="section">
<h3><a name="Adding_instances"></a>Adding instances</h3>
<p>To add (marshall) a current state of an RDFBean object into the underlying RDF model, use <tt>add()</tt> method:</p>
<div class="source">
<div class="source"><pre class="prettyprint">Person person = new Person();
person.setId("http://example.com/persons/jdoe");
person.setName("John Doe");
...
Resource r = manager.add(person);
</pre></div></div>
<p>The method creates new RDF resource in the underlying model and populates it with the statements constructed from RDFBean data properties. The method returns a reference to the new resource (RDF4J <a class="externalLink" href="http://docs.rdf4j.org/javadoc/latest/org/eclipse/rdf4j/model/Resource.html">Resource</a> object).</p>
<p>If the resource representing this object already exists in the model, the method returns immediately without any model updates. You can use the <tt>update()</tt> method (see below) to modify existing resources. </p></div>
<div class="section">
<h3><a name="Updating_instances"></a>Updating instances</h3>
<p><tt>update()</tt> method updates the existing RDF resource in the model to synchronize it with the current state of an RDFBean object:</p>
<div class="source">
<div class="source"><pre class="prettyprint">...
person.setEmail("[email protected]");
Resource r = manager.update(person);
</pre></div></div>
<p>The code above sets new property of our Person instance and updates it in the RDF model, thus synchronizing the RDF resource with the actual object state. </p></div>
<div class="section">
<h3><a name="Retrieving_instances"></a>Retrieving instances</h3>
<p>RDFBean class instances can be retrieved (unmarshalled) from their RDF representations using <tt>get()</tt> method:</p>
<div class="source">
<div class="source"><pre class="prettyprint">...
Person person2 = manager.get("http://example.com/persons/jdoe", Person.class);
</pre></div></div>
<p>This method returns new instance of specified RDFBean class filled with data retrieved from the RDF model.</p>
<p>In the example above, we assume that the RDFBean identifier has been declared without namespace prefix. Otherwise, we would have to pass only the local part of the identifier URI as an argument:</p>
<div class="source">
<div class="source"><pre class="prettyprint">... // assuming 'http://example.com/persons/' is a prefix declared in @RDFSubject
Person person2 = manager.get("jdoe", Person.class);
</pre></div></div>
<p>The <tt>get()</tt> method returns <tt>null</tt> if no RDF resource matching the given RDFBean identifier and class is found.</p>
<p>If we already have a reference to the Resource (e.g., a value returned by <tt>add()</tt> or <tt>update()</tt> method), we can retrive the matching RDFBean instance using that value:</p>
<div class="source">
<div class="source"><pre class="prettyprint">...
Person person2 = (Person) manager.get(r);
</pre></div></div>
<p>The <tt>getAll()</tt> method iterates over all RDFBeans of a specified class in the model:</p>
<div class="source">
<div class="source"><pre class="prettyprint">// Displays the names of all Persons in the model:
CloseableIteration<Person, Exception> iter = manager.getAll(Person.class);
while (iter.hasNext()) {
Person p = iter.next();
System.out.println(p.getName());
}
iter.close();
</pre></div></div></div></div>
<div class="section">
<h2><a name="Working_with_RDFBean_interfaces"></a>Working with RDFBean interfaces</h2>
<p>This is an alternative mapping technique which is based on using RDFBean interfaces and dynamic proxy objects.</p>
<p>Let’s extract the interface from our RDFBean <tt>Person</tt> class and annotate it the same way:</p>
<div class="source">
<div class="source"><pre class="prettyprint">@RDFBean("http://xmlns.com/foaf/0.1/Person")
public interface IPerson {
@RDFSubject
String getId();
@RDF("http://xmlns.com/foaf/0.1/name")
String getName();
void setName(String name);
//... other data properties
}
</pre></div></div>
<p>As soon as we have this interface, we can map it directly to an RDF resource in the model. For that, we need to obtain an instance of the dynamic proxy object using <tt>create()</tt> method of RDFBeanManager:</p>
<div class="source">
<div class="source"><pre class="prettyprint">IPerson person = manager.create("http://example.com/persons/jdoe", IPerson.class);
</pre></div></div>
<p>The <tt>create()</tt> method returns an object implementing our <tt>IPerson</tt> interface and matching the RDFBean with the specified identifier in the model. This proxy object has the same behaviour as an instance of the class implementing that interface, with the exception that the object data is stored not in the Java heap, but directly in statements within the underlying RDF model. So, the call:</p>
<div class="source">
<div class="source"><pre class="prettyprint">person.setName("John Doe");
</pre></div></div>
<p>will cause a statement with predicate <tt>http://xmlns.com/foaf/0.1/name</tt> and the given literal value to be created or updated in the model. Similarly, the <tt>getName()</tt> method returns the value retrieved directly from that statement.</p>
<p>If no resource matching the specified RDFBean identifier exists in the model, <tt>create()</tt> returns an empty instance, that is all its <tt>getXXX()</tt> methods return nulls. The underlying RDF model will be unchanged until the first <tt>setXXX()</tt> method is called.</p>
<p>To instantiate the proxy objects for existing RDFBeans, the <tt>create()</tt> method with a Resource argument can be used. The method returns null if the specified Resource doesn’t exist in the model:</p>
<div class="source">
<div class="source"><pre class="prettyprint">IPerson person = manager.create(r);
</pre></div></div></div>
<div class="section">
<h2><a name="Managing_RDFBeans_in_the_model"></a>Managing RDFBeans in the model</h2>
<div class="section">
<h3><a name="Resolving_RDFBean_identifiers"></a>Resolving RDFBean identifiers</h3>
<p>If an RDFBean identifier is known, it can be resolved to an RDF resource using the identifier’s String value and RDFBean class:</p>
<div class="source">
<div class="source"><pre class="prettyprint">...
Resource r = manager.getResource("http://example.com/persons/jdoe", Person.class);
</pre></div></div>
<p>or, if a namespace prefix is set for identifiers:</p>
<div class="source">
<div class="source"><pre class="prettyprint">... // assuming 'http://example.com/persons/' is a prefix
Resource r = manager.getResource("jdoe", Person.class);
</pre></div></div>
<p>The method returns null if no matching Resource is found in the model.</p></div>
<div class="section">
<h3><a name="Deleting_RDFBeans"></a>Deleting RDFBeans</h3>
<p>RDFBean representation can be deleted from RDF model with <tt>delete()</tt> method:</p>
<div class="source">
<div class="source"><pre class="prettyprint">...
manager.delete("http://example.com/persons/jdoe", Person.class);
</pre></div></div>
<p>or, using a reference to the Resource: </p>
<div class="source">
<div class="source"><pre class="prettyprint">...
manager.delete(r);
</pre></div></div></div></div>
<div class="section">
<h2><a name="Advanced_topics"></a>Advanced topics</h2>
<div class="section">
<h3><a name="Cascade_databinding"></a>Cascade databinding</h3>
<p><tt>add()</tt> and <tt>update()</tt> methods performs cascade databinding. This means that if a marshalling object has other RDFBeans as its properties, they will be marshalled and added to the model recursively. It allows to manipulate the entire complex object models with single method calls.</p>
<p>For example, let the <tt>Person</tt> class declare a <tt>knows</tt> property (probably, mapped to <tt>foaf:knows</tt>) to link Persons one another (for simplicity, we assume that cardinality of this property is 1):</p>
<div class="source">
<div class="source"><pre class="prettyprint">Person john = new Person();
john.setId("http://example.com/persons/john");
...
Person mary = new Person();
mary.setId("http://example.com/persons/mary");
...
john.setKnows(mary);
</pre></div></div>
<p>Calling <tt>manager.add(john)</tt> will result in adding both objects (<tt>john</tt> and <tt>mary</tt>) and generating a statement to link their RDF representations with the <tt>knows</tt> property.</p>
<p>Similarly, on retrieving the <tt>john</tt> RDFBean, the <tt>mary</tt> object will be automatically unmarshalled and assigned to <tt>john.knows</tt> property, thus reconstructing the whole graph of related objects.</p>
<p>The dynamic proxies follow the same principle: when a getter method is called and the property references to another RDFBean, the proxy object is automatically created and returned:</p>
<div class="source">
<div class="source"><pre class="prettyprint">IPerson john = manager.create("http://example.com/persons/john", IPerson.class);
IPerson mary = manager.create("http://example.com/persons/mary", IPerson.class);
john.setKnows(mary);
...
john.getKnows().setName("Mary"); // getKnows() returns the proxy equals to mary
System.out.println(mary.getName()); // -- will be "Mary"
</pre></div></div></div>
<div class="section">
<h3><a name="Arrays_and_Collections"></a>Arrays and Collections</h3>
<p>RDFBeans framework supports Java arrays and basic Collection types, such as Sets and Lists. By default, the array or Collection properties are represented with multiple RDF statements:</p>
<div class="source">
<div class="source"><pre class="prettyprint">private Collection<Person> knows;
...
@RDF("foaf:knows")
public Collection<Person> getKnows() {
return knows;
}
...
Set<Person> others = new HashSet<>();
others.add(mary);
others.add(jim);
others.add(pete);
john.setKnows(others);
...
manager.add(john);
</pre></div></div>
<p>This will result in three <tt>foaf:knows</tt> statements generated for <tt>john</tt> in the RDF model. When these statements are parsed back to unmarshall the <tt>john</tt> object from the model, it is not guaranteed that the Collection will preserve the original order of its elements. Because of this, the default behavior might be undesirable for arrays and ordered Collections, like Lists. For this types, it is recommended to use an ordered RDF Sequence (<a class="externalLink" href="http://www.w3.org/TR/rdf-schema/#ch_seq">rdf:Seq</a>). container to hold the property values. This can be specified with the <tt>@RDFContainer</tt> annotation:</p>
<div class="source">
<div class="source"><pre class="prettyprint">@RDF("foaf:publications")
@RDFContainer(ContainerType.SEQ)
public Document[] getPublications() {
return publications;
}
</pre></div></div></div>
<div class="section">
<h3><a name="Anonymous_RDFBeans"></a>Anonymous RDFBeans</h3>
<p>If an RDFBean class does not declare an RDFBean identifier (<tt>@RDFSubject</tt>) property, or this property value is not assigned, the object is <i>anonymous RDFBean</i>. Anonymous RDFBeans are represented in the RDF model as the <a class="externalLink" href="http://www.w3.org/TR/2014/REC-rdf11-mt-20140225/#blank-nodes">Blank nodes</a> and have few limitations like unability of retrieving with any identifier value. However, it is still possible to use these objects in properties of other RDFBeans. </p></div>
<div class="section">
<h3><a name="Transactions"></a>Transactions</h3>
<p>By default, RDFBeanManager methods add or delete individual RDF statements in a transaction-safe manner. A method starts new transaction on RepositoryConnection before any update and commit it automatically after updates are completed. If the method throws an exception, the entire transaction is rolled back that guarantees that all updates the method made to this point will not take effect.</p>
<p>The behaviour is different if the method is invoked when RepositoryConnection already has an active transaction. In this case, the method does not start new transaction, but re-uses existing one by adding new operations to it. The updates will not take effect until the transaction is committed. If an exception is thrown by the method, the transaction status is not changed (the client code is free to roll it back on it’s own).</p>
<p>With this explicit transaction management, one can group multiple RDFBeanManager operations and treat them as a single update, as shown in the below example:</p>
<div class="source">
<div class="source"><pre class="prettyprint">RepositoryConnection con = rdfBeanManager.getRepositoryConnection();
// start a transaction
con.begin();
try {
// Add few RDFBean objects
rdfBeanManager.add(object1);
rdfBeanManager.add(object2);
rdfBeanManager.add(object3);
// Commit the above adds at once
con.commit();
}
catch (Throwable t) {
// Something went wrong, we roll the transaction back
con.rollback();
throw t;
}
</pre></div></div></div></div>
</div>
</div>
</div>
<hr/>
<footer>
<div class="container-fluid">
<div class="row-fluid">
<p >Copyright © 2017.
All rights reserved.
</p>
</div>
</div>
</footer>
</body>
</html>