KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mapper > dbms > ConstraintSpec


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.mapper.dbms;
24
25
26 /**
27  * Class containing information for relational table constraint creation (shared object).
28  *
29  */

30 public class ConstraintSpec
31 {
32     private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
33     private static final String JavaDoc RCSName = "$Name: $";
34     
35     /* dbms table constraintstypes */
36     public static final byte CONSTRAINT_UNIQUE = 0;
37     
38     private static final String JavaDoc uniqueString = "unique";
39     
40     protected byte type;
41     protected ColumnSpec[] columns = null;
42     
43     //////////////////////////////////////////////////////////////////////////
44
// CONSTRUCTORS
45
//////////////////////////////////////////////////////////////////////////
46
protected ConstraintSpec() {}
47     
48     public ConstraintSpec(String JavaDoc type)
49     {
50         this.type = parseType(type);
51     }
52     
53     public String JavaDoc generateConstraintClause()
54     {
55         StringBuffer JavaDoc clause = new StringBuffer JavaDoc();
56         clause.append("UNIQUE");
57         clause.append(generateColumnList());
58         return clause.toString();
59     }
60     
61     public String JavaDoc generateColumnList()
62     {
63         StringBuffer JavaDoc clause = new StringBuffer JavaDoc();
64         clause.append('(');
65         for (int i = 0; i < columns.length; i++)
66         {
67             clause.append(columns[i].getName());
68             clause.append(",");
69         }
70         clause.setCharAt(clause.length() - 1, ')');
71         return clause.toString();
72     }
73     
74     //////////////////////////////////////////////////////////////////////////
75
// ACCESSORS
76
//////////////////////////////////////////////////////////////////////////
77
public byte getType()
78     {
79         return type;
80     }
81     
82     public void setColumns(ColumnSpec[] columns)
83     {
84         this.columns = columns;
85     }
86
87     private byte parseType(String JavaDoc type)
88     {
89         if (!type.equals(uniqueString))
90             throw new RuntimeException JavaDoc("The DBMS table type" + type + " used in tableSpec.xml is unknown.");
91         return CONSTRAINT_UNIQUE;
92     }
93 }
94
Popular Tags