// build BEL kam node label
Integer tid = node2term.get(i);
String nl = terms.get(tid);
List<Integer> pids = tpmtidx.get(tid);
for (Integer pid : pids) {
TableParameter param = pt.getTableParameter(pid);
TableNamespace ns = param.getNamespace();
nl = nl.replaceFirst("#", ns == null ?
quoteParameter(param.getValue()) :
ns.getPrefix() + ":" + quoteParameter(param.getValue()));
}
Integer knl = valueIndexMap.get(nl);
if (knl == null) {
knl = saveObject(1, nl);
valueIndexMap.put(nl, knl);
}
String tf = nl.substring(0, nl.indexOf('('));
int fv = FunctionEnum.getFunctionEnum(tf).getValue();
// XXX offset
knps.setInt(1, eqId + 1);
knps.setInt(2, fv);
knps.setInt(3, knl);
knps.addBatch();
}
knps.executeBatch();
PreparedStatement knpps = getPreparedStatement(KAM_NODE_PARAMETER_SQL);
PreparedStatement knups = getPreparedStatement(KAM_PARAMETER_UUID_SQL);
final Map<Integer, Integer> gpi = pt.getGlobalIndex();
final Map<Integer, SkinnyUUID> guu = pt.getGlobalUUIDs();
final Set<Integer> seenKamNodes = sizedHashSet(nodes.size());
final Set<Integer> seenGlobalIds = sizedHashSet(gpi.size());
// load kam node parameters
final Map<Integer, Integer> nti = pnt.getNodeTermIndex();
for (int i = 0, n = nodes.size(); i < n; i++) {
final Integer ti = nti.get(i);
// XXX offset
final Integer eqId = eqn.get(i) + 1;
// don't add kam node parameters if we have already seen the
// equivalent node.
if (seenKamNodes.contains(eqId)) {
continue;
}
List<Integer> gtpl = tpmtidx.get(ti);
if (hasItems(gtpl)) {
for (int j = 0; j < gtpl.size(); j++) {
// get parameter index, retrieve global parameter, and set
Integer parameterIndex = gtpl.get(j);
final Integer gid = gpi.get(parameterIndex);
// XXX offset
knpps.setInt(1, gid + 1);
knpps.setInt(2, eqId);
knpps.setInt(3, j);
knpps.addBatch();
if (seenGlobalIds.contains(gid)) {
continue;
}
SkinnyUUID uuid = guu.get(gid);
if (uuid != null) {
// XXX offset
knups.setInt(1, gid + 1);
knups.setLong(2, uuid.getMostSignificantBits());
knups.setLong(3, uuid.getLeastSignificantBits());
knups.addBatch();
}
seenGlobalIds.add(gid);
}
}
// track equivalent kam node
seenKamNodes.add(eqId);
}
knpps.executeBatch();
PreparedStatement pps = getPreparedStatement(TERM_PARAMETER_SQL);
PreparedStatement tps = getPreparedStatement(TERM_SQL);
final Map<Integer, Integer> termNodes = pnt.getTermNodeIndex();
// load term parameters and terms
int tpindex = 0;
for (int ti = 0; ti < terms.size(); ti++) {
String t = terms.get(ti);
// find node equivalence
Integer nodeId = termNodes.get(ti);
// XXX offset
final Integer eqId = eqn.get(nodeId) + 1;
Integer ctl = valueIndexMap.get(t);
if (ctl == null) {
ctl = saveObject(1, t);
valueIndexMap.put(t, ctl);
}
// XXX offset
tps.setInt(1, ti + 1);
// XXX offset
tps.setInt(2, eqId);
tps.setInt(3, ctl);
tps.addBatch();
int ord = 0;
List<Integer> pl = tpmtidx.get(ti);
if (hasItems(pl)) {
for (Integer pi : pl) {
TableParameter p = pt.getIndexTableParameter().get(pi);
Integer cpv = valueIndexMap.get(p.getValue());
if (cpv == null) {
cpv = saveObject(1, p.getValue());
valueIndexMap.put(p.getValue(), cpv);
}
final Integer gid = gpi.get(pi);
// XXX offset
pps.setInt(1, tpindex + 1);
// XXX offset
pps.setInt(2, gid + 1);
// XXX offset
pps.setInt(3, ti + 1);
// find index for the parameter's namespace
TableNamespace tn = p.getNamespace();
Integer ni = null;
if (tn != null) {
ni = nt.getNamespaceIndex().get(tn);
}