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
This commit is contained in:
Manuele Simi 2009-09-27 20:08:18 +00:00
parent 2f81819f91
commit aca4200071
3 changed files with 50 additions and 41 deletions

View File

@ -93,7 +93,7 @@
<Shareable level="VO"/>
<Type>application</Type>
<Files>
<File>org.gcube.informationsystem.collector.testsuite.jar</File>
<File>lib/org.gcube.informationsystem.collector.testsuite.jar</File>
</Files>
</Software>
</Packages>

View File

@ -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;
}

View File

@ -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());