io.odysz.semantic.syn.ExchangeBlock Maven / Gradle / Ivy
package io.odysz.semantic.syn;
import java.io.PrintStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import io.odysz.anson.Anson;
import io.odysz.module.rs.AnResultset;
import io.odysz.semantic.CRUD;
public class ExchangeBlock extends Anson {
public static final String ExchangeFlagCol = "change";
public String srcnode;
public String peer;
public HashMap nv;
public AnResultset chpage;
public HashMap entities;
public AnResultset anspage;
/**
* Is the synode has more challenge blocks, which is
* need to behandled before closing exchange?
*/
public boolean hasmore() {
return chpage != null && chpage.size() > 0
|| anspage != null && anspage.size() > 0;
}
public ExchangeBlock(String src, String peer, String sessionId, ExessionAct exstate) {
srcnode = src;
session = sessionId;
act = exstate.state;
this.peer = peer;
}
public ExchangeBlock nv(HashMap nyquvect) {
nv = Nyquence.clone(nyquvect);
return this;
}
public int enitities() {
return entities == null ? 0
: entities.values()
.stream()
.filter(rs -> rs != null)
.mapToInt(rs -> rs.getRowCount()).sum();
}
public int answers() {
return anspage != null ? anspage.size() : 0;
}
public int enitities(String tbl) {
return entities == null || !entities.containsKey(tbl)
? 0 : entities.get(tbl).getRowCount();
}
/**
* Copy answer from {@code p}
*
* @param p
* @return this
*/
public ExchangeBlock answers(ExessionPersist p) {
this.anspage = p.answerPage;
return this;
}
public void removeChgsub(AnResultset challenpage, String synode) throws SQLException {
if (challenpage == null)
return;
if (anspage == null) {
// anspage = new ArrayList>();
HashMap cols = challenpage.colnames();
if (!cols.containsKey(ChangeLogs.ChangeFlag.toUpperCase()))
cols.put(ChangeLogs.ChangeFlag.toUpperCase(),
new Object[] {cols.size() + 1, // column index state at 1
ChangeLogs.ChangeFlag});
anspage = new AnResultset(cols);
}
if (challenpage != null) {
ArrayList
© 2015 - 2025 Weber Informatics LLC | Privacy Policy