Xquery doesn't free bind variables files
I use XQuery to batch process xml files, to transform them and to push them in a queue. Once the xml of a file is in the queue, I
would like to remove the file form the actual directory.
I can't the xquery context seems not to release the files used as bind variables. Is there a workaround? The new release doesn't
solve the problem.
Here is the example, made with the TestBindString sample of OTN XQuery page and modified, of a program inputting from 3 files that I
would like to move to another folder once treated.
import java.sql.*;
import oracle.xml.parser.v2.*;
import oracle.xquery.*;
import java.io.*;
import java.util.*;
import oracle.xquery.exec.*;
public class testBindString {
public static void main(String argv[]) {
XQueryContext ctx = new XQueryContext();
String path = "C:\\XQuery\\Tutorial";
String[] fNames = {"bib1.xml","bib2.xml","bib3.xml"};
try
{
// create a string from the file
PreparedXQuery xq = ctx.prepareXQuery(
"<bib> { "+
" for $b in document(bind(\"filename\"))/bib/book "+
" where $b/publisher = 'Addison-Wesley' and $b/@year > 1991 "+
" return "+
" <book year='{ $b/@year }'> "+
" { $b/title } "+
" </book> "+
" }</bib>");
// Loop over the input arguments
for (int i = 0; i < fNames.length; i++) {
System.out.println(" Binding value "+i);
xq.setString("filename", path+"\\"+fNames);
System.out.println(" Executing Query... ");
XQueryResultSet rset = xq.executeQuery();
int pos = 0;
while (rset.next()) {
System.out.println(" ---- Fetching Node["+pos+"] ---- ");
pos ++;
XMLNode node = rset.getNode();
System.out.println(" NODE "+ node.getNodeName());
node.print(System.out);
}
File f = new File(path,fNames);
if (f.exists()){
File fbis = new File("C:\\XQuery\\backup",fNames);
if (fbis.exists()) fbis.delete();
boolean success =f.renameTo(fbis);
System.out.println("remove status: " + success);
}
}
}
catch (Exception e)
{
System.out.println(" got exception "+e.getMessage());
}
}
}
James Somers