View Javadoc

1   // $Id: Index.java,v 1.1 2007/10/30 10:09:47 kameleono Exp $ 
2   package net.sourceforge.sql2java;
3   
4   import java.util.ArrayList;
5   import java.util.HashMap;
6   import java.util.List;
7   import java.util.Map;
8   
9   public class Index {
10      private Table table;
11      private String name;
12      private boolean unique;
13      private Map columns;
14      
15  // -- Constructors ------------------------------------------------------------
16      
17      public Index() {
18          this("");
19      }
20      
21      public Index(String name) {
22          this(name, null);
23      }
24      
25      public Index(String name, Table table) {
26          this(name, table, new HashMap());
27      }
28      
29      public Index(String name, Table table, Map columns) {
30          this.name = name;
31          this.table = table;
32          this.columns = columns;
33          this.table.addIndex(this);
34      }
35      
36  // -- Column List Manipulation ------------------------------------------------
37      
38      public void addIndexColumn(IndexColumn column) {
39          if (null != column) {
40              columns.put(column.getName().toLowerCase(), column);
41          }
42      }
43      
44      public void removeIndexColumn(Column column) {
45          if (null != column) {
46              columns.remove(column.getName().toLowerCase());
47          }
48      }
49  
50  // -- Getters -----------------------------------------------------------------
51      
52      public Table getTable() {
53          return table;
54      }
55      
56      public String getName() {
57          return name;
58      }
59      
60      public boolean isUnique() {
61          return unique;
62      }
63  
64      public Map getIndexColumns() {
65          return columns;
66      }
67      
68      public List getIndexColumnsList() {
69          List list = new ArrayList();
70          list.addAll(columns.values());
71          return list;
72      }
73      
74  // -- Setters -----------------------------------------------------------------
75      
76      public void setName(String name) {
77          this.name = name;
78      }
79      
80      public void setUnique(boolean unique) {
81          this.unique = unique;
82      }
83      
84      public void setTable(Table table) {
85          this.table = table;
86      }
87  }