01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.jdbc.schema;
20:
21: import org.apache.commons.lang.StringUtils;
22:
23: /**
24: * Represents a database index. Can also represent a partial index,
25: * aligning with {@link java.sql.DatabaseMetaData}.
26: *
27: * @author Abe White
28: * @author Stephen Kim
29: */
30: public class Index extends LocalConstraint {
31:
32: private boolean _unique = false;
33:
34: /**
35: * Default constructor.
36: */
37: public Index() {
38: }
39:
40: /**
41: * Constructor.
42: *
43: * @param name the name of the index
44: * @param table the table of the index
45: */
46: public Index(String name, Table table) {
47: super (name, table);
48: }
49:
50: /**
51: * Return true if this is a UNIQUE index.
52: */
53: public boolean isUnique() {
54: return _unique;
55: }
56:
57: /**
58: * Set whether this is a UNIQUE index.
59: */
60: public void setUnique(boolean unique) {
61: _unique = unique;
62: }
63:
64: public boolean isLogical() {
65: return false;
66: }
67:
68: /**
69: * Indexes are equal if they have the same name, the same columns, and
70: * are both unique/not unique.
71: */
72: public boolean equalsIndex(Index idx) {
73: if (idx == this )
74: return true;
75: if (idx == null)
76: return false;
77:
78: if (isUnique() != idx.isUnique())
79: return false;
80: if (!StringUtils.equalsIgnoreCase(getFullName(), idx
81: .getFullName()))
82: return false;
83: return equalsLocalConstraint(idx);
84: }
85: }
|