Coverage report

  %line %branch
org.apache.torque.engine.database.model.Domain
74% 
97% 

 1  
 package org.apache.torque.engine.database.model;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2005 The Apache Software Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License")
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.apache.torque.engine.platform.Platform;
 21  
 import org.xml.sax.Attributes;
 22  
 
 23  
 /**
 24  
  * A Class for holding data about a column used in an Application.
 25  
  *
 26  
  * @author <a href="mailto:mpoeschl@marmot.at>Martin Poeschl</a>
 27  
  * @version $Id: Domain.java 239626 2005-08-24 12:19:51Z henning $
 28  
  */
 29  
 public class Domain
 30  
 {
 31  
     private String name;
 32  
     private String description;
 33  
     private String size;
 34  
     private String scale;
 35  
     /** type as defined in schema.xml */
 36  
     private SchemaType torqueType;
 37  
     private String sqlType;
 38  
     private String defaultValue;
 39  
 
 40  
     /**
 41  
      * Creates a new instance with a <code>null</code> name.
 42  
      */
 43  
     public Domain()
 44  1821
     {
 45  1821
         this.name = null;
 46  1821
     }
 47  
 
 48  
     /**
 49  
      * Creates a new Domain and set the name
 50  
      *
 51  
      * @param name column name
 52  
      */
 53  
     public Domain(String name)
 54  0
     {
 55  0
         this.name = name;
 56  0
     }
 57  
 
 58  
     /**
 59  
      * Creates a new Domain and set the name
 60  
      */
 61  
     public Domain(SchemaType type)
 62  450
     {
 63  450
         this.name = null;
 64  450
         this.torqueType = type;
 65  450
         this.sqlType = type.getName();
 66  450
     }
 67  
 
 68  
     /**
 69  
      * Creates a new Domain and set the name
 70  
      */
 71  
     public Domain(SchemaType type, String sqlType)
 72  124
     {
 73  124
         this.name = null;
 74  124
         this.torqueType = type;
 75  124
         this.sqlType = sqlType;
 76  124
     }
 77  
 
 78  
     /**
 79  
      * Creates a new Domain and set the name
 80  
      */
 81  
     public Domain(SchemaType type, String sqlType, String size, String scale)
 82  5
     {
 83  5
         this.name = null;
 84  5
         this.torqueType = type;
 85  5
         this.sqlType = sqlType;
 86  5
         this.size = size;
 87  5
         this.scale = scale;
 88  5
     }
 89  
 
 90  
     /**
 91  
      * Creates a new Domain and set the name
 92  
      */
 93  
     public Domain(SchemaType type, String sqlType, String size)
 94  1
     {
 95  1
         this.name = null;
 96  1
         this.torqueType = type;
 97  1
         this.sqlType = sqlType;
 98  1
         this.size = size;
 99  1
     }
 100  
 
 101  
     public Domain(Domain domain)
 102  3485
     {
 103  3485
         copy(domain);
 104  3485
     }
 105  
 
 106  
     public void copy(Domain domain)
 107  
     {
 108  3523
         this.defaultValue = domain.getDefaultValue();
 109  3523
         this.description = domain.getDescription();
 110  3523
         this.name = domain.getName();
 111  3523
         this.scale = domain.getScale();
 112  3523
         this.size = domain.getSize();
 113  3523
         this.sqlType = domain.getSqlType();
 114  3523
         this.torqueType = domain.getType();
 115  3523
     }
 116  
 
 117  
     /**
 118  
      * Imports a column from an XML specification
 119  
      */
 120  
     public void loadFromXML(Attributes attrib, Platform platform)
 121  
     {
 122  38
         SchemaType schemaType = SchemaType.getEnum(attrib.getValue("type"));
 123  38
         copy(platform.getDomainForSchemaType(schemaType));
 124  
         //Name
 125  38
         name = attrib.getValue("name");
 126  
         //Default column value.
 127  38
         defaultValue = attrib.getValue("default");
 128  38
         size = attrib.getValue("size");
 129  38
         scale = attrib.getValue("scale");
 130  
 
 131  38
         description = attrib.getValue("description");
 132  38
     }
 133  
 
 134  
     /**
 135  
      * @return Returns the description.
 136  
      */
 137  
     public String getDescription()
 138  
     {
 139  3524
         return description;
 140  
     }
 141  
 
 142  
     /**
 143  
      * @param description The description to set.
 144  
      */
 145  
     public void setDescription(String description)
 146  
     {
 147  0
         this.description = description;
 148  0
     }
 149  
 
 150  
     /**
 151  
      * @return Returns the name.
 152  
      */
 153  
     public String getName()
 154  
     {
 155  3561
         return name;
 156  
     }
 157  
 
 158  
     /**
 159  
      * @param name The name to set.
 160  
      */
 161  
     public void setName(String name)
 162  
     {
 163  0
         this.name = name;
 164  0
     }
 165  
 
 166  
     /**
 167  
      * @return Returns the scale.
 168  
      */
 169  
     public String getScale()
 170  
     {
 171  5317
         return scale;
 172  
     }
 173  
 
 174  
     /**
 175  
      * @param scale The scale to set.
 176  
      */
 177  
     public void setScale(String scale)
 178  
     {
 179  0
         this.scale = scale;
 180  0
     }
 181  
 
 182  
     /**
 183  
      * Replaces the size if the new value is not null.
 184  
      *
 185  
      * @param value The size to set.
 186  
      */
 187  
     public void replaceScale(String value)
 188  
     {
 189  1778
         this.scale = StringUtils.defaultString(value, getScale());
 190  1778
     }
 191  
 
 192  
     /**
 193  
      * @return Returns the size.
 194  
      */
 195  
     public String getSize()
 196  
     {
 197  5322
         return size;
 198  
     }
 199  
 
 200  
     /**
 201  
      * @param size The size to set.
 202  
      */
 203  
     public void setSize(String size)
 204  
     {
 205  1
         this.size = size;
 206  1
     }
 207  
 
 208  
     /**
 209  
      * Replaces the size if the new value is not null.
 210  
      *
 211  
      * @param value The size to set.
 212  
      */
 213  
     public void replaceSize(String value)
 214  
     {
 215  1778
         this.size = StringUtils.defaultString(value, getSize());
 216  1778
     }
 217  
 
 218  
     /**
 219  
      * @return Returns the torqueType.
 220  
      */
 221  
     public SchemaType getType()
 222  
     {
 223  3668
         return torqueType;
 224  
     }
 225  
 
 226  
     /**
 227  
      * @param torqueType The torqueType to set.
 228  
      */
 229  
     public void setType(SchemaType torqueType)
 230  
     {
 231  2
         this.torqueType = torqueType;
 232  2
     }
 233  
 
 234  
     /**
 235  
      * @param torqueType The torqueType to set.
 236  
      */
 237  
     public void setType(String torqueType)
 238  
     {
 239  0
         this.torqueType = SchemaType.getEnum(torqueType);
 240  0
     }
 241  
 
 242  
     /**
 243  
      * Replaces the default value if the new value is not null.
 244  
      *
 245  
      * @param value The defaultValue to set.
 246  
      */
 247  
     public void replaceType(String value)
 248  
     {
 249  0
         this.torqueType = SchemaType.getEnum(
 250  
                 StringUtils.defaultString(value, getType().getName()));
 251  0
     }
 252  
 
 253  
     /**
 254  
      * @return Returns the defaultValue.
 255  
      */
 256  
     public String getDefaultValue()
 257  
     {
 258  5364
         return defaultValue;
 259  
     }
 260  
 
 261  
     /**
 262  
      * Return a string that will give this column a default value.
 263  
      * @deprecated
 264  
      */
 265  
     public String getDefaultSetting()
 266  
     {
 267  0
         StringBuffer dflt = new StringBuffer(0);
 268  0
         if (getDefaultValue() != null)
 269  
         {
 270  0
             dflt.append("default ");
 271  0
             if (TypeMap.isTextType(getType()))
 272  
             {
 273  
                 // TODO: Properly SQL-escape the text.
 274  0
                 dflt.append('\'').append(getDefaultValue()).append('\'');
 275  
             }
 276  
             else
 277  
             {
 278  0
                 dflt.append(getDefaultValue());
 279  
             }
 280  
         }
 281  0
         return dflt.toString();
 282  
     }
 283  
 
 284  
     /**
 285  
      * @param defaultValue The defaultValue to set.
 286  
      */
 287  
     public void setDefaultValue(String defaultValue)
 288  
     {
 289  0
         this.defaultValue = defaultValue;
 290  0
     }
 291  
 
 292  
     /**
 293  
      * Replaces the default value if the new value is not null.
 294  
      *
 295  
      * @param value The defaultValue to set.
 296  
      */
 297  
     public void replaceDefaultValue(String value)
 298  
     {
 299  1778
         this.defaultValue = StringUtils.defaultString(value, getDefaultValue());
 300  1778
     }
 301  
 
 302  
     /**
 303  
      * @return Returns the sqlType.
 304  
      */
 305  
     public String getSqlType()
 306  
     {
 307  3641
         return sqlType;
 308  
     }
 309  
 
 310  
     /**
 311  
      * @param sqlType The sqlType to set.
 312  
      */
 313  
     public void setSqlType(String sqlType)
 314  
     {
 315  0
         this.sqlType = sqlType;
 316  0
     }
 317  
 
 318  
     /**
 319  
      * Return the size and scale in brackets for use in an sql schema.
 320  
      *
 321  
      * @return size and scale or an empty String if there are no values
 322  
      *         available.
 323  
      */
 324  
     public String printSize()
 325  
     {
 326  61
         if (size != null && scale != class="keyword">null)
 327  
         {
 328  33
             return '(' + size + ',' + scale + ')';
 329  
         }
 330  28
         else if (size != null)
 331  
         {
 332  5
             return '(' + size + ')';
 333  
         }
 334  
         else
 335  
         {
 336  23
             return "";
 337  
         }
 338  
     }
 339  
 
 340  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.