/*
 * Created on Nov 24, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package gov.nasa.jsc.plum.DBManager;

import java.io.Serializable;

/**
 * @author randrews
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Field implements Cloneable, Serializable{

    private String name,type,defaultvalue,extra;
    private boolean canbenull,key,unique;
    
    
    
    /**
     * @param name The name of the field
     * @param type The type of the field
     */
    public Field(String name, String type) {
        super();
        this.name = name;
        this.type = type;
        canbenull=true;
        key=false;
        unique=false;
        defaultvalue="NULL";
        extra="";
        
    }
    
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
    
    /**
     * @param name The name of the field
     * @param type The type of the field
     * @param defaultvalue The default value
     * @param extra Any extra properties
     * @param canbenull The null-allowed flag
     * @param unique Whether the field must have unique values
     * @param key Whether this is a primary key
     */    
    public Field(String name,String type,boolean canbenull,boolean key,boolean unique,String defaultvalue,String extra){
        this.name=name;
        this.type=type;
        this.canbenull=canbenull;
        this.key=key;
        this.unique=unique;
        this.defaultvalue=defaultvalue;
        this.extra=extra;
    }
    
    
    public String toString(){
        String str="";
        str=name+" "+type;
        if(!getNull())str+=" not null";
        if(!type.startsWith("blob")) // BLOBs can't have default values
            if(type.startsWith("varchar"))
                str+=" default \""+getDefault()+"\"";
            else
                str+=" default "+getDefault();
        if(extra!="")str+=" "+extra;
        if(getUnique())str+=" unique";
        if(getKey())str+=" primary key";
        return str;
    }
    

    /**
     * @return Returns the null flag.
     */
    public boolean getNull() {
        return canbenull;
    }
    /**
     * @param canbenull The null flag to set.
     */
    public void setNull(boolean canbenull) {
        this.canbenull = canbenull;
    }
    /**
     * @return Returns the default value.
     */
    public String getDefault() {
        return defaultvalue;
    }
    /**
     * @param defaultvalue The default value to set.
     */
    public void setDefault(String defaultvalue) {
        this.defaultvalue = defaultvalue;
    }
    /**
     * @return Returns the extra properties string.
     */
    public String getExtra() {
        return extra;
    }
    /**
     * @param extra The extra properties string to set.
     */
    public void setExtra(String extra) {
        this.extra = extra;
    }
    /**
     * @return Returns the key flag.
     */
    public boolean getKey() {
        return key;
    }
    /**
     * @param key The key flag to set.
     */
    public void setKey(boolean key) {
        this.key = key;
    }
    /**
     * @return Returns the name.
     */
    public String getName() {
        return name;
    }
    /**
     * @param name The name to set.
     */
    public void setName(String name) {
        this.name = name;
    }
    /**
     * @return Returns the type.
     */
    public String getType() {
        return type;
    }
    /**
     * @param type The type to set.
     */
    public void setType(String type) {
        this.type = type;
    }
    /**
     * @return Returns the unique.
     */
    public boolean getUnique() {
        return unique;
    }
    /**
     * @param unique The unique to set.
     */
    public void setUnique(boolean unique) {
        this.unique = unique;
    }
}
