import com.softwareag.tamino.db.api.accessor.TQuery; import com.softwareag.tamino.db.api.accessor.TNonXMLObjectAccessor; import com.softwareag.tamino.db.api.accessor.TSystemAccessor; import com.softwareag.tamino.db.api.accessor.TAccessLocation; import com.softwareag.tamino.db.api.common.*; import com.softwareag.tamino.db.api.connection.*; import com.softwareag.tamino.db.api.objectModel.*; import com.softwareag.tamino.db.api.response.*; import java.io.*; public class ProcessNonXMLFile { public ProcessNonXMLFile(String databaseURI, String collection, String filename) throws TConnectionException { // Obtain the connection factory TConnectionFactory connectionFactory = TConnectionFactory.getInstance(); // Obtain the connection to the database connection = connectionFactory.newConnection( databaseURI ); // Obtain the concrete TXMLObjectAccessor accessor = connection.newNonXMLObjectAccessor( TAccessLocation.newInstance( collection ) ); } private void performInsert(TNonXMLObject nonXMLObject) { // TResponse represents an access response from Tamino TResponse response = null; // Insert the non-XML document try { // Invoke the insert operation and obtain the response response = accessor.insert( nonXMLObject ); // Show the collection, doctype and id System.out.println( "Insert succeeded, ino:collection:" + nonXMLObject.getCollection() + ", ino:doctype:" + nonXMLObject.getDoctype() + ", ino:id:" + nonXMLObject.getId() ); } catch (Exception e) { e.printStackTrace(); } } private void performQuery(TQuery query) { // Now lets make a query on the updated object try { TResponse response = accessor.query( query ); // Obtain the TNonXMLObjectIterator from the response TNonXMLObjectIterator iterator = response.getNonXMLObjectIterator(); if ( !iterator.hasNext() ) return; TNonXMLObject nonXMLObject = iterator.next(); // Write the Non-XML content to a ByteArrayOutputStream ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); nonXMLObject.writeTo( outputStream ); System.out.println( "Queried document, Content:" + outputStream ); } catch (Exception e) { e.printStackTrace(); } } private void show() { try { // Instantiate a TNonXMLObject from File with name=filename, in Collection collection // with doctype ino:nonXML, docname=test.smi and Content-Type application/smi. // This document can be referenced directly via URL: // http://DATABASE_URI/COLLECTION/ino:nonXML/test.smi // and the appropriate player should be loaded by the browser (eg Real Player). TNonXMLObject nonXMLObject = TNonXMLObject.newInstance( FILENAME , COLLECTION, "ino:nonXML" , "test.smi" , "application/smi" ); // Initiate the insert. performInsert( nonXMLObject ); // Construct a query expression so that the inserted document can be referenced TQuery query = TQuery.newInstance( nonXMLObject.getDoctype() + "[@ino:id=\"" + nonXMLObject.getId() + "\"]" ); // Initiate the query performQuery( query ); } catch (Exception e) { e.printStackTrace(); } finally { try { // Close the connection connection.close(); } catch (Exception e) { e.printStackTrace(); } } } public static void main(String[] args) throws TException { ProcessNonXMLFile processNonXMLFile = new ProcessNonXMLFile( DATABASE_URI , COLLECTION, FILENAME ); processNonXMLFile.show(); } //*********************** Please change these fields ************************************** // URI of the Tamino database, please edit accordingly private final static String DATABASE_URI = "http://natserv2/tamino/xml2"; // Collection of the Tamino database, please edit accordingly private final static String COLLECTION = "ino:etc"; // Filename for input, please edit accordingly private final static String FILENAME = "E:/Temp/Test.smi"; //***************************************************************************************** // The database connection TConnection connection = null; // The accessor, here a TNonXMLObjectAccessor TNonXMLObjectAccessor accessor = null; }