KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
24  * ColumnSpec.java
25  *
26  * Created on 11 janvier 2001, 16:57
27  */

28
29 package org.xquark.mapper.dbms;
30
31 import java.util.Arrays JavaDoc;
32
33 import org.xquark.mapper.metadata.RepositoryConstants;
34
35 /**
36  * Class containing information for relational table creation (shared object).
37  *
38  */

39 public class TableSpec
40 {
41     private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
42     private static final String JavaDoc RCSName = "$Name: $";
43
44     /* table types (IDs) */
45     public static final byte TYPE_REPOSITORY = 0;
46     public static final byte TYPE_COLLECTIONS = 1;
47     public static final byte TYPE_TABLES = 2;
48     public static final byte TYPE_TABLE_SEQ = 3;
49     public static final byte TYPE_PATHS = 4;
50     public static final byte TYPE_DUAL = 5;
51     public static final byte TYPE_PATH_SEQ = 6;
52     public static final byte TYPE_DOCS = 7;
53     public static final byte TYPE_DOC_SEQ = 8;
54     public static final byte TYPE_FREE_DOC = 9;
55     public static final byte TYPE_STRUCT = 10;
56     public static final byte TYPE_DATA = 11;
57     public static final byte TYPE_USER_DATA = 12;
58     public static final byte TYPE_EXTRA = 13;
59     public static final byte TYPE_QUERY_TMP = 14;
60     
61     /* Categories */
62     public static final byte CAT_QUERY_TMP = 0;
63     public static final byte CAT_REPOSITORY = 1;
64     public static final byte CAT_COLLECTION = 2;
65     public static final byte CAT_USER_TABLE = 3;
66     
67     public static final int CAT_COUNT = 4;
68     
69     /* dbms table types */
70     public static final byte TABLE_DEFAULT = 0;
71     public static final byte TABLE_SEQUENCE = 1;
72     public static final byte TABLE_INDEX_ORGANIZED = 2;
73     public static final byte TABLE_TEMPORARY = 3;
74     
75     private static final byte[] tableTypes =
76     {TABLE_DEFAULT, TABLE_INDEX_ORGANIZED, TABLE_SEQUENCE, TABLE_TEMPORARY};
77      /* Alphabetically sorted */
78      private static final String JavaDoc[] tableTypeStrings =
79      {"default", "index_organized", "sequence", "temporary"};
80       
81     /* dbms types */
82     public static final short ANY = 0;
83     // other values are defined in AbstractConnectionFactory
84

85     private byte type;
86     private byte dbmsType;
87     private byte cat;
88     
89     private boolean sequence = false;
90     private short dbms;
91     private String JavaDoc suffix;
92     private ColumnSpec[] columns;
93     private ConstraintSpec[] constraints;
94     private IndexSpec[] indexes;
95
96     //////////////////////////////////////////////////////////////////////////
97
// CONSTRUCTORS
98
//////////////////////////////////////////////////////////////////////////
99
public TableSpec() {}
100     
101     public TableSpec(byte cat, byte type)
102     {
103         this.cat = cat;
104         this.type = type;
105     }
106     
107     public TableSpec(byte cat, byte type, boolean sequence,
108                                 String JavaDoc suffix, short dbms, String JavaDoc dbmsType)
109     {
110         set(cat, type, sequence, suffix, dbms, dbmsType);
111     }
112     
113     public String JavaDoc getTableName()
114     {
115         StringBuffer JavaDoc tableName = new StringBuffer JavaDoc();
116         tableName.append(RepositoryConstants.TABLE_PREFIX);
117         tableName.append(suffix);
118         
119         return tableName.toString();
120     }
121     
122     public String JavaDoc getTableName(short collectionID)
123     {
124         StringBuffer JavaDoc tableName = new StringBuffer JavaDoc();
125         tableName.append(RepositoryConstants.TABLE_PREFIX);
126         tableName.append(collectionID);
127         tableName.append('_');
128         tableName.append(suffix);
129         
130         return tableName.toString();
131     }
132     
133     public String JavaDoc getAllCollectionsWildcardTableName()
134     {
135         StringBuffer JavaDoc tableName = new StringBuffer JavaDoc();
136         tableName.append(RepositoryConstants.TABLE_PREFIX);
137         tableName.append("%_");
138         tableName.append(suffix);
139         
140         return tableName.toString();
141     }
142     
143     public String JavaDoc getTableName(short collectionID, short tableID)
144     {
145         StringBuffer JavaDoc tableName = new StringBuffer JavaDoc();
146         tableName.append(RepositoryConstants.TABLE_PREFIX);
147         tableName.append(collectionID);
148         tableName.append('_');
149         tableName.append(suffix);
150         tableName.append(tableID);
151         
152         return tableName.toString();
153     }
154     
155     //////////////////////////////////////////////////////////////////////////
156
// ACCESSORS
157
//////////////////////////////////////////////////////////////////////////
158
public void set(byte cat, byte type, boolean sequence,
159                                 String JavaDoc suffix, short dbms, String JavaDoc dbmsType)
160     {
161         this.cat = cat;
162         this.type = type;
163         this.sequence = sequence;
164         this.suffix = suffix;
165         this.dbms = dbms;
166         this.dbmsType = parseDBMSType(dbmsType);
167     }
168     
169     public String JavaDoc getSuffix()
170     {
171         return suffix;
172     }
173     
174     public byte getType()
175     {
176         return type;
177     }
178     
179     public byte getDBMSType()
180     {
181         return dbmsType;
182     }
183     
184     public short getDBMSVendor()
185     {
186         return dbms;
187     }
188     
189     public boolean isSequence()
190     {
191         return sequence;
192     }
193     
194     public ColumnSpec[] getColumns()
195     {
196         return columns;
197     }
198     
199     public ConstraintSpec[] getConstraints()
200     {
201         return constraints;
202     }
203     
204     public IndexSpec[] getIndexes()
205     {
206         return indexes;
207     }
208     
209     public void setSuffix(String JavaDoc suffix)
210     {
211         this.suffix = suffix;
212     }
213     
214     public void setColumns(ColumnSpec[] columns)
215     {
216         this.columns = columns;
217     }
218
219     public void setConstraints(ConstraintSpec[] constraints)
220     {
221         this.constraints = constraints;
222     }
223
224     public void setIndexes(IndexSpec[] indexes)
225     {
226         this.indexes = indexes;
227     }
228
229     private byte parseDBMSType(String JavaDoc type)
230     {
231         int index = Arrays.binarySearch(tableTypeStrings, type);
232         if (index < 0)
233             throw new RuntimeException JavaDoc("The DBMS table type" + type + " used in tableSpec.xml is unknown.");
234         return tableTypes[index];
235     }
236 }
237
Popular Tags