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"/> <Shareable level="VO"/>
<Type>application</Type> <Type>application</Type>
<Files> <Files>
<File>org.gcube.informationsystem.collector.testsuite.jar</File> <File>lib/org.gcube.informationsystem.collector.testsuite.jar</File>
</Files> </Files>
</Software> </Software>
</Packages> </Packages>

View File

@ -35,44 +35,48 @@ public class QueryManager extends XMLStorageManager {
int attempts = 0; int attempts = 0;
ResourceSet result = null; ResourceSet result = null;
Collection currentCollection = null; Collection currentCollection = null;
currentCollection = this.loadAllCollections();
this.lock(); State.getDataManager().lock();
while ((retry) && (attempts < MAXQUERYATTEMPTS)) { try {
try { currentCollection = this.loadAllCollections();
// execute query and get results in ResourceSet while ((retry) && (attempts < MAXQUERYATTEMPTS)) {
if (currentCollection == null) try {
result = query.execute(this.rootCollection); // execute query and get results in ResourceSet
else if (currentCollection == null)
result = query.execute(currentCollection); result = query.execute(this.rootCollection);
retry = false; else
} catch (XMLDBException edb) { result = query.execute(currentCollection);
logger.error("Failed to execute XQuery " + query.toString()); retry = false;
logger.error("Error details: " + edb.errorCode + " " + edb.getMessage(), edb); } catch (XMLDBException edb) {
// if the cause is a NullPointer, this can be due to a temporary logger.error("Failed to execute XQuery " + query.toString());
// lock on the database instance logger.error("Error details: " + edb.errorCode + " " + edb.getMessage(), edb);
if (edb.getCause() instanceof java.lang.NullPointerException) { // if the cause is a NullPointer, this can be due to a temporary
retry = true; // lock on the database instance
attempts++; if (edb.getCause() instanceof java.lang.NullPointerException) {
logger.warn("Trying a new attempt for query execution"); retry = true;
} else attempts++;
retry = false; logger.warn("Trying a new attempt for query execution");
} else
} catch (Exception e) { retry = false;
logger.error("", e);
// if the cause is a NullPointer, this can be due to a temporary } catch (Exception e) {
// lock on the database instance logger.error("", e);
if (e instanceof java.lang.NullPointerException) { // if the cause is a NullPointer, this can be due to a temporary
retry = true; // lock on the database instance
attempts++; if (e instanceof java.lang.NullPointerException) {
logger.warn("Trying a new attempt for query execution"); retry = true;
} else attempts++;
retry = false; 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++; //operationsCounter++;
this.resetCollection(currentCollection);
this.unlock();
//this.checkConnection(); //this.checkConnection();
return result; return result;
} }

View File

@ -314,8 +314,12 @@ public class XMLStorageManager {
*/ */
public void storeResource(PersistentResource resource) throws XMLStorageNotAvailableException, MalformedResourceException { public void storeResource(PersistentResource resource) throws XMLStorageNotAvailableException, MalformedResourceException {
if (status != STATUS.INITIALISED) this.lock();
throw new XMLStorageNotAvailableException("XMLStorage not initialized"); if (status != STATUS.INITIALISED) {
this.unlock();
throw new XMLStorageNotAvailableException("XMLStorage not initialized");
}
Collection currentCollection = null; Collection currentCollection = null;
if (resource.getType() == RESOURCETYPE.Profile) { if (resource.getType() == RESOURCETYPE.Profile) {
// the entry contains a gCube resource profile // the entry contains a gCube resource profile
@ -327,9 +331,10 @@ public class XMLStorageManager {
if (currentCollection == null) { if (currentCollection == null) {
logger.error("Unable to open the Collection"); logger.error("Unable to open the Collection");
this.unlock();
throw new XMLStorageNotAvailableException("Unable to open the Collection"); throw new XMLStorageNotAvailableException("Unable to open the Collection");
} }
this.lock();
try { try {
XMLResource document = (XMLResource) currentCollection.createResource(resource.getID(), "XMLResource"); XMLResource document = (XMLResource) currentCollection.createResource(resource.getID(), "XMLResource");
document.setContent(resource.toString()); document.setContent(resource.toString());