Coverage report

  %line %branch
org.apache.torque.engine.database.model.ConstraintNameGenerator
89% 
94% 

 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 java.util.List;
 20  
 
 21  
 import org.apache.commons.logging.Log;
 22  
 import org.apache.commons.logging.LogFactory;
 23  
 
 24  
 import org.apache.torque.engine.EngineException;
 25  
 
 26  
 /**
 27  
  * A <code>NameGenerator</code> implementation for table-specific
 28  
  * constraints.  Conforms to the maximum column name length for the
 29  
  * type of database in use.
 30  
  *
 31  
  * @author <a href="mailto:dlr@finemaltcoding.com>Daniel Rall</a>
 32  
  * @version $Id: ConstraintNameGenerator.java 239624 2005-08-24 12:18:03Z henning $
 33  
  */
 34  2
 public class ConstraintNameGenerator implements NameGenerator
 35  
 {
 36  
     /** Logging class from commons.logging */
 37  18
     private static Log log = LogFactory.getLog(ConstraintNameGenerator.class);
 38  
 
 39  
     /**
 40  
      * First element of <code>inputs</code> should be of type {@link
 41  
      * org.apache.torque.engine.database.model.Database}, second
 42  
      * should be a table name, third is the type identifier (spared if
 43  
      * trimming is necessary due to database type length constraints),
 44  
      * and the fourth is a <code>Integer</code> indicating the number
 45  
      * of this contraint.
 46  
      *
 47  
      * @see org.apache.torque.engine.database.model.NameGenerator
 48  
      */
 49  
     public String generateName(List inputs)
 50  
         throws EngineException
 51  
     {
 52  32
         StringBuffer name = new StringBuffer();
 53  32
         Database db = (Database) inputs.get(0);
 54  32
         name.append((String) inputs.get(1));
 55  32
         String namePostfix = (String) inputs.get(2);
 56  32
         String constraintNbr = inputs.get(3).toString();
 57  
 
 58  
         // Calculate maximum RDBMS-specific column character limit.
 59  32
         int maxBodyLength = -1;
 60  
         try
 61  
         {
 62  32
             int maxColumnNameLength = db.getPlatform().getMaxColumnNameLength();
 63  32
             maxBodyLength = (maxColumnNameLength - namePostfix.length()
 64  
                     - constraintNbr.length() - 2);
 65  
 
 66  32
             if (log.isDebugEnabled())
 67  
             {
 68  0
                 log.debug("maxColumnNameLength=" + maxColumnNameLength
 69  
                         + " maxBodyLength=" + maxBodyLength);
 70  
             }
 71  
         }
 72  0
         catch (NumberFormatException maxLengthUnknown)
 73  
         {
 74  32
         }
 75  
 
 76  
         // Do any necessary trimming.
 77  32
         if (maxBodyLength != -1 && name.length() > maxBodyLength)
 78  
         {
 79  3
             name.setLength(maxBodyLength);
 80  
         }
 81  
 
 82  32
         name.append(STD_SEPARATOR_CHAR).append(namePostfix)
 83  
             .append(STD_SEPARATOR_CHAR).append(constraintNbr);
 84  
 
 85  32
         return name.toString();
 86  
     }
 87  
 }

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