1 package org.apache.torque.engine.database.model; 2 3 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 34 public class ConstraintNameGenerator implements NameGenerator 35 { 36 37 private static Log log = LogFactory.getLog(ConstraintNameGenerator.class); 38 39 49 public String generateName(List inputs) 50 throws EngineException 51 { 52 StringBuffer name = new StringBuffer (); 53 Database db = (Database) inputs.get(0); 54 name.append((String ) inputs.get(1)); 55 String namePostfix = (String ) inputs.get(2); 56 String constraintNbr = inputs.get(3).toString(); 57 58 int maxBodyLength = -1; 60 try 61 { 62 int maxColumnNameLength = db.getPlatform().getMaxColumnNameLength(); 63 maxBodyLength = (maxColumnNameLength - namePostfix.length() 64 - constraintNbr.length() - 2); 65 66 if (log.isDebugEnabled()) 67 { 68 log.debug("maxColumnNameLength=" + maxColumnNameLength 69 + " maxBodyLength=" + maxBodyLength); 70 } 71 } 72 catch (NumberFormatException maxLengthUnknown) 73 { 74 } 75 76 if (maxBodyLength != -1 && name.length() > maxBodyLength) 78 { 79 name.setLength(maxBodyLength); 80 } 81 82 name.append(STD_SEPARATOR_CHAR).append(namePostfix) 83 .append(STD_SEPARATOR_CHAR).append(constraintNbr); 84 85 return name.toString(); 86 } 87 } 88 | Popular Tags |