From aca42000719fdf783feb0e5a5fdbfa729ca6984a Mon Sep 17 00:00:00 2001 From: Manuele Simi Date: Sun, 27 Sep 2009 20:08:18 +0000 Subject: [PATCH] XQuery locking issue fixed git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/information-system/gCubeIS/Collector@15579 82a268e6-3cf1-43bd-a215-b396298e98cf --- etc/profile.xml | 2 +- .../impl/xmlstorage/exist/QueryManager.java | 78 ++++++++++--------- .../xmlstorage/exist/XMLStorageManager.java | 11 ++- 3 files changed, 50 insertions(+), 41 deletions(-) diff --git a/etc/profile.xml b/etc/profile.xml index d5ccb84..1ea081a 100644 --- a/etc/profile.xml +++ b/etc/profile.xml @@ -93,7 +93,7 @@ application - org.gcube.informationsystem.collector.testsuite.jar + lib/org.gcube.informationsystem.collector.testsuite.jar diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/QueryManager.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/QueryManager.java index e5fcd90..ac08de6 100644 --- a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/QueryManager.java +++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/QueryManager.java @@ -35,44 +35,48 @@ public class QueryManager extends XMLStorageManager { int attempts = 0; ResourceSet result = null; Collection currentCollection = null; - currentCollection = this.loadAllCollections(); - this.lock(); - while ((retry) && (attempts < MAXQUERYATTEMPTS)) { - try { - // execute query and get results in ResourceSet - if (currentCollection == null) - result = query.execute(this.rootCollection); - else - result = query.execute(currentCollection); - retry = false; - } catch (XMLDBException edb) { - logger.error("Failed to execute XQuery " + query.toString()); - logger.error("Error details: " + edb.errorCode + " " + edb.getMessage(), edb); - // if the cause is a NullPointer, this can be due to a temporary - // lock on the database instance - if (edb.getCause() instanceof java.lang.NullPointerException) { - retry = true; - attempts++; - logger.warn("Trying a new attempt for query execution"); - } else - retry = false; - - } catch (Exception e) { - logger.error("", e); - // if the cause is a NullPointer, this can be due to a temporary - // lock on the database instance - if (e instanceof java.lang.NullPointerException) { - retry = true; - attempts++; - logger.warn("Trying a new attempt for query execution"); - } else - retry = false; - - } - } + + State.getDataManager().lock(); + try { + currentCollection = this.loadAllCollections(); + while ((retry) && (attempts < MAXQUERYATTEMPTS)) { + try { + // execute query and get results in ResourceSet + if (currentCollection == null) + result = query.execute(this.rootCollection); + else + result = query.execute(currentCollection); + retry = false; + } catch (XMLDBException edb) { + logger.error("Failed to execute XQuery " + query.toString()); + logger.error("Error details: " + edb.errorCode + " " + edb.getMessage(), edb); + // if the cause is a NullPointer, this can be due to a temporary + // lock on the database instance + if (edb.getCause() instanceof java.lang.NullPointerException) { + retry = true; + attempts++; + logger.warn("Trying a new attempt for query execution"); + } else + retry = false; + + } catch (Exception e) { + logger.error("", e); + // if the cause is a NullPointer, this can be due to a temporary + // lock on the database instance + if (e instanceof java.lang.NullPointerException) { + retry = true; + attempts++; + logger.warn("Trying a new attempt for query execution"); + } else + retry = false; + + } + } + this.resetCollection(currentCollection); + } catch (Exception e) { + logger.error("Failed to execute the XQuery", e); + } finally {State.getDataManager().unlock(); } //operationsCounter++; - this.resetCollection(currentCollection); - this.unlock(); //this.checkConnection(); return result; } diff --git a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorageManager.java b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorageManager.java index acccd60..f5d1b0e 100755 --- a/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorageManager.java +++ b/src/org/gcube/informationsystem/collector/impl/xmlstorage/exist/XMLStorageManager.java @@ -314,8 +314,12 @@ public class XMLStorageManager { */ public void storeResource(PersistentResource resource) throws XMLStorageNotAvailableException, MalformedResourceException { - if (status != STATUS.INITIALISED) - throw new XMLStorageNotAvailableException("XMLStorage not initialized"); + this.lock(); + if (status != STATUS.INITIALISED) { + this.unlock(); + throw new XMLStorageNotAvailableException("XMLStorage not initialized"); + } + Collection currentCollection = null; if (resource.getType() == RESOURCETYPE.Profile) { // the entry contains a gCube resource profile @@ -327,9 +331,10 @@ public class XMLStorageManager { if (currentCollection == null) { logger.error("Unable to open the Collection"); + this.unlock(); throw new XMLStorageNotAvailableException("Unable to open the Collection"); } - this.lock(); + try { XMLResource document = (XMLResource) currentCollection.createResource(resource.getID(), "XMLResource"); document.setContent(resource.toString());