Skip to main content
summaryrefslogtreecommitdiffstats
blob: 210fea37bd02809e1cc72477f9c58a1f0f311b53 (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
/*******************************************************************************
 * 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.internal.vendor;

import java.util.ArrayList;

import org.eclipse.datatools.modelbase.sql.schema.Database;
import org.eclipse.jpt.utility.internal.StringTools;

class MySQL
	extends AbstractVendor
{
	// singleton
	private static final Vendor INSTANCE = new MySQL();

	/**
	 * Return the singleton.
	 */
	static Vendor instance() {
		return INSTANCE;
	}

	/**
	 * Ensure single instance.
	 */
	private MySQL() {
		super();
	}

	@Override
	public String getDTPVendorName() {
		return "MySql"; //$NON-NLS-1$
	}

	/**
	 * The DTP model for MySQL has a database that contains no catalogs;
	 * but, instead, directly holds a single schema with the same name as
	 * the database. (This is hard-coded in MySqlCatalogDatabase.getSchemas().)
	 * Although you can qualify identifiers with a database name
	 * in MySQL, only the database specified at login seems to be available
	 * in the DTP model....
	 * 
	 * NB: In MySQL DDL, SCHEMA is a synonym for DATABASE; but the JDBC
	 * method DatabaseMetaData.getSchemas() returns an empty list,
	 * while getCatalogs() returns a list of the available databases.
	 * You can also use the JDBC method Connection.setCatalog(String) to
	 * set the default database.
	 */
	@Override
	CatalogStrategy getCatalogStrategy() {
		return NoCatalogStrategy.instance();
	}

	/**
	 * MySQL is a bit unusual, so we force exact matches.
	 * (e.g. MySQL folds database and table names to lowercase on Windows
	 * by default; but that default can be changed by the
	 * 'lower_case_table_names' system variable. This is because databases are
	 * stored as directories and tables are stored as files in the underlying
	 * O/S; and the case-sensitivity of the names is determined by the behavior
	 * of filenames on the O/S. Then, to complicate things,
	 * none of the other identifiers, like index and column names, are folded;
	 * but they are case-insensitive, unless delimited. See
	 * http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html.)
	 */
	@Override
	FoldingStrategy getFoldingStrategy() {
		return NonFoldingStrategy.instance();
	}

	@Override
	void addDefaultSchemaNamesTo(Database database, String userName, ArrayList<String> names) {
		names.add(database.getName());
	}

	/**
	 * MySQL is the only vendor that allows a digit.
	 * Although, the name cannnot be *all* digits.
	 */
	@Override
	boolean characterIsRegularNameStart(char c) {
		return Character.isDigit(c) || super.characterIsRegularNameStart(c);
	}

	@Override
	char[] getExtendedRegularNameStartCharacters() {
		return EXTENDED_REGULAR_NAME_START_CHARACTERS;
	}
	private static final char[] EXTENDED_REGULAR_NAME_START_CHARACTERS = new char[] { '_', '$' };

	/**
	 * By default, MySQL delimits identifiers with backticks (`); but it
	 * can also be configured to use double-quotes.
	 */
	@Override
	boolean identifierIsDelimited(String identifier) {
		return StringTools.stringIsDelimited(identifier, BACKTICK)
					|| super.identifierIsDelimited(identifier);
	}
	private static final char BACKTICK = '`';

}

Back to the top