01: /*
02: * This is free software, licensed under the Gnu Public License (GPL)
03: * get a copy from <http://www.gnu.org/licenses/gpl.html>
04: * @version $Id: PrimaryKey.java,v 1.3 2004/03/07 14:22:03 hzeller Exp $
05: * @author <a href="mailto:martin.grotzke@javakaffee.de">Martin Grotzke</a>
06: */
07: package henplus.sqlmodel;
08:
09: import java.util.HashMap;
10: import java.util.Map;
11:
12: public final class PrimaryKey {
13:
14: public static final int INVALID_INDEX = -1;
15:
16: private String _name;
17: private Map /*<String, ColumnPkInfo>*/_columns; // column name -> pk info specific to column
18:
19: public PrimaryKey() {
20: _columns = new HashMap();
21: }
22:
23: public void addColumn(String columnName, String columnPkName,
24: int columnPkIndex) {
25: _columns.put(columnName, new ColumnPkInfo(columnPkName,
26: columnPkIndex));
27: }
28:
29: public boolean columnParticipates(String column) {
30: return _columns.containsKey(column);
31: }
32:
33: /*
34: public int getColumnIndex(String column) {
35: int result = INVALID_INDEX;
36: ColumnPkInfo info = (ColumnPkInfo)_columns.get(column);
37: if (info != null)
38: result = info.getColumnIndex();
39: return result;
40: }
41: */
42:
43: public ColumnPkInfo getColumnPkInfo(String column) {
44: return (ColumnPkInfo) _columns.get(column);
45: }
46:
47: public Map getColumns() {
48: return _columns;
49: }
50:
51: public String getName() {
52: return _name;
53: }
54:
55: public void setName(String string) {
56: _name = string;
57: }
58:
59: public boolean equals(Object other) {
60: if (other != null && other instanceof PrimaryKey) {
61: PrimaryKey o = (PrimaryKey) other;
62: if (_name != null && !_name.equals(o.getName())
63: || _name == null && o.getName() != null)
64: return false;
65:
66: if (_columns != null && !_columns.equals(o.getColumns())
67: || _columns == null && o.getColumns() != null)
68: return false;
69:
70: return true;
71: }
72: return false;
73: }
74:
75: }
|