| 1 |
|
package org.apache.torque.engine.database.model; |
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
import java.util.List; |
| 23 |
|
|
| 24 |
|
import org.apache.commons.logging.Log; |
| 25 |
|
import org.apache.commons.logging.LogFactory; |
| 26 |
|
|
| 27 |
|
import org.apache.torque.engine.EngineException; |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
@author |
| 35 |
|
@version |
| 36 |
|
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0.33 |
|
| 37 |
|
public class ConstraintNameGenerator implements NameGenerator |
| 38 |
|
{ |
| 39 |
|
|
| 40 |
|
private static Log log = LogFactory.getLog(ConstraintNameGenerator.class); |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
@link |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
@see |
| 51 |
|
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 5 |
Complexity Density: 0.33 |
|
| 52 |
0
|
public String generateName(List inputs)... |
| 53 |
|
throws EngineException |
| 54 |
|
{ |
| 55 |
0
|
StringBuffer name = new StringBuffer(); |
| 56 |
0
|
Database db = (Database) inputs.get(0); |
| 57 |
0
|
name.append((String) inputs.get(1)); |
| 58 |
0
|
String namePostfix = (String) inputs.get(2); |
| 59 |
0
|
String constraintNbr = inputs.get(3).toString(); |
| 60 |
|
|
| 61 |
|
|
| 62 |
0
|
int maxBodyLength = -1; |
| 63 |
0
|
try |
| 64 |
|
{ |
| 65 |
0
|
int maxColumnNameLength = db.getPlatform().getMaxColumnNameLength(); |
| 66 |
0
|
maxBodyLength = (maxColumnNameLength - namePostfix.length() |
| 67 |
|
- constraintNbr.length() - 2); |
| 68 |
|
|
| 69 |
0
|
if (log.isDebugEnabled()) |
| 70 |
|
{ |
| 71 |
0
|
log.debug("maxColumnNameLength=" + maxColumnNameLength |
| 72 |
|
+ " maxBodyLength=" + maxBodyLength); |
| 73 |
|
} |
| 74 |
|
} |
| 75 |
|
catch (NumberFormatException maxLengthUnknown) |
| 76 |
|
{ |
| 77 |
|
} |
| 78 |
|
|
| 79 |
|
|
| 80 |
0
|
if (maxBodyLength != -1 && name.length() > maxBodyLength) |
| 81 |
|
{ |
| 82 |
0
|
name.setLength(maxBodyLength); |
| 83 |
|
} |
| 84 |
|
|
| 85 |
0
|
name.append(STD_SEPARATOR_CHAR).append(namePostfix) |
| 86 |
|
.append(STD_SEPARATOR_CHAR).append(constraintNbr); |
| 87 |
|
|
| 88 |
0
|
return name.toString(); |
| 89 |
|
} |
| 90 |
|
} |