Coverage Report - org.apache.ojb.broker.metadata.torque.TorqueTablePreprocessor
 
Classes in this File Line Coverage Branch Coverage Complexity
TorqueTablePreprocessor
N/A
N/A
2.2
 
 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.ClassDescriptor;
 19  
 import org.apache.ojb.broker.metadata.DescriptorRepository;
 20  
 import org.apache.ojb.broker.metadata.FieldDescriptor;
 21  
 
 22  
 import java.util.HashMap;
 23  
 import java.util.Iterator;
 24  
 
 25  
 public class TorqueTablePreprocessor {
 26  
 
 27  
     private DescriptorRepository repository;
 28  
     private HashMap standardTables = new HashMap();
 29  
 
 30  
     public TorqueTablePreprocessor(DescriptorRepository repository) {
 31  
         this.repository = repository;
 32  
     }
 33  
 
 34  
     public void buildStandardTables() {
 35  
         Iterator classDescriptorIterators = this.repository.iterator();
 36  
         while (classDescriptorIterators.hasNext()) {
 37  
             ClassDescriptor cd = (ClassDescriptor) classDescriptorIterators.next();
 38  
             if(cd.isAbstract() || cd.isInterface())
 39  
             {
 40  
                 System.out.println("Skip table build for abstract base class / interface called "+cd.getClassNameOfObject());
 41  
             }
 42  
             else
 43  
             {
 44  
                 buildStandardTable(cd);
 45  
             }
 46  
         }
 47  
     }
 48  
 
 49  
     public HashMap getStandardTables() {
 50  
         return this.standardTables;
 51  
     }
 52  
 
 53  
     private void buildStandardTable(ClassDescriptor cd) {
 54  
         String tableName = cd.getFullTableName();
 55  
         TableDescriptor tableDescriptor = (TableDescriptor) this.standardTables.get(tableName);
 56  
         if (tableDescriptor == null) {
 57  
             tableDescriptor = new TableDescriptor();
 58  
             tableDescriptor.setName(tableName);
 59  
             this.standardTables.put(tableName, tableDescriptor);
 60  
         }
 61  
 
 62  
         buildStandardTableFieldDescriptors(cd.getFieldDescriptions(), tableDescriptor);
 63  
         tableDescriptor.getIndices().addAll(cd.getIndexes());
 64  
         tableDescriptor.getReferences().addAll(cd.getObjectReferenceDescriptors());
 65  
     }
 66  
 
 67  
     private void buildStandardTableFieldDescriptors(FieldDescriptor fieldDescriptors[], TableDescriptor tableDescriptor) {
 68  
         if (fieldDescriptors != null) {
 69  
             for (int i = 0; i < fieldDescriptors.length; i++) {
 70  
                 tableDescriptor.addColumn(fieldDescriptors[i]);
 71  
             }
 72  
         }
 73  
     }
 74  
 }