Skip to content
Snippets Groups Projects
Verified Commit 459e275f authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: use entityDoesNotExistException instead of nullpointer

parent c21e4d0c
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,7 @@ package caosdb.server.database.backend.transaction; ...@@ -27,6 +27,7 @@ package caosdb.server.database.backend.transaction;
import caosdb.server.caching.Cache; import caosdb.server.caching.Cache;
import caosdb.server.database.CacheableBackendTransaction; import caosdb.server.database.CacheableBackendTransaction;
import caosdb.server.database.backend.interfaces.GetFileRecordByPathImpl; import caosdb.server.database.backend.interfaces.GetFileRecordByPathImpl;
import caosdb.server.database.exceptions.EntityDoesNotExistException;
import caosdb.server.database.exceptions.TransactionException; import caosdb.server.database.exceptions.TransactionException;
import caosdb.server.database.proto.SparseEntity; import caosdb.server.database.proto.SparseEntity;
import org.apache.commons.jcs.access.behavior.ICacheAccess; import org.apache.commons.jcs.access.behavior.ICacheAccess;
...@@ -62,7 +63,11 @@ public class GetFileRecordByPath extends CacheableBackendTransaction<String, Spa ...@@ -62,7 +63,11 @@ public class GetFileRecordByPath extends CacheableBackendTransaction<String, Spa
@Override @Override
public SparseEntity executeNoCache() throws TransactionException { public SparseEntity executeNoCache() throws TransactionException {
final GetFileRecordByPathImpl t = getImplementation(GetFileRecordByPathImpl.class); final GetFileRecordByPathImpl t = getImplementation(GetFileRecordByPathImpl.class);
return t.execute(getKey()); SparseEntity result = t.execute(getKey());
if (result == null) {
throw new EntityDoesNotExistException();
}
return result;
} }
public Integer getId() { public Integer getId() {
......
...@@ -79,8 +79,8 @@ public class Message extends Exception implements Comparable<Message>, ToElement ...@@ -79,8 +79,8 @@ public class Message extends Exception implements Comparable<Message>, ToElement
this(type, code, null, null); this(type, code, null, null);
} }
public Message(final Integer code, final String description) { public Message(Integer code, String description) {
this("Message", code, description, null); this(MessageType.Info, code, description);
} }
public Message(final MessageType type, final Integer code, final String description) { public Message(final MessageType type, final Integer code, final String description) {
...@@ -96,6 +96,10 @@ public class Message extends Exception implements Comparable<Message>, ToElement ...@@ -96,6 +96,10 @@ public class Message extends Exception implements Comparable<Message>, ToElement
this(type, code, description, null); this(type, code, description, null);
} }
public Message(MessageType type, String description) {
this(type.toString(), 0, description);
}
public Message( public Message(
final String type, final Integer code, final String description, final String body) { final String type, final Integer code, final String description, final String body) {
this.code = code; this.code = code;
......
...@@ -26,10 +26,12 @@ import static caosdb.server.FileSystem.getFromFileSystem; ...@@ -26,10 +26,12 @@ import static caosdb.server.FileSystem.getFromFileSystem;
import static java.net.URLDecoder.decode; import static java.net.URLDecoder.decode;
import caosdb.server.database.backend.implementation.MySQL.ConnectionException; import caosdb.server.database.backend.implementation.MySQL.ConnectionException;
import caosdb.server.database.exceptions.EntityDoesNotExistException;
import caosdb.server.database.misc.TransactionBenchmark; import caosdb.server.database.misc.TransactionBenchmark;
import caosdb.server.entity.Entity; import caosdb.server.entity.Entity;
import caosdb.server.entity.FileProperties; import caosdb.server.entity.FileProperties;
import caosdb.server.entity.Message; import caosdb.server.entity.Message;
import caosdb.server.entity.Message.MessageType;
import caosdb.server.entity.RetrieveEntity; import caosdb.server.entity.RetrieveEntity;
import caosdb.server.entity.container.TransactionContainer; import caosdb.server.entity.container.TransactionContainer;
import caosdb.server.permissions.EntityPermission; import caosdb.server.permissions.EntityPermission;
...@@ -162,7 +164,10 @@ public class FileSystemResource extends AbstractCaosDBServerResource { ...@@ -162,7 +164,10 @@ public class FileSystemResource extends AbstractCaosDBServerResource {
final String entId = final String entId =
getEntityID((directory.endsWith("/") ? directory : directory + "/") + file.getName()); getEntityID((directory.endsWith("/") ? directory : directory + "/") + file.getName());
if (entId == null) { if (entId == null) {
new Message("Orphaned file").addToElement(celem); new Message(
MessageType.Warning,
"Orphaned file. The file is not tracked. This is probably a harmless inconsistency but it might be a sign of other problems.")
.addToElement(celem);
} else { } else {
celem.setAttribute("id", entId); celem.setAttribute("id", entId);
} }
...@@ -188,8 +193,8 @@ public class FileSystemResource extends AbstractCaosDBServerResource { ...@@ -188,8 +193,8 @@ public class FileSystemResource extends AbstractCaosDBServerResource {
final Transaction<?> t = new RetrieveSparseEntityByPath(c); final Transaction<?> t = new RetrieveSparseEntityByPath(c);
try { try {
t.execute(); t.execute();
} catch (NullPointerException npe) { } catch (EntityDoesNotExistException exception) {
// For example files in file system without corresponding File records. // This file in the file system has no corresponding File record.
return null; return null;
} }
final long t2 = System.currentTimeMillis(); final long t2 = System.currentTimeMillis();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment