%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.torque.engine.database.model.ConstraintNameGenerator |
|
|
1 | package org.apache.torque.engine.database.model; |
|
2 | ||
3 | /* |
|
4 | * Licensed to the Apache Software Foundation (ASF) under one |
|
5 | * or more contributor license agreements. See the NOTICE file |
|
6 | * distributed with this work for additional information |
|
7 | * regarding copyright ownership. The ASF licenses this file |
|
8 | * to you under the Apache License, Version 2.0 (the |
|
9 | * "License"); you may not use this file except in compliance |
|
10 | * with the License. You may obtain a copy of the License at |
|
11 | * |
|
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
13 | * |
|
14 | * Unless required by applicable law or agreed to in writing, |
|
15 | * software distributed under the License is distributed on an |
|
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|
17 | * KIND, either express or implied. See the License for the |
|
18 | * specific language governing permissions and limitations |
|
19 | * under the License. |
|
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 | * A <code>NameGenerator</code> implementation for table-specific |
|
31 | * constraints. Conforms to the maximum column name length for the |
|
32 | * type of database in use. |
|
33 | * |
|
34 | * @author <a href="mailto:dlr@finemaltcoding.com>Daniel Rall</a> |
|
35 | * @version $Id: ConstraintNameGenerator.java 473814 2006-11-11 22:30:30Z tv $ |
|
36 | */ |
|
37 | 24 | public class ConstraintNameGenerator implements NameGenerator |
38 | { |
|
39 | /** Logging class from commons.logging */ |
|
40 | 216 | private static Log log = LogFactory.getLog(ConstraintNameGenerator.class); |
41 | ||
42 | /** |
|
43 | * First element of <code>inputs</code> should be of type {@link |
|
44 | * org.apache.torque.engine.database.model.Database}, second |
|
45 | * should be a table name, third is the type identifier (spared if |
|
46 | * trimming is necessary due to database type length constraints), |
|
47 | * and the fourth is a <code>Integer</code> indicating the number |
|
48 | * of this contraint. |
|
49 | * |
|
50 | * @see org.apache.torque.engine.database.model.NameGenerator |
|
51 | */ |
|
52 | public String generateName(List inputs) |
|
53 | throws EngineException |
|
54 | { |
|
55 | 384 | StringBuffer name = new StringBuffer(); |
56 | 384 | Database db = (Database) inputs.get(0); |
57 | 384 | name.append((String) inputs.get(1)); |
58 | 384 | String namePostfix = (String) inputs.get(2); |
59 | 384 | String constraintNbr = inputs.get(3).toString(); |
60 | ||
61 | // Calculate maximum RDBMS-specific column character limit. |
|
62 | 384 | int maxBodyLength = -1; |
63 | try |
|
64 | { |
|
65 | 384 | int maxColumnNameLength = db.getPlatform().getMaxColumnNameLength(); |
66 | 384 | maxBodyLength = (maxColumnNameLength - namePostfix.length() |
67 | - constraintNbr.length() - 2); |
|
68 | ||
69 | 384 | if (log.isDebugEnabled()) |
70 | { |
|
71 | 0 | log.debug("maxColumnNameLength=" + maxColumnNameLength |
72 | + " maxBodyLength=" + maxBodyLength); |
|
73 | } |
|
74 | } |
|
75 | 0 | catch (NumberFormatException maxLengthUnknown) |
76 | { |
|
77 | 384 | } |
78 | ||
79 | // Do any necessary trimming. |
|
80 | 384 | if (maxBodyLength != -1 && name.length() > maxBodyLength) |
81 | { |
|
82 | 36 | name.setLength(maxBodyLength); |
83 | } |
|
84 | ||
85 | 384 | name.append(STD_SEPARATOR_CHAR).append(namePostfix) |
86 | .append(STD_SEPARATOR_CHAR).append(constraintNbr); |
|
87 | ||
88 | 384 | return name.toString(); |
89 | } |
|
90 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |