01: package net.sourceforge.squirrel_sql.plugins.mssql.sql.constraint;
02:
03: /*
04: * Copyright (C) 2004 Ryan Walberg <generalpf@yahoo.com>
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20:
21: import java.util.ArrayList;
22: import java.util.List;
23:
24: public class TableConstraints {
25:
26: private ArrayList<MssqlConstraint> _constraints;
27:
28: /** Creates a new instance of TableConstraints */
29: public TableConstraints() {
30: _constraints = new ArrayList<MssqlConstraint>();
31: }
32:
33: public MssqlConstraint[] getConstraints() {
34:
35: return _constraints.toArray(new MssqlConstraint[_constraints
36: .size()]);
37: }
38:
39: public void addConstraint(MssqlConstraint constraint) {
40: _constraints.add(constraint);
41: }
42:
43: public List<DefaultConstraint> getDefaultsForColumn(
44: String columnName) {
45: ArrayList<DefaultConstraint> results = new ArrayList<DefaultConstraint>();
46: for (int i = 0; i < _constraints.size(); i++) {
47: MssqlConstraint constraint = _constraints.get(i);
48: if (constraint instanceof DefaultConstraint) {
49: DefaultConstraint def = (DefaultConstraint) constraint;
50: if (def.constrainsColumn(columnName))
51: results.add(def);
52: }
53: }
54: return results;
55: }
56:
57: public List<CheckConstraint> getCheckConstraints() {
58: ArrayList<CheckConstraint> results = new ArrayList<CheckConstraint>();
59: for (int i = 0; i < _constraints.size(); i++) {
60: MssqlConstraint constraint = _constraints.get(i);
61: if (constraint instanceof CheckConstraint) {
62: results.add((CheckConstraint) constraint);
63: }
64: }
65: return results;
66: }
67:
68: public List<ForeignKeyConstraint> getForeignKeyConstraints() {
69: ArrayList<ForeignKeyConstraint> results = new ArrayList<ForeignKeyConstraint>();
70: for (int i = 0; i < _constraints.size(); i++) {
71: MssqlConstraint constraint = _constraints.get(i);
72: if (constraint instanceof ForeignKeyConstraint) {
73: results.add((ForeignKeyConstraint) constraint);
74: }
75: }
76: return results;
77: }
78:
79: public List<PrimaryKeyConstraint> getPrimaryKeyConstraints() {
80: ArrayList<PrimaryKeyConstraint> results = new ArrayList<PrimaryKeyConstraint>();
81: for (int i = 0; i < _constraints.size(); i++) {
82: MssqlConstraint constraint = _constraints.get(i);
83: if (constraint instanceof PrimaryKeyConstraint) {
84: results.add((PrimaryKeyConstraint) constraint);
85: }
86: }
87: return results;
88: }
89:
90: }
|