1 /*
2 * Copyright 2003 - 2013 The eFaps Team
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * Revision: $Rev$
17 * Last Changed: $Date$
18 * Last Changed By: $Author$
19 */
20
21 package org.efaps.db.databases.information;
22
23 import java.io.Serializable;
24
25 import org.apache.commons.lang3.builder.ToStringBuilder;
26
27 /**
28 * The class is used to store information about foreign keys within SQL tables.
29 *
30 * @author The eFaps Team
31 * @version $Id$
32 */
33 public class ForeignKeyInformation
34 implements Serializable
35 {
36 /**
37 * Needed for serialization.
38 */
39 private static final long serialVersionUID = 1L;
40 /**
41 * Name of the foreign key.
42 */
43 private final String fkName;
44
45 /**
46 * Column name which references the foreign key.
47 */
48 private final String colName;
49
50 /**
51 * Name of the referenced SQL table.
52 */
53 private final String refTableName;
54
55 /**
56 * Name of column in the referenced SQL table.
57 */
58 private final String refColName;
59
60 /**
61 * Is the foreign key a cascade delete, means that if the foreign row is
62 * deleted, this row referencing the foreign row must also be deleted?
63 */
64 private final boolean cascadeDelete;
65
66 /**
67 * Constructor to initialize all instance variables.
68 *
69 * @param _foreignKeyName name of foreign key
70 * @param _columnName name of column name
71 * @param _referencedTableName name of referenced SQL table
72 * @param _referencedColumnName name of column within referenced SQL table
73 * @param _cascadeDelete delete cascade activated
74 */
75 protected ForeignKeyInformation(final String _foreignKeyName,
76 final String _columnName,
77 final String _referencedTableName,
78 final String _referencedColumnName,
79 final boolean _cascadeDelete)
80 {
81 this.fkName = _foreignKeyName.toUpperCase();
82 this.colName = _columnName.toUpperCase();
83 this.refTableName = _referencedTableName.toUpperCase();
84 this.refColName = _referencedColumnName.toUpperCase();
85 this.cascadeDelete = _cascadeDelete;
86 }
87
88 /**
89 * Returns string representation of this class instance. The information
90 * includes {@link #fkName}, {@link #colName}, {@link #refTableName},
91 * {@link #refColName} and {@link #cascadeDelete}.
92 *
93 * @return string representation for the foreign key information
94 */
95 @Override
96 public String toString()
97 {
98 return ToStringBuilder.reflectionToString(this);
99 }
100 }