Make context's static, and autoCommit for remainders

This commit is contained in:
Peter Dietz
2013-10-21 18:09:41 -04:00
parent fee4188716
commit 4f684e25ad
4 changed files with 16 additions and 12 deletions

View File

@@ -55,7 +55,6 @@ public class BitstreamResource {
log.error(e.getMessage());
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
@GET

View File

@@ -44,7 +44,11 @@ public class CollectionsResource {
public String listHTML() {
StringBuilder everything = new StringBuilder();
try {
org.dspace.core.Context context = new org.dspace.core.Context();
if(context == null || !context.isValid() ) {
context = new org.dspace.core.Context();
//Failed SQL is ignored as a failed SQL statement, prevent: current transaction is aborted, commands ignored until end of transaction block
context.getDBConnection().setAutoCommit(true);
}
org.dspace.content.Collection[] collections = org.dspace.content.Collection.findAll(context);
for(org.dspace.content.Collection collection : collections) {
@@ -52,12 +56,12 @@ public class CollectionsResource {
everything.append("<li><a href='" + servletContext.getContextPath() + "/collections/" + collection.getID() + "'>" + collection.getID() + " - " + collection.getName() + "</a></li>\n");
}
return "<html><title>Hello!</title><body>Collections<br/><ul>" + everything.toString() + "</ul>.</body></html> ";
} catch (SQLException e) {
log.error(e.getMessage());
return "ERROR: " + e.getMessage();
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
return "<html><title>Hello!</title><body>Collections<br/><ul>" + everything.toString() + "</ul>.</body></html> ";
}
@GET

View File

@@ -28,7 +28,7 @@ http://localhost:8080/<webapp>/communities
public class CommunitiesResource {
private static Logger log = Logger.getLogger(CommunitiesResource.class);
private static Context context;
private static org.dspace.core.Context context;
/*
The "GET" annotation indicates this method will respond to HTTP Get requests.
@@ -41,18 +41,19 @@ public class CommunitiesResource {
try {
if(context == null || !context.isValid() ) {
context = new Context();
//Failed SQL is ignored as a failed SQL statement, prevent: current transaction is aborted, commands ignored until end of transaction block
context.getDBConnection().setAutoCommit(true);
}
org.dspace.content.Community[] communities = org.dspace.content.Community.findAllTop(context);
for(org.dspace.content.Community community : communities) {
everything.append(community.getName() + "<br/>\n");
}
return "<html><title>Hello!</title><body>Communities:<br/>" + everything.toString() + ".</body></html> ";
} catch (SQLException e) {
log.error(e.getMessage());
return "ERROR: " + e.getMessage();
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
return "<html><title>Hello!</title><body>Communities:<br/>" + everything.toString() + ".</body></html> ";
}
//TODO Respond to html for communities/:id
@@ -83,7 +84,7 @@ public class CommunitiesResource {
} catch (SQLException e) {
log.error(e.getMessage());
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
} //finally?
}
@GET
@@ -106,6 +107,6 @@ public class CommunitiesResource {
} catch (SQLException e) {
log.error(e.getMessage());
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
} //finally?
}
}

View File

@@ -28,7 +28,7 @@ public class ItemsResource {
Logger log = Logger.getLogger(ItemsResource.class);
//ItemList - Not Implemented
Context context;
private static org.dspace.core.Context context;
@GET
@Path("/{item_id}")