All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.odysz.semantic.syn.ChangeLogs Maven / Gradle / Ivy

package io.odysz.semantic.syn;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;

import io.odysz.anson.Anson;
import io.odysz.anson.AnsonField;
import io.odysz.module.rs.AnResultset;
import io.odysz.semantic.CRUD;
import io.odysz.semantic.meta.SynChangeMeta;
import io.odysz.semantics.x.SemanticException;

public class ChangeLogs extends Anson {

	public static final String ChangeFlag = "change";

	@AnsonField(ignoreTo=true)
	SynChangeMeta chm;
	
	HashMap nyquvect;

	// HashMap exchangenv;

	/** 
	 * clone {@code nyquvect} into my nyq-vector.
	 * @param nyquvect
	 * @return
	 */
	public ChangeLogs nyquvect(final HashMap nyquvect) {
		this.nyquvect = Nyquence.clone(nyquvect);
		return this;
	}

	/**
	 * 0: change statement, CRUD.C: insert, CRUD.U: remove-subs, CRUD.D: remove-log),
* 1: change-crud,
2: synoder,
3: uids,
4: nyquence
*/ AnResultset answers; public AnResultset challenge; public ChangeLogs challenge(AnResultset challenge) { this.challenge = challenge; return this; } // private boolean dirty; public ChangeLogs(SynChangeMeta changemeta) { this.chm = changemeta; // dirty = false; } /** * Add remove command to change log, chgs. * @param challenge * @param synode * @throws SQLException */ @SuppressWarnings("serial") public void remove_sub(AnResultset challenge, String synode) throws SQLException { if (answers == null) answers = new AnResultset(checkChangeCol(challenge.getColnames())) .results(new ArrayList>() {}); ArrayList row = challenge.getRowAt(challenge.currentRow()-1); row.add(answers.getColumex(ChangeFlag)-1, CRUD.U); answers.append(row); // dirty = true; } public static Nyquence parseNyq(Object[] c) { return new Nyquence((long)c[4]); } /** * Check and extend column {@link #ChangeFlag}, which is for changing flag of change-logs. * * @param answer * @return this */ public static HashMap checkChangeCol(HashMap colnames) { if (!colnames.containsKey(ChangeFlag.toUpperCase())) { colnames.put(ChangeFlag.toUpperCase(), new Object[] {Integer.valueOf(colnames.size() + 1), ChangeFlag}); } return colnames; } public void clear() { challenge = null; answers = null; entities = null; } // public HashMap> entities; HashMap entities; public ChangeLogs entities(String tbl, AnResultset entities) { if (this.entities == null) this.entities = new HashMap(); this.entities.put(tbl, entities); return this; } public ChangeLogs entities(HashMap entities) throws SemanticException { if (this.entities != null) throw new SemanticException("There are entities already exist to be handled."); this.entities = entities; return this; } /** Get challenge's row count */ public int challenges() { return challenge == null ? 0 : challenge.getRowCount(); } public int enitities(String tbl) { return entities != null && entities.containsKey(tbl) ? entities.get(tbl).size() : 0; } public int answers() { return answers == null ? 0 : answers.getRowCount(); } AnResultset synodes; public ChangeLogs synodes(AnResultset rs) { synodes = rs; return this; } public Object enitities() { return this.entities == null ? 0 : this.entities.values().stream().mapToInt(r -> r.getRowCount()).sum(); } private Exchanging step; public Exchanging stepping() { return step; } /** * Set mode and state. * @param m * @param s * @return this */ public ChangeLogs stepping(int m, int s) { step = new Exchanging(m); step.state = s; return this; } private String session; public String session() { return session; } public ChangeLogs session(String ss) { session = ss; return this; } }