Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
schaertl_andreas
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
supervision
schaertl_andreas
Commits
b49e4c9f
Commit
b49e4c9f
authored
4 years ago
by
Andreas Schärtl
Browse files
Options
Downloads
Patches
Plain Diff
uloapi: GraphDB: improve error handling
parent
d402c693
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
experimental/uloapi/src/main/java/info/mathhub/uloapi/query/GraphDB.java
+46
-4
46 additions, 4 deletions
...oapi/src/main/java/info/mathhub/uloapi/query/GraphDB.java
with
46 additions
and
4 deletions
experimental/uloapi/src/main/java/info/mathhub/uloapi/query/GraphDB.java
+
46
−
4
View file @
b49e4c9f
...
...
@@ -36,6 +36,16 @@ public class GraphDB {
T
op
(
RepositoryManager
manager
,
Repository
repository
,
RepositoryConnection
connection
);
}
/**
* Functional interface that defines a function that takes nothing, does something
* and returns nothing.
*
* Functional programmers hate this.
*/
private
interface
Procedure
{
void
apply
()
throws
Exception
;
}
/**
* Run an operation on a remote repository.
*
...
...
@@ -52,6 +62,9 @@ public class GraphDB {
Repository
repository
=
null
;
RepositoryConnection
connection
=
null
;
Exception
err
=
null
;
T
result
=
null
;
try
{
manager
=
new
RemoteRepositoryManager
(
serverUrl
);
manager
.
init
();
...
...
@@ -61,20 +74,49 @@ public class GraphDB {
}
connection
=
repository
.
getConnection
();
return
op
.
op
(
manager
,
repository
,
connection
);
result
=
op
.
op
(
manager
,
repository
,
connection
);
}
catch
(
Exception
e
)
{
err
=
e
;
}
finally
{
if
(
connection
!=
null
)
{
connection
.
close
(
);
err
=
chain
(
err
,
connection
:
:
close
);
}
if
(
repository
!=
null
)
{
repository
.
shutDown
(
);
err
=
chain
(
err
,
repository
:
:
shutDown
);
}
if
(
manager
!=
null
)
{
manager
.
shutDown
();
err
=
chain
(
err
,
manager:
:
shutDown
);
}
}
if
(
err
!=
null
)
{
throw
new
OperationException
(
"execute failed"
,
err
);
}
return
result
;
}
/**
* Execute proc and return {@code e} if not {@code null}, the exception
* caused by {@code proc} or {@code null}.
* @return If {@code e} is not {@code null}, always return {@code e}.
* Otherwise, if {@code proc} caused an exception, return that exception or
* return {@code null} if {@code proc} did not cause an exception.
*/
private
static
Exception
chain
(
Exception
e
,
Procedure
proc
)
{
Exception
ret
=
e
;
try
{
proc
.
apply
();
}
catch
(
Exception
ne
)
{
if
(
ret
==
null
)
{
ret
=
ne
;
}
}
return
ret
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment