1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db;
14 import java.util.Collection;
17 import org.simantics.databoard.accessor.Accessor;
18 import org.simantics.databoard.binding.Binding;
19 import org.simantics.databoard.binding.mutable.Variant;
20 import org.simantics.databoard.type.Datatype;
21 import org.simantics.databoard.util.binary.RandomAccessBinary;
22 import org.simantics.db.adaption.Adapter;
23 import org.simantics.db.exception.AdaptionException;
24 import org.simantics.db.exception.AssumptionException;
25 import org.simantics.db.exception.BindingException;
26 import org.simantics.db.exception.DatabaseException;
27 import org.simantics.db.exception.DoesNotContainValueException;
28 import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
29 import org.simantics.db.exception.NoInverseException;
30 import org.simantics.db.exception.NoSingleResultException;
31 import org.simantics.db.exception.ResourceNotFoundException;
32 import org.simantics.db.exception.ServiceException;
33 import org.simantics.db.exception.ValidationException;
34 import org.simantics.db.procedure.SyncListener;
35 import org.simantics.db.procedure.SyncMultiListener;
36 import org.simantics.db.procedure.SyncMultiProcedure;
37 import org.simantics.db.procedure.SyncProcedure;
38 import org.simantics.db.procedure.SyncSetListener;
39 import org.simantics.db.request.MultiRead;
40 import org.simantics.db.request.Read;
41 import org.simantics.scl.compiler.types.Type;
45 * For accessing and manipulating the graph data in synchronous manner. A client
46 * receives ReadGraph instances for performing requests in {@link Read} and
47 * {@link MultiRead} as well as for reacting to request results using
48 * {@link SyncProcedure}, {@link SyncListener}, {@link SyncMultiProcedure},
49 * {@link SyncMultiListener} and {@link SyncSetListener}
51 * ReadGraph instances are stateful and may not be stored and used outside the
52 * supplier method activation. The methods receiving ReadGraph should not block
53 * for long periods of time since that may delay the processing of other
54 * requests. For an asynchronous counterpart with the same functionality as
55 * ReadGraph see {@link AsyncReadGraph}
58 * All collections returned by the methods on this interface must not be
59 * modified by clients unless explicitly stated otherwise.
62 * @author Antti Villberg
63 * @see RequestProcessor
64 * @see AsyncRequestProcessor
70 public interface ReadGraph extends AsyncReadGraph, RequestProcessor {
74 * @see AsyncReadGraph#forURI
76 String getURI(Resource resource) throws AssumptionException, ValidationException, ServiceException;
77 String getPossibleURI(Resource resource) throws ValidationException, ServiceException;
80 * Gets a unique resource associated to the given identifier. See <a
81 * href="https://www.simantics.org/wiki/index.php/URI">Simantics Wiki page
82 * on URIs</a> for more details.
84 * @param uri the identifier
85 * @return the resource
86 * @throws ResourceNotFoundException if a resource for the given identifier
88 * @throws ValidationException if a resource could not be produced due to
90 * @throws ServiceException on connection and database failures
91 * @see AsyncReadGraph#forResourceByURI
93 Resource getResource(String uri) throws ResourceNotFoundException, ValidationException, ServiceException;
96 * Gets a unique resource associated to the given identifier. See <a
97 * href="https://www.simantics.org/wiki/index.php/URI">Simantics Wiki page
98 * on URIs</a> for more details.
100 * @param uri the identifier
101 * @return the resource
102 * @throws ResourceNotFoundException if a resource for the given identifier
104 * @throws ValidationException if a resource could not be produced due to
106 * @throws ServiceException on connection and database failures
107 * @see AsyncReadGraph#forResourceByURI
109 Resource getPossibleResource(String uri) throws ResourceNotFoundException, ValidationException, ServiceException;
112 * Gets a builtin resource. For a list of builtin resources see TODO Wiki
114 * @param uri the identifier
115 * @return the resource
116 * @throws ResourceNotFoundException if resouce was not found
117 * @throws ServiceException on connection and database failures
118 * @see AsyncReadGraph#forBuiltin
120 Resource getBuiltin(String id) throws ResourceNotFoundException, ServiceException;
123 * Gets all statements (subject, p, o) such that
124 * {@link ReadGraph#isSubrelationOf(p, relation)} returns true. The result
125 * may include asserted statements for which s does not equal subject. See
126 * the assertion mechanisn TODO for more details. If the relation is
127 * functional the request returns a single statement according to the
128 * functional statement shadowing rules TODO if possible. If an invalid
129 * graph is encountered an exception is thrown.
131 * @param subject a resource
132 * @param relation a resource
133 * @return the statements
134 * @throws ManyObjectsForFunctionalRelationException on invalid graph with
135 * more than one functional object
136 * @throws ServiceException on connection and database failures
137 * @see AsyncReadGraph#forEachStatement
138 * @see AsyncReadGraph#forStatementSet
140 Collection<Statement> getStatements(Resource subject, Resource relation)
141 throws ManyObjectsForFunctionalRelationException, ServiceException;
144 * Gets all statements (s, p, o) asserted by subject such that
145 * {@link ReadGraph#isSubrelationOf(p, relation)} returns true. See the
146 * assertion mechanism TODO for more details. If the relation is functional
147 * the request returns a single statement according to the functional
148 * statement shadowing rules TODO if possible. If an invalid graph is
149 * encountered an exception is thrown.
151 * @param subject a resource
152 * @param relation a resource
153 * @return the statements
154 * @throws ManyObjectsForFunctionalRelationException on invalid graph with
155 * more than one functional object
156 * @throws ServiceException on connection and database failures
157 * @see AsyncReadGraph#forEachAssertedStatement
158 * @see AsyncReadGraph#forAssertedStatementSet
160 Collection<Statement> getAssertedStatements(Resource subject, Resource relation)
161 throws ManyObjectsForFunctionalRelationException, ServiceException;
164 * Gets all predicates p from statements (subject, p, o) such that
165 * {@link ReadGraph#isSubrelationOf(p, relation)} returns true. See the
166 * assertion mechanism TODO for more details. If the relation is functional
167 * the request returns a single statement according to the functional
168 * statement shadowing rules TODO if possible. If an invalid graph is
169 * encountered an exception is thrown.
171 * @param subject a resource
172 * @param relation a resource
173 * @return the predicates
174 * @throws ManyObjectsForFunctionalRelationException on invalid graph with
175 * more than one object
176 * @throws ServiceException on connection and database failures
177 * @see AsyncReadGraph#forEachPredicate
178 * @see AsyncReadGraph#forPredicateSet
180 Collection<Resource> getPredicates(Resource subject) throws ServiceException;
183 * Gets a subset of all types of the subject such that no pair of returned
184 * types inherit each other and all types of the subject are supertypes
185 * of some type in the returned set.
187 * @param subject a resource
188 * @return the principal types
189 * @throws ServiceException on connection and database failures
190 * @see AsyncReadGraph#forEachPrincipalType
191 * @see AsyncReadGraph#forPrincipalTypeSet
193 Collection<Resource> getPrincipalTypes(Resource subject) throws ServiceException;
196 * Gets the full type hierarchy for subject.
198 * @param subject a resource
199 * @return the type hierarchy
200 * @throws ServiceException on connection and database failures
201 * @see AsyncReadGraph#forTypes
203 Set<Resource> getTypes(Resource subject) throws ServiceException;
206 * Gets the full supertype hierarchy for subject.
208 * @param subject a resource
209 * @return the supertype hierarchy
210 * @throws ServiceException on connection and database failures
211 * @see AsyncReadGraph#forSupertypes
213 Set<Resource> getSupertypes(Resource subject) throws ServiceException;
216 * Gets the full superrelation hierarchy for subject.
218 * @param subject a resource
219 * @return the superrelation hierarchy
220 * @throws ServiceException on connection and database failures
221 * @see AsyncReadGraph#forSuperrelations
223 Set<Resource> getSuperrelations(Resource subject) throws ServiceException;
224 Resource getPossibleSuperrelation(Resource subject) throws ServiceException;
227 * Gets all objects o from statements (subject, p, o) such that
228 * {@link ReadGraph#isSubrelationOf(p, relation)} returns true. See the
229 * assertion mechanisn TODO for more details. If the relation is functional
230 * the request returns a single object according to the functional statement
231 * shadowing rules TODO if possible. If an invalid graph is encountered an
232 * exception is thrown.
234 * @param subject a resource
235 * @param relation a resource
236 * @return the objects
237 * @throws ManyObjectsForFunctionalRelationException on invalid graph with
238 * more than one functional object
239 * @throws ServiceException on connection and database failures
240 * @see AsyncReadGraph#forEachObject
241 * @see AsyncReadGraph#forObjectSet
243 Collection<Resource> getObjects(Resource subject, Resource relation)
244 throws ServiceException;
247 * Gets all objects o (s, p, o) asserted by subject such that
248 * {@link ReadGraph#isSubrelationOf(p, relation)} returns true. See the
249 * assertion mechanism TODO for more details. If the relation is functional
250 * the request returns a single object according to the functional statement
251 * shadowing rules TODO if possible. If an invalid graph is encountered an
252 * exception is thrown.
254 * @param subject a resource
255 * @param relation a resource
256 * @return the objects
257 * @throws ManyObjectsForFunctionalRelationException on invalid graph with
258 * more than one functional object
259 * @throws ServiceException on connection and database failures
260 * @see AsyncReadGraph#forEachAssertedStatement
261 * @see AsyncReadGraph#forAssertedStatementSet
263 Collection<Resource> getAssertedObjects(Resource subject, Resource relation)
264 throws ManyObjectsForFunctionalRelationException, ServiceException;
267 * Gets the inverse r of relation such that (relation, InverseOf, r). The
268 * methods assumes an inverse exists.
270 * @param relation a resource
271 * @return the inverse
272 * @throws NoInverseException if inverse was not fond
273 * @throws ManyObjectsForFunctionalRelationException on invalid graph with
274 * more than one functional object
275 * @throws ServiceException on connection and database failures
276 * @see AsyncReadGraph#forInverse
278 Resource getInverse(Resource relation) throws NoInverseException, ManyObjectsForFunctionalRelationException,
282 * Gets a single object as returned by {@link ReadGraph#getObjects}. Assumes
285 * @param subject a resource
286 * @param relation a resource
287 * @return the single object
288 * @throws NoSingleResultException if the amount of valid objects was not
290 * @throws ManyObjectsForFunctionalRelationException on invalid graph with
291 * more than one functional object
292 * @throws ServiceException on connection and database failures
293 * @see AsyncReadGraph#forSingleObject
295 Resource getSingleObject(Resource subject, Resource relation) throws NoSingleResultException,
296 ManyObjectsForFunctionalRelationException, ServiceException;
299 * Gets a single statement as returned by {@link ReadGraph#getStatements}.
300 * Assumes a single statement.
302 * @param subject a resource
303 * @param relation a resource
304 * @return the single statement
305 * @throws NoSingleResultException if the amount of valid statements was not
307 * @throws ManyObjectsForFunctionalRelationException on invalid graph with
308 * more than one functional object
309 * @throws ServiceException on connection and database failures
310 * @see AsyncReadGraph#forSingleStatement
312 Statement getSingleStatement(Resource subject, Resource relation) throws NoSingleResultException,
313 ManyObjectsForFunctionalRelationException, ServiceException;
316 * Gets a single type t as returned by {@link ReadGraph#getPrincipalTypes}. Assumes a single type.
318 * @param subject a resource
319 * @param baseType a resource
320 * @return the single type
321 * @throws NoSingleResultException if the amount of valid types was not one
322 * @throws ServiceException on connection and database failures
323 * @see AsyncReadGraph#forSingleType
325 Resource getSingleType(Resource subject) throws NoSingleResultException, ServiceException;
328 * Gets a single type t as returned by {@link ReadGraph#getTypes} where
329 * {@link ReadGraph#isInheritedFrom(t, baseType)}. Assumes a single type.
331 * @param subject a resource
332 * @param baseType a resource
333 * @return the single type
334 * @throws NoSingleResultException if the amount of valid types was not one
335 * @throws ServiceException on connection and database failures
336 * @see AsyncReadGraph#forSingleType
338 Resource getSingleType(Resource subject, Resource baseType) throws NoSingleResultException, ServiceException;
341 * Gets a value associated to subject. Infers {@link Binding} from type t =
342 * {@link ReadGraph#getSingleType(subject, Value)}
344 * @param subject a resource
346 * @throws DoesNotContainValueException if the subject did not contain a
348 * @throws ServiceException on connection and database failure
349 * @see AsyncReadGraph#forValue
351 <T> T getValue(Resource subject) throws DoesNotContainValueException, ServiceException;
354 * Gets a value associated to subject as a Variant. Infers {@link Binding} from type t =
355 * {@link ReadGraph#getSingleType(subject, Value)}
357 * @param subject a resource
359 * @throws DoesNotContainValueException if the subject did not contain a
361 * @throws ServiceException on connection and database failure
362 * @see AsyncReadGraph#forValue
364 Variant getVariantValue(Resource subject) throws DoesNotContainValueException, ServiceException;
367 * Gets a value associated to subject using the given {@link Binding}.
369 * @param subject a resource
370 * @param binding a binding
372 * @throws DoesNotContainValueException if the subject did not contain a
374 * @throws BindingException if value could not be produced using the given
376 * @throws ServiceException on connection and database failure
377 * @see AsyncReadGraph#forValue
379 <T> T getValue(Resource subject, Binding binding) throws DoesNotContainValueException, BindingException,
383 * Gets a single value associated to o such that (subject, r, o) and
384 * {@link ReadGraph#isSubrelationOf(r, relation)}. Assumes a single value.
385 * Infers {@link Binding} from type t =
386 * {@link ReadGraph#getSingleType(o, Value)}
388 * @param subject a resource
389 * @param relation a resource
391 * @throws NoSingleResultException if the amount of valid values was not one
392 * @throws DoesNotContainValueException if suitable o did not contain a
394 * @throws ServiceException on connection and database failure
395 * @see AsyncReadGraph#forRelatedValue
397 <T> T getRelatedValue(Resource subject, Resource relation) throws NoSingleResultException,
398 DoesNotContainValueException, ServiceException;
401 * Gets a single value associated to o such that (subject, r, o) and
402 * {@link ReadGraph#isSubrelationOf(r, relation)} as a Variant. Assumes a single value.
403 * Infers {@link Binding} from type t =
404 * {@link ReadGraph#getSingleType(o, Value)}
406 * @param subject a resource
407 * @param relation a resource
409 * @throws NoSingleResultException if the amount of valid values was not one
410 * @throws DoesNotContainValueException if suitable o did not contain a
412 * @throws ServiceException on connection and database failure
413 * @see AsyncReadGraph#forRelatedValue
415 Variant getRelatedVariantValue(Resource subject, Resource relation) throws NoSingleResultException,
416 DoesNotContainValueException, ServiceException;
419 * Gets a single value associated to o such that (subject, r, o) and
420 * {@link ReadGraph#isSubrelationOf(r, relation)}. Uses the given
421 * {@link Binding}. Assumes a single value.
423 * @param subject a resource
424 * @param relation a resource
426 * @throws NoSingleResultException if the amount of valid values was not one
427 * @throws DoesNotContainValueException if suitable o did not contain a
429 * @throws BindingException if value could not be produced using the given
431 * @throws ServiceException on connection and database failure
432 * @see AsyncReadGraph#forRelatedValue
434 <T> T getRelatedValue(Resource subject, Resource relation, Binding binding) throws NoSingleResultException,
435 DoesNotContainValueException, BindingException, ServiceException;
438 * Tries to adapt the specified resource into an instance of the specified
439 * class T. No guarantees are made on return values of this method. The
440 * returned values can be cached results of previous invocation or they can
441 * be new result object instances. See {@link #adaptUnique(Resource, Class)}
442 * for alternative behaviour.
444 * @param resource a resource
445 * @param clazz the adapter class
447 * @throws AdaptionException if suitable adapter was not found
448 * @throws ValidationException from the adapter
449 * @throws ServiceException on connection and database failure
450 * @see AsyncReadGraph#forAdapted
451 * @see #adaptUnique(Resource, Class)
453 <T> T adapt(Resource resource, Class<T> clazz) throws AdaptionException, ValidationException, ServiceException;
457 * Same as: adapt(getSingleObject(resource, relation), clazz);
459 * @param resource a resource
460 * @param relation a resource
461 * @param clazz the adapter class
463 * @throws AdaptionException if suitable adapter was not found
464 * @throws ValidationException from the adapter
465 * @throws ServiceException on connection and database failure
466 * @see AsyncReadGraph#forAdapted
467 * @see #adaptUnique(Resource, Class)
469 <T> T adaptRelated(Resource resource, Resource relation, Class<T> clazz) throws AdaptionException, NoSingleResultException, ValidationException, ServiceException;
475 * Resource r = getPossibleObject(resource, relation);
476 * if(r == null) return null;
477 * return getPossibleAdapter(r, clazz);
479 * @param resource a resource
480 * @param relation a resource
481 * @param clazz the adapter class
483 * @throws AdaptionException if suitable adapter was not found
484 * @throws ValidationException from the adapter
485 * @throws ServiceException on connection and database failure
486 * @see AsyncReadGraph#forAdapted
487 * @see #adaptUnique(Resource, Class)
489 <T> T getPossibleRelatedAdapter(Resource resource, Resource relation, Class<T> clazz) throws ValidationException, ServiceException;
491 <T,C> T adaptContextual(Resource resource, C context, Class<C> contextClass, Class<T> clazz) throws AdaptionException, NoSingleResultException, ValidationException, ServiceException;
492 <T,C> T getPossibleContextualAdapter(Resource resource, C context, Class<C> contextClass, Class<T> clazz) throws ValidationException, ServiceException;
495 * Tries to adapt the specified resource into an instance of the specified
496 * class T. The difference to {@link #adapt(Resource, Class)} is that this
497 * method does everything possible to return a new object instance for each
498 * separate invocation.
501 * The only case when this cannot be guaranteed is when the adaption result
502 * comes from an {@link Adapter} implementation which can internally do
503 * anything, like always return the same singleton instance.
506 * @param resource a resource
507 * @param clazz the adapter class
509 * @throws AdaptionException if suitable adapter was not found
510 * @throws ValidationException from the adapter
511 * @throws ServiceException on connection and database failure
512 * @see AsyncReadGraph#forAdapted
513 * @see #adapt(Resource, Class)
515 <T> T adaptUnique(Resource resource, Class<T> clazz) throws AdaptionException, ValidationException,
519 * As {@link #getInverse} but returns null instead of an exception if
520 * inverse was not found.
522 * @param relation a resource
523 * @return the inverse or null
524 * @throws ManyObjectsForFunctionalRelationException on invalid graph with
525 * more than one functional object
526 * @throws ServiceException on connection and database failures
527 * @see AsyncReadGraph#forPossibleInverse
529 Resource getPossibleInverse(Resource relation) throws ManyObjectsForFunctionalRelationException, ServiceException;
532 * As {@link #getSingleObject} but returns null instead of an exception if
533 * object was not found.
535 * @param subject a resource
536 * @param relation a resource
537 * @return the object or null
538 * @throws ManyObjectsForFunctionalRelationException on invalid graph with
539 * more than one functional object
540 * @throws ServiceException on connection and database failures
541 * @see AsyncReadGraph#forPossibleObject
543 Resource getPossibleObject(Resource subject, Resource relation) throws ManyObjectsForFunctionalRelationException,
547 * As {@link #getSingleStatement} but returns null instead of an exception
548 * if statement was not found.
550 * @param subject a resource
551 * @param relation a resource
552 * @return the statement or null
553 * @throws ManyObjectsForFunctionalRelationException on invalid graph with
554 * more than one functional object
555 * @throws ServiceException on connection and database failures
556 * @see AsyncReadGraph#forPossibleStatement
558 Statement getPossibleStatement(Resource subject, Resource relation)
559 throws ManyObjectsForFunctionalRelationException, ServiceException;
562 * As {@link #getSingleType} but returns null instead of an exception if
563 * type was not found.
565 * @param subject a resource
566 * @param baseType a resource
567 * @return the type or null
568 * @throws ServiceException on connection and database failures
569 * @see AsyncReadGraph#forPossibleType
571 Resource getPossibleType(Resource subject, Resource baseType) throws ServiceException;
574 * As {@link #getValue} but returns null instead of an exception if value
577 * @param subject a resource
578 * @return the value or null
579 * @throws ServiceException on connection and database failures
580 * @see AsyncReadGraph#forPossibleValue
582 <T> T getPossibleValue(Resource subject) throws ServiceException;
585 * As {@link #getValue} but returns null instead of an exception if value
588 * @param subject a resource
589 * @param binding a {@link Binding}
590 * @return the value or null
591 * @throws BindingException if value could not be produced using the given
593 * @throws ServiceException on connection and database failures
594 * @see AsyncReadGraph#forPossibleValue
596 <T> T getPossibleValue(Resource subject, Binding binding) throws BindingException, ServiceException;
599 * As {@link #getPossibleRelatedValue} but returns null instead of an
600 * exception if value was not found.
602 * @param subject a resource
603 * @param relation a resource
604 * @return the value or null
605 * @throws ManyObjectsForFunctionalRelationException on invalid graph with
606 * more than one functional object
607 * @throws ServiceException on connection and database failures
608 * @see AsyncReadGraph#forPossibleRelatedValue
610 <T> T getPossibleRelatedValue(Resource subject, Resource relation)
611 throws ManyObjectsForFunctionalRelationException, ServiceException;
614 * As {@link #getPossibleRelatedValue} but returns null instead of an
615 * exception if value was not found.
617 * @param subject a resource
618 * @param relation a resource
619 * @param binding a {@link Binding}
620 * @return the value or null
621 * @throws ManyObjectsForFunctionalRelationException on invalid graph with
622 * more than one functional object
623 * @throws BindingException if value could not be produced using the given
625 * @throws ServiceException on connection and database failures
626 * @see AsyncReadGraph#forPossibleRelatedValue
628 <T> T getPossibleRelatedValue(Resource subject, Resource relation, Binding binding)
629 throws ManyObjectsForFunctionalRelationException, BindingException, ServiceException;
632 * As {@link #adapt} but returns null instead of an exception if adapter was
635 * @param subject a resource
636 * @param clazz a Class
637 * @return the adapter or null
638 * @throws ValidationException when ?
639 * @throws ServiceException on connection and database failures
640 * @see {@link AsyncReadGraph#forPossibleAdapted}
642 <T> T getPossibleAdapter(Resource resource, Class<T> clazz) throws ValidationException, ServiceException;
645 * As {@link #adaptUnique} but returns null instead of an exception if
646 * adapter was not found
648 * @param subject a resource
649 * @param clazz a Class
650 * @return the adapter or null
651 * @throws ValidationException when ?
652 * @throws ServiceException on connection and database failures
653 * @see {@link AsyncReadGraph#forPossibleAdapted}
655 <T> T getPossibleUniqueAdapter(Resource resource, Class<T> clazz) throws ValidationException, ServiceException;
658 * Returns true if type is included in the result of {@link #getTypes(resource)}
660 * @param subject a resource
661 * @param type a resource
662 * @return indicates if resource is an instance of type
663 * @throws ServiceException on connection and database failures
664 * @see {@link AsyncReadGraph#forIsInstanceOf}
666 boolean isInstanceOf(Resource resource, Resource type) throws ServiceException;
669 * Returns true if type equals resource or type is included in the result of
670 * {@link #getSupertypes(resource)}
672 * @param subject a resource
673 * @param type a resource
674 * @return indicates if resource is inherited from type
675 * @throws ServiceException on connection and database failures
676 * @see {@link AsyncReadGraph#forIsInheritedFrom}
678 boolean isInheritedFrom(Resource resource, Resource type) throws ServiceException;
681 * Returns true if relation equals resource or relation is included in the result of
682 * {@link #getSuperrelations(resource)}
684 * @param subject a resource
685 * @param relation a resource
686 * @return indicates if resource is a subrelation of relation
687 * @throws ServiceException on connection and database failures
688 * @see {@link AsyncReadGraph#forIsSubrelationOf}
690 boolean isSubrelationOf(Resource resource, Resource relation) throws ServiceException;
693 * Returns true if the result of {@link #getStatements(subject, IsWeaklyRelatedTo)} is nonempty.
695 * @param subject a resource
696 * @return indicates that subject has statements
697 * @throws ServiceException on connection and database failures
698 * @see {@link AsyncReadGraph#forHasStatement}
700 boolean hasStatement(Resource subject) throws ServiceException;
703 * Returns true if the result of {@link #getStatements(subject, relation)} is nonempty.
705 * @param subject a resource
706 * @param relation a resource
707 * @return indicates that subject has statements with predicates as subrelation of relation
708 * @throws ServiceException on connection and database failures
709 * @see {@link AsyncReadGraph#forHasStatement}
711 boolean hasStatement(Resource subject, Resource relation) throws ServiceException;
714 * Returns true if a statement (subject, relation, object) exists after assertions.
716 * @param subject a resource
717 * @param relation a resource
718 * @param object a resource
719 * @return indicates that the given statement exists
720 * @throws ServiceException on connection and database failures
721 * @see {@link AsyncReadGraph#forHasStatement}
723 boolean hasStatement(Resource subject, Resource relation, Resource object) throws ServiceException;
726 * Returns true if there is a value associated with subject.
727 * IMPLEMENTATION NOTE:
728 * Current implementation fetches the value from server. If the value is
729 * large (i.e. not stored in the cluster) this is highly inefficient.
731 * @param subject a resource
732 * @return indicates that a value exists
733 * @throws ServiceException on connection and database failures
734 * @see {@link AsyncReadGraph#forHasValue}
736 boolean hasValue(Resource subject) throws ServiceException;
739 * Returns the data type of the literal.
742 * @throws DatabaseException
744 Datatype getDataType(Resource subject) throws DatabaseException;
747 * Returns an accessory that can be used to partially read the literal
748 * or write if the graph is WriteGraph. The returned accessory is closed
749 * automatically when the transaction ends. The modifications are written
750 * back to graph at transaction completion.
752 * @param <T> is typed accessory for modifying the literal value.
753 * @param resource is the literal containing the value.
754 * @return interface to partially read and write the literal value.
755 * @throws DatabaseException
757 <T extends Accessor> T getAccessor(Resource resource) throws DatabaseException;
760 * Returns an RandomAccessBinary that can be used to partially read the literal
761 * or write if the graph is WriteGraph. The returned interface is closed
762 * automatically when the transaction ends. The modifications are written
763 * back to graph at transaction completion.
766 * @param resource is the literal containing the value.
767 * @return interface to partially read and write the literal value.
768 * @throws DatabaseException
770 RandomAccessBinary getRandomAccessBinary(Resource resource) throws DatabaseException;
771 // @SuppressWarnings("rawtypes")
772 // Function getValueFunction(Resource resource) throws DatabaseException;
775 * Get the value associated with a graph {@link Resource}, using a possible context object and
776 * a default data type binding. An exception is thrown, if the value is not found.
778 * See {@link #getValue2(Resource, Object, Binding)} for more details.
780 * @param r A graph resource with which the value is associated
781 * @param context A context object that is used for acquiring the value, can be {@code null}
782 * @return The value of the graph node.
783 * @throws DoesNotContainValueException No value is associated with the graph node.
784 * @throws DatabaseException Other errors, such as an error in casting the value to the return type or
785 * a runtime error in the value function.
786 * @see #getValue2(Resource, Object, Binding)
787 * @see #getPossibleValue2(Resource, Object)
789 <T> T getValue2(Resource subject, Object context) throws DatabaseException;
792 * Get the value associated with a graph {@link Resource}, using a possible context object and
793 * a default data type binding as a Variant. An exception is thrown, if the value is not found.
795 * See {@link #getValue2(Resource, Object, Binding)} for more details.
797 * @param r A graph resource with which the value is associated
798 * @param context A context object that is used for acquiring the value, can be {@code null}
799 * @return The value of the graph node.
800 * @throws DoesNotContainValueException No value is associated with the graph node.
801 * @throws DatabaseException Other errors, such as an error in casting the value to the return type or
802 * a runtime error in the value function.
803 * @see #getValue2(Resource, Object, Binding)
804 * @see #getPossibleValue2(Resource, Object)
806 Variant getVariantValue2( Resource r, Object context ) throws DatabaseException;
809 * Get a possible value associated with a graph {@link Resource}, using a possible context object and
810 * a desired value binding. Unlike {@link #getValue2(Resource, Object)}, this methods
811 * returns {@code null} for missing values instead of throwing an exception.
813 * See {@link #getValue2(Resource, Object, Binding)} for more details.
815 * @param r A graph resource with which the value is associated
816 * @param context A context object that is used for acquiring the value, can be {@code null}
817 * @return The value of the graph node.
818 * @throws DatabaseException Usually should not happen. A null value is returned for possible errors.
819 * @see #getValue2(Resource, Object)
820 * @see #getPossibleValue2(Resource, Object, Binding)
822 <T> T getPossibleValue2(Resource subject, Object context) throws DatabaseException;
825 * Get the value associated with a graph {@link Resource}, using a possible context object and
826 * a desired value binding. An exception is thrown, if the value is not found.
828 * The following methods are tried in order to retrieve the value:
830 * <li>If the given resource is a {@code L0.Literal}, the value of the literal is returned, using the binding specified by {@code binding}.</li>
831 * <li>If the resource is a {@code L0.ExternalValue}, the value is acquired using
832 * {@link ReflectionUtils#getValue(String)} with the resource URI.</li>
833 * <li>If the resource is associated with a suitable value converter with relation {@code L0.ConvertsToValueWith}
834 * (see {@link #requestValueFunction(Resource)}), the value function is called with the graph, the resource
835 * and the context object.</li>
838 * @param r A graph resource with which the value is associated
839 * @param context A context object that is used for acquiring the value, can be {@code null}
840 * @param binding A binding for the value type
841 * @return The value of the graph node.
842 * @throws DoesNotContainValueException No value is associated with the graph node.
843 * @throws DatabaseException Other errors, such as an error in casting the value to the return type or
844 * a runtime error in the value function.
845 * @see #getValue2(Resource, Object)
846 * @see #getPossibleValue2(Resource, Object, Binding)
848 <T> T getValue2(Resource subject, Object context, Binding binding) throws DatabaseException;
851 * Get a possible value associated with a graph {@link Resource}, using a possible context object and
852 * a desired value binding. Unlike {@link #getValue2(Resource, Object, Binding)}, this methods
853 * returns {@code null} for missing values instead of throwing an exception.
855 * See {@link #getValue2(Resource, Object, Binding)} for more details.
857 * @param r A graph resource with which the value is associated
858 * @param context A context object that is used for acquiring the value, can be {@code null}
859 * @param binding A binding for the value type
860 * @return The value of the graph node.
861 * @throws DatabaseException Usually should not happen. A null value is returned for possible errors.
862 * @see #getValue2(Resource, Object, Bindinge)
863 * @see #getPossibleValue2(Resource, Object)
865 <T> T getPossibleValue2(Resource subject, Object context, Binding binding) throws DatabaseException;
868 * Get the single value associated with a graph resource related with a given subject.
869 * An exception is thrown, if a unique object resource or a value for it is not found.
871 * See {@link #getValue2(Resource, Object, Binding)} for more details.
873 * @param subject A graph resource that indicates the subject node
874 * @param relation A graph resource that indicates the predicate of a relation
875 * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
876 * @throws NoSingleResultException The number of suitable object resources is not equal to 1 (zero or greater than one)
877 * @throws DoesNotContainValueException No value is associated with the graph node.
878 * @throws DatabaseException Other errors, such as an error in casting the value to the return type or
879 * a runtime error in the value function.
880 * @see #getRelatedValue2(Resource, Resource, Binding)
881 * @see #getRelatedValue2(Resource, Resource, Object)
882 * @see #getRelatedValue2(Resource, Resource, Object, Binding)
883 * @see #getPossibleRelatedValue2(Resource, Resource)
885 <T> T getRelatedValue2(Resource subject, Resource relation) throws DatabaseException;
888 * Get a possible single value associated with a graph resource related with a given subject.
889 * A {@code null} value is returned for missing values or other errors.
891 * See {@link #getValue2(Resource, Object, Binding)} for more details.
893 * @param subject A graph resource that indicates the subject node
894 * @param relation A graph resource that indicates the predicate of a relation
895 * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
896 * @throws DatabaseException Usually should not happen. A {@code null} value is returned for possible errors.
897 * @see #getPossibleRelatedValue2(Resource, Resource, Binding)
898 * @see #getPossibleRelatedValue2(Resource, Resource, Object)
899 * @see #getPossibleRelatedValue2(Resource, Resource, Object, Binding)
900 * @see #getRelatedValue2(Resource, Resource)
902 <T> T getPossibleRelatedValue2(Resource subject, Resource relation) throws DatabaseException;
905 * Get a possible single value associated with a graph resource related with a given subject.
906 * A {@code null} value is returned for missing values or other errors.
908 * See {@link #getValue2(Resource, Object, Binding)} for more details.
910 * @param subject A graph resource that indicates the subject node
911 * @param relation A graph resource that indicates the predicate of a relation
912 * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
913 * @throws DatabaseException Usually should not happen. A {@code null} value is returned for possible errors.
914 * @see #getPossibleRelatedValue2(Resource, Resource, Binding)
915 * @see #getPossibleRelatedValue2(Resource, Resource, Object)
916 * @see #getPossibleRelatedValue2(Resource, Resource, Object, Binding)
917 * @see #getRelatedValue2(Resource, Resource)
919 Variant getRelatedVariantValue2( Resource subject, Resource relation ) throws DatabaseException;
922 * Get the single value associated with a graph resource related with a given subject, a possible context object.
923 * An exception is thrown, if a unique object resource or a value for it is not found.
925 * See {@link #getValue2(Resource, Object, Binding)} for more details.
927 * @param subject A graph resource that indicates the subject node
928 * @param relation A graph resource that indicates the predicate of a relation
929 * @param context A context object that is used for acquiring the value, can be {@code null}
930 * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
931 * @throws NoSingleResultException The number of suitable object resources is not equal to 1 (zero or greater than one)
932 * @throws DoesNotContainValueException No value is associated with the graph node.
933 * @throws DatabaseException Other errors, such as an error in casting the value to the return type or
934 * a runtime error in the value function.
935 * @see #getRelatedValue2(Resource, Resource)
936 * @see #getRelatedValue2(Resource, Resource, Binding)
937 * @see #getRelatedValue2(Resource, Resource, Object, Binding)
938 * @see #getPossibleRelatedValue2(Resource, Resource, Object)
940 <T> T getRelatedValue2(Resource subject, Resource relation, Object context) throws DatabaseException;
943 * Get the single value associated with a graph resource related with a given subject, a possible context object.
944 * An exception is thrown, if a unique object resource or a value for it is not found.
946 * See {@link #getValue2(Resource, Object, Binding)} for more details.
948 * @param subject A graph resource that indicates the subject node
949 * @param relation A graph resource that indicates the predicate of a relation
950 * @param context A context object that is used for acquiring the value, can be {@code null}
951 * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
952 * @throws NoSingleResultException The number of suitable object resources is not equal to 1 (zero or greater than one)
953 * @throws DoesNotContainValueException No value is associated with the graph node.
954 * @throws DatabaseException Other errors, such as an error in casting the value to the return type or
955 * a runtime error in the value function.
956 * @see #getRelatedValue2(Resource, Resource, Object)
957 * @see #getPossibleRelatedValue2(Resource, Resource, Object)
959 Variant getRelatedVariantValue2( Resource subject, Resource relation, Object context ) throws DatabaseException;
962 * Get a possible single value associated with a graph resource related with a given subject and a possible context object.
963 * A {@code null} value is returned for missing values or other errors.
965 * See {@link #getValue2(Resource, Object, Binding)} for more details.
967 * @param subject A graph resource that indicates the subject node
968 * @param relation A graph resource that indicates the predicate of a relation
969 * @param context A context object that is used for acquiring the value, can be {@code null}
970 * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
971 * @throws DatabaseException Usually should not happen. A {@code null} value is returned for possible errors.
972 * @see #getPossibleRelatedValue2(Resource, Resource)
973 * @see #getPossibleRelatedValue2(Resource, Resource, Binding)
974 * @see #getPossibleRelatedValue2(Resource, Resource, Object, Binding)
975 * @see #getRelatedValue2(Resource, Resource, Object)
977 <T> T getPossibleRelatedValue2(Resource subject, Resource relation, Object context) throws DatabaseException;
980 * Get the single value associated with a graph resource related with a given subject and
981 * a desired value binding. An exception is thrown, if a unique object resource or a value for it is not found.
983 * See {@link #getValue2(Resource, Object, Binding)} for more details.
985 * @param subject A graph resource that indicates the subject node
986 * @param relation A graph resource that indicates the predicate of a relation
987 * @param binding A binding for the value type
988 * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
989 * @throws NoSingleResultException The number of suitable object resources is not equal to 1 (zero or greater than one)
990 * @throws DoesNotContainValueException No value is associated with the graph node.
991 * @throws DatabaseException Other errors, such as an error in casting the value to the return type or
992 * a runtime error in the value function.
993 * @see #getRelatedValue2(Resource, Resource)
994 * @see #getRelatedValue2(Resource, Resource, Object)
995 * @see #getRelatedValue2(Resource, Resource, Object, Binding)
996 * @see #getPossibleRelatedValue2(Resource, Resource, Binding)
998 <T> T getRelatedValue2(Resource subject, Resource relation, Binding binding) throws DatabaseException;
1001 * Get a possible single value associated with a graph resource related with a given subject and
1002 * a desired value binding. A {@code null} value is returned for missing values or other errors.
1004 * See {@link #getValue2(Resource, Object, Binding)} for more details.
1006 * @param subject A graph resource that indicates the subject node
1007 * @param relation A graph resource that indicates the predicate of a relation
1008 * @param binding A binding for the value type
1009 * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
1010 * @throws DatabaseException Usually should not happen. A {@code null} value is returned for possible errors.
1011 * @see #getPossibleRelatedValue2(Resource, Resource)
1012 * @see #getPossibleRelatedValue2(Resource, Resource, Object)
1013 * @see #getPossibleRelatedValue2(Resource, Resource, Object, Binding)
1014 * @see #getRelatedValue2(Resource, Resource, Binding)
1016 <T> T getPossibleRelatedValue2(Resource subject, Resource relation, Binding binding) throws DatabaseException;
1019 * Get the single value associated with a graph resource related with a given subject, a possible context object and
1020 * a desired value binding. An exception is thrown, if a unique object resource or a value for it is not found.
1022 * See {@link #getValue2(Resource, Object, Binding)} for more details.
1024 * @param subject A graph resource that indicates the subject node
1025 * @param relation A graph resource that indicates the predicate of a relation
1026 * @param context A context object that is used for acquiring the value, can be {@code null}
1027 * @param binding A binding for the value type
1028 * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
1029 * @throws NoSingleResultException The number of suitable object resources is not equal to 1 (zero or greater than one)
1030 * @throws DoesNotContainValueException No value is associated with the graph node.
1031 * @throws DatabaseException Other errors, such as an error in casting the value to the return type or
1032 * a runtime error in the value function.
1033 * @see #getRelatedValue2(Resource, Resource)
1034 * @see #getRelatedValue2(Resource, Resource, Binding)
1035 * @see #getRelatedValue2(Resource, Resource, Object)
1036 * @see #getPossibleRelatedValue2(Resource, Resource, Object, Binding)
1038 <T> T getRelatedValue2(Resource subject, Resource relation, Object context, Binding binding) throws DatabaseException;
1041 * Get a possible single value associated with a graph resource related with a given subject, a possible context object and
1042 * a desired value binding. A {@code null} value is returned for missing values or other errors.
1044 * See {@link #getValue2(Resource, Object, Binding)} for more details.
1046 * @param subject A graph resource that indicates the subject node
1047 * @param relation A graph resource that indicates the predicate of a relation
1048 * @param context A context object that is used for acquiring the value, can be {@code null}
1049 * @param binding A binding for the value type
1050 * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
1051 * @throws DatabaseException Usually should not happen. A {@code null} value is returned for possible errors.
1052 * @see #getPossibleRelatedValue2(Resource, Resource)
1053 * @see #getPossibleRelatedValue2(Resource, Resource, Binding)
1054 * @see #getPossibleRelatedValue2(Resource, Resource, Object)
1055 * @see #getRelatedValue2(Resource, Resource, Object, Binding)
1057 <T> T getPossibleRelatedValue2(Resource subject, Resource relation, Object context, Binding binding) throws DatabaseException;
1060 * Get the parsed SCL type declaration from the string value of a graph resource that is the unique object of a
1061 * given subject and predicate.
1063 * See {@link #getValue2(Resource, Object, Binding)} for more details.
1065 * @param subject A resource that indicates the subject of a statement
1066 * @param relation A resource that indicates the predicate of the statement
1067 * @return A compiled SCL type definition of the string value of a unique object resource
1068 * @throws DatabaseException For any errors in locating a unique value or compiling it as an SCL type statement
1070 Type getRelatedValueType(Resource subject, Resource relation) throws DatabaseException;
1072 boolean setSynchronous(boolean value);
1073 boolean getSynchronous();