ZTBCookbook

From AnalysisWiki

Jump to: navigation, search

[edit] About this page

This page contains useful recipes for ZTB-related stuff.

[edit] Basic pattern

           import com.knowledgeforum.k5.common.K5TBConnector;

           import org.zoolib.ZTuple;
           import org.zoolib.ZTxn;
           import org.zoolib.tuplebase.ZTB;
           import org.zoolib.tuplebase.ZTBIter;
           import org.zoolib.tuplebase.ZTBQuery;
           import org.zoolib.tuplebase.ZTBSpec;
           import org.zoolib.tuplebase.ZTBTxn;

           String host = "my.fqdn.host.com";
           int port = 26026;
           String db = "My Database";
           String pass = "somethingobscure";

           K5TBConnector.HostInfo theHI_Raw = new K5TBConnector.HostInfo(host, port, db);
           ZTB tb = K5TBConnector.sGetTB_Raw(theHI_Raw, null, pass);
           if (tb == null) {
           	System.out.println("no TB connection");
           	System.exit(1);
           }
           for (;;) {
          	ZTxn txn = new ZTxn();
           	ZTBTxn tbTxn = new ZTBTxn(txn,tb);
          	ZTBQuery authors = new ZTBQuery(ZTBSpec.sEquals("Object", "author"));
           	for (ZTBIter authorsIter = new ZTBIter(tbTxn, authors); authorsIter.hasValue(); authorsIter.advance()) {
           		ZTuple a = authorsIter.get();
           		String aName = a.getString("fnam") + " " + a.getString("lnam") + " (" + a.getString("unam") + ") ";
           		}
           	if (txn.commit()) break;
           	}

[edit] How to retrieve a single tuple from a ZTBSpec

Say you create a ZTBSpec that you know will return a single ZTuple, or that you're only interested in the first returned value. Use something like:

ZTBSpec problemSpec = ZTBSpec.sEquals("Link", "addresses").and(ZTBSpec.sEquals("from", new ZID(iParentID)));
String problem = (new ZTBIter(iTBTxn, problemSpec)).get().getString("text");

Personal tools