01: /*
02: * Copyright 2003 (C) TJDO.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the TJDO License version 1.0.
06: * See the terms of the TJDO License in the documentation provided with this software.
07: *
08: * $Id: MySQLAdapter.java,v 1.4 2004/03/22 04:58:13 jackknifebarber Exp $
09: */
10:
11: package com.triactive.jdo.store;
12:
13: import java.sql.DatabaseMetaData;
14: import java.sql.ResultSet;
15:
16: /**
17: * Provides methods for adapting SQL language elements to the MySQL
18: * database.
19: *
20: * @author <a href="mailto:mmartin5@austin.rr.com">Mike Martin</a>
21: */
22:
23: public class MySQLAdapter extends DatabaseAdapter {
24: /**
25: * A string containing the list of MySQL keywords that are not also SQL/92
26: * <dfn>reserved words</dfn>, separated by commas.
27: * This list is normally obtained dynamically from the driver using
28: * DatabaseMetaData.getSQLKeywords(), but MySQL drivers are known to return
29: * an imcomplete list.
30: * <p>
31: * This list was produced based on the reserved word list in the MySQL
32: * Manual (Version 4.0.10-gamma) at http://www.mysql.com/doc/en/Reserved_words.html.
33: */
34:
35: public static final String NONSQL92_RESERVED_WORDS = "ANALYZE,AUTO_INCREMENT,BDB,BERKELEYDB,BIGINT,BINARY,BLOB,BTREE,"
36: + "CHANGE,COLUMNS,DATABASE,DATABASES,DAY_HOUR,DAY_MINUTE,DAY_SECOND,"
37: + "DELAYED,DISTINCTROW,DIV,ENCLOSED,ERRORS,ESCAPED,EXPLAIN,FIELDS,"
38: + "FORCE,FULLTEXT,FUNCTION,GEOMETRY,HASH,HELP,HIGH_PRIORITY,"
39: + "HOUR_MINUTE,HOUR_SECOND,IF,IGNORE,INDEX,INFILE,INNODB,KEYS,KILL,"
40: + "LIMIT,LINES,LOAD,LOCALTIME,LOCALTIMESTAMP,LOCK,LONG,LONGBLOB,"
41: + "LONGTEXT,LOW_PRIORITY,MASTER_SERVER_ID,MEDIUMBLOB,MEDIUMINT,"
42: + "MEDIUMTEXT,MIDDLEINT,MINUTE_SECOND,MOD,MRG_MYISAM,OPTIMIZE,"
43: + "OPTIONALLY,OUTFILE,PURGE,REGEXP,RENAME,REPLACE,REQUIRE,RETURNS,"
44: + "RLIKE,RTREE,SHOW,SONAME,SPATIAL,SQL_BIG_RESULT,SQL_CALC_FOUND_ROWS,"
45: + "SQL_SMALL_RESULT,SSL,STARTING,STRAIGHT_JOIN,STRIPED,TABLES,"
46: + "TERMINATED,TINYBLOB,TINYINT,TINYTEXT,TYPES,UNLOCK,UNSIGNED,USE,"
47: + "USER_RESOURCES,VARBINARY,VARCHARACTER,WARNINGS,XOR,YEAR_MONTH,"
48: + "ZEROFILL";
49:
50: public MySQLAdapter(DatabaseMetaData metadata) {
51: super (metadata);
52:
53: keywords.addAll(parseKeywordList(NONSQL92_RESERVED_WORDS));
54: }
55:
56: public String getVendorID() {
57: return "mysql";
58: }
59:
60: public TableExpression newTableExpression(QueryStatement qs,
61: Table table, SQLIdentifier rangeVar) {
62: return new TableExprAsJoins(qs, table, rangeVar);
63: }
64:
65: public TypeInfo newTypeInfo(ResultSet rs) {
66: TypeInfo ti = new MySQLTypeInfo(rs);
67:
68: /*
69: * Exclude BINARY and VARBINARY so we don't use them. These equate to
70: * CHAR(m) BINARY and VARCHAR(m) BINARY respectively, which aren't true
71: * binary types (e.g. trailing space characters are stripped).
72: */
73: if (ti.typeName.equalsIgnoreCase("binary")
74: || ti.typeName.equalsIgnoreCase("varbinary"))
75: return null;
76:
77: return ti;
78: }
79:
80: public boolean createIndexesBeforeForeignKeys() {
81: return true;
82: }
83:
84: public boolean supportsAlterTableDropConstraint() {
85: return false;
86: }
87:
88: public boolean supportsDeferredConstraints() {
89: return false;
90: }
91: }
|