} catch (ResourceNotFoundException e) {
- throw new ResourceNotFoundException(e);
+ throw new ResourceNotFoundException(id, e);
} catch (ValidationException e) {
} catch (ResourceNotFoundException e) {
- throw new ResourceNotFoundException(e);
+ throw new ResourceNotFoundException(id, e);
} catch (ServiceException e) {
if( relation == null) throw new IllegalArgumentException("relation can not be null");
try {
-
int single = processor.getSingleObject(this, subject, relation);
- if(single == 0) throw new NoSingleResultException("subject=" + subject + " relation="+relation);
+ if (single == 0) {
+ if (EMPTY_RESOURCE_CHECK) {
+ if (!hasStatement(subject)) {
+ throw new EmptyResourceException("Resource " + debugString(subject));
+ }
+ }
+ throw new NoSingleResultException("No single object for subject " + debugString(subject)
+ + " and relation " + debugString(relation), single);
+ }
return processor.querySupport.getResource(single);
-
} catch (NoSingleResultException e) {
-
- if(EMPTY_RESOURCE_CHECK) {
- if(!hasStatement(subject)) throw new EmptyResourceException("Resource " + debugString(subject));
- }
-
- throw new NoSingleResultException("No single object for subject "
- + debugString(subject) + " and relation "
- + debugString(relation), e);
-
+ throw e;
} catch (DatabaseException e) {
-
throw new ServiceException(e);
-
}
-
}
@Override
- final public Statement getSingleStatement(final Resource subject,
- final Resource relation) throws NoSingleResultException,
- ManyObjectsForFunctionalRelationException, ServiceException {
-
+ final public Statement getSingleStatement(final Resource subject, final Resource relation) throws NoSingleResultException, ManyObjectsForFunctionalRelationException, ServiceException {
assert (subject != null);
assert (relation != null);
-
try {
-
Collection<Statement> statements = getStatements(subject, relation);
- if(statements.size() == 1) return statements.iterator().next();
- else throw new NoSingleResultException("");
-
- } catch (NoSingleResultException e) {
-
- if(EMPTY_RESOURCE_CHECK) {
- if(!hasStatement(subject)) throw new EmptyResourceException("Resource " + debugString(subject));
- }
-
- throw new NoSingleResultException("No single statement for subject "
- + debugString(subject) + " and relation "
- + debugString(relation), e);
-
- } catch (DatabaseException e) {
-
- throw new ServiceException(e);
-
- }
-
+ if (statements.size() == 1) {
+ return statements.iterator().next();
+ } else {
+ if (EMPTY_RESOURCE_CHECK)
+ if (!hasStatement(subject))
+ throw new EmptyResourceException("Resource " + debugString(subject));
+ throw new NoSingleResultException("No single statement for subject " + debugString(subject)
+ + " and relation " + debugString(relation), statements.size());
+ }
+ } catch (ServiceException e) {
+ throw new ServiceException(e);
+ }
}
@Override
- final public Resource getSingleType(final Resource subject) throws NoSingleResultException,
- ServiceException {
-
+ final public Resource getSingleType(final Resource subject) throws NoSingleResultException, ServiceException {
assert (subject != null);
-
try {
-
ArrayList<Resource> principalTypes = (ArrayList<Resource>)getPrincipalTypes(subject);
- if(principalTypes.size() == 1) return principalTypes.get(0);
- else throw new NoSingleResultException("");
-
- } catch (NoSingleResultException e) {
-
- throw new NoSingleResultException(e);
-
+ if (principalTypes.size() == 1) {
+ return principalTypes.get(0);
+ } else {
+ throw new NoSingleResultException("No single type for subject " + debugString(subject), principalTypes.size());
+ }
} catch (ServiceException e) {
-
throw new ServiceException(e);
-
}
-
}
@Override
assert (baseType != null);
try {
-
return syncRequest(new SingleType(subject, baseType));
-
- } catch (NoSingleResultException e) {
-
- throw new NoSingleResultException(new NoSingleResultException("subject=" + subject + ", baseType=" + baseType, e));
-
- } catch (ServiceException e) {
-
- throw new ServiceException(e);
-
} catch (DatabaseException e) {
-
- throw new ServiceException(INTERNAL_ERROR_STRING, e);
-
+ throw new NoSingleResultException("subject=" + subject + ", baseType=" + baseType, 0, e);
}
-
}
@Override
assert (relation != null);
try {
-
Resource object = getSingleObject(subject, relation);
return getValue(object);
-
} catch (NoSingleResultException e) {
-
- throw new NoSingleResultException(e);
-
+ throw new NoSingleResultException("No single value found for subject " + debugString(subject) + " and relation " + debugString(relation), e.getResultCount(), e);
} catch (DoesNotContainValueException e) {
-
try {
Layer0 L0 = processor.getL0(this);
Resource object = getPossibleObject(subject, relation);
if(isInstanceOf(object, L0.Literal)) {
throw new DoesNotContainValueException(e);
} else {
- throw new InvalidLiteralException("The object " + object + " is not an instance of L0.Literal (use getRelatedValue2 instead)");
+ throw new InvalidLiteralException("The object " + object + " is not an instance of L0.Literal (use getRelatedValue2 instead)", e);
}
} else {
- throw new DoesNotContainValueException("The object " + object + " is not an instance of L0.Value");
+ throw new DoesNotContainValueException("The object " + object + " is not an instance of L0.Value", e);
}
} catch (DoesNotContainValueException e2) {
throw e2;
} catch (DatabaseException e2) {
throw new InternalException("The client failed to analyse the cause of the following exception", e);
}
-
} catch (ServiceException e) {
-
throw new ServiceException(e);
-
- }
-
+ }
}
@Override
assert (relation != null);
try {
-
Resource object = getSingleObject(subject, relation);
return getVariantValue(object);
-
} catch (NoSingleResultException e) {
-
- throw new NoSingleResultException(e);
-
+ throw new NoSingleResultException("No single object for subject " + debugString(subject) + " and relation " + debugString(relation), e.getResultCount(), e);
} catch (DoesNotContainValueException e) {
-
try {
Layer0 L0 = processor.getL0(this);
Resource object = getPossibleObject(subject, relation);
if(isInstanceOf(object, L0.Literal)) {
throw new DoesNotContainValueException(e);
} else {
- throw new InvalidLiteralException("The object " + object + " is not an instance of L0.Literal (use getRelatedValue2 instead)");
+ throw new InvalidLiteralException("The object " + object + " is not an instance of L0.Literal (use getRelatedValue2 instead)", e);
}
} else {
- throw new DoesNotContainValueException("The object " + object + " is not an instance of L0.Value");
+ throw new DoesNotContainValueException("The object " + object + " is not an instance of L0.Value", e);
}
} catch (DoesNotContainValueException e2) {
throw e2;
} catch (DatabaseException e2) {
throw new InternalException("The client failed to analyse the cause of the following exception", e);
}
-
} catch (ServiceException e) {
-
throw new ServiceException(e);
-
}
-
}
@Override
assert (relation != null);
try {
-
Resource object = getSingleObject(subject, relation);
return getValue(object, binding);
-
} catch (NoSingleResultException e) {
-
String message = "";
-
try {
-
String subjectName = NameUtils.getSafeName(this, subject, true);
String relationName = NameUtils.getSafeName(this, relation, true);
message = "Subject: " + subjectName + ", Relation: " + relationName;
-
} catch (DatabaseException e2) {
}
-
- throw new NoSingleResultException(message);
-
+ throw new NoSingleResultException(message, e.getResultCount(), e);
} catch (DoesNotContainValueException e) {
-
throw new DoesNotContainValueException(e);
-
} catch (ServiceException e) {
-
throw new ServiceException(e);
-
- } catch (DatabaseException e) {
-
- throw new ServiceException(INTERNAL_ERROR_STRING, e);
-
}
-
}
@Override
import org.simantics.db.common.procedure.wrapper.NoneToAsyncProcedure;
import org.simantics.db.common.procedure.wrapper.SyncToAsyncProcedure;
import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.NoSingleResultException;
import org.simantics.db.impl.ClusterI;
import org.simantics.db.impl.ClusterI.ClusterTypeEnum;
import org.simantics.db.impl.ForEachObjectContextProcedure;
import org.simantics.db.procore.cluster.ValueTableSmall;
import org.simantics.db.request.AsyncRead;
import org.simantics.db.service.DirectQuerySupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class DirectQuerySupportImpl implements DirectQuerySupport {
+ private static final Logger LOGGER = LoggerFactory.getLogger(DirectQuerySupportImpl.class);
+
final private SessionImplSocket session;
DirectQuerySupportImpl(SessionImplSocket session) {
int so = cluster.getSingleObject(subject, procedure, session.clusterTranslator);
if(so == 0) {
if(result == 0) {
- procedure.exception(graph, new DatabaseException("No objects " + subject + " " + procedure.predicateKey));
+ procedure.exception(graph, new NoSingleResultException("No objects " + subject + " " + procedure.predicateKey, result));
// graph.dec();
} else {
getValue4(graph, cluster, result, context, procedure);
if(result == 0) {
getValue4(graph, cluster, so, context, procedure);
} else {
- procedure.exception(graph, new DatabaseException("Multiple objects"));
+ procedure.exception(graph, new NoSingleResultException("Multiple objects for " + subject + " " + procedure.predicateKey, result));
// graph.dec();
}
}
} catch (DatabaseException e) {
- e.printStackTrace();
+ LOGGER.error("Could not compute related value for subject {} with predicate {}", subject, procedure.predicateKey);
}
}
private static final long serialVersionUID = 1647209154838034514L;
- public NoSingleResultException(NoSingleResultException cause) {
- super(cause.getMessage());
- }
-
- public NoSingleResultException(DatabaseException cause) {
- super(cause.getMessage());
- }
+ private final int resultCount;
- public NoSingleResultException(String message, Throwable cause) {
- super(message, cause);
+ public NoSingleResultException(String message, int resultCount, Throwable cause) {
+ super(message + " [resultCount=" + resultCount + "]", cause);
+ this.resultCount = resultCount;
}
- public NoSingleResultException(String message, int ... rs) {
- super(message, rs);
- }
-
- public NoSingleResultException(String message) {
- super(message);
+ public NoSingleResultException(String message, int resultCount, int ... rs) {
+ super(message + " [resultCount=" + resultCount + "]", rs);
+ this.resultCount = resultCount;
}
- public NoSingleResultException(String message, DatabaseException cause) {
- super(message, cause);
+ public NoSingleResultException(String message, int resultCount) {
+ super(message + " [resultCount=" + resultCount + "]");
+ this.resultCount = resultCount;
}
- public NoSingleResultException(String message, Resource ... resources) {
- super(message, resources);
+ public NoSingleResultException(String message, int resultCount, Resource ... resources) {
+ super(message + " [resultCount=" + resultCount + "]", resources);
+ this.resultCount = resultCount;
}
+ public int getResultCount() {
+ return resultCount;
+ }
}