/* Generated by Together */

package cobalt.deployment.descriptor.dist;

import java.util.Set;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.HashSet;
import java.util.HashMap;

import cobalt.deployment.descriptor.EjbDescriptor;
import cobalt.deployment.descriptor.EntityEjbDescriptor;
import cobalt.deployment.descriptor.MethodDescriptor;
import cobalt.deployment.descriptor.Field;
import cobalt.deployment.descriptor.FieldTable;
import cobalt.deployment.common.MustNotNullException;
import cobalt.deployment.util.CommonUtil;

public class Jeus30CMPEjbDescriptor extends Jeus30EntityEjbDescriptor {
    public Jeus30CMPEjbDescriptor(EjbDescriptor descriptor)
    {
        super(descriptor);
        findMtds = new HashMap();
        fieldmap = new HashMap(); // (Field, column-name)
        primKeys = new HashSet();

        setFetchSize(10);
        setInitCaching(false);

        organize();
    }

    public boolean isInitCaching() {
        return getBoolean("init-caching", false);
    }

    public String isInitCachingValue() {
        return getString("init-caching");
    }

    public void setInitCaching(boolean initCaching) {
        setBoolean("init-caching", initCaching);
    }

    public int getFetchSize() {
        return getInt("fetch-size", 10);
    }

    public String getFetchSizeValue() {
        return getString("fetch-size");
    }

    public void setFetchSize(int fetchSize) {
        setInt("fetch-size", fetchSize);
    }

    public String  getDbVendor() {
        return getString("db-vendor");
    }

    public void setDbVendor(String dbVendor)
    	throws MustNotNullException {
        setString("db-vendor", dbVendor);
    }

    public String  getDsName(){
        return getString("data-source-name");
    }

    public void setDsName(String dsName)
    	throws MustNotNullException {
        setString("data-source-name", dsName);
    }

    public boolean isCreateTable() {
        return getBoolean("is-creating-table", false);
    }

    public String isCreateTableValue() {
        return getString("is-creating-table");
    }

    public void setCreateTable(boolean createTable) {
        setBoolean("is-creating-table", createTable);
    }

    public boolean isDeleteTable() {
        return getBoolean("is-deleting-table", false);
    }

    public String isDeleteTableValue() {
        return getString("is-deleting-table");
    }

    public void setDeleteTable(boolean deleteTable) {
        setBoolean("is-deleting-table", deleteTable);
    }

    public String  getTableName() {
        return getString("table-name");
    }

    public void setTableName(String tableName) {
        setString("table-name", tableName, "");
    }

    public String getIsolationLevel() {
        return getString("isolation-level");
    }

    public void setIsolationLevel(String isolationLevel) {
        setString("isolation-level", isolationLevel, "");
    }

    public void addFindMtd(MethodDescriptor mtd, String sql)
    {
		findMtds.put(mtd, sql);
    }

    public void removeFindMtd(MethodDescriptor mtd)
    {
        findMtds.remove(mtd);
    }

    public static String[] getAvailableTypes()
    {
        return Field.getAvailableTypes();
    }

    public HashMap getFindMtds(){ return findMtds; }

    public Iterator getFindMtdIterator() { return findMtds.keySet().iterator(); }

    public String getFindSql(MethodDescriptor method) { return (String)findMtds.get(method); }

    public void putFindSql(MethodDescriptor method, String sql) {
        findMtds.put(method, sql);
    }

    public void removeFindSql(MethodDescriptor method) {
        findMtds.remove(method);
    }

    public void setFindMtds(HashMap findMtds){ this.findMtds = findMtds; }

    public HashMap getFieldmap(){ return fieldmap; }

    public void setFieldmap(HashMap fieldmap){ this.fieldmap = fieldmap; }

    public Iterator getFieldIterator() { return fieldmap.keySet().iterator(); }

    public String getField(Object field)
    {
        return (String)fieldmap.get(field);
    }

    public void setField(Object field, String columnname)
    {
        fieldmap.put(field, columnname);
    }

    public Field getField(String name)
    {
        EntityEjbDescriptor entity = (EntityEjbDescriptor)descriptor;
        return entity.getFields().getField(name);
    }

    public Set getPrimKeys(){ return primKeys; }

    public Iterator getPrimKeyIterator() { return primKeys.iterator(); }

    public void setPrimKeys(Set primKeys){ this.primKeys = primKeys; }

    public void addPrimKey(String key) {
        primKeys.add(key);
    }
    public void removePrimKey(String key) {
        primKeys.remove(key);
    }
    public boolean containsPrimKey(String key) {
        return primKeys.contains(key);
    }

    public Set getFields()
    {
        return fieldmap.keySet();
    }

    private void organize()
    {
        FieldTable ft = ((EntityEjbDescriptor)descriptor).getFields();
        Field field;
        Enumeration enum = ft.getFieldElements();
        int i=0;
        while ( enum.hasMoreElements() ) {
            field = (Field)enum.nextElement();
            fieldmap.put(field, field.getName());
        }
        Iterator iterator = descriptor.getFinderMethods().iterator();
        while ( iterator.hasNext() ) {
        	addFindMtd((MethodDescriptor)iterator.next(), "");
        }
    }

    public static String[] availableDbVendor =
  		{ "oracle", "informix", "db2", "mssql", "sybase" };
    public static String[] availableIsolationLevel =
	    { "TRANSACTION_SERIALIZABLE", "TRANSACTION_READ_COMMITED" ,
          "TRANSACTION_READ_UNCOMMITED" ,"TRANSACTION_REPEATABLE_READ",
          "TRANSACTION_NONE" };
    private HashMap findMtds;
    private HashMap fieldmap;
    private Set primKeys;
}
