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

io.odysz.semantic.meta.SynSubsMeta Maven / Gradle / Ivy

package io.odysz.semantic.meta;

import static io.odysz.common.LangExt.len;
import static io.odysz.common.Utils.loadTxt;

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

import io.odysz.module.rs.AnResultset;
import io.odysz.transact.sql.parts.Resulving;

/**
 * syn_sbuscribe DDL
 *
 * @author Ody
 *
 */
public class SynSubsMeta extends SemanticTableMeta {

	final SynChangeMeta chgm;

	public final String changeId;
	// public final String domain;
	// public final String entbl;
	// public final String uids;
	public final String synodee;
	private String[] subcols;

	public SynSubsMeta(SynChangeMeta chgm, String ... conn) {
		super("syn_subscribe", conn);

		changeId= "changeId";
		synodee = "synodee";
		this.chgm = chgm;

		ddlSqlite = loadTxt(SynSubsMeta.class, "syn_subscribe.sqlite.ddl");
	}

	public String[] cols() {
		// return new String[] {domain, entbl, synodee, uids};
		return new String[] {changeId, synodee};
	}

	/**
	 * Generate values for parameter of Insert.values();
	 * 
	 * @param subs row index not the same when return
	 * @param skips ignored synodes
	 * @return values
	 */
	public ArrayList> insubVals(AnResultset subs, Set skips) {
		
		ArrayList> v = new ArrayList>(subs.getRowCount() - len(skips));

		return v;
	}

	/**
	 * @return [changeId, synodee]
	 */
	public String[] insertCols() {
		if (this.subcols == null)
			// this.subcols = new String[] { domain, entbl, synodee, uids };
			this.subcols = new String[] {changeId, synodee}; // FIXME TODO add "domain"
		return subcols;
	}

	/**
	 * 
	 * @param chlogs
	 * @return
	 * @throws SQLException
	 */
	public ArrayList insertSubVal(AnResultset chlogs) throws SQLException {
		String[] cols = insertCols();
		ArrayList val = new ArrayList (cols.length);

		/*
		for (int cx = 0; cx < cols.length; cx++) {
			val.add(new Object[] {cols[cx], chlogs.getString(cols[cx])});
		}
		*/
		val.add(new Object[] {cols[0], chlogs.getString(chgm.pk)});
		val.add(new Object[] {cols[1], chlogs.getString(synodee)});

		return val;
	}

	@SuppressWarnings("serial")
	public ArrayList insertSubVal(String org, String entbl, String synodee, String uds) throws SQLException {
		return new ArrayList() {

			/*
			{add(new Object[] {subcols[0], org});}
			{add(new Object[] {subcols[1], entbl});}
			{add(new Object[] {subcols[2], synodee});}
			{add(new Object[] {subcols[3], uids});}
			*/
			{add(new Object[] {changeId, new Resulving(chgm.tbl, chgm.pk)});}
			{add(new Object[] {subcols[2], synodee});}
		};
	}

	/**
	 * ISSUE: why not merge with {@link SyntityMeta#replace()}?
	 * @return
	 * @throws SQLException
	 * @throws TransException
	public SynSubsMeta replace() throws SQLException, TransException {
		TableMeta mdb = Connects.getMeta(conn, tbl);
		if (!(mdb instanceof SyntityMeta))
			DBSynmantics.replaceMeta(tbl, this, conn);
		if (isNull(this.ftypes) && mdb.ftypes() != null)
			this.ftypes = mdb.ftypes();
		return this;
	}
	 */
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy