perfsonar-dev - r1764 - in branches/yi-udel/perfsonar: schema/example-instances/sonar/LS schema/example-instances/sonar/LS/xquery src/org/perfsonar/service/lookupService/xmlType
Subject: perfsonar development work
List archive
r1764 - in branches/yi-udel/perfsonar: schema/example-instances/sonar/LS schema/example-instances/sonar/LS/xquery src/org/perfsonar/service/lookupService/xmlType
Chronological Thread
- From:
- To:
- Subject: r1764 - in branches/yi-udel/perfsonar: schema/example-instances/sonar/LS schema/example-instances/sonar/LS/xquery src/org/perfsonar/service/lookupService/xmlType
- Date: Wed, 15 Nov 2006 16:18:07 -0500
Author: yi
Date: 2006-11-15 16:18:06 -0500 (Wed, 15 Nov 2006)
New Revision: 1764
Added:
branches/yi-udel/perfsonar/schema/example-instances/sonar/LS/xquery/
branches/yi-udel/perfsonar/schema/example-instances/sonar/LS/xquery/QueryScratch.txt
branches/yi-udel/perfsonar/schema/example-instances/sonar/LS/xquery/external-summary.xq
branches/yi-udel/perfsonar/schema/example-instances/sonar/LS/xquery/local-summary.xq
Modified:
branches/yi-udel/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSSummary.java
Log:
integrated XQuery version of summary for BDB into LSSummary
Added:
branches/yi-udel/perfsonar/schema/example-instances/sonar/LS/xquery/QueryScratch.txt
Added:
branches/yi-udel/perfsonar/schema/example-instances/sonar/LS/xquery/external-summary.xq
Added:
branches/yi-udel/perfsonar/schema/example-instances/sonar/LS/xquery/local-summary.xq
Modified:
branches/yi-udel/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSSummary.java
===================================================================
---
branches/yi-udel/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSSummary.java
2006-11-15 20:15:23 UTC (rev 1763)
+++
branches/yi-udel/perfsonar/src/org/perfsonar/service/lookupService/xmlType/LSSummary.java
2006-11-15 21:18:06 UTC (rev 1764)
@@ -26,6 +26,7 @@
import
org.perfsonar.service.commons.storage.xmldb.exist.xmlrpc.ExistDbXmlrpcXmlStorageManager;
import
org.perfsonar.service.commons.storage.xmldb.exist.rest.ExistDbHttpXmlStorageManager;
+import java.io.FileReader;
import java.io.IOException;
import java.io.File;
import java.util.ArrayList;
@@ -56,9 +57,9 @@
* name of property in config file
*/
private static final String LS_SUMMARY_STYLESHEET =
"component.ls_summary_loader.stylesheet";
+ private static final String LS_SUMMARY_XQUERY =
"component.ls_summary_loader.xquery";
-
// -------------------------------------------- Instance variables
/**
@@ -68,6 +69,11 @@
/**
+ * location of summary XQuery
+ */
+ private String summaryXQuery = "";
+
+ /**
* Storage Manager Type
*/
private String smType;
@@ -96,6 +102,8 @@
super(xmlStorageManager);
+ // ----------------------------------------------------------
+ // set summary sheet
String temp = null;
try {
temp = configuration.getProperty(LS_SUMMARY_STYLESHEET);
@@ -112,6 +120,24 @@
}
logger.debug("LSSummary: LS XSLT=" + getSummarySheet());
+ // ----------------------------------------------------------
+ // set summary XQuery
+ temp = null;
+ try {
+ temp = configuration.getProperty(LS_SUMMARY_XQUERY);
+ }
+ catch(SystemException e) {
+ temp = null;
+ }
+
+ if(temp != null) {
+ setSummaryXQuery(temp);
+ }
+ else {
+ // we need to throw an error or something...
+ }
+ logger.debug("LSSummary: LS XQuery=" + getSummaryXQuery());
+
smType = configuration.getProperty("service.ls.db_type");
lsUtil = new LSUtilities();
@@ -134,8 +160,23 @@
return summarySheet;
}
+ /**
+ * Set the value of the summary XQuery
+ */
+ public void setSummaryXQuery(String newSummaryXQuery) {
+ summaryXQuery = newSummaryXQuery;
+ return;
+ }
+
/**
+ * get the value of the summary XQuery
+ */
+ public String getSummaryXQuery() {
+ return summaryXQuery;
+ }
+
+ /**
* Scheduler Action for LS Summary
*/
public Message performAction(Message request)
@@ -155,33 +196,58 @@
results = (String[])edbres.getResultAsStringArray();
}
else if(xmlStorageManager instanceof BerkeleyDbXmlStorageManager) {
- query = XQUERY_UPDATE_DECLARE + "data(collection(\"" +
LS_STORE_CONTAINER + "\"))";
- edbres = (XmlDbResult)xmlStorageManager.fetch(query);
- results = (String[])edbres.getResultAsStringArray();
+ logger.debug("LSSummary: XQuery Starting...");
+
+ try {
+ // TODO: any better ways to read a query string from
a file?
+ query = "";
+ FileReader inputStream = new
FileReader(getSummaryXQuery());
+ int c;
+ while ((c = inputStream.read()) != -1)
+ query += (char)c;
+ inputStream.close();
+
+ edbres = (XmlDbResult)xmlStorageManager.fetch(query);
+ results = (String[])edbres.getResultAsStringArray();
+ }
+ catch(Exception err) {
+ logger.error("LSSummary: Caught XQuery Processing Error");
+ }
}
else {
throw new SystemException("error.common.storage.xmldb.query",
"No database exists");
}
-
- //Make sure we got something (don't want to do this on an empty set)
+
+ // Make sure we got something (don't want to do this on an empty set)
if(results.length != 0 && results[0] != null) {
- logger.debug("LSSummary: XSLT Starting...");
- try {
-
- //create a factory and transformer using the stylesheet
- TransformerFactory factory =
TransformerFactory.newInstance();
- Transformer transformer = factory.newTemplates(new
StreamSource(new File(getSummarySheet()))).newTransformer();
-
- //need a spot to store the output (temporarily)
- StringWriter sw = new StringWriter();
- transformer.transform(new StreamSource(new
StringReader(results[0])), new StreamResult(sw));
-
- output = sw.toString();
- }
- catch(Exception err) {
- logger.error("LSSummary: Caught XSLT Processing Error");
- }
-
+ try {
+ if(xmlStorageManager instanceof
ExistDbXmlrpcXmlStorageManager ||
+ xmlStorageManager instanceof
ExistDbHttpXmlStorageManager) {
+ logger.debug("LSSummary: XSLT Starting...");
+
+ //create a factory and transformer using the
stylesheet
+ TransformerFactory factory =
TransformerFactory.newInstance();
+ Transformer transformer =
factory.newTemplates(new StreamSource(new
File(getSummarySheet()))).newTransformer();
+
+ //need a spot to store the output
(temporarily)
+ StringWriter sw = new StringWriter();
+ transformer.transform(new StreamSource(new
StringReader(results[0])), new StreamResult(sw));
+
+ output = sw.toString();
+ }
+ else if(xmlStorageManager instanceof
BerkeleyDbXmlStorageManager) {
+ // because in the summary query, all results
are wrapped by a root element
+ // so results[0] is all the results
+ output = results[0];
+ }
+ else {
+ throw new
SystemException("error.common.storage.xmldb.query", "No database exists");
+ }
+ }
+ catch(Exception err) {
+ logger.error("LSSummary: Caught XSLT Processing Error");
+ }
+
//We essentually get back a string (but its really a message) so
// using a new XMLUtils function we can get this into NMWG format
Message result = (Message)XMLUtils.stringToElement(output,
lsUtil.getParserFile(), "message");
- r1764 - in branches/yi-udel/perfsonar: schema/example-instances/sonar/LS schema/example-instances/sonar/LS/xquery src/org/perfsonar/service/lookupService/xmlType, svnlog, 11/15/2006
Archive powered by MHonArc 2.6.16.