View Javadoc

1   /* $Id: Constraint.java,v 1.4 2006/01/10 16:36:57 psionides Exp $ */
2   package net.sourceforge.jdbdump.dump;
3   
4   import java.io.Serializable;
5   
6   /***
7    * Represents a table or column constraint.
8    * <br /><br />
9    * A constraint can be assigned either to a single column (e.g. "..., cash integer CHECK (cash > 0), ...")
10   * or to the entire table (e.g. "..., CONSTRAINT table_pkey PRIMARY KEY (id), ..."). It has three
11   * attributes: its name (not always used, in the second example that would be "table_pkey"), its text
12   * (entire SQL expression used in create table command), and its type which can be PRIMARE_KEY,
13   * FOREIGN_KEY or OTHER.  
14   * 
15   * @author jsuder
16   */
17  
18  public class Constraint implements Serializable {
19  
20  	/***
21  	 * A category to which this constraint belongs.
22  	 */
23  	public enum ConstraintType {
24  		/*** A table's primary key. */
25  		PRIMARY_KEY,
26  		
27  		/*** A table's foreign key (key imported from another table). */
28  		FOREIGN_KEY,
29  		
30  		/*** Other type of constraint (e.g. CHECK constraint). */
31  		OTHER
32  	};
33  	
34  	/*** ID used in serialization process. */
35  	private static final long serialVersionUID = 4284615059751156727L;
36  
37  	/*** Entire SQL expression used in create table command to add this constraint. */
38  	private String fullText;
39  	
40  	/*** Constraint type (see enum ConstraintType description). */
41  	private ConstraintType type;
42  	
43  	/*** Constraint's name (may be empty). */
44  	private String name;
45      
46  	/***
47  	 * Creates a new constraint with a given name, type and contents.
48  	 * @param name the constraint's name (may be empty)
49  	 * @param type constraint type (see enum ConstraintType description)
50  	 * @param fullText SQL expression used in create table command to add this constraint
51  	 */
52  	
53      public Constraint(String name, ConstraintType type, String fullText) {
54      	this.name = name;
55      	this.fullText = fullText;
56      	this.type = type;
57      }
58      
59      /***
60       * Returns this constraint's command.
61       * @return a part of the CREATE TABLE command which refers to this constraint
62       */
63      
64      public String getText() {
65      	return fullText;
66      }
67      
68      /***
69       * Returns this constraint's name.
70       * @return constraint's name
71       */
72      
73      public String getName() {
74      	return name;
75      }
76      
77      /***
78       * Returns this constraint's type ((see ConstraintType enum).
79       * @return constraint's type
80       */
81      
82      public ConstraintType getType() {
83      	return type;
84      }
85  }