[Mulgara-svn] r519 - branches/nw-interface/src/jar/itql/java/org/mulgara/itql
pag at mulgara.org
pag at mulgara.org
Tue Nov 6 21:42:27 UTC 2007
Author: pag
Date: 2007-11-06 15:42:26 -0600 (Tue, 06 Nov 2007)
New Revision: 519
Modified:
branches/nw-interface/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBean.java
Log:
Cleaned up formatting, added generics, and removed all warnings. This last one required suppressing warnings for use of deprecated methods, since we are keeping them going for legacy clients.
Modified: branches/nw-interface/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBean.java
===================================================================
--- branches/nw-interface/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBean.java 2007-11-06 21:40:09 UTC (rev 518)
+++ branches/nw-interface/src/jar/itql/java/org/mulgara/itql/ItqlInterpreterBean.java 2007-11-06 21:42:26 UTC (rev 519)
@@ -31,7 +31,6 @@
import java.io.*;
import java.net.MalformedURLException;
import java.net.URI;
-import java.net.URISyntaxException;
import java.util.*;
import javax.xml.soap.SOAPException;
import org.w3c.dom.*;
@@ -146,7 +145,7 @@
*/
public static String[] splitQuery(String multiQuery) {
- List singleQueryList = new ArrayList();
+ List<String> singleQueryList = new ArrayList<String>();
// Inside a URI?
boolean INSIDE_URI = false;
@@ -157,11 +156,8 @@
// Start index for next single query
int startIndex = 0;
- if (log.isDebugEnabled()) {
+ if (log.isDebugEnabled()) log.debug("About to break up query: " + multiQuery);
- log.debug("About to break up query: " + multiQuery);
- }
-
multiQuery = multiQuery.trim();
// Iterate along the multi query and strip out the single queries.
@@ -175,59 +171,39 @@
// (OK so maybe it won't appear in a legal URI but let things further
// down handle this)
case '\'':
-
if (!INSIDE_URI) {
-
if (INSIDE_TEXT) {
-
// Check for an \' inside a literal
if ( (lineIndex > 1) && (multiQuery.charAt(lineIndex - 1) != '\\')) {
-
INSIDE_TEXT = false;
}
} else {
-
INSIDE_TEXT = true;
}
}
-
break;
// URI start - if not in a literal
case '<':
-
if (!INSIDE_TEXT) {
-
INSIDE_URI = true;
}
-
break;
// URI end - if not in a literal
case '>':
-
if (!INSIDE_TEXT) {
-
INSIDE_URI = false;
}
-
break;
case ';':
-
if (!INSIDE_TEXT && !INSIDE_URI) {
-
- String singleQuery =
- multiQuery.substring(startIndex, lineIndex + 1).trim();
+ String singleQuery = multiQuery.substring(startIndex, lineIndex + 1).trim();
startIndex = lineIndex + 1;
singleQueryList.add(singleQuery);
-
- if (log.isDebugEnabled()) {
-
- log.debug("Found single query: " + singleQuery);
- }
+ if (log.isDebugEnabled()) log.debug("Found single query: " + singleQuery);
}
-
break;
default:
@@ -236,11 +212,10 @@
// Lasy query is not terminated with a ';'
if (startIndex < multiQuery.length()) {
-
singleQueryList.add(multiQuery.substring(startIndex, multiQuery.length()));
}
- return (String[]) singleQueryList.toArray(new String[singleQueryList.size()]);
+ return singleQueryList.toArray(new String[singleQueryList.size()]);
}
/**
@@ -277,7 +252,8 @@
*
* @return the alias namespace map associated with this bean.
*/
- public Map getAliasMap() {
+ @SuppressWarnings("deprecation")
+ public Map<String,URI> getAliasMap() {
return this.interpreter.getAliasesInUse();
}
@@ -295,8 +271,8 @@
/**
* Begin a new transaction by setting the autocommit off
*
- * @param name the name of the transaction ( debug purposes only )
- * @throws QueryException EXCEPTION TO DO
+ * @param name the name of the transaction (debug purposes only)
+ * @throws QueryException Error setting up the transaction.
*/
public void beginTransaction(String name) throws QueryException {
@@ -308,7 +284,7 @@
// do what the autointerpreter does, but don't worry about the result
Connection localConnection = interpreter.getLocalConnection();
autocommitCmd.execute(localConnection);
- interpreter.updateOnConnectionState(localConnection);
+ interpreter.updateConnectionsForTx(localConnection, autocommitCmd);
} catch (QueryException qe) {
throw qe;
} catch (Exception e) {
@@ -433,24 +409,24 @@
}
}
+
/**
* Answer TQL queries.
*
- * @param queryString PARAMETER TO DO
+ * @param queryString A query to execute
* @return the answer String to the TQL query
- * @throws Exception EXCEPTION TO DO
+ * @throws Exception General exception type to cover all possible conditions,
+ * including bad query syntax, network errors, unknown graphs, etc.
*/
public String executeQueryToString(String queryString) throws Exception {
-
String result = DOM2Writer.nodeToString(this.execute(queryString), false);
- if (log.isDebugEnabled()) {
- log.debug("Sending result to caller : " + result);
- }
+ if (log.isDebugEnabled()) log.debug("Sending result to caller : " + result);
return result;
}
+
/**
* Executes a semicolon delimited string of queries. <p>
*
@@ -475,11 +451,11 @@
* org.mulgara.query.Answer}, the messages are {@link
* java.lang.String}s
*/
- public List executeQueryToList(String queryString) {
-
+ public List<Object> executeQueryToList(String queryString) {
return executeQueryToList(queryString, false);
}
+
/**
* Executes a semicolon delimited string of queries. <p>
*
@@ -498,22 +474,17 @@
* {@link org.mulgara.query.Answer} or a {@link java.lang.String} (error)
* message. </p>
*
- * @param queryString semi-colon delimited string containing the queries to be
- * executed
+ * @param queryString semi-colon delimited string containing the queries to be executed
* @param keepExceptions return exceptions, don't convert them to a string.
- * @return a list of answers, messages and errors, answers are of type {@link
- * org.mulgara.query.Answer}, the messages are {@link
- * java.lang.String}s
+ * @return a list of answers, messages and errors, answers are of type
+ * {@link org.mulgara.query.Answer}, the messages are {@link java.lang.String}s
*/
- public List executeQueryToList(String queryString, boolean keepExceptions) {
+ public List<Object> executeQueryToList(String queryString, boolean keepExceptions) {
- List answers = new ArrayList();
+ List<Object> answers = new ArrayList<Object>();
- if (log.isDebugEnabled()) {
+ if (log.isDebugEnabled()) log.debug("Received a TQL query : " + queryString);
- log.debug("Received a TQL query : " + queryString);
- }
-
String[] queries = splitQuery(queryString);
for (int queryIndex = 0; queryIndex < queries.length; queryIndex++) {
@@ -521,21 +492,17 @@
String singleQuery = queries[queryIndex];
// Resolve the query
- if (log.isDebugEnabled()) {
+ if (log.isDebugEnabled()) log.debug("Executing query : " + singleQuery);
- log.debug("Executing query : " + singleQuery);
- }
-
- // end if
// execute it
answers.add(this.executeQueryToNiceResult(singleQuery, keepExceptions));
}
- // end for
// Send the answers back to the caller
return answers;
}
+
/**
* Executes a {@link java.util.Map} of queries, returning the results of those
* queries in a map keyed with the same keys as the input map. <p>
@@ -576,35 +543,29 @@
* @param queries a map of keys to queries to be executed
* @return a map of answers and error messages
*/
- public Map executeQueryToMap(Map queries) {
+ public Map<Object,Object> executeQueryToMap(Map<Object,String> queries) {
// create the answer map
- HashMap answers = new HashMap();
+ HashMap<Object,Object> answers = new HashMap<Object,Object>();
// iterate over the queries
- for (Iterator keyIter = queries.keySet().iterator(); keyIter.hasNext(); ) {
+ for (Iterator<Object> keyIter = queries.keySet().iterator(); keyIter.hasNext(); ) {
// get the key and the query
Object key = keyIter.next();
- String query = (String) queries.get(key);
+ String query = queries.get(key);
// log the query we're executing
- if (log.isDebugEnabled()) {
+ if (log.isDebugEnabled()) log.debug("Executing " + key + " -> " + query);
- log.debug("Executing " + key + " -> " + query);
- }
-
- // end if
// execute the query
answers.put(key, this.executeQueryToNiceResult(query, false));
}
- // end for
// return the answers
return answers;
}
- // getSession()
/**
* Builds a {@link org.mulgara.query.Query} from the given <var>query</var>.
@@ -653,16 +614,14 @@
try {
answer.close();
} catch (TuplesException te) { /* use the following exception */ }
- throw new IllegalStateException("The execute update method should not " +
- "return an Answer object!");
- }
- if (exception != null) {
-
- throw exception;
+ throw new IllegalStateException("The execute update method should not return an Answer object!");
}
+
+ if (exception != null) throw exception;
}
+
/**
* Returns true if a quit command has been entered, simply calls the
* interpreter.isQuitRequested.
@@ -686,7 +645,6 @@
* @see ItqlInterpreter#getLastMessage()
*/
public String getLastMessage() {
-
return interpreter.getLastMessage();
}
@@ -713,7 +671,6 @@
* @throws ItqlInterpreterException if the query fails.
*/
public Answer executeQuery(String itql) throws ItqlInterpreterException {
-
try {
executeCommand(itql);
} catch (Exception e) {
@@ -762,7 +719,8 @@
return numberOfStatements;
}
- /**
+
+ /**
* Backup all the data on the specified server or model to a client local file.
* The database is not changed by this method.
*
@@ -782,6 +740,7 @@
}
}
+
/**
* Backup all the data on the specified server to an output stream.
* The database is not changed by this method.
@@ -800,6 +759,7 @@
}
}
+
/**
* Load the contents of an InputStream into a database/model. The method assumes
* the source to be RDF/XML.
@@ -816,6 +776,7 @@
return load(inputStream, DUMMY_RDF_SOURCE, destinationURI);
}
+
/**
* Load the contents of an InputStream or a URI into a database/model.
* <p>
@@ -846,6 +807,7 @@
return numberOfStatements;
}
+
/**
* Restore all the data on the specified server. If the database is not
* currently empty then the database will contain the union of its current
@@ -859,6 +821,7 @@
restore(inputStream, serverURI, DUMMY_RDF_SOURCE);
}
+
/**
* Restore all the data on the specified server. If the database is not
* currently empty then the database will contain the union of its current
@@ -900,10 +863,7 @@
Element variables = (Element) parent.appendChild(VARIABLES);
for (int column = 0; column < answer.getVariables().length; column++) {
-
- Element variable =
- (Element) variables.appendChild(doc.createElement(
- answer.getVariables()[column].getName()));
+ variables.appendChild(doc.createElement(answer.getVariables()[column].getName()));
}
// Add any solutions
@@ -918,9 +878,7 @@
Object object = answer.getObject(column);
// If the node is null, don't add a tag at all
- if (object == null) {
- continue;
- }
+ if (object == null) continue;
// Otherwise, add a tag for the node
Element variable =
@@ -963,8 +921,9 @@
} catch (TuplesException e) {
throw new QueryException("Couldn't build query", e);
}
- } // appendSolutions
+ }
+
//
// Internal methods
//
@@ -993,14 +952,12 @@
// log the query response
if (log.isDebugEnabled()) {
-
log.debug("Query response message = " + interpreter.getLastMessage());
}
// end if
// turn the answer into a form we can handle
if (answer != null) {
-
// set this as the answer
result = answer;
} else {
@@ -1010,25 +967,20 @@
// error has occurred at the interpreter
if (log.isDebugEnabled()) {
-
- log.debug("Adding query error to map - " +
- this.interpreter.getLastException());
+ log.debug("Adding query error to map - " + this.interpreter.getLastException());
}
// end if
// set this as the answer
if (keepExceptions) {
-
result = this.interpreter.getLastException();
} else {
-
result = this.interpreter.getLastException().getMessage();
}
} else {
// log that we're adding the response message
if (log.isDebugEnabled()) {
-
log.debug("Adding response message to map - " + interpreter.getLastMessage());
}
@@ -1044,7 +996,6 @@
} catch (Exception e) {
if (keepExceptions) {
-
result = e;
} else {
@@ -1053,7 +1004,6 @@
Throwable lastCause = e;
while (cause != null) {
-
lastCause = cause;
cause = cause.getCause();
}
@@ -1063,7 +1013,6 @@
String exceptionMessage = lastCause.getMessage();
if (exceptionMessage == null) {
-
exceptionMessage = lastCause.toString();
}
@@ -1073,7 +1022,6 @@
// log the message
if (log.isDebugEnabled()) {
-
log.debug(exceptionMessage);
}
@@ -1093,11 +1041,10 @@
}
}
- // try-catch
- // return the result
return result;
}
+
/**
* Sets the serverURI of the interpreter. This method now does nothing.
* @param serverURI The new URI of the server for the interpreter
@@ -1108,11 +1055,13 @@
// Do nothing
}
+
/**
* Sets the aliases associated with this bean.
*
* @param aliasMap the alias map associated with this bean
*/
+ @SuppressWarnings("deprecation")
public void setAliasMap(HashMap<String,URI> aliasMap) {
((TqlInterpreter)parser).setAliasMap(aliasMap);
interpreter.setAliasesInUse(aliasMap);
@@ -1121,6 +1070,7 @@
/**
* Clears the last error of the interpreter.
*/
+ @SuppressWarnings("deprecation")
public void clearLastError() {
// Set the last error to be null
interpreter.clearLastException();
@@ -1132,14 +1082,10 @@
* container or the user has not called close().
*/
protected void finalize() throws Throwable {
-
try {
-
// close the interpreter session
this.close();
-
} finally {
-
super.finalize();
}
}
More information about the Mulgara-svn
mailing list