01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.jdbc.metadata;
12:
13: import com.versant.core.metadata.ModelMetaData;
14: import com.versant.core.metadata.ClassMetaData;
15: import com.versant.core.jdbc.JdbcConfig;
16: import com.versant.core.util.BeanUtils;
17: import com.versant.core.jdbc.sql.diff.ControlParams;
18: import com.versant.core.jdbc.JdbcConfig;
19:
20: import java.io.Serializable;
21: import java.util.ArrayList;
22: import java.util.HashSet;
23: import java.util.Collections;
24:
25: /**
26: * Extra JDBC specific meta data attached to JDOMetaData.
27: */
28: public class JdbcMetaData {
29:
30: private final ModelMetaData jmd;
31: private final ControlParams migrationParams;
32:
33: /**
34: * These are all the tables required for the key generators.
35: */
36: public JdbcTable[] keyGenTables;
37: /**
38: * This is the max number of simple fields in the primary key of the
39: * table for any class.
40: */
41: public int maxPkSimpleColumns;
42:
43: public JdbcMetaData(ModelMetaData jmd, JdbcConfig config) {
44: this .jmd = jmd;
45: migrationParams = new ControlParams();
46: BeanUtils.setProperties(migrationParams,
47: config.jdbcMigrationControlProps);
48: }
49:
50: public ControlParams getMigrationParams() {
51: return migrationParams;
52: }
53:
54: /**
55: * Get all tables for store sorted in name order. Tables for classes
56: * flagged as doNotCreateTable are left out.
57: */
58: public ArrayList getTables() {
59: return getTables(false);
60: }
61:
62: /**
63: * Get all tables for store sorted in name order. If all is false tables
64: * for classes flagged as doNotCreateTable are left out.
65: */
66: public ArrayList getTables(boolean all) {
67: HashSet tables = new HashSet();
68: ClassMetaData[] classes = jmd.classes;
69: for (int i = classes.length - 1; i >= 0; i--) {
70: ClassMetaData cmd = jmd.classes[i];
71: JdbcClass jdbcClass = (JdbcClass) cmd.storeClass;
72: if (!all && jdbcClass.doNotCreateTable) {
73: continue;
74: }
75: jdbcClass.getTables(tables);
76: }
77: ArrayList a = new ArrayList(tables);
78:
79: JdbcTable[] keyGenTables = ((JdbcMetaData) jmd.jdbcMetaData).keyGenTables;
80: if (keyGenTables != null) {
81: for (int i = 0; i < keyGenTables.length; i++) {
82: JdbcTable keyGenTable = keyGenTables[i];
83: if (keyGenTable != null) {
84: a.add(keyGenTable);
85: }
86: }
87: }
88: Collections.sort(a);
89: return a;
90: }
91:
92: }
|