Skip to main content
summaryrefslogtreecommitdiffstats
blob: ce05d768f8493e8ac512cf1d803655dcf88406a9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*******************************************************************************
 * Copyright (c) 2009 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
 * 
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.db.tests.internal;

import java.sql.Connection;
import java.sql.DriverManager;

import junit.framework.TestCase;

/**
 * These aren't tests. They are just an easy way to dump JDBC metadata to the
 * console.
 */
@SuppressWarnings("nls")
public class JDBCTests extends TestCase {

	public JDBCTests(String name) {
		super(name);
	}

	public void testDerby() throws Exception {
		this.dumpMetaData(DERBY);
	}

	public void testMySQL() throws Exception {
		this.dumpMetaData(MYSQL);
	}

	public void testOracle() throws Exception {
		this.dumpMetaData(ORACLE);
	}

	public void testPostgreSQL() throws Exception {
		this.dumpMetaData(POSTGRESQL);
	}

	public void testSybase() throws Exception {
		this.dumpMetaData(SYBASE);
	}

	protected void dumpMetaData(ConnectionConfig config) throws Exception {
		System.out.println("***** PLATFORM: " + config.platformName + " *****");
		System.out.println();
		Class.forName(config.driverClassName);
		Connection connection = DriverManager.getConnection(this.buildURL(config), config.user, config.password);
		System.out.println("CATALOGS:");
		JDBCTools.dump(connection.getMetaData().getCatalogs());
		System.out.println();
		System.out.println("SCHEMATA:");
		JDBCTools.dump(connection.getMetaData().getSchemas());
		connection.close();
		System.out.println();
	}

	protected String buildURL(ConnectionConfig config) {
		return "jdbc:" + config.databaseURL;
	}

	protected static final ConnectionConfig DERBY =
		new ConnectionConfig(
			"Derby",
			"org.apache.derby.jdbc.EmbeddedDriver",
			"derby:C:/derby/data/test",
			null,
			null
		);

	protected static final ConnectionConfig MYSQL =
		new ConnectionConfig(
			"MySQL",
			"com.mysql.jdbc.Driver",
			"mysql://localhost:3306",
			"root",
			"oracle"
		);

	protected static final ConnectionConfig ORACLE =
		new ConnectionConfig(
			"Oracle",
			"oracle.jdbc.OracleDriver",
			"oracle:thin:@localhost:1521:orcl",
			"scott",
			"tiger"
		);

	protected static final ConnectionConfig POSTGRESQL =
		new ConnectionConfig(
			"PostgreSQL",
			"org.postgresql.Driver",
			"postgresql:postgres",
			"postgres",
			"oracle"
		);

	// the Sybase server must be configured explicitly to "localhost"
	// in the config file [SYBASE]/ini/sql.ini
	protected static final ConnectionConfig SYBASE =
		new ConnectionConfig(
			"Sybase",
			"com.sybase.jdbc3.jdbc.SybDriver",
			"sybase:Tds:localhost:5000",
			"sa",
			"oracle"
		);

	protected static class ConnectionConfig {
		protected final String platformName;
		protected final String driverClassName;
		protected final String databaseURL;
		protected final String user;
		protected final String password;
		protected ConnectionConfig(
				String platformName,
				String driverClassName,
				String databaseURL,
				String user,
				String password
		) {
			super();
			this.platformName = platformName;
			this.driverClassName = driverClassName;
			this.databaseURL = databaseURL;
			this.user = user;
			this.password = password;
		}
	}

}

Back to the top