KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdbc > metadata > JdbcMetaData


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdbc.metadata;
13
14 import com.versant.core.metadata.ModelMetaData;
15 import com.versant.core.metadata.ClassMetaData;
16 import com.versant.core.jdbc.JdbcConfig;
17 import com.versant.core.util.BeanUtils;
18 import com.versant.core.jdbc.sql.diff.ControlParams;
19 import com.versant.core.jdbc.JdbcConfig;
20
21 import java.io.Serializable JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Collections JavaDoc;
25
26 /**
27  * Extra JDBC specific meta data attached to JDOMetaData.
28  */

29 public class JdbcMetaData {
30
31     private final ModelMetaData jmd;
32     private final ControlParams migrationParams;
33
34     /**
35      * These are all the tables required for the key generators.
36      */

37     public JdbcTable[] keyGenTables;
38     /**
39      * This is the max number of simple fields in the primary key of the
40      * table for any class.
41      */

42     public int maxPkSimpleColumns;
43
44     public JdbcMetaData(ModelMetaData jmd, JdbcConfig config) {
45         this.jmd = jmd;
46         migrationParams = new ControlParams();
47         BeanUtils.setProperties(migrationParams,
48                 config.jdbcMigrationControlProps);
49     }
50
51     public ControlParams getMigrationParams() {
52         return migrationParams;
53     }
54
55     /**
56      * Get all tables for store sorted in name order. Tables for classes
57      * flagged as doNotCreateTable are left out.
58      */

59     public ArrayList JavaDoc getTables() {
60         return getTables(false);
61     }
62
63     /**
64      * Get all tables for store sorted in name order. If all is false tables
65      * for classes flagged as doNotCreateTable are left out.
66      */

67     public ArrayList JavaDoc getTables(boolean all) {
68         HashSet JavaDoc tables = new HashSet JavaDoc();
69         ClassMetaData[] classes = jmd.classes;
70         for (int i = classes.length - 1; i >= 0; i--) {
71             ClassMetaData cmd = jmd.classes[i];
72             JdbcClass jdbcClass = (JdbcClass)cmd.storeClass;
73             if (!all && jdbcClass.doNotCreateTable) {
74                 continue;
75             }
76             jdbcClass.getTables(tables);
77         }
78         ArrayList JavaDoc a = new ArrayList JavaDoc(tables);
79
80         JdbcTable[] keyGenTables = ((JdbcMetaData)jmd.jdbcMetaData).keyGenTables;
81         if (keyGenTables != null) {
82             for (int i = 0; i < keyGenTables.length; i++) {
83                 JdbcTable keyGenTable = keyGenTables[i];
84                 if (keyGenTable != null) {
85                     a.add(keyGenTable);
86                 }
87             }
88         }
89         Collections.sort(a);
90         return a;
91     }
92
93 }
94
Popular Tags