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

io.odysz.module.xtable.DefaultTableStruct Maven / Gradle / Ivy

There is a newer version: 1.5.3
Show newest version
package io.odysz.module.xtable;

import java.util.LinkedHashMap;

public class DefaultTableStruct implements ITableStruct {
	protected static final String attrNameTableID = "tableID";
	protected static final String attrNameColumns = "columns";
	protected static final String attrNamePks = "pk";
	
	protected LinkedHashMap pkIdx;
	protected String pkDef;
	protected LinkedHashMap colIdx;
	protected String colDef;

	public DefaultTableStruct(String colDefs, String pkDefs) {
		pkDef = pkDefs;
		colDef = colDefs;
	}
	
	@Override
	public LinkedHashMap pkIdx() {
		if (pkIdx == null) {
			pkIdx = buildIdx(pkDef);
		}
		return pkIdx;
	}
	
	@Override
	public String pkDefs() {
		return pkDef;
	}
	
	@Override
	public LinkedHashMap colIdx() {
		if (colIdx == null) {
			colIdx = buildIdx(colDef);
		}
		return colIdx;
	}
	
	protected static LinkedHashMap buildIdx(String defs) {
		if (defs == null) return null;
		LinkedHashMap idx = new LinkedHashMap();
		String[] fns = defs.split(",");
		if (fns == null) return null;
		for (int i = 0; i < fns.length; i++)
			idx.put(fns[i].trim(), i);
		return idx;
	}

	@Override
	public String colDefs() {
		return colDef;
	}
	
	@Override
	public String attrTableID() {
		return attrNameTableID;
	}
	
	@Override
	public String attrPks() {
		return attrNamePks;
	}
	
	@Override
	public String attrCols() {
		return attrNameColumns;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy