KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > extractor > metadata > Table


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.extractor.metadata;
24
25 import java.util.ArrayList JavaDoc;
26 import java.util.List JavaDoc;
27
28 public class Table extends NamedNode
29 {
30
31     private static final String JavaDoc RCSRevision = "$Revision: 1.3 $";
32     private static final String JavaDoc RCSName = "$Name: $";
33
34
35     public static final int TABLE = 0;
36     public static final int VIEW = 1;
37     public static final int SYNONYM = 1;
38
39     protected int _type;
40    protected List JavaDoc _keys;
41
42
43    /**
44    @roseuid 3B278EF20158
45     */

46    public Table()
47    {
48
49    }
50
51    /**
52    @param name
53    @roseuid 3B278EF20180
54     */

55    public Table(String JavaDoc name)
56    {
57         super (name);
58         _alias = name;
59    }
60
61    public Table(String JavaDoc name, String JavaDoc alias)
62    {
63         super (name);
64         _alias = alias;
65    }
66
67    /**
68    @param key
69    @roseuid 3B278EF20298
70     */

71    public void addKey(Attribute key)
72    {
73         if (null == _keys) {
74             _keys = new ArrayList JavaDoc();
75         }
76         List JavaDoc list = new ArrayList JavaDoc ();
77         list.add(key);
78         _keys.add(list);
79         return ;
80    }
81
82    public void addKey(List JavaDoc key)
83    {
84         if (null == _keys) {
85             _keys = new ArrayList JavaDoc();
86         }
87         _keys.add(key);
88         return ;
89    }
90
91    /**
92    @param keys
93    @roseuid 3B278EF202F2
94     */

95    public void setKeys(List JavaDoc keys)
96    {
97         _keys = keys;
98    }
99
100    /**
101    @return org.xquark.xqueryparser.xquery.List
102    @roseuid 3B278EF20360
103     */

104    public List JavaDoc getKeys()
105    {
106         return _keys;
107    }
108
109    public Attribute findAttribute(String JavaDoc attributeName){
110         String JavaDoc str = attributeName.toLowerCase() ;
111         Attribute retVal = (Attribute) findChild(attributeName) ;
112         return retVal ;
113     }
114
115     public int getType() { return _type; }
116
117     public void setType(int type) { _type = type;}
118
119 // public String getFullName() {
120
// StringBuffer retVal = new StringBuffer();
121
// String name = null;
122
// name = getFather().getFather().getName();
123
// if (null != name) {
124
// retVal.append(name);
125
// retVal.append('.');
126
// }
127
//
128
// name = getFather().getName();
129
// if (null != name) {
130
// retVal.append(name);
131
// retVal.append('.');
132
// }
133
//
134
// retVal.append(_name);
135
// return retVal.toString();
136
// }
137

138     public String JavaDoc pprint()
139     {
140         StringBuffer JavaDoc retVal = new StringBuffer JavaDoc();
141
142         String JavaDoc newLine = System.getProperty("line.separator");
143
144         retVal.append("---------- Table : ");
145         retVal.append(_name);
146         retVal.append(" ----------");
147         retVal.append(newLine);
148
149         for (int i = 0; i < _children.size(); i++) {
150             retVal.append(((NamedNode)_children.get(i)).pprint());
151             retVal.append(newLine);
152         }
153         return retVal.toString();
154     }
155
156 }
157
158 /*
159 Table.load(DatabaseMetaData,String,String,String){
160         Table table = new Table (tableName) ;
161         Column column = null ;
162         ResultSet resultSet = null ;
163         String str = null ;
164         try {
165             resultSet = _databaseMetaData.getColumns(catalogName , schemaName,tableName,null );
166             while (resultSet.next()) {
167 // TABLE_CAT, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, DATA_TYPE, TYPE_NAME,
168 // COLUMN_SIZE, BUFFER_LENGTH, DECIMAL_DIGITS, NUM_PREC_RADIX, NULLABLE,
169 // REMARKS, COLUMN_DEF, SQL_DATA_TYPE, SQL_DATETIME_SUB, CHAR_OCTET_LENGTH,
170 // ORDINAL_POSITION, IS_NULLABLE, SS_DATA_TYPE
171                 column = new Column () ;
172                 str = resultSet.getString ( "COLUMN_NAME");
173                 str = str.toLowerCase() ;
174                 column.setName(str);
175                 table.addColumn ( column );
176             }
177             resultSet = _databaseMetaData.getPrimaryKeys(catalogName , schemaName,tableName );
178             while (resultSet.next()) {
179 // TABLE_CAT, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME, DATA_TYPE, TYPE_NAME,
180 // COLUMN_SIZE, BUFFER_LENGTH, DECIMAL_DIGITS, NUM_PREC_RADIX, NULLABLE,
181 // REMARKS, COLUMN_DEF, SQL_DATA_TYPE, SQL_DATETIME_SUB, CHAR_OCTET_LENGTH,
182 // ORDINAL_POSITION, IS_NULLABLE, SS_DATA_TYPE
183                 str = resultSet.getString ( "COLUMN_NAME");
184                 str = str.toLowerCase() ;
185                 column=table.findColumn(str);
186                 table.addKey ( column );
187             }
188         }
189         catch (Exception ex) {
190             ex.printStackTrace();
191         }
192         return table ;
193     }
194
195 Table.setName(String){
196         _name = aName;
197     }
198
199
200
201
202  */

203
Popular Tags