commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/model Column.java
Date Mon, 28 Oct 2002 16:13:28 GMT
jstrachan    2002/10/28 08:13:28

  Modified:    sql/src/java/org/apache/commons/sql/model Column.java
  Log:
  applied J. Russell Smyth 's patches
  
  removed nullable and isNullable attributes added by Steven Caswell - see
  previous message - in short, these are not DB attributes, but JDBC
  attributes, unreliable, db dependent, and are handled by the already
  existing "required" attribute. 
  
  removed charOctetLength - this is db implementation details that should
  never be reflected in the db independent model. (I will be sending
  another suggestion on how to handle this later) 
  
  changed scale,precisionRadix, and ordinalPosition  from Integer to int -
  no good reason to keep this as an Integer, and makes their use more
  cumbersome. 
  
  typeCode is an int and is expected to be a java.sql.Types value.
  Though have preserved the String type property.
  
  removed getIsTextType - dosnt belong here. It is already in TypeMap
  where it does belong.
  
  removed getTypeString - this is not the right place to create SQL code -
  it could vary by platform. Explained more fully in previous message.
  
  removed getSQLTypeCode - dosnt belong here, it is in TypeMap already.
  
  
  Revision  Changes    Path
  1.7       +37 -82    jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/model/Column.java
  
  Index: Column.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/model/Column.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Column.java	23 Oct 2002 10:10:55 -0000	1.6
  +++ Column.java	28 Oct 2002 16:13:28 -0000	1.7
  @@ -71,26 +71,25 @@
       private boolean primaryKey = false;
       private boolean required = false;
       private boolean autoIncrement = false;
  -    private boolean nullable = false;
  +    private int typeCode;
       private String type;
       private int size = 0;
  -    private String defaultValue;
  -    private Integer scale = null;
  -    private String isNullable;
  -    private Boolean isTextType = new Boolean(false);
  -    private Integer precisionRadix = null;
  -    private Integer charOctetLength = null;
  -    private Integer ordinalPosition = null;
  +    private String defaultValue = null;
  +    private int scale = 0;
  +    private int precisionRadix = 10;
  +    private int ordinalPosition = 0;
       
       public Column() 
       {
       }
   
  -    public Column(String name, String type, int size, boolean required, boolean 
  +    
  +    public Column(String name, int typeCode, int size, boolean required, boolean 
                     primaryKey, boolean autoIncrement, String defaultValue) 
       {
           this.name = name;
  -        this.type = type;
  +        this.typeCode = typeCode;
  +        this.type = TypeMap.getJdbcTypeName(typeCode);
           this.size = size;
           this.required = required;
           this.primaryKey = primaryKey;
  @@ -99,18 +98,24 @@
       }
   
       public Column(String name, String type, int size, boolean required, boolean 
  +                  primaryKey, boolean autoIncrement, String defaultValue  ) 
  +    {
  +        this(name, TypeMap.getJdbcTypeCode(type), size, required, primaryKey, autoIncrement,
defaultValue);
  +    }
  +
  +    public Column(String name, int typeCode, int size, boolean required, boolean 
                     primaryKey, boolean autoIncrement, String defaultValue, 
  -                  Integer scale, String isNullable) 
  +                  int scale) 
       {
           this.name = name;
  -        this.type = type;
  +        this.typeCode = typeCode;
  +        this.type = TypeMap.getJdbcTypeName(typeCode);
           this.size = size;
           this.required = required;
           this.primaryKey = primaryKey;
           this.autoIncrement = autoIncrement;
           this.defaultValue = defaultValue;
           this.scale = scale;
  -        this.isNullable = isNullable;
       }
   
       public String toString()
  @@ -158,34 +163,29 @@
           this.autoIncrement = autoIncrement;
       }
       
  -    public String getType()
  +    public int getTypeCode()
       {
  -        return type;
  +        return typeCode;
       }
       
  -    public void setType(String type)
  +    public void setTypeCode(int typeCode)
       {
  -        this.type = type;
  +        this.typeCode = typeCode;
  +        this.type = TypeMap.getJdbcTypeName(typeCode);
       }
   
  -    public boolean getNullable()
  +    public String getType() 
       {
  -        return this.nullable;
  -    }
  -    
  -    public void setNullable(boolean nullable)
  -    {
  -        this.nullable = nullable;
  -    }
  -    
  -    public String getIsNullable()
  -    {
  -        return this.isNullable;
  +        return type;
       }
       
  -    public void setIsNullable(String isNullable)
  +    /**
  +     * Set this columns type by name
  +     */
  +    public void setType(String type)
       {
  -        this.isNullable = isNullable;
  +        this.type = type;
  +        this.typeCode = TypeMap.getJdbcTypeCode(type);
       }
       
       public int getSize()
  @@ -198,26 +198,16 @@
           this.size = size;
       }
   
  -    public Integer getScale()
  +    public int getScale()
       {
           return this.scale;
       }
       
  -    public void setScale(Integer scale)
  +    public void setScale(int scale)
       {
           this.scale = scale;
       }
   
  -    public Boolean getIsTextType()
  -    {
  -        return this.isTextType;
  -    }
  -
  -    public void setIsTextType(Boolean isTextType)
  -    {
  -        this.isTextType = isTextType;
  -    }
  -    
       public String getDefaultValue()
       {
           return defaultValue;
  @@ -228,61 +218,26 @@
           this.defaultValue = defaultValue;
       }
   
  -    public Integer getPrecisionRadix()
  +    public int getPrecisionRadix()
       {
           return this.precisionRadix;
       }
       
  -    public void setPrecisionRadix(Integer precisionRadix)
  +    public void setPrecisionRadix(int precisionRadix)
       {
           this.precisionRadix = precisionRadix;
       }
   
  -    public Integer getCharOctetLength()
  -    {
  -        return this.charOctetLength;
  -    }
  -    
  -    public void setCharOctetLength(Integer charOctetLength)
  -    {
  -        this.charOctetLength = charOctetLength;
  -    }
  -
  -    public Integer getOrdinalPosition()
  +    public int getOrdinalPosition()
       {
           return this.ordinalPosition;
       }
       
  -    public void setOrdinalPosition(Integer ordinalPosition)
  +    public void setOrdinalPosition(int ordinalPosition)
       {
           this.ordinalPosition = ordinalPosition;
       }
       
  -    // Helper methods
  -    //-------------------------------------------------------------------------       
        
  -    
  -    /**
  -     * @return the full SQL type string including the size, such as "VARCHAR (2000)"
  -     */
  -    public String getTypeString() {
  -        if ( this.scale != null ) {
  -            return getType() + " (" + getSize() + "," + getScale() + ")";
  -        }
  -        else
  -        {
  -            if ( getSize() > 0 ) {
  -                return getType() + " (" + getSize() + ")";
  -            }
  -        }
  -        return getType();
  -    }
   
   
  -    /**
  -     * @return the SQL type code for this column which matches the enumeration of 
  -     * {@link java.sql.Types}.
  -     */
  -    public int getSQLTypeCode() {
  -        return TypeMap.getSQLTypeCode(getType());
  -    }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message