1 package org.apache.ojb.broker.metadata.torque; 2 3 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 } 68 | Popular Tags |