Coverage report

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

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

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