Hi
I’m using Tamino 4.1.4.4 on a Windows 2000 server. I’m having a problem trying to limit the number of record returned from an xquery.
This is the code:
TConnection connection = TConnectionFactory.getInstance().newConnection(databaseURI);
TXMLObjectAccessor accessor = connection.newXMLObjectAccessor(TAccessLocation.newInstance(collectionName), TDOMObjectModel.getInstance());
TLocalTransaction tloc = connection.useLocalTransactionMode();
TXQuery query = TXQuery.newInstance(xqueryString);
TResponse response = accessor.xquery(query, 10);
StringWriter stringWriter = new StringWriter();
if ( response.hasFirstXMLObject() )
{
TXMLObjectIterator toi = response.getXMLObjectIterator();
while (toi.hasNext())
{
TXMLObject to = toi.next();
to.writeTo(stringWriter);
recordCount++;
}
}
The recordCount is 43 despite the xquery having a quantity of 10 specified - xquery(query, 10)
Any ideas?
Hi,
Well, firstly let me tell you that although you find 43 records in the response, it doesn’t mean that all of them are being fetched from a single server response. the Java API for Tamino would fetch you the 10 records ( as mentioned in accessor.xquery() ) first. And, allow you to iterate through the same. The very moment when a hasNext() is issued for the 11th record. the API would make another server call and fetch you the next 10 records, and so on.
Hope that answers your question…
Rahul Roy
Tamino API for Java
Software AG (INDIA)
Hello,
I get the following error trying to use cursors:
Tamino access failure (INOXIE8305, Invalid cursor handle)
I have checked to documentation and cannot find the answer to my problem. I don’t understand the
explanation:
The supplied cursor handle is invalid: either it was never created during the current session, or the corresponding cursor was closed in the meantime.
How do I create a cursor handle?
Thanks in advance,
Julien Martin.
Rahul Roy
That solved it - thankyou very much.
Julien,
Could you kindly elaborate a bit more on this issue? Or perhaps, if possible paste in a sample source that reproduces the issue at your end.
Looking forward to help you solve this…
Rahul Roy
Tamino API for Java
Software AG (INDIA)
Hello Rahul Roy and thanks for the answer,
Here is how my app is built:
1. I have a Service Locator method as follows:
/**
* Method obtaining and returning a TXMLObjectAccessor
* @param uri String e.g. "http://localhost/tamino/estela"
* @param collection String e.g. "ibermarcreferencec"
* @return TXMLObjectAccessor
*/
public TXMLObjectAccessor getTXMLObjectAccessor(String uri, String collection) {
TXMLObjectAccessor xmlObjectAccessor = null;
try {
TConnection connection = TConnectionFactory.getInstance().newConnection(uri);
connection.usesLocalTransactionMode();
xmlObjectAccessor =
connection.newXMLObjectAccessor(
TAccessLocation.newInstance(collection),
TJDOMObjectModel.getInstance());
} catch (TServerNotAvailableException e) {
e.printStackTrace();
}
return xmlObjectAccessor;
}
</pre><BR><BR>2. and an execute method that executes the search:<BR><BR><pre class="ip-ubbcode-code-pre"> /**
* This method is the heart of the search engine. It stores the results into the servlet session as well as the search.
* @return <tt>true</tt> if the search yields a result greater than 0, <tt>false</tt> otherwise.
*/
public boolean execute() {
OPCServiceLocator service_locator = OPCServiceLocator.getInstance();
//TODO: externalize those two strings
TXMLObjectAccessor xmlObjectAccessor = service_locator.getTXMLObjectAccessor("http://localhost/tamino/prueba_2", "ibermarcreferencec");
TXQuery xquery = TXQuery.newInstance(opcquery.getXQuery() + footer);
try {
TResponse response = xmlObjectAccessor.xquery(xquery, 5);
List list = OPCConvertUtil.convertResponseIntoDisplayableList(response);
if (response.hasQueryContent() && response != null) {
OPCSessionUtil.putTResponseIntoSession(response);
OPCSessionUtil.putSearchResultsIntoSession(list);
}
return response.hasQueryContent();
} catch (TXQueryException e) {
e.printStackTrace();
return false;
}
}
Any idea why I get this exception?
Thanks in advance,
Julien Martin. Software AG Spain.
Software AG Spain
Hi Julien,
Sorry for the delay in replying, OK! about your issue - as you mentioned in your personal mail. that the below code works fine :-
connection.useLocalTransactionMode();
response = xmlObjectAccessor.xquery(xquery, 10);
I’d herein like to add something for your information that, the ObjectAccessor.xquery(xquery, 10) method internally uses server side cursors. These server side cursors are managed internally by tamino using the user’s session information, i.e. the user’s session key and session id. This data is obviously not available incase of AutoCommitMode, which eventually results in a failure at tamino’s end whilst trying to re-fetch data in the second call.
Rahul Roy
Tamino API for Java
Software AG (INDIA)