Coverage Report - org.apache.ojb.broker.metadata.torque.TorqueIndexGenerator
 
Classes in this File Line Coverage Branch Coverage Complexity
TorqueIndexGenerator
N/A
N/A
2.667
 
 1  
 package org.apache.ojb.broker.metadata.torque;
 2  
 
 3  
 /* Copyright 2002-2005 The Apache Software Foundation
 4  
  *
 5  
  * Licensed under the Apache License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  *     http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 import org.apache.ojb.broker.metadata.IndexDescriptor;
 19  
 
 20  
 import java.util.Vector;
 21  
 
 22  
 public class TorqueIndexGenerator {
 23  
 
 24  
     public void generateIndices(Vector indexDescriptors, StringBuffer buffer) {
 25  
         int numIndexes = indexDescriptors.size();
 26  
         for (int i = 0; i < numIndexes; i++) {
 27  
             IndexDescriptor index = (IndexDescriptor) indexDescriptors.get(i);
 28  
             String indexTag = getIndexTag(index);
 29  
 
 30  
             buffer.append("        <");
 31  
             buffer.append(indexTag);
 32  
             if (index.getName() != null) {
 33  
                 buffer.append(" name=\"");
 34  
                 buffer.append(index.getName());
 35  
                 buffer.append("\"");
 36  
             }
 37  
             buffer.append(">\n");
 38  
 
 39  
             generateStringVector(index.getIndexColumns(), indexTag + "-column", "name", "            ", buffer);
 40  
             buffer.append("        </");
 41  
             buffer.append(indexTag);
 42  
             buffer.append(">\n");
 43  
         }
 44  
     }
 45  
 
 46  
     private String getIndexTag(IndexDescriptor indexDescriptor) {
 47  
         if (indexDescriptor.isUnique()) {
 48  
             return "unique";
 49  
         } else {
 50  
             return "index";
 51  
         }
 52  
     }
 53  
 
 54  
     private void generateStringVector(Vector strings, String element, String attribute, String indentation, StringBuffer buffer) {
 55  
         for (int i = 0; i < strings.size(); i++) {
 56  
             buffer.append(indentation);
 57  
             buffer.append("<");
 58  
             buffer.append(element);
 59  
             buffer.append(" ");
 60  
             buffer.append(attribute);
 61  
             buffer.append("=\"");
 62  
             buffer.append(strings.get(i));
 63  
             buffer.append("\"/>\n");
 64  
         }
 65  
     }
 66  
 
 67  
 }