Tamino Samples in Java

I am just in Tamino. Can anyone provide some samples in Java, on insert/update records in Tamino.

Thanks in advance,
N.V.Sairam.

Hi,
I am using the DOM API for Java to perform operations on the Tamino DB…
Here is a sample code showing how you can insert a record in a Tamino DB.

import com.softwareag.tamino.api.dom.;
import org.w3c.dom.
;

public class myClass {

public insertRecord(Element element)
{
try
{
TaminoClient tamino = new TaminoClient(“http://localhost/tamino/mydb/mycollection”);
tamino.startSession();
TaminoResult tr= tamino.insert(element);
tamino.commit(false);
tamino.endSession();
}
catch (TaminoError e){
System.out.println("Tamino Error Text: " + e.errorText );
System.out.println("Tamino Error Code: " + e.responseCode );
}
}
}

You can find more samples along with the full API reference in the section named “HTTP Client API for Java” under DOM APIs in Tamino documentation.

Hope this helps.

if you have questions feel free to drop a mail …
Regards, Johann

import java.io.;
import java.util.
;
import java.text.;

import org.w3c.dom.;
import com.docuverse.dom.;
import com.softwareag.tamino.api.dom.
;

import javax.xml.transform.;
import javax.xml.transform.stream.
;
import javax.xml.transform.dom.*;

/**
* Title:
* Description:
* Copyright: Copyright © 2001
* Company:
* @author
* @version 1.0
*/

public class TClientDemo {

public TClientDemo() {
}

public static void main(String[] args) {
try {
TClientDemo tClientDemo1 = new TClientDemo();
TaminoClient tamino = new TaminoClient(“http://localhost/tamino/xmldb”);
Integer rc;

tamino.setAcceptCharset(“UTF-8”); // the charset we want our documents to be coded
tamino.setPageSize(0); // pagesize 0 returns the result set as a whole
tamino.startSession(); // open a session

TaminoResult tr = tamino.query("//article[//author ~= ‘stonebraker’]", “sigmod”);
rc = new Integer(tr.getReturnValue());
if (rc.intValue() > 0) {
System.out.println(tr.toString());
}
else {
// print the title of each article found, using the DOM API
System.out.println(tr.getTotalCount() + " documents returned");
System.out.println("-- Now using DOM API");
Enumeration articleList = tr; // TaminoResult implements the Enumeration interface
int i = 1;
while (articleList.hasMoreElements()) {
Element el = (Element)articleList.nextElement();
System.out.print(el.getNodeName() + " " + i++ + “: “);
System.out.println(el.getElementsByTagName(“title”).item(0).getChildNodes().item(0).getNodeValue());
}

// print the title of each article found, using a style sheet and the SAXON XSLT processor
System.out.println(”-- Now using SAXON stylesheet processor”);
TransformerFactory factory = TransformerFactory.newInstance();
Templates template = factory.newTemplates(new StreamSource(new File(“sigmod.xsl”)));
Transformer transformer = template.newTransformer();
StringWriter result = new StringWriter();

transformer.transform(new DOMSource(tr.getDocument()), new StreamResult(result));
System.out.println(result.getBuffer());

// fetch ol’ Atkins from the patients in the sample collection
System.out.println("-- Now fetching and modifying good ol’ Atkins");

tr = tamino.query("/patient[name/surname = ‘Atkins’]", “sample”);
rc = new Integer(tr.getReturnValue());
if (rc.intValue() > 0) {
System.out.println(tr.toString());
}
System.out.println(tr.getTotalCount() + " documents returned");

// get the Document - we need it for creating new nodes
Document responseDoc = tr.getDocument();
// extract the patient from the whole Tamino response
Element patient = (Element)tr.getElement().getFirstChild();
// locate the tag - we need it as an anchor for locating the position of the new
Element submitted = (Element)patient.getElementsByTagName(“submitted”).item(0);

// create a new
Element examination = responseDoc.createElement(“examination”);

// create a new
Element date = responseDoc.createElement(“date”);
// create a #text node, fill it with the system date and append it to
date.appendChild(responseDoc.createTextNode(new SimpleDateFormat(“yyyyMMdd:HHmmssSSS”).format(new Date())));
// append the to
examination.appendChild(date);

// create a new , create #text node, append #text to - same as above
Element remarks = responseDoc.createElement(“remarks”);
remarks.appendChild(responseDoc.createTextNode(“this is a remark”));
examination.appendChild(remarks);

// insert into s child list, before the right sibling (if any) of submitted
patient.insertBefore(examination, submitted.getNextSibling());

// update the in Tamino
tr = tamino.update(patient, “sample”, “patient”);
rc = new Integer(tr.getReturnValue());
if (rc.intValue() > 0) {
System.out.println(tr.toString());
}

tamino.commit(false);
}
tamino.endSession(); // close the session
}
catch (TaminoError e){
System.out.println("Tamino Error Text: " + e.errorText );
System.out.println("Tamino Error Code: " + e.responseCode );
e.printStackTrace();
}
catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}

Here’s Johann’s previous example of Saxon and Tamino morphed into a servlet:

code:

import java.io.;
import javax.servlet.
;
import javax.servlet.http.;

import javax.xml.transform.;
import javax.xml.transform.dom.;
import javax.xml.transform.stream.
;
import com.softwareag.tamino.api.dom.*;


public class TaminoSaxonServlet2 extends HttpServlet {

public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(“text/html”);
PrintWriter writer = response.getWriter();

// get input parms from request
String field = request.getParameter(“field”);
String value = request.getParameter(“value”);

// call Tamino with parms
TaminoClient taminoClient;
TaminoResult taminoResult;
try {
taminoClient = new TaminoClient(“http://my.url/tamino/testdb/events2 \n”);
taminoClient.startSession();
taminoClient.setPageSize(20);
taminoResult = taminoClient.query(“event[//” + field + “=”" + value + “”]");
taminoClient.endSession();
}
catch (TaminoError e) {
writer.println("Error contacting Tamino: "
+ e + “

”);
return;
}

// transform tamino result directly into servlet response
try {
TransformerFactory factory = TransformerFactory.newInstance();
Templates template = factory.newTemplates(
new StreamSource(new File(
“C:\tomcat_apps\samps\samps_webapp\events.xsl”)));
Transformer transformer = template.newTransformer();
transformer.transform(new DOMSource(taminoResult.getDocument()),
new StreamResult(writer) );
}
catch (TransformerException e) {
writer.println("Error applying stylesheet: "
+ e + “

”);
return;
}
}
}


hai,
I am a new user to tamino. I am trying to run the samples given by the software itself. These are the steps i did.

1. I created a database using tamino manager with name “durga”.
2. I created a collection Globalcol through X-plorer toll .
3. I tried to run the sample Demoinsert, I run this like in this way
java DemoInsert http://localhost/tamino/durga/Globalcol
Then the output was Telephone[@LoginName=“Wehlmann125”] not found.


Even i tried to run demoPing sample also it is also giveng some error. Till now i am run any sample properly.

Plase help me if anybody knows about it

Another small question.
Can’t we store xml documents with out DTD or SCHEMA in the tamino.

Thanks inadvance.
Dhiraja

Hi Dhiraja,

was there a stacktrace with either error? If so, could you please post them so we can see some further information?

A simple way of testing that the various Tamino components are working is to issue a query from a Web Browser.
Perhaps this discussion will help you find the problem.

It is possible to store XML documents without a DTD/Schema in Tamino, in the ino:etc collection.

Cheers,
Trevor.

Hello,

I saw in tamino FAQ that we can store we formed xml files without schema/DTD into tamino database. If anybody knows how to do it. Plase help me.


regards
dhiraja

Hi Dhiraja,

it is possible to store “schema-less” documents into the “ino:etc” collection.

Cheers,
Trevor.

hai trevor,

Thank you for your reply. I follwed that discussion. The same type errors i am getting. There you wrote that check your webserver configuration. That thing is little bit confusing. If you tell me clearly what are the i have to follow. that is very helpful for me. i tried in this way.

When i am giving this URL : ttp://localhost/tamino/Welcome3_1_1_4?diagnose=Ping , it is giving the following message.

<?xml version="1.0" encoding="iso-8859-1" ?>

- <ino:response xmlns:ino=“http://namespaces.softwareag.com/tamino/response2” xmlns:xql=“http://metalab.unc.edu/xql/”>

- <ino:message ino:returnvalue=“8554”>

<ino:messagetext ino:code=“INOXME8554”>No message received</ino:messagetext>

</ino:message>

</ino:response>

Than what should i do?

Thank your once again.

regards

dhiraja

Hi Dhiraja,

I must apologize: the previous posting in which I mentioned the use of the “diagnose” command is not entirely clear.
The Tamino command is actually “_diagnose” with an underscore character at the beginning.
(This gets lost in the posted URL, because the Browser underlines the whole URL…)

Please try this link: http://localhost/tamino/Welcome3_1_1_4?_diagnose=Ping and see what happens.

Thanks,
Trevor.

hi,

I read the same i.e you can store the schema-less documents in ino:etc collection. But my problem is that how can i create that collection. Is there any steps to do that. I am doing a project using xml in that i could not write schemas because it will add new elements in runtime and then it will send it to database.


Thanks
Dhiraja

Hi Dhiraja,

the ino:etc collection is an internal Tamino collection, so you don’t need to create it yourself.

I’m not 100% sure about the logistics of this collection’s creation - I remember there being something about it not being listed until there was something inserted into it.

Perhaps you should just try to insert your documents into ino:etc using your program, then report back (to the Forums) if you receive an error.

HTH,
Trevor.

hi,

I am able to insert sehema-less documents into ino:etc collection. Thank you

regards
Bhavnai