-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.db;\r
-\r
-import java.util.Collection;\r
-import java.util.Set;\r
-\r
-import org.simantics.databoard.accessor.Accessor;\r
-import org.simantics.databoard.binding.Binding;\r
-import org.simantics.databoard.binding.mutable.Variant;\r
-import org.simantics.databoard.type.Datatype;\r
-import org.simantics.databoard.util.binary.RandomAccessBinary;\r
-import org.simantics.db.adaption.Adapter;\r
-import org.simantics.db.exception.AdaptionException;\r
-import org.simantics.db.exception.AssumptionException;\r
-import org.simantics.db.exception.BindingException;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.exception.DoesNotContainValueException;\r
-import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
-import org.simantics.db.exception.NoInverseException;\r
-import org.simantics.db.exception.NoSingleResultException;\r
-import org.simantics.db.exception.ResourceNotFoundException;\r
-import org.simantics.db.exception.ServiceException;\r
-import org.simantics.db.exception.ValidationException;\r
-import org.simantics.db.procedure.SyncListener;\r
-import org.simantics.db.procedure.SyncMultiListener;\r
-import org.simantics.db.procedure.SyncMultiProcedure;\r
-import org.simantics.db.procedure.SyncProcedure;\r
-import org.simantics.db.procedure.SyncSetListener;\r
-import org.simantics.db.request.MultiRead;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.scl.compiler.types.Type;\r
-\r
-/**\r
- * \r
- * For accessing and manipulating the graph data in synchronous manner. A client\r
- * receives ReadGraph instances for performing requests in {@link Read} and\r
- * {@link MultiRead} as well as for reacting to request results using\r
- * {@link SyncProcedure}, {@link SyncListener}, {@link SyncMultiProcedure},\r
- * {@link SyncMultiListener} and {@link SyncSetListener}\r
- * <p>\r
- * ReadGraph instances are stateful and may not be stored and used outside the\r
- * supplier method activation. The methods receiving ReadGraph should not block\r
- * for long periods of time since that may delay the processing of other\r
- * requests. For an asynchronous counterpart with the same functionality as\r
- * ReadGraph see {@link AsyncReadGraph}\r
- * \r
- * <p>\r
- * All collections returned by the methods on this interface must not be\r
- * modified by clients unless explicitly stated otherwise.\r
- * \r
- * @version 0.7\r
- * @author Antti Villberg\r
- * @see RequestProcessor\r
- * @see AsyncRequestProcessor\r
- * @see AsyncReadGraph\r
- * @see Resource\r
- * @see Statement\r
- * @noimplement\r
- */\r
-public interface ReadGraph extends AsyncReadGraph, RequestProcessor {\r
-\r
- /**\r
- * \r
- * @see AsyncReadGraph#forURI\r
- */\r
- String getURI(Resource resource) throws AssumptionException, ValidationException, ServiceException;\r
- String getPossibleURI(Resource resource) throws ValidationException, ServiceException;\r
-\r
- /**\r
- * Gets a unique resource associated to the given identifier. See <a\r
- * href="https://www.simantics.org/wiki/index.php/URI">Simantics Wiki page\r
- * on URIs</a> for more details.\r
- * \r
- * @param uri the identifier\r
- * @return the resource\r
- * @throws ResourceNotFoundException if a resource for the given identifier\r
- * was not specified\r
- * @throws ValidationException if a resource could not be produced due to\r
- * invalid semantics\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forResourceByURI\r
- */\r
- Resource getResource(String uri) throws ResourceNotFoundException, ValidationException, ServiceException;\r
-\r
- /**\r
- * Gets a unique resource associated to the given identifier. See <a\r
- * href="https://www.simantics.org/wiki/index.php/URI">Simantics Wiki page\r
- * on URIs</a> for more details.\r
- * \r
- * @param uri the identifier\r
- * @return the resource\r
- * @throws ResourceNotFoundException if a resource for the given identifier\r
- * was not specified\r
- * @throws ValidationException if a resource could not be produced due to\r
- * invalid semantics\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forResourceByURI\r
- */\r
- Resource getPossibleResource(String uri) throws ResourceNotFoundException, ValidationException, ServiceException;\r
-\r
- /**\r
- * Gets a builtin resource. For a list of builtin resources see TODO Wiki\r
- * \r
- * @param uri the identifier\r
- * @return the resource\r
- * @throws ResourceNotFoundException if resouce was not found\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forBuiltin\r
- */\r
- Resource getBuiltin(String id) throws ResourceNotFoundException, ServiceException;\r
-\r
- /**\r
- * Gets all statements (subject, p, o) such that\r
- * {@link ReadGraph#isSubrelationOf(p, relation)} returns true. The result\r
- * may include asserted statements for which s does not equal subject. See\r
- * the assertion mechanisn TODO for more details. If the relation is\r
- * functional the request returns a single statement according to the\r
- * functional statement shadowing rules TODO if possible. If an invalid\r
- * graph is encountered an exception is thrown.\r
- * \r
- * @param subject a resource\r
- * @param relation a resource\r
- * @return the statements\r
- * @throws ManyObjectsForFunctionalRelationException on invalid graph with\r
- * more than one functional object\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forEachStatement\r
- * @see AsyncReadGraph#forStatementSet\r
- */\r
- Collection<Statement> getStatements(Resource subject, Resource relation)\r
- throws ManyObjectsForFunctionalRelationException, ServiceException;\r
-\r
- /**\r
- * Gets all statements (s, p, o) asserted by subject such that\r
- * {@link ReadGraph#isSubrelationOf(p, relation)} returns true. See the\r
- * assertion mechanism TODO for more details. If the relation is functional\r
- * the request returns a single statement according to the functional\r
- * statement shadowing rules TODO if possible. If an invalid graph is\r
- * encountered an exception is thrown.\r
- * \r
- * @param subject a resource\r
- * @param relation a resource\r
- * @return the statements\r
- * @throws ManyObjectsForFunctionalRelationException on invalid graph with\r
- * more than one functional object\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forEachAssertedStatement\r
- * @see AsyncReadGraph#forAssertedStatementSet\r
- */\r
- Collection<Statement> getAssertedStatements(Resource subject, Resource relation)\r
- throws ManyObjectsForFunctionalRelationException, ServiceException;\r
-\r
- /**\r
- * Gets all predicates p from statements (subject, p, o) such that\r
- * {@link ReadGraph#isSubrelationOf(p, relation)} returns true. See the\r
- * assertion mechanism TODO for more details. If the relation is functional\r
- * the request returns a single statement according to the functional\r
- * statement shadowing rules TODO if possible. If an invalid graph is\r
- * encountered an exception is thrown.\r
- * \r
- * @param subject a resource\r
- * @param relation a resource\r
- * @return the predicates\r
- * @throws ManyObjectsForFunctionalRelationException on invalid graph with\r
- * more than one object\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forEachPredicate\r
- * @see AsyncReadGraph#forPredicateSet\r
- */\r
- Collection<Resource> getPredicates(Resource subject) throws ServiceException;\r
-\r
- /**\r
- * Gets a subset of all types of the subject such that no pair of returned\r
- * types inherit each other and all types of the subject are supertypes\r
- * of some type in the returned set.\r
- * \r
- * @param subject a resource\r
- * @return the principal types\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forEachPrincipalType\r
- * @see AsyncReadGraph#forPrincipalTypeSet\r
- */\r
- Collection<Resource> getPrincipalTypes(Resource subject) throws ServiceException;\r
-\r
- /**\r
- * Gets the full type hierarchy for subject.\r
- * \r
- * @param subject a resource\r
- * @return the type hierarchy\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forTypes\r
- */\r
- Set<Resource> getTypes(Resource subject) throws ServiceException;\r
-\r
- /**\r
- * Gets the full supertype hierarchy for subject.\r
- * \r
- * @param subject a resource\r
- * @return the supertype hierarchy\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forSupertypes\r
- */\r
- Set<Resource> getSupertypes(Resource subject) throws ServiceException;\r
-\r
- /**\r
- * Gets the full superrelation hierarchy for subject.\r
- * \r
- * @param subject a resource\r
- * @return the superrelation hierarchy\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forSuperrelations\r
- */\r
- Set<Resource> getSuperrelations(Resource subject) throws ServiceException;\r
- Resource getPossibleSuperrelation(Resource subject) throws ServiceException;\r
-\r
- /**\r
- * Gets all objects o from statements (subject, p, o) such that\r
- * {@link ReadGraph#isSubrelationOf(p, relation)} returns true. See the\r
- * assertion mechanisn TODO for more details. If the relation is functional\r
- * the request returns a single object according to the functional statement\r
- * shadowing rules TODO if possible. If an invalid graph is encountered an\r
- * exception is thrown.\r
- * \r
- * @param subject a resource\r
- * @param relation a resource\r
- * @return the objects\r
- * @throws ManyObjectsForFunctionalRelationException on invalid graph with\r
- * more than one functional object\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forEachObject\r
- * @see AsyncReadGraph#forObjectSet\r
- */\r
- Collection<Resource> getObjects(Resource subject, Resource relation)\r
- throws ServiceException;\r
-\r
- /**\r
- * Gets all objects o (s, p, o) asserted by subject such that\r
- * {@link ReadGraph#isSubrelationOf(p, relation)} returns true. See the\r
- * assertion mechanism TODO for more details. If the relation is functional\r
- * the request returns a single object according to the functional statement\r
- * shadowing rules TODO if possible. If an invalid graph is encountered an\r
- * exception is thrown.\r
- * \r
- * @param subject a resource\r
- * @param relation a resource\r
- * @return the objects\r
- * @throws ManyObjectsForFunctionalRelationException on invalid graph with\r
- * more than one functional object\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forEachAssertedStatement\r
- * @see AsyncReadGraph#forAssertedStatementSet\r
- */\r
- Collection<Resource> getAssertedObjects(Resource subject, Resource relation)\r
- throws ManyObjectsForFunctionalRelationException, ServiceException;\r
-\r
- /**\r
- * Gets the inverse r of relation such that (relation, InverseOf, r). The\r
- * methods assumes an inverse exists.\r
- * \r
- * @param relation a resource\r
- * @return the inverse\r
- * @throws NoInverseException if inverse was not fond\r
- * @throws ManyObjectsForFunctionalRelationException on invalid graph with\r
- * more than one functional object\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forInverse\r
- */\r
- Resource getInverse(Resource relation) throws NoInverseException, ManyObjectsForFunctionalRelationException,\r
- ServiceException;\r
-\r
- /**\r
- * Gets a single object as returned by {@link ReadGraph#getObjects}. Assumes\r
- * a single object.\r
- * \r
- * @param subject a resource\r
- * @param relation a resource\r
- * @return the single object\r
- * @throws NoSingleResultException if the amount of valid objects was not\r
- * one\r
- * @throws ManyObjectsForFunctionalRelationException on invalid graph with\r
- * more than one functional object\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forSingleObject\r
- */\r
- Resource getSingleObject(Resource subject, Resource relation) throws NoSingleResultException,\r
- ManyObjectsForFunctionalRelationException, ServiceException;\r
-\r
- /**\r
- * Gets a single statement as returned by {@link ReadGraph#getStatements}.\r
- * Assumes a single statement.\r
- * \r
- * @param subject a resource\r
- * @param relation a resource\r
- * @return the single statement\r
- * @throws NoSingleResultException if the amount of valid statements was not\r
- * one\r
- * @throws ManyObjectsForFunctionalRelationException on invalid graph with\r
- * more than one functional object\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forSingleStatement\r
- */\r
- Statement getSingleStatement(Resource subject, Resource relation) throws NoSingleResultException,\r
- ManyObjectsForFunctionalRelationException, ServiceException;\r
-\r
- /**\r
- * Gets a single type t as returned by {@link ReadGraph#getPrincipalTypes}. Assumes a single type.\r
- * \r
- * @param subject a resource\r
- * @param baseType a resource\r
- * @return the single type\r
- * @throws NoSingleResultException if the amount of valid types was not one\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forSingleType\r
- */\r
- Resource getSingleType(Resource subject) throws NoSingleResultException, ServiceException;\r
-\r
- /**\r
- * Gets a single type t as returned by {@link ReadGraph#getTypes} where\r
- * {@link ReadGraph#isInheritedFrom(t, baseType)}. Assumes a single type.\r
- * \r
- * @param subject a resource\r
- * @param baseType a resource\r
- * @return the single type\r
- * @throws NoSingleResultException if the amount of valid types was not one\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forSingleType\r
- */\r
- Resource getSingleType(Resource subject, Resource baseType) throws NoSingleResultException, ServiceException;\r
-\r
- /**\r
- * Gets a value associated to subject. Infers {@link Binding} from type t =\r
- * {@link ReadGraph#getSingleType(subject, Value)}\r
- * \r
- * @param subject a resource\r
- * @return the value\r
- * @throws DoesNotContainValueException if the subject did not contain a\r
- * resource\r
- * @throws ServiceException on connection and database failure\r
- * @see AsyncReadGraph#forValue\r
- */\r
- <T> T getValue(Resource subject) throws DoesNotContainValueException, ServiceException;\r
-\r
- /**\r
- * Gets a value associated to subject as a Variant. Infers {@link Binding} from type t =\r
- * {@link ReadGraph#getSingleType(subject, Value)}\r
- * \r
- * @param subject a resource\r
- * @return the value\r
- * @throws DoesNotContainValueException if the subject did not contain a\r
- * resource\r
- * @throws ServiceException on connection and database failure\r
- * @see AsyncReadGraph#forValue\r
- */\r
- Variant getVariantValue(Resource subject) throws DoesNotContainValueException, ServiceException;\r
- \r
- /**\r
- * Gets a value associated to subject using the given {@link Binding}.\r
- * \r
- * @param subject a resource\r
- * @param binding a binding\r
- * @return the value\r
- * @throws DoesNotContainValueException if the subject did not contain a\r
- * resource\r
- * @throws BindingException if value could not be produced using the given\r
- * {@link Binding}\r
- * @throws ServiceException on connection and database failure\r
- * @see AsyncReadGraph#forValue\r
- */\r
- <T> T getValue(Resource subject, Binding binding) throws DoesNotContainValueException, BindingException,\r
- ServiceException;\r
-\r
- /**\r
- * Gets a single value associated to o such that (subject, r, o) and\r
- * {@link ReadGraph#isSubrelationOf(r, relation)}. Assumes a single value.\r
- * Infers {@link Binding} from type t =\r
- * {@link ReadGraph#getSingleType(o, Value)}\r
- * \r
- * @param subject a resource\r
- * @param relation a resource\r
- * @return the value\r
- * @throws NoSingleResultException if the amount of valid values was not one\r
- * @throws DoesNotContainValueException if suitable o did not contain a\r
- * resource\r
- * @throws ServiceException on connection and database failure\r
- * @see AsyncReadGraph#forRelatedValue\r
- */\r
- <T> T getRelatedValue(Resource subject, Resource relation) throws NoSingleResultException,\r
- DoesNotContainValueException, ServiceException;\r
-\r
- /**\r
- * Gets a single value associated to o such that (subject, r, o) and\r
- * {@link ReadGraph#isSubrelationOf(r, relation)} as a Variant. Assumes a single value.\r
- * Infers {@link Binding} from type t =\r
- * {@link ReadGraph#getSingleType(o, Value)}\r
- * \r
- * @param subject a resource\r
- * @param relation a resource\r
- * @return the value\r
- * @throws NoSingleResultException if the amount of valid values was not one\r
- * @throws DoesNotContainValueException if suitable o did not contain a\r
- * resource\r
- * @throws ServiceException on connection and database failure\r
- * @see AsyncReadGraph#forRelatedValue\r
- */\r
- Variant getRelatedVariantValue(Resource subject, Resource relation) throws NoSingleResultException,\r
- DoesNotContainValueException, ServiceException; \r
-\r
- /**\r
- * Gets a single value associated to o such that (subject, r, o) and\r
- * {@link ReadGraph#isSubrelationOf(r, relation)}. Uses the given\r
- * {@link Binding}. Assumes a single value.\r
- * \r
- * @param subject a resource\r
- * @param relation a resource\r
- * @return the value\r
- * @throws NoSingleResultException if the amount of valid values was not one\r
- * @throws DoesNotContainValueException if suitable o did not contain a\r
- * resource\r
- * @throws BindingException if value could not be produced using the given\r
- * {@link Binding}\r
- * @throws ServiceException on connection and database failure\r
- * @see AsyncReadGraph#forRelatedValue\r
- */\r
- <T> T getRelatedValue(Resource subject, Resource relation, Binding binding) throws NoSingleResultException,\r
- DoesNotContainValueException, BindingException, ServiceException;\r
-\r
- /**\r
- * Tries to adapt the specified resource into an instance of the specified\r
- * class T. No guarantees are made on return values of this method. The\r
- * returned values can be cached results of previous invocation or they can\r
- * be new result object instances. See {@link #adaptUnique(Resource, Class)}\r
- * for alternative behaviour.\r
- * \r
- * @param resource a resource\r
- * @param clazz the adapter class\r
- * @return\r
- * @throws AdaptionException if suitable adapter was not found\r
- * @throws ValidationException from the adapter\r
- * @throws ServiceException on connection and database failure\r
- * @see AsyncReadGraph#forAdapted\r
- * @see #adaptUnique(Resource, Class)\r
- */\r
- <T> T adapt(Resource resource, Class<T> clazz) throws AdaptionException, ValidationException, ServiceException;\r
-\r
- /**\r
- * \r
- * Same as: adapt(getSingleObject(resource, relation), clazz);\r
- * \r
- * @param resource a resource\r
- * @param relation a resource\r
- * @param clazz the adapter class\r
- * @return\r
- * @throws AdaptionException if suitable adapter was not found\r
- * @throws ValidationException from the adapter\r
- * @throws ServiceException on connection and database failure\r
- * @see AsyncReadGraph#forAdapted\r
- * @see #adaptUnique(Resource, Class)\r
- */\r
- <T> T adaptRelated(Resource resource, Resource relation, Class<T> clazz) throws AdaptionException, NoSingleResultException, ValidationException, ServiceException;\r
-\r
- /**\r
- * \r
- * Same as:\r
- * \r
- * Resource r = getPossibleObject(resource, relation);\r
- * if(r == null) return null;\r
- * return getPossibleAdapter(r, clazz);\r
- * \r
- * @param resource a resource\r
- * @param relation a resource\r
- * @param clazz the adapter class\r
- * @return\r
- * @throws AdaptionException if suitable adapter was not found\r
- * @throws ValidationException from the adapter\r
- * @throws ServiceException on connection and database failure\r
- * @see AsyncReadGraph#forAdapted\r
- * @see #adaptUnique(Resource, Class)\r
- */\r
- <T> T getPossibleRelatedAdapter(Resource resource, Resource relation, Class<T> clazz) throws ValidationException, ServiceException;\r
-\r
- <T,C> T adaptContextual(Resource resource, C context, Class<C> contextClass, Class<T> clazz) throws AdaptionException, NoSingleResultException, ValidationException, ServiceException;\r
- <T,C> T getPossibleContextualAdapter(Resource resource, C context, Class<C> contextClass, Class<T> clazz) throws ValidationException, ServiceException;\r
- \r
- /**\r
- * Tries to adapt the specified resource into an instance of the specified\r
- * class T. The difference to {@link #adapt(Resource, Class)} is that this\r
- * method does everything possible to return a new object instance for each\r
- * separate invocation.\r
- * \r
- * <p>\r
- * The only case when this cannot be guaranteed is when the adaption result\r
- * comes from an {@link Adapter} implementation which can internally do\r
- * anything, like always return the same singleton instance.\r
- * </p>\r
- * \r
- * @param resource a resource\r
- * @param clazz the adapter class\r
- * @return\r
- * @throws AdaptionException if suitable adapter was not found\r
- * @throws ValidationException from the adapter\r
- * @throws ServiceException on connection and database failure\r
- * @see AsyncReadGraph#forAdapted\r
- * @see #adapt(Resource, Class)\r
- */\r
- <T> T adaptUnique(Resource resource, Class<T> clazz) throws AdaptionException, ValidationException,\r
- ServiceException;\r
-\r
- /**\r
- * As {@link #getInverse} but returns null instead of an exception if\r
- * inverse was not found.\r
- * \r
- * @param relation a resource\r
- * @return the inverse or null\r
- * @throws ManyObjectsForFunctionalRelationException on invalid graph with\r
- * more than one functional object\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forPossibleInverse\r
- */\r
- Resource getPossibleInverse(Resource relation) throws ManyObjectsForFunctionalRelationException, ServiceException;\r
-\r
- /**\r
- * As {@link #getSingleObject} but returns null instead of an exception if\r
- * object was not found.\r
- * \r
- * @param subject a resource\r
- * @param relation a resource\r
- * @return the object or null\r
- * @throws ManyObjectsForFunctionalRelationException on invalid graph with\r
- * more than one functional object\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forPossibleObject\r
- */\r
- Resource getPossibleObject(Resource subject, Resource relation) throws ManyObjectsForFunctionalRelationException,\r
- ServiceException;\r
-\r
- /**\r
- * As {@link #getSingleStatement} but returns null instead of an exception\r
- * if statement was not found.\r
- * \r
- * @param subject a resource\r
- * @param relation a resource\r
- * @return the statement or null\r
- * @throws ManyObjectsForFunctionalRelationException on invalid graph with\r
- * more than one functional object\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forPossibleStatement\r
- */\r
- Statement getPossibleStatement(Resource subject, Resource relation)\r
- throws ManyObjectsForFunctionalRelationException, ServiceException;\r
-\r
- /**\r
- * As {@link #getSingleType} but returns null instead of an exception if\r
- * type was not found.\r
- * \r
- * @param subject a resource\r
- * @param baseType a resource\r
- * @return the type or null\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forPossibleType\r
- */\r
- Resource getPossibleType(Resource subject, Resource baseType) throws ServiceException;\r
-\r
- /**\r
- * As {@link #getValue} but returns null instead of an exception if value\r
- * was not found.\r
- * \r
- * @param subject a resource\r
- * @return the value or null\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forPossibleValue\r
- */\r
- <T> T getPossibleValue(Resource subject) throws ServiceException;\r
-\r
- /**\r
- * As {@link #getValue} but returns null instead of an exception if value\r
- * was not found.\r
- * \r
- * @param subject a resource\r
- * @param binding a {@link Binding}\r
- * @return the value or null\r
- * @throws BindingException if value could not be produced using the given\r
- * {@link Binding}\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forPossibleValue\r
- */\r
- <T> T getPossibleValue(Resource subject, Binding binding) throws BindingException, ServiceException;\r
-\r
- /**\r
- * As {@link #getPossibleRelatedValue} but returns null instead of an\r
- * exception if value was not found.\r
- * \r
- * @param subject a resource\r
- * @param relation a resource\r
- * @return the value or null\r
- * @throws ManyObjectsForFunctionalRelationException on invalid graph with\r
- * more than one functional object\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forPossibleRelatedValue\r
- */\r
- <T> T getPossibleRelatedValue(Resource subject, Resource relation)\r
- throws ManyObjectsForFunctionalRelationException, ServiceException;\r
-\r
- /**\r
- * As {@link #getPossibleRelatedValue} but returns null instead of an\r
- * exception if value was not found.\r
- * \r
- * @param subject a resource\r
- * @param relation a resource\r
- * @param binding a {@link Binding}\r
- * @return the value or null\r
- * @throws ManyObjectsForFunctionalRelationException on invalid graph with\r
- * more than one functional object\r
- * @throws BindingException if value could not be produced using the given\r
- * {@link Binding}\r
- * @throws ServiceException on connection and database failures\r
- * @see AsyncReadGraph#forPossibleRelatedValue\r
- */\r
- <T> T getPossibleRelatedValue(Resource subject, Resource relation, Binding binding)\r
- throws ManyObjectsForFunctionalRelationException, BindingException, ServiceException;\r
-\r
- /**\r
- * As {@link #adapt} but returns null instead of an exception if adapter was\r
- * not found\r
- * \r
- * @param subject a resource\r
- * @param clazz a Class\r
- * @return the adapter or null\r
- * @throws ValidationException when ?\r
- * @throws ServiceException on connection and database failures\r
- * @see {@link AsyncReadGraph#forPossibleAdapted}\r
- */\r
- <T> T getPossibleAdapter(Resource resource, Class<T> clazz) throws ValidationException, ServiceException;\r
-\r
- /**\r
- * As {@link #adaptUnique} but returns null instead of an exception if\r
- * adapter was not found\r
- * \r
- * @param subject a resource\r
- * @param clazz a Class\r
- * @return the adapter or null\r
- * @throws ValidationException when ?\r
- * @throws ServiceException on connection and database failures\r
- * @see {@link AsyncReadGraph#forPossibleAdapted}\r
- */\r
- <T> T getPossibleUniqueAdapter(Resource resource, Class<T> clazz) throws ValidationException, ServiceException;\r
-\r
- /**\r
- * Returns true if type is included in the result of {@link #getTypes(resource)}\r
- * \r
- * @param subject a resource\r
- * @param type a resource\r
- * @return indicates if resource is an instance of type\r
- * @throws ServiceException on connection and database failures\r
- * @see {@link AsyncReadGraph#forIsInstanceOf}\r
- */\r
- boolean isInstanceOf(Resource resource, Resource type) throws ServiceException;\r
-\r
- /**\r
- * Returns true if type equals resource or type is included in the result of\r
- * {@link #getSupertypes(resource)}\r
- * \r
- * @param subject a resource\r
- * @param type a resource\r
- * @return indicates if resource is inherited from type\r
- * @throws ServiceException on connection and database failures\r
- * @see {@link AsyncReadGraph#forIsInheritedFrom}\r
- */\r
- boolean isInheritedFrom(Resource resource, Resource type) throws ServiceException;\r
-\r
- /**\r
- * Returns true if relation equals resource or relation is included in the result of\r
- * {@link #getSuperrelations(resource)}\r
- * \r
- * @param subject a resource\r
- * @param relation a resource\r
- * @return indicates if resource is a subrelation of relation\r
- * @throws ServiceException on connection and database failures\r
- * @see {@link AsyncReadGraph#forIsSubrelationOf}\r
- */\r
- boolean isSubrelationOf(Resource resource, Resource relation) throws ServiceException;\r
-\r
- /**\r
- * Returns true if the result of {@link #getStatements(subject, IsWeaklyRelatedTo)} is nonempty.\r
- * \r
- * @param subject a resource\r
- * @return indicates that subject has statements\r
- * @throws ServiceException on connection and database failures\r
- * @see {@link AsyncReadGraph#forHasStatement}\r
- */\r
- boolean hasStatement(Resource subject) throws ServiceException;\r
-\r
- /**\r
- * Returns true if the result of {@link #getStatements(subject, relation)} is nonempty.\r
- * \r
- * @param subject a resource\r
- * @param relation a resource\r
- * @return indicates that subject has statements with predicates as subrelation of relation\r
- * @throws ServiceException on connection and database failures\r
- * @see {@link AsyncReadGraph#forHasStatement}\r
- */\r
- boolean hasStatement(Resource subject, Resource relation) throws ServiceException;\r
-\r
- /**\r
- * Returns true if a statement (subject, relation, object) exists after assertions.\r
- * \r
- * @param subject a resource\r
- * @param relation a resource\r
- * @param object a resource\r
- * @return indicates that the given statement exists\r
- * @throws ServiceException on connection and database failures\r
- * @see {@link AsyncReadGraph#forHasStatement}\r
- */\r
- boolean hasStatement(Resource subject, Resource relation, Resource object) throws ServiceException;\r
-\r
- /**\r
- * Returns true if there is a value associated with subject.\r
- * IMPLEMENTATION NOTE:\r
- * Current implementation fetches the value from server. If the value is\r
- * large (i.e. not stored in the cluster) this is highly inefficient.\r
- * \r
- * @param subject a resource\r
- * @return indicates that a value exists\r
- * @throws ServiceException on connection and database failures\r
- * @see {@link AsyncReadGraph#forHasValue}\r
- */\r
- boolean hasValue(Resource subject) throws ServiceException;\r
-\r
- /**\r
- * Returns the data type of the literal.\r
- * @param subject\r
- * @return\r
- * @throws DatabaseException\r
- */\r
- Datatype getDataType(Resource subject) throws DatabaseException;\r
-\r
- /**\r
- * Returns an accessory that can be used to partially read the literal\r
- * or write if the graph is WriteGraph. The returned accessory is closed\r
- * automatically when the transaction ends. The modifications are written\r
- * back to graph at transaction completion.\r
- * \r
- * @param <T> is typed accessory for modifying the literal value. \r
- * @param resource is the literal containing the value.\r
- * @return interface to partially read and write the literal value.\r
- * @throws DatabaseException\r
- */\r
- <T extends Accessor> T getAccessor(Resource resource) throws DatabaseException;\r
- \r
- /**\r
- * Returns an RandomAccessBinary that can be used to partially read the literal\r
- * or write if the graph is WriteGraph. The returned interface is closed\r
- * automatically when the transaction ends. The modifications are written\r
- * back to graph at transaction completion.\r
- * \r
- * @param <T>\r
- * @param resource is the literal containing the value.\r
- * @return interface to partially read and write the literal value.\r
- * @throws DatabaseException\r
- */\r
- RandomAccessBinary getRandomAccessBinary(Resource resource) throws DatabaseException;\r
-// @SuppressWarnings("rawtypes")\r
-// Function getValueFunction(Resource resource) throws DatabaseException;\r
-\r
- /**\r
- * Get the value associated with a graph {@link Resource}, using a possible context object and\r
- * a default data type binding. An exception is thrown, if the value is not found.\r
- * <p>\r
- * See {@link #getValue2(Resource, Object, Binding)} for more details.\r
- * \r
- * @param r A graph resource with which the value is associated\r
- * @param context A context object that is used for acquiring the value, can be {@code null}\r
- * @return The value of the graph node.\r
- * @throws DoesNotContainValueException No value is associated with the graph node.\r
- * @throws DatabaseException Other errors, such as an error in casting the value to the return type or\r
- * a runtime error in the value function.\r
- * @see #getValue2(Resource, Object, Binding)\r
- * @see #getPossibleValue2(Resource, Object)\r
- */\r
- <T> T getValue2(Resource subject, Object context) throws DatabaseException;\r
- \r
- /**\r
- * Get the value associated with a graph {@link Resource}, using a possible context object and\r
- * a default data type binding as a Variant. An exception is thrown, if the value is not found.\r
- * <p>\r
- * See {@link #getValue2(Resource, Object, Binding)} for more details.\r
- * \r
- * @param r A graph resource with which the value is associated\r
- * @param context A context object that is used for acquiring the value, can be {@code null}\r
- * @return The value of the graph node.\r
- * @throws DoesNotContainValueException No value is associated with the graph node.\r
- * @throws DatabaseException Other errors, such as an error in casting the value to the return type or\r
- * a runtime error in the value function.\r
- * @see #getValue2(Resource, Object, Binding)\r
- * @see #getPossibleValue2(Resource, Object)\r
- */\r
- Variant getVariantValue2( Resource r, Object context ) throws DatabaseException;\r
- \r
- /**\r
- * Get a possible value associated with a graph {@link Resource}, using a possible context object and\r
- * a desired value binding. Unlike {@link #getValue2(Resource, Object)}, this methods\r
- * returns {@code null} for missing values instead of throwing an exception.\r
- * <p>\r
- * See {@link #getValue2(Resource, Object, Binding)} for more details.\r
- * \r
- * @param r A graph resource with which the value is associated\r
- * @param context A context object that is used for acquiring the value, can be {@code null}\r
- * @return The value of the graph node.\r
- * @throws DatabaseException Usually should not happen. A null value is returned for possible errors.\r
- * @see #getValue2(Resource, Object)\r
- * @see #getPossibleValue2(Resource, Object, Binding)\r
- */\r
- <T> T getPossibleValue2(Resource subject, Object context) throws DatabaseException;\r
- \r
- /**\r
- * Get the value associated with a graph {@link Resource}, using a possible context object and\r
- * a desired value binding. An exception is thrown, if the value is not found.\r
- * <p>\r
- * The following methods are tried in order to retrieve the value:\r
- * <ol>\r
- * <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>\r
- * <li>If the resource is a {@code L0.ExternalValue}, the value is acquired using\r
- * {@link ReflectionUtils#getValue(String)} with the resource URI.</li>\r
- * <li>If the resource is associated with a suitable value converter with relation {@code L0.ConvertsToValueWith}\r
- * (see {@link #requestValueFunction(Resource)}), the value function is called with the graph, the resource\r
- * and the context object.</li>\r
- * </ul>\r
- * \r
- * @param r A graph resource with which the value is associated\r
- * @param context A context object that is used for acquiring the value, can be {@code null}\r
- * @param binding A binding for the value type\r
- * @return The value of the graph node.\r
- * @throws DoesNotContainValueException No value is associated with the graph node.\r
- * @throws DatabaseException Other errors, such as an error in casting the value to the return type or\r
- * a runtime error in the value function.\r
- * @see #getValue2(Resource, Object)\r
- * @see #getPossibleValue2(Resource, Object, Binding)\r
- */\r
- <T> T getValue2(Resource subject, Object context, Binding binding) throws DatabaseException;\r
- \r
- /**\r
- * Get a possible value associated with a graph {@link Resource}, using a possible context object and\r
- * a desired value binding. Unlike {@link #getValue2(Resource, Object, Binding)}, this methods\r
- * returns {@code null} for missing values instead of throwing an exception.\r
- * <p>\r
- * See {@link #getValue2(Resource, Object, Binding)} for more details.\r
- * \r
- * @param r A graph resource with which the value is associated\r
- * @param context A context object that is used for acquiring the value, can be {@code null}\r
- * @param binding A binding for the value type\r
- * @return The value of the graph node.\r
- * @throws DatabaseException Usually should not happen. A null value is returned for possible errors.\r
- * @see #getValue2(Resource, Object, Bindinge)\r
- * @see #getPossibleValue2(Resource, Object)\r
- */\r
- <T> T getPossibleValue2(Resource subject, Object context, Binding binding) throws DatabaseException;\r
- \r
- /**\r
- * Get the single value associated with a graph resource related with a given subject.\r
- * An exception is thrown, if a unique object resource or a value for it is not found.\r
- * <p>\r
- * See {@link #getValue2(Resource, Object, Binding)} for more details.\r
- * \r
- * @param subject A graph resource that indicates the subject node\r
- * @param relation A graph resource that indicates the predicate of a relation\r
- * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.\r
- * @throws NoSingleResultException The number of suitable object resources is not equal to 1 (zero or greater than one) \r
- * @throws DoesNotContainValueException No value is associated with the graph node.\r
- * @throws DatabaseException Other errors, such as an error in casting the value to the return type or\r
- * a runtime error in the value function.\r
- * @see #getRelatedValue2(Resource, Resource, Binding)\r
- * @see #getRelatedValue2(Resource, Resource, Object)\r
- * @see #getRelatedValue2(Resource, Resource, Object, Binding)\r
- * @see #getPossibleRelatedValue2(Resource, Resource)\r
- */\r
- <T> T getRelatedValue2(Resource subject, Resource relation) throws DatabaseException;\r
-\r
- /**\r
- * Get a possible single value associated with a graph resource related with a given subject.\r
- * A {@code null} value is returned for missing values or other errors.\r
- * <p>\r
- * See {@link #getValue2(Resource, Object, Binding)} for more details.\r
- * \r
- * @param subject A graph resource that indicates the subject node\r
- * @param relation A graph resource that indicates the predicate of a relation\r
- * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.\r
- * @throws DatabaseException Usually should not happen. A {@code null} value is returned for possible errors.\r
- * @see #getPossibleRelatedValue2(Resource, Resource, Binding)\r
- * @see #getPossibleRelatedValue2(Resource, Resource, Object)\r
- * @see #getPossibleRelatedValue2(Resource, Resource, Object, Binding)\r
- * @see #getRelatedValue2(Resource, Resource)\r
- */\r
- <T> T getPossibleRelatedValue2(Resource subject, Resource relation) throws DatabaseException;\r
- \r
- /**\r
- * Get a possible single value associated with a graph resource related with a given subject.\r
- * A {@code null} value is returned for missing values or other errors.\r
- * <p>\r
- * See {@link #getValue2(Resource, Object, Binding)} for more details.\r
- * \r
- * @param subject A graph resource that indicates the subject node\r
- * @param relation A graph resource that indicates the predicate of a relation\r
- * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.\r
- * @throws DatabaseException Usually should not happen. A {@code null} value is returned for possible errors.\r
- * @see #getPossibleRelatedValue2(Resource, Resource, Binding)\r
- * @see #getPossibleRelatedValue2(Resource, Resource, Object)\r
- * @see #getPossibleRelatedValue2(Resource, Resource, Object, Binding)\r
- * @see #getRelatedValue2(Resource, Resource)\r
- */\r
- Variant getRelatedVariantValue2( Resource subject, Resource relation ) throws DatabaseException;\r
- \r
- /**\r
- * Get the single value associated with a graph resource related with a given subject, a possible context object.\r
- * An exception is thrown, if a unique object resource or a value for it is not found.\r
- * <p>\r
- * See {@link #getValue2(Resource, Object, Binding)} for more details.\r
- * \r
- * @param subject A graph resource that indicates the subject node\r
- * @param relation A graph resource that indicates the predicate of a relation\r
- * @param context A context object that is used for acquiring the value, can be {@code null}\r
- * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.\r
- * @throws NoSingleResultException The number of suitable object resources is not equal to 1 (zero or greater than one) \r
- * @throws DoesNotContainValueException No value is associated with the graph node.\r
- * @throws DatabaseException Other errors, such as an error in casting the value to the return type or\r
- * a runtime error in the value function.\r
- * @see #getRelatedValue2(Resource, Resource)\r
- * @see #getRelatedValue2(Resource, Resource, Binding)\r
- * @see #getRelatedValue2(Resource, Resource, Object, Binding)\r
- * @see #getPossibleRelatedValue2(Resource, Resource, Object)\r
- */\r
- <T> T getRelatedValue2(Resource subject, Resource relation, Object context) throws DatabaseException;\r
- \r
- /**\r
- * Get the single value associated with a graph resource related with a given subject, a possible context object.\r
- * An exception is thrown, if a unique object resource or a value for it is not found.\r
- * <p>\r
- * See {@link #getValue2(Resource, Object, Binding)} for more details.\r
- * \r
- * @param subject A graph resource that indicates the subject node\r
- * @param relation A graph resource that indicates the predicate of a relation\r
- * @param context A context object that is used for acquiring the value, can be {@code null}\r
- * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.\r
- * @throws NoSingleResultException The number of suitable object resources is not equal to 1 (zero or greater than one) \r
- * @throws DoesNotContainValueException No value is associated with the graph node.\r
- * @throws DatabaseException Other errors, such as an error in casting the value to the return type or\r
- * a runtime error in the value function.\r
- * @see #getRelatedValue2(Resource, Resource, Object)\r
- * @see #getPossibleRelatedValue2(Resource, Resource, Object)\r
- */\r
- Variant getRelatedVariantValue2( Resource subject, Resource relation, Object context ) throws DatabaseException;\r
- \r
- /**\r
- * Get a possible single value associated with a graph resource related with a given subject and a possible context object.\r
- * A {@code null} value is returned for missing values or other errors.\r
- * <p>\r
- * See {@link #getValue2(Resource, Object, Binding)} for more details.\r
- * \r
- * @param subject A graph resource that indicates the subject node\r
- * @param relation A graph resource that indicates the predicate of a relation\r
- * @param context A context object that is used for acquiring the value, can be {@code null}\r
- * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.\r
- * @throws DatabaseException Usually should not happen. A {@code null} value is returned for possible errors.\r
- * @see #getPossibleRelatedValue2(Resource, Resource)\r
- * @see #getPossibleRelatedValue2(Resource, Resource, Binding)\r
- * @see #getPossibleRelatedValue2(Resource, Resource, Object, Binding)\r
- * @see #getRelatedValue2(Resource, Resource, Object)\r
- */\r
- <T> T getPossibleRelatedValue2(Resource subject, Resource relation, Object context) throws DatabaseException;\r
-\r
- /**\r
- * Get the single value associated with a graph resource related with a given subject and\r
- * a desired value binding. An exception is thrown, if a unique object resource or a value for it is not found.\r
- * <p>\r
- * See {@link #getValue2(Resource, Object, Binding)} for more details.\r
- * \r
- * @param subject A graph resource that indicates the subject node\r
- * @param relation A graph resource that indicates the predicate of a relation\r
- * @param binding A binding for the value type\r
- * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.\r
- * @throws NoSingleResultException The number of suitable object resources is not equal to 1 (zero or greater than one) \r
- * @throws DoesNotContainValueException No value is associated with the graph node.\r
- * @throws DatabaseException Other errors, such as an error in casting the value to the return type or\r
- * a runtime error in the value function.\r
- * @see #getRelatedValue2(Resource, Resource)\r
- * @see #getRelatedValue2(Resource, Resource, Object)\r
- * @see #getRelatedValue2(Resource, Resource, Object, Binding)\r
- * @see #getPossibleRelatedValue2(Resource, Resource, Binding)\r
- */\r
- <T> T getRelatedValue2(Resource subject, Resource relation, Binding binding) throws DatabaseException;\r
-\r
- /**\r
- * Get a possible single value associated with a graph resource related with a given subject and\r
- * a desired value binding. A {@code null} value is returned for missing values or other errors.\r
- * <p>\r
- * See {@link #getValue2(Resource, Object, Binding)} for more details.\r
- * \r
- * @param subject A graph resource that indicates the subject node\r
- * @param relation A graph resource that indicates the predicate of a relation\r
- * @param binding A binding for the value type\r
- * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.\r
- * @throws DatabaseException Usually should not happen. A {@code null} value is returned for possible errors.\r
- * @see #getPossibleRelatedValue2(Resource, Resource)\r
- * @see #getPossibleRelatedValue2(Resource, Resource, Object)\r
- * @see #getPossibleRelatedValue2(Resource, Resource, Object, Binding)\r
- * @see #getRelatedValue2(Resource, Resource, Binding)\r
- */\r
- <T> T getPossibleRelatedValue2(Resource subject, Resource relation, Binding binding) throws DatabaseException;\r
- \r
- /**\r
- * Get the single value associated with a graph resource related with a given subject, a possible context object and\r
- * a desired value binding. An exception is thrown, if a unique object resource or a value for it is not found.\r
- * <p>\r
- * See {@link #getValue2(Resource, Object, Binding)} for more details.\r
- * \r
- * @param subject A graph resource that indicates the subject node\r
- * @param relation A graph resource that indicates the predicate of a relation\r
- * @param context A context object that is used for acquiring the value, can be {@code null}\r
- * @param binding A binding for the value type\r
- * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.\r
- * @throws NoSingleResultException The number of suitable object resources is not equal to 1 (zero or greater than one) \r
- * @throws DoesNotContainValueException No value is associated with the graph node.\r
- * @throws DatabaseException Other errors, such as an error in casting the value to the return type or\r
- * a runtime error in the value function.\r
- * @see #getRelatedValue2(Resource, Resource)\r
- * @see #getRelatedValue2(Resource, Resource, Binding)\r
- * @see #getRelatedValue2(Resource, Resource, Object)\r
- * @see #getPossibleRelatedValue2(Resource, Resource, Object, Binding)\r
- */\r
- <T> T getRelatedValue2(Resource subject, Resource relation, Object context, Binding binding) throws DatabaseException;\r
-\r
- /**\r
- * Get a possible single value associated with a graph resource related with a given subject, a possible context object and\r
- * a desired value binding. A {@code null} value is returned for missing values or other errors.\r
- * <p>\r
- * See {@link #getValue2(Resource, Object, Binding)} for more details.\r
- * \r
- * @param subject A graph resource that indicates the subject node\r
- * @param relation A graph resource that indicates the predicate of a relation\r
- * @param context A context object that is used for acquiring the value, can be {@code null}\r
- * @param binding A binding for the value type\r
- * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.\r
- * @throws DatabaseException Usually should not happen. A {@code null} value is returned for possible errors.\r
- * @see #getPossibleRelatedValue2(Resource, Resource)\r
- * @see #getPossibleRelatedValue2(Resource, Resource, Binding)\r
- * @see #getPossibleRelatedValue2(Resource, Resource, Object)\r
- * @see #getRelatedValue2(Resource, Resource, Object, Binding)\r
- */\r
- <T> T getPossibleRelatedValue2(Resource subject, Resource relation, Object context, Binding binding) throws DatabaseException;\r
- \r
- /**\r
- * Get the parsed SCL type declaration from the string value of a graph resource that is the unique object of a\r
- * given subject and predicate.\r
- * <p>\r
- * See {@link #getValue2(Resource, Object, Binding)} for more details.\r
- * \r
- * @param subject A resource that indicates the subject of a statement\r
- * @param relation A resource that indicates the predicate of the statement\r
- * @return A compiled SCL type definition of the string value of a unique object resource\r
- * @throws DatabaseException For any errors in locating a unique value or compiling it as an SCL type statement\r
- */\r
- Type getRelatedValueType(Resource subject, Resource relation) throws DatabaseException;\r
- \r
- boolean setSynchronous(boolean value);\r
- boolean getSynchronous();\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2018 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import org.simantics.databoard.accessor.Accessor;
+import org.simantics.databoard.binding.Binding;
+import org.simantics.databoard.binding.mutable.Variant;
+import org.simantics.databoard.type.Datatype;
+import org.simantics.databoard.util.binary.RandomAccessBinary;
+import org.simantics.db.adaption.Adapter;
+import org.simantics.db.exception.AdaptionException;
+import org.simantics.db.exception.AssumptionException;
+import org.simantics.db.exception.BindingException;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.DoesNotContainValueException;
+import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
+import org.simantics.db.exception.NoInverseException;
+import org.simantics.db.exception.NoSingleResultException;
+import org.simantics.db.exception.ResourceNotFoundException;
+import org.simantics.db.exception.ServiceException;
+import org.simantics.db.exception.ValidationException;
+import org.simantics.db.procedure.SyncListener;
+import org.simantics.db.procedure.SyncMultiListener;
+import org.simantics.db.procedure.SyncMultiProcedure;
+import org.simantics.db.procedure.SyncProcedure;
+import org.simantics.db.procedure.SyncSetListener;
+import org.simantics.db.request.Read;
+import org.simantics.scl.compiler.types.Type;
+
+/**
+ *
+ * For accessing and manipulating the graph data in synchronous manner. A client
+ * receives ReadGraph instances for performing requests in {@link Read} and
+ * {@link MultiRead} as well as for reacting to request results using
+ * {@link SyncProcedure}, {@link SyncListener}, {@link SyncMultiProcedure},
+ * {@link SyncMultiListener} and {@link SyncSetListener}
+ * <p>
+ * ReadGraph instances are stateful and may not be stored and used outside the
+ * supplier method activation. The methods receiving ReadGraph should not block
+ * for long periods of time since that may delay the processing of other
+ * requests. For an asynchronous counterpart with the same functionality as
+ * ReadGraph see {@link AsyncReadGraph}
+ *
+ * <p>
+ * All collections returned by the methods on this interface must not be
+ * modified by clients unless explicitly stated otherwise.
+ *
+ * @version 0.7
+ * @author Antti Villberg
+ * @see RequestProcessor
+ * @see AsyncRequestProcessor
+ * @see AsyncReadGraph
+ * @see Resource
+ * @see Statement
+ * @noimplement
+ */
+public interface ReadGraph extends RequestProcessor {
+
+ /**
+ *
+ * @see AsyncReadGraph#forURI
+ */
+ String getURI(Resource resource) throws AssumptionException, ValidationException, ServiceException;
+ String getPossibleURI(Resource resource) throws ValidationException, ServiceException;
+
+ /**
+ * Gets a unique resource associated to the given identifier. See <a
+ * href="https://www.simantics.org/wiki/index.php/URI">Simantics Wiki page
+ * on URIs</a> for more details.
+ *
+ * @param uri the identifier
+ * @return the resource
+ * @throws ResourceNotFoundException if a resource for the given identifier
+ * was not specified
+ * @throws ValidationException if a resource could not be produced due to
+ * invalid semantics
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forResourceByURI
+ */
+ Resource getResource(String uri) throws ResourceNotFoundException, ValidationException, ServiceException;
+
+ /**
+ * Gets a unique resource associated to the given identifier. See <a
+ * href="https://www.simantics.org/wiki/index.php/URI">Simantics Wiki page
+ * on URIs</a> for more details.
+ *
+ * @param uri the identifier
+ * @return the resource
+ * @throws ResourceNotFoundException if a resource for the given identifier
+ * was not specified
+ * @throws ValidationException if a resource could not be produced due to
+ * invalid semantics
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forResourceByURI
+ */
+ Resource getPossibleResource(String uri) throws ResourceNotFoundException, ValidationException, ServiceException;
+
+ /**
+ * Computes a map of objects related to resource with L0.ConsistsOf that also contain a L0.HasName property
+ *
+ * @param resource the resource
+ * @return the children
+ * @throws ValidationException if a resource could not be produced due to
+ * invalid semantics
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forResourceByURI
+ */
+ Map<String,Resource> getChildren(Resource resource) throws ValidationException, ServiceException;
+
+ /**
+ * Gets a builtin resource. For a list of builtin resources see TODO Wiki
+ *
+ * @param uri the identifier
+ * @return the resource
+ * @throws ResourceNotFoundException if resouce was not found
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forBuiltin
+ */
+ Resource getBuiltin(String id) throws ResourceNotFoundException, ServiceException;
+
+ /**
+ * Gets all statements (subject, p, o) such that
+ * {@link ReadGraph#isSubrelationOf(p, relation)} returns true. The result
+ * may include asserted statements for which s does not equal subject. See
+ * the assertion mechanisn TODO for more details. If the relation is
+ * functional the request returns a single statement according to the
+ * functional statement shadowing rules TODO if possible. If an invalid
+ * graph is encountered an exception is thrown.
+ *
+ * @param subject a resource
+ * @param relation a resource
+ * @return the statements
+ * @throws ManyObjectsForFunctionalRelationException on invalid graph with
+ * more than one functional object
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forEachStatement
+ * @see AsyncReadGraph#forStatementSet
+ */
+ Collection<Statement> getStatements(Resource subject, Resource relation)
+ throws ManyObjectsForFunctionalRelationException, ServiceException;
+
+ /**
+ * Gets all statements (s, p, o) asserted by subject such that
+ * {@link ReadGraph#isSubrelationOf(p, relation)} returns true. See the
+ * assertion mechanism TODO for more details. If the relation is functional
+ * the request returns a single statement according to the functional
+ * statement shadowing rules TODO if possible. If an invalid graph is
+ * encountered an exception is thrown.
+ *
+ * @param subject a resource
+ * @param relation a resource
+ * @return the statements
+ * @throws ManyObjectsForFunctionalRelationException on invalid graph with
+ * more than one functional object
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forEachAssertedStatement
+ * @see AsyncReadGraph#forAssertedStatementSet
+ */
+ Collection<Statement> getAssertedStatements(Resource subject, Resource relation)
+ throws ManyObjectsForFunctionalRelationException, ServiceException;
+
+ /**
+ * Gets all predicates p from statements (subject, p, o) such that
+ * {@link ReadGraph#isSubrelationOf(p, relation)} returns true. See the
+ * assertion mechanism TODO for more details. If the relation is functional
+ * the request returns a single statement according to the functional
+ * statement shadowing rules TODO if possible. If an invalid graph is
+ * encountered an exception is thrown.
+ *
+ * @param subject a resource
+ * @param relation a resource
+ * @return the predicates
+ * @throws ManyObjectsForFunctionalRelationException on invalid graph with
+ * more than one object
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forEachPredicate
+ * @see AsyncReadGraph#forPredicateSet
+ */
+ Collection<Resource> getPredicates(Resource subject) throws ServiceException;
+
+ /**
+ * Gets a subset of all types of the subject such that no pair of returned
+ * types inherit each other and all types of the subject are supertypes
+ * of some type in the returned set.
+ *
+ * @param subject a resource
+ * @return the principal types
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forEachPrincipalType
+ * @see AsyncReadGraph#forPrincipalTypeSet
+ */
+ Collection<Resource> getPrincipalTypes(Resource subject) throws ServiceException;
+
+ /**
+ * Gets the full type hierarchy for subject.
+ *
+ * @param subject a resource
+ * @return the type hierarchy
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forTypes
+ */
+ Set<Resource> getTypes(Resource subject) throws ServiceException;
+
+ /**
+ * Gets the full supertype hierarchy for subject.
+ *
+ * @param subject a resource
+ * @return the supertype hierarchy
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forSupertypes
+ */
+ Set<Resource> getSupertypes(Resource subject) throws ServiceException;
+
+ /**
+ * Gets the full superrelation hierarchy for subject.
+ *
+ * @param subject a resource
+ * @return the superrelation hierarchy
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forSuperrelations
+ */
+ Set<Resource> getSuperrelations(Resource subject) throws ServiceException;
+ Resource getPossibleSuperrelation(Resource subject) throws ServiceException;
+
+ /**
+ * Gets all objects o from statements (subject, p, o) such that
+ * {@link ReadGraph#isSubrelationOf(p, relation)} returns true. See the
+ * assertion mechanisn TODO for more details. If the relation is functional
+ * the request returns a single object according to the functional statement
+ * shadowing rules TODO if possible. If an invalid graph is encountered an
+ * exception is thrown.
+ *
+ * @param subject a resource
+ * @param relation a resource
+ * @return the objects
+ * @throws ManyObjectsForFunctionalRelationException on invalid graph with
+ * more than one functional object
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forEachObject
+ * @see AsyncReadGraph#forObjectSet
+ */
+ Collection<Resource> getObjects(Resource subject, Resource relation)
+ throws ServiceException;
+
+ /**
+ * Gets all objects o (s, p, o) asserted by subject such that
+ * {@link ReadGraph#isSubrelationOf(p, relation)} returns true. See the
+ * assertion mechanism TODO for more details. If the relation is functional
+ * the request returns a single object according to the functional statement
+ * shadowing rules TODO if possible. If an invalid graph is encountered an
+ * exception is thrown.
+ *
+ * @param subject a resource
+ * @param relation a resource
+ * @return the objects
+ * @throws ManyObjectsForFunctionalRelationException on invalid graph with
+ * more than one functional object
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forEachAssertedStatement
+ * @see AsyncReadGraph#forAssertedStatementSet
+ */
+ Collection<Resource> getAssertedObjects(Resource subject, Resource relation)
+ throws ManyObjectsForFunctionalRelationException, ServiceException;
+
+ /**
+ * Gets the inverse r of relation such that (relation, InverseOf, r). The
+ * methods assumes an inverse exists.
+ *
+ * @param relation a resource
+ * @return the inverse
+ * @throws NoInverseException if inverse was not fond
+ * @throws ManyObjectsForFunctionalRelationException on invalid graph with
+ * more than one functional object
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forInverse
+ */
+ Resource getInverse(Resource relation) throws NoInverseException, ManyObjectsForFunctionalRelationException,
+ ServiceException;
+
+ /**
+ * Gets a single object as returned by {@link ReadGraph#getObjects}. Assumes
+ * a single object.
+ *
+ * @param subject a resource
+ * @param relation a resource
+ * @return the single object
+ * @throws NoSingleResultException if the amount of valid objects was not
+ * one
+ * @throws ManyObjectsForFunctionalRelationException on invalid graph with
+ * more than one functional object
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forSingleObject
+ */
+ Resource getSingleObject(Resource subject, Resource relation) throws NoSingleResultException,
+ ManyObjectsForFunctionalRelationException, ServiceException;
+
+ /**
+ * Gets a single statement as returned by {@link ReadGraph#getStatements}.
+ * Assumes a single statement.
+ *
+ * @param subject a resource
+ * @param relation a resource
+ * @return the single statement
+ * @throws NoSingleResultException if the amount of valid statements was not
+ * one
+ * @throws ManyObjectsForFunctionalRelationException on invalid graph with
+ * more than one functional object
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forSingleStatement
+ */
+ Statement getSingleStatement(Resource subject, Resource relation) throws NoSingleResultException,
+ ManyObjectsForFunctionalRelationException, ServiceException;
+
+ /**
+ * Gets a single type t as returned by {@link ReadGraph#getPrincipalTypes}. Assumes a single type.
+ *
+ * @param subject a resource
+ * @param baseType a resource
+ * @return the single type
+ * @throws NoSingleResultException if the amount of valid types was not one
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forSingleType
+ */
+ Resource getSingleType(Resource subject) throws NoSingleResultException, ServiceException;
+
+ /**
+ * Gets a single type t as returned by {@link ReadGraph#getTypes} where
+ * {@link ReadGraph#isInheritedFrom(t, baseType)}. Assumes a single type.
+ *
+ * @param subject a resource
+ * @param baseType a resource
+ * @return the single type
+ * @throws NoSingleResultException if the amount of valid types was not one
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forSingleType
+ */
+ Resource getSingleType(Resource subject, Resource baseType) throws NoSingleResultException, ServiceException;
+
+ /**
+ * Gets a value associated to subject. Infers {@link Binding} from type t =
+ * {@link ReadGraph#getSingleType(subject, Value)}
+ *
+ * @param subject a resource
+ * @return the value
+ * @throws DoesNotContainValueException if the subject did not contain a
+ * resource
+ * @throws ServiceException on connection and database failure
+ * @see AsyncReadGraph#forValue
+ */
+ <T> T getValue(Resource subject) throws DoesNotContainValueException, ServiceException;
+
+ /**
+ * Gets a value associated to subject as a Variant. Infers {@link Binding} from type t =
+ * {@link ReadGraph#getSingleType(subject, Value)}
+ *
+ * @param subject a resource
+ * @return the value
+ * @throws DoesNotContainValueException if the subject did not contain a
+ * resource
+ * @throws ServiceException on connection and database failure
+ * @see AsyncReadGraph#forValue
+ */
+ Variant getVariantValue(Resource subject) throws DoesNotContainValueException, ServiceException;
+
+ /**
+ * Gets a value associated to subject using the given {@link Binding}.
+ *
+ * @param subject a resource
+ * @param binding a binding
+ * @return the value
+ * @throws DoesNotContainValueException if the subject did not contain a
+ * resource
+ * @throws BindingException if value could not be produced using the given
+ * {@link Binding}
+ * @throws ServiceException on connection and database failure
+ * @see AsyncReadGraph#forValue
+ */
+ <T> T getValue(Resource subject, Binding binding) throws DoesNotContainValueException, BindingException,
+ ServiceException;
+
+ /**
+ * Gets a single value associated to o such that (subject, r, o) and
+ * {@link ReadGraph#isSubrelationOf(r, relation)}. Assumes a single value.
+ * Infers {@link Binding} from type t =
+ * {@link ReadGraph#getSingleType(o, Value)}
+ *
+ * @param subject a resource
+ * @param relation a resource
+ * @return the value
+ * @throws NoSingleResultException if the amount of valid values was not one
+ * @throws DoesNotContainValueException if suitable o did not contain a
+ * resource
+ * @throws ServiceException on connection and database failure
+ * @see AsyncReadGraph#forRelatedValue
+ */
+ <T> T getRelatedValue(Resource subject, Resource relation) throws NoSingleResultException,
+ DoesNotContainValueException, ServiceException;
+
+ /**
+ * Gets a single value associated to o such that (subject, r, o) and
+ * {@link ReadGraph#isSubrelationOf(r, relation)} as a Variant. Assumes a single value.
+ * Infers {@link Binding} from type t =
+ * {@link ReadGraph#getSingleType(o, Value)}
+ *
+ * @param subject a resource
+ * @param relation a resource
+ * @return the value
+ * @throws NoSingleResultException if the amount of valid values was not one
+ * @throws DoesNotContainValueException if suitable o did not contain a
+ * resource
+ * @throws ServiceException on connection and database failure
+ * @see AsyncReadGraph#forRelatedValue
+ */
+ Variant getRelatedVariantValue(Resource subject, Resource relation) throws NoSingleResultException,
+ DoesNotContainValueException, ServiceException;
+
+ /**
+ * Gets a single value associated to o such that (subject, r, o) and
+ * {@link ReadGraph#isSubrelationOf(r, relation)}. Uses the given
+ * {@link Binding}. Assumes a single value.
+ *
+ * @param subject a resource
+ * @param relation a resource
+ * @return the value
+ * @throws NoSingleResultException if the amount of valid values was not one
+ * @throws DoesNotContainValueException if suitable o did not contain a
+ * resource
+ * @throws BindingException if value could not be produced using the given
+ * {@link Binding}
+ * @throws ServiceException on connection and database failure
+ * @see AsyncReadGraph#forRelatedValue
+ */
+ <T> T getRelatedValue(Resource subject, Resource relation, Binding binding) throws NoSingleResultException,
+ DoesNotContainValueException, BindingException, ServiceException;
+
+ /**
+ * Tries to adapt the specified resource into an instance of the specified
+ * class T. No guarantees are made on return values of this method. The
+ * returned values can be cached results of previous invocation or they can
+ * be new result object instances. See {@link #adaptUnique(Resource, Class)}
+ * for alternative behaviour.
+ *
+ * @param resource a resource
+ * @param clazz the adapter class
+ * @return
+ * @throws AdaptionException if suitable adapter was not found
+ * @throws ValidationException from the adapter
+ * @throws ServiceException on connection and database failure
+ * @see AsyncReadGraph#forAdapted
+ * @see #adaptUnique(Resource, Class)
+ */
+ <T> T adapt(Resource resource, Class<T> clazz) throws AdaptionException, ValidationException, ServiceException;
+
+ /**
+ *
+ * Same as: adapt(getSingleObject(resource, relation), clazz);
+ *
+ * @param resource a resource
+ * @param relation a resource
+ * @param clazz the adapter class
+ * @return
+ * @throws AdaptionException if suitable adapter was not found
+ * @throws ValidationException from the adapter
+ * @throws ServiceException on connection and database failure
+ * @see AsyncReadGraph#forAdapted
+ * @see #adaptUnique(Resource, Class)
+ */
+ <T> T adaptRelated(Resource resource, Resource relation, Class<T> clazz) throws AdaptionException, NoSingleResultException, ValidationException, ServiceException;
+
+ /**
+ *
+ * Same as:
+ *
+ * Resource r = getPossibleObject(resource, relation);
+ * if(r == null) return null;
+ * return getPossibleAdapter(r, clazz);
+ *
+ * @param resource a resource
+ * @param relation a resource
+ * @param clazz the adapter class
+ * @return
+ * @throws AdaptionException if suitable adapter was not found
+ * @throws ValidationException from the adapter
+ * @throws ServiceException on connection and database failure
+ * @see AsyncReadGraph#forAdapted
+ * @see #adaptUnique(Resource, Class)
+ */
+ <T> T getPossibleRelatedAdapter(Resource resource, Resource relation, Class<T> clazz) throws ValidationException, ServiceException;
+
+ <T,C> T adaptContextual(Resource resource, C context, Class<C> contextClass, Class<T> clazz) throws AdaptionException, NoSingleResultException, ValidationException, ServiceException;
+ <T,C> T getPossibleContextualAdapter(Resource resource, C context, Class<C> contextClass, Class<T> clazz) throws ValidationException, ServiceException;
+
+ /**
+ * Tries to adapt the specified resource into an instance of the specified
+ * class T. The difference to {@link #adapt(Resource, Class)} is that this
+ * method does everything possible to return a new object instance for each
+ * separate invocation.
+ *
+ * <p>
+ * The only case when this cannot be guaranteed is when the adaption result
+ * comes from an {@link Adapter} implementation which can internally do
+ * anything, like always return the same singleton instance.
+ * </p>
+ *
+ * @param resource a resource
+ * @param clazz the adapter class
+ * @return
+ * @throws AdaptionException if suitable adapter was not found
+ * @throws ValidationException from the adapter
+ * @throws ServiceException on connection and database failure
+ * @see AsyncReadGraph#forAdapted
+ * @see #adapt(Resource, Class)
+ */
+ <T> T adaptUnique(Resource resource, Class<T> clazz) throws AdaptionException, ValidationException,
+ ServiceException;
+
+ /**
+ * As {@link #getInverse} but returns null instead of an exception if
+ * inverse was not found.
+ *
+ * @param relation a resource
+ * @return the inverse or null
+ * @throws ManyObjectsForFunctionalRelationException on invalid graph with
+ * more than one functional object
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forPossibleInverse
+ */
+ Resource getPossibleInverse(Resource relation) throws ManyObjectsForFunctionalRelationException, ServiceException;
+
+ /**
+ * As {@link #getSingleObject} but returns null instead of an exception if
+ * object was not found.
+ *
+ * @param subject a resource
+ * @param relation a resource
+ * @return the object or null
+ * @throws ManyObjectsForFunctionalRelationException on invalid graph with
+ * more than one functional object
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forPossibleObject
+ */
+ Resource getPossibleObject(Resource subject, Resource relation) throws ManyObjectsForFunctionalRelationException,
+ ServiceException;
+
+ /**
+ * As {@link #getSingleStatement} but returns null instead of an exception
+ * if statement was not found.
+ *
+ * @param subject a resource
+ * @param relation a resource
+ * @return the statement or null
+ * @throws ManyObjectsForFunctionalRelationException on invalid graph with
+ * more than one functional object
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forPossibleStatement
+ */
+ Statement getPossibleStatement(Resource subject, Resource relation)
+ throws ManyObjectsForFunctionalRelationException, ServiceException;
+
+ /**
+ * As {@link #getSingleType} but returns null instead of an exception if
+ * type was not found.
+ *
+ * @param subject a resource
+ * @param baseType a resource
+ * @return the type or null
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forPossibleType
+ */
+ Resource getPossibleType(Resource subject, Resource baseType) throws ServiceException;
+
+ /**
+ * As {@link #getValue} but returns null instead of an exception if value
+ * was not found.
+ *
+ * @param subject a resource
+ * @return the value or null
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forPossibleValue
+ */
+ <T> T getPossibleValue(Resource subject) throws ServiceException;
+
+ /**
+ * As {@link #getValue} but returns null instead of an exception if value
+ * was not found.
+ *
+ * @param subject a resource
+ * @param binding a {@link Binding}
+ * @return the value or null
+ * @throws BindingException if value could not be produced using the given
+ * {@link Binding}
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forPossibleValue
+ */
+ <T> T getPossibleValue(Resource subject, Binding binding) throws BindingException, ServiceException;
+
+ /**
+ * As {@link #getPossibleRelatedValue} but returns null instead of an
+ * exception if value was not found.
+ *
+ * @param subject a resource
+ * @param relation a resource
+ * @return the value or null
+ * @throws ManyObjectsForFunctionalRelationException on invalid graph with
+ * more than one functional object
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forPossibleRelatedValue
+ */
+ <T> T getPossibleRelatedValue(Resource subject, Resource relation)
+ throws ManyObjectsForFunctionalRelationException, ServiceException;
+
+ /**
+ * As {@link #getPossibleRelatedValue} but returns null instead of an
+ * exception if value was not found.
+ *
+ * @param subject a resource
+ * @param relation a resource
+ * @param binding a {@link Binding}
+ * @return the value or null
+ * @throws ManyObjectsForFunctionalRelationException on invalid graph with
+ * more than one functional object
+ * @throws BindingException if value could not be produced using the given
+ * {@link Binding}
+ * @throws ServiceException on connection and database failures
+ * @see AsyncReadGraph#forPossibleRelatedValue
+ */
+ <T> T getPossibleRelatedValue(Resource subject, Resource relation, Binding binding)
+ throws ManyObjectsForFunctionalRelationException, BindingException, ServiceException;
+
+ /**
+ * As {@link #adapt} but returns null instead of an exception if adapter was
+ * not found
+ *
+ * @param subject a resource
+ * @param clazz a Class
+ * @return the adapter or null
+ * @throws ValidationException when ?
+ * @throws ServiceException on connection and database failures
+ * @see {@link AsyncReadGraph#forPossibleAdapted}
+ */
+ <T> T getPossibleAdapter(Resource resource, Class<T> clazz) throws ValidationException, ServiceException;
+
+ /**
+ * As {@link #adaptUnique} but returns null instead of an exception if
+ * adapter was not found
+ *
+ * @param subject a resource
+ * @param clazz a Class
+ * @return the adapter or null
+ * @throws ValidationException when ?
+ * @throws ServiceException on connection and database failures
+ * @see {@link AsyncReadGraph#forPossibleAdapted}
+ */
+ <T> T getPossibleUniqueAdapter(Resource resource, Class<T> clazz) throws ValidationException, ServiceException;
+
+ /**
+ * Returns true if type is included in the result of {@link #getTypes(resource)}
+ *
+ * @param subject a resource
+ * @param type a resource
+ * @return indicates if resource is an instance of type
+ * @throws ServiceException on connection and database failures
+ * @see {@link AsyncReadGraph#forIsInstanceOf}
+ */
+ boolean isInstanceOf(Resource resource, Resource type) throws ServiceException;
+
+ /**
+ * Returns true if type equals resource or type is included in the result of
+ * {@link #getSupertypes(resource)}
+ *
+ * @param subject a resource
+ * @param type a resource
+ * @return indicates if resource is inherited from type
+ * @throws ServiceException on connection and database failures
+ * @see {@link AsyncReadGraph#forIsInheritedFrom}
+ */
+ boolean isInheritedFrom(Resource resource, Resource type) throws ServiceException;
+
+ /**
+ * Returns true if relation equals resource or relation is included in the result of
+ * {@link #getSuperrelations(resource)}
+ *
+ * @param subject a resource
+ * @param relation a resource
+ * @return indicates if resource is a subrelation of relation
+ * @throws ServiceException on connection and database failures
+ * @see {@link AsyncReadGraph#forIsSubrelationOf}
+ */
+ boolean isSubrelationOf(Resource resource, Resource relation) throws ServiceException;
+
+ /**
+ * Returns true if the result of {@link #getStatements(subject, IsWeaklyRelatedTo)} is nonempty.
+ *
+ * @param subject a resource
+ * @return indicates that subject has statements
+ * @throws ServiceException on connection and database failures
+ * @see {@link AsyncReadGraph#forHasStatement}
+ */
+ boolean hasStatement(Resource subject) throws ServiceException;
+
+ /**
+ * Returns true if the result of {@link #getStatements(subject, relation)} is nonempty.
+ *
+ * @param subject a resource
+ * @param relation a resource
+ * @return indicates that subject has statements with predicates as subrelation of relation
+ * @throws ServiceException on connection and database failures
+ * @see {@link AsyncReadGraph#forHasStatement}
+ */
+ boolean hasStatement(Resource subject, Resource relation) throws ServiceException;
+
+ /**
+ * Returns true if a statement (subject, relation, object) exists after assertions.
+ *
+ * @param subject a resource
+ * @param relation a resource
+ * @param object a resource
+ * @return indicates that the given statement exists
+ * @throws ServiceException on connection and database failures
+ * @see {@link AsyncReadGraph#forHasStatement}
+ */
+ boolean hasStatement(Resource subject, Resource relation, Resource object) throws ServiceException;
+
+ /**
+ * Returns true if there is a value associated with subject.
+ * IMPLEMENTATION NOTE:
+ * Current implementation fetches the value from server. If the value is
+ * large (i.e. not stored in the cluster) this is highly inefficient.
+ *
+ * @param subject a resource
+ * @return indicates that a value exists
+ * @throws ServiceException on connection and database failures
+ * @see {@link AsyncReadGraph#forHasValue}
+ */
+ boolean hasValue(Resource subject) throws ServiceException;
+
+ /**
+ * Returns the data type of the literal.
+ * @param subject
+ * @return
+ * @throws DatabaseException
+ */
+ Datatype getDataType(Resource subject) throws DatabaseException;
+
+ /**
+ * Returns an accessory that can be used to partially read the literal
+ * or write if the graph is WriteGraph. The returned accessory is closed
+ * automatically when the transaction ends. The modifications are written
+ * back to graph at transaction completion.
+ *
+ * @param <T> is typed accessory for modifying the literal value.
+ * @param resource is the literal containing the value.
+ * @return interface to partially read and write the literal value.
+ * @throws DatabaseException
+ */
+ <T extends Accessor> T getAccessor(Resource resource) throws DatabaseException;
+
+ /**
+ * Returns an RandomAccessBinary that can be used to partially read the literal
+ * or write if the graph is WriteGraph. The returned interface is closed
+ * automatically when the transaction ends. The modifications are written
+ * back to graph at transaction completion.
+ *
+ * @param <T>
+ * @param resource is the literal containing the value.
+ * @return interface to partially read and write the literal value.
+ * @throws DatabaseException
+ */
+ RandomAccessBinary getRandomAccessBinary(Resource resource) throws DatabaseException;
+// @SuppressWarnings("rawtypes")
+// Function getValueFunction(Resource resource) throws DatabaseException;
+
+ /**
+ * Get the value associated with a graph {@link Resource}, using a possible context object and
+ * a default data type binding. An exception is thrown, if the value is not found.
+ * <p>
+ * See {@link #getValue2(Resource, Object, Binding)} for more details.
+ *
+ * @param r A graph resource with which the value is associated
+ * @param context A context object that is used for acquiring the value, can be {@code null}
+ * @return The value of the graph node.
+ * @throws DoesNotContainValueException No value is associated with the graph node.
+ * @throws DatabaseException Other errors, such as an error in casting the value to the return type or
+ * a runtime error in the value function.
+ * @see #getValue2(Resource, Object, Binding)
+ * @see #getPossibleValue2(Resource, Object)
+ */
+ <T> T getValue2(Resource subject, Object context) throws DatabaseException;
+
+ /**
+ * Get the value associated with a graph {@link Resource}, using a possible context object and
+ * a default data type binding as a Variant. An exception is thrown, if the value is not found.
+ * <p>
+ * See {@link #getValue2(Resource, Object, Binding)} for more details.
+ *
+ * @param r A graph resource with which the value is associated
+ * @param context A context object that is used for acquiring the value, can be {@code null}
+ * @return The value of the graph node.
+ * @throws DoesNotContainValueException No value is associated with the graph node.
+ * @throws DatabaseException Other errors, such as an error in casting the value to the return type or
+ * a runtime error in the value function.
+ * @see #getValue2(Resource, Object, Binding)
+ * @see #getPossibleValue2(Resource, Object)
+ */
+ Variant getVariantValue2( Resource r, Object context ) throws DatabaseException;
+
+ /**
+ * Get a possible value associated with a graph {@link Resource}, using a possible context object and
+ * a desired value binding. Unlike {@link #getValue2(Resource, Object)}, this methods
+ * returns {@code null} for missing values instead of throwing an exception.
+ * <p>
+ * See {@link #getValue2(Resource, Object, Binding)} for more details.
+ *
+ * @param r A graph resource with which the value is associated
+ * @param context A context object that is used for acquiring the value, can be {@code null}
+ * @return The value of the graph node.
+ * @throws DatabaseException Usually should not happen. A null value is returned for possible errors.
+ * @see #getValue2(Resource, Object)
+ * @see #getPossibleValue2(Resource, Object, Binding)
+ */
+ <T> T getPossibleValue2(Resource subject, Object context) throws DatabaseException;
+
+ /**
+ * Get the value associated with a graph {@link Resource}, using a possible context object and
+ * a desired value binding. An exception is thrown, if the value is not found.
+ * <p>
+ * The following methods are tried in order to retrieve the value:
+ * <ol>
+ * <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>
+ * <li>If the resource is a {@code L0.ExternalValue}, the value is acquired using
+ * {@link ReflectionUtils#getValue(String)} with the resource URI.</li>
+ * <li>If the resource is associated with a suitable value converter with relation {@code L0.ConvertsToValueWith}
+ * (see {@link #requestValueFunction(Resource)}), the value function is called with the graph, the resource
+ * and the context object.</li>
+ * </ul>
+ *
+ * @param r A graph resource with which the value is associated
+ * @param context A context object that is used for acquiring the value, can be {@code null}
+ * @param binding A binding for the value type
+ * @return The value of the graph node.
+ * @throws DoesNotContainValueException No value is associated with the graph node.
+ * @throws DatabaseException Other errors, such as an error in casting the value to the return type or
+ * a runtime error in the value function.
+ * @see #getValue2(Resource, Object)
+ * @see #getPossibleValue2(Resource, Object, Binding)
+ */
+ <T> T getValue2(Resource subject, Object context, Binding binding) throws DatabaseException;
+
+ /**
+ * Get a possible value associated with a graph {@link Resource}, using a possible context object and
+ * a desired value binding. Unlike {@link #getValue2(Resource, Object, Binding)}, this methods
+ * returns {@code null} for missing values instead of throwing an exception.
+ * <p>
+ * See {@link #getValue2(Resource, Object, Binding)} for more details.
+ *
+ * @param r A graph resource with which the value is associated
+ * @param context A context object that is used for acquiring the value, can be {@code null}
+ * @param binding A binding for the value type
+ * @return The value of the graph node.
+ * @throws DatabaseException Usually should not happen. A null value is returned for possible errors.
+ * @see #getValue2(Resource, Object, Bindinge)
+ * @see #getPossibleValue2(Resource, Object)
+ */
+ <T> T getPossibleValue2(Resource subject, Object context, Binding binding) throws DatabaseException;
+
+ /**
+ * Get the single value associated with a graph resource related with a given subject.
+ * An exception is thrown, if a unique object resource or a value for it is not found.
+ * <p>
+ * See {@link #getValue2(Resource, Object, Binding)} for more details.
+ *
+ * @param subject A graph resource that indicates the subject node
+ * @param relation A graph resource that indicates the predicate of a relation
+ * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
+ * @throws NoSingleResultException The number of suitable object resources is not equal to 1 (zero or greater than one)
+ * @throws DoesNotContainValueException No value is associated with the graph node.
+ * @throws DatabaseException Other errors, such as an error in casting the value to the return type or
+ * a runtime error in the value function.
+ * @see #getRelatedValue2(Resource, Resource, Binding)
+ * @see #getRelatedValue2(Resource, Resource, Object)
+ * @see #getRelatedValue2(Resource, Resource, Object, Binding)
+ * @see #getPossibleRelatedValue2(Resource, Resource)
+ */
+ <T> T getRelatedValue2(Resource subject, Resource relation) throws DatabaseException;
+
+ /**
+ * Get a possible single value associated with a graph resource related with a given subject.
+ * A {@code null} value is returned for missing values or other errors.
+ * <p>
+ * See {@link #getValue2(Resource, Object, Binding)} for more details.
+ *
+ * @param subject A graph resource that indicates the subject node
+ * @param relation A graph resource that indicates the predicate of a relation
+ * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
+ * @throws DatabaseException Usually should not happen. A {@code null} value is returned for possible errors.
+ * @see #getPossibleRelatedValue2(Resource, Resource, Binding)
+ * @see #getPossibleRelatedValue2(Resource, Resource, Object)
+ * @see #getPossibleRelatedValue2(Resource, Resource, Object, Binding)
+ * @see #getRelatedValue2(Resource, Resource)
+ */
+ <T> T getPossibleRelatedValue2(Resource subject, Resource relation) throws DatabaseException;
+
+ /**
+ * Get a possible single value associated with a graph resource related with a given subject.
+ * A {@code null} value is returned for missing values or other errors.
+ * <p>
+ * See {@link #getValue2(Resource, Object, Binding)} for more details.
+ *
+ * @param subject A graph resource that indicates the subject node
+ * @param relation A graph resource that indicates the predicate of a relation
+ * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
+ * @throws DatabaseException Usually should not happen. A {@code null} value is returned for possible errors.
+ * @see #getPossibleRelatedValue2(Resource, Resource, Binding)
+ * @see #getPossibleRelatedValue2(Resource, Resource, Object)
+ * @see #getPossibleRelatedValue2(Resource, Resource, Object, Binding)
+ * @see #getRelatedValue2(Resource, Resource)
+ */
+ Variant getRelatedVariantValue2( Resource subject, Resource relation ) throws DatabaseException;
+
+ /**
+ * Get the single value associated with a graph resource related with a given subject, a possible context object.
+ * An exception is thrown, if a unique object resource or a value for it is not found.
+ * <p>
+ * See {@link #getValue2(Resource, Object, Binding)} for more details.
+ *
+ * @param subject A graph resource that indicates the subject node
+ * @param relation A graph resource that indicates the predicate of a relation
+ * @param context A context object that is used for acquiring the value, can be {@code null}
+ * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
+ * @throws NoSingleResultException The number of suitable object resources is not equal to 1 (zero or greater than one)
+ * @throws DoesNotContainValueException No value is associated with the graph node.
+ * @throws DatabaseException Other errors, such as an error in casting the value to the return type or
+ * a runtime error in the value function.
+ * @see #getRelatedValue2(Resource, Resource)
+ * @see #getRelatedValue2(Resource, Resource, Binding)
+ * @see #getRelatedValue2(Resource, Resource, Object, Binding)
+ * @see #getPossibleRelatedValue2(Resource, Resource, Object)
+ */
+ <T> T getRelatedValue2(Resource subject, Resource relation, Object context) throws DatabaseException;
+
+ /**
+ * Get the single value associated with a graph resource related with a given subject, a possible context object.
+ * An exception is thrown, if a unique object resource or a value for it is not found.
+ * <p>
+ * See {@link #getValue2(Resource, Object, Binding)} for more details.
+ *
+ * @param subject A graph resource that indicates the subject node
+ * @param relation A graph resource that indicates the predicate of a relation
+ * @param context A context object that is used for acquiring the value, can be {@code null}
+ * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
+ * @throws NoSingleResultException The number of suitable object resources is not equal to 1 (zero or greater than one)
+ * @throws DoesNotContainValueException No value is associated with the graph node.
+ * @throws DatabaseException Other errors, such as an error in casting the value to the return type or
+ * a runtime error in the value function.
+ * @see #getRelatedValue2(Resource, Resource, Object)
+ * @see #getPossibleRelatedValue2(Resource, Resource, Object)
+ */
+ Variant getRelatedVariantValue2( Resource subject, Resource relation, Object context ) throws DatabaseException;
+
+ /**
+ * Get a possible single value associated with a graph resource related with a given subject and a possible context object.
+ * A {@code null} value is returned for missing values or other errors.
+ * <p>
+ * See {@link #getValue2(Resource, Object, Binding)} for more details.
+ *
+ * @param subject A graph resource that indicates the subject node
+ * @param relation A graph resource that indicates the predicate of a relation
+ * @param context A context object that is used for acquiring the value, can be {@code null}
+ * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
+ * @throws DatabaseException Usually should not happen. A {@code null} value is returned for possible errors.
+ * @see #getPossibleRelatedValue2(Resource, Resource)
+ * @see #getPossibleRelatedValue2(Resource, Resource, Binding)
+ * @see #getPossibleRelatedValue2(Resource, Resource, Object, Binding)
+ * @see #getRelatedValue2(Resource, Resource, Object)
+ */
+ <T> T getPossibleRelatedValue2(Resource subject, Resource relation, Object context) throws DatabaseException;
+
+ /**
+ * Get the single value associated with a graph resource related with a given subject and
+ * a desired value binding. An exception is thrown, if a unique object resource or a value for it is not found.
+ * <p>
+ * See {@link #getValue2(Resource, Object, Binding)} for more details.
+ *
+ * @param subject A graph resource that indicates the subject node
+ * @param relation A graph resource that indicates the predicate of a relation
+ * @param binding A binding for the value type
+ * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
+ * @throws NoSingleResultException The number of suitable object resources is not equal to 1 (zero or greater than one)
+ * @throws DoesNotContainValueException No value is associated with the graph node.
+ * @throws DatabaseException Other errors, such as an error in casting the value to the return type or
+ * a runtime error in the value function.
+ * @see #getRelatedValue2(Resource, Resource)
+ * @see #getRelatedValue2(Resource, Resource, Object)
+ * @see #getRelatedValue2(Resource, Resource, Object, Binding)
+ * @see #getPossibleRelatedValue2(Resource, Resource, Binding)
+ */
+ <T> T getRelatedValue2(Resource subject, Resource relation, Binding binding) throws DatabaseException;
+
+ /**
+ * Get a possible single value associated with a graph resource related with a given subject and
+ * a desired value binding. A {@code null} value is returned for missing values or other errors.
+ * <p>
+ * See {@link #getValue2(Resource, Object, Binding)} for more details.
+ *
+ * @param subject A graph resource that indicates the subject node
+ * @param relation A graph resource that indicates the predicate of a relation
+ * @param binding A binding for the value type
+ * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
+ * @throws DatabaseException Usually should not happen. A {@code null} value is returned for possible errors.
+ * @see #getPossibleRelatedValue2(Resource, Resource)
+ * @see #getPossibleRelatedValue2(Resource, Resource, Object)
+ * @see #getPossibleRelatedValue2(Resource, Resource, Object, Binding)
+ * @see #getRelatedValue2(Resource, Resource, Binding)
+ */
+ <T> T getPossibleRelatedValue2(Resource subject, Resource relation, Binding binding) throws DatabaseException;
+
+ /**
+ * Get the single value associated with a graph resource related with a given subject, a possible context object and
+ * a desired value binding. An exception is thrown, if a unique object resource or a value for it is not found.
+ * <p>
+ * See {@link #getValue2(Resource, Object, Binding)} for more details.
+ *
+ * @param subject A graph resource that indicates the subject node
+ * @param relation A graph resource that indicates the predicate of a relation
+ * @param context A context object that is used for acquiring the value, can be {@code null}
+ * @param binding A binding for the value type
+ * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
+ * @throws NoSingleResultException The number of suitable object resources is not equal to 1 (zero or greater than one)
+ * @throws DoesNotContainValueException No value is associated with the graph node.
+ * @throws DatabaseException Other errors, such as an error in casting the value to the return type or
+ * a runtime error in the value function.
+ * @see #getRelatedValue2(Resource, Resource)
+ * @see #getRelatedValue2(Resource, Resource, Binding)
+ * @see #getRelatedValue2(Resource, Resource, Object)
+ * @see #getPossibleRelatedValue2(Resource, Resource, Object, Binding)
+ */
+ <T> T getRelatedValue2(Resource subject, Resource relation, Object context, Binding binding) throws DatabaseException;
+
+ /**
+ * Get a possible single value associated with a graph resource related with a given subject, a possible context object and
+ * a desired value binding. A {@code null} value is returned for missing values or other errors.
+ * <p>
+ * See {@link #getValue2(Resource, Object, Binding)} for more details.
+ *
+ * @param subject A graph resource that indicates the subject node
+ * @param relation A graph resource that indicates the predicate of a relation
+ * @param context A context object that is used for acquiring the value, can be {@code null}
+ * @param binding A binding for the value type
+ * @return The value of the unique graph node that is asserted as the object of the given subject and predicate.
+ * @throws DatabaseException Usually should not happen. A {@code null} value is returned for possible errors.
+ * @see #getPossibleRelatedValue2(Resource, Resource)
+ * @see #getPossibleRelatedValue2(Resource, Resource, Binding)
+ * @see #getPossibleRelatedValue2(Resource, Resource, Object)
+ * @see #getRelatedValue2(Resource, Resource, Object, Binding)
+ */
+ <T> T getPossibleRelatedValue2(Resource subject, Resource relation, Object context, Binding binding) throws DatabaseException;
+
+ /**
+ * Get the parsed SCL type declaration from the string value of a graph resource that is the unique object of a
+ * given subject and predicate.
+ * <p>
+ * See {@link #getValue2(Resource, Object, Binding)} for more details.
+ *
+ * @param subject A resource that indicates the subject of a statement
+ * @param relation A resource that indicates the predicate of the statement
+ * @return A compiled SCL type definition of the string value of a unique object resource
+ * @throws DatabaseException For any errors in locating a unique value or compiling it as an SCL type statement
+ */
+ Type getRelatedValueType(Resource subject, Resource relation) throws DatabaseException;
+
+ boolean setSynchronous(boolean value);
+ boolean getSynchronous();
+
+ boolean isImmutable(Resource resource) throws DatabaseException;
+
+ int thread();
+
+}