KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > store > MySQLAdapter


1 /*
2  * Copyright 2003 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: MySQLAdapter.java,v 1.4 2004/03/22 04:58:13 jackknifebarber Exp $
9  */

10
11 package com.triactive.jdo.store;
12
13 import java.sql.DatabaseMetaData JavaDoc;
14 import java.sql.ResultSet JavaDoc;
15
16
17 /**
18  * Provides methods for adapting SQL language elements to the MySQL
19  * database.
20  *
21  * @author <a HREF="mailto:mmartin5@austin.rr.com">Mike Martin</a>
22  */

23
24 public class MySQLAdapter extends DatabaseAdapter
25 {
26     /**
27      * A string containing the list of MySQL keywords that are not also SQL/92
28      * <dfn>reserved words</dfn>, separated by commas.
29      * This list is normally obtained dynamically from the driver using
30      * DatabaseMetaData.getSQLKeywords(), but MySQL drivers are known to return
31      * an imcomplete list.
32      * <p>
33      * This list was produced based on the reserved word list in the MySQL
34      * Manual (Version 4.0.10-gamma) at http://www.mysql.com/doc/en/Reserved_words.html.
35      */

36
37     public static final String JavaDoc NONSQL92_RESERVED_WORDS =
38         "ANALYZE,AUTO_INCREMENT,BDB,BERKELEYDB,BIGINT,BINARY,BLOB,BTREE," +
39         "CHANGE,COLUMNS,DATABASE,DATABASES,DAY_HOUR,DAY_MINUTE,DAY_SECOND," +
40         "DELAYED,DISTINCTROW,DIV,ENCLOSED,ERRORS,ESCAPED,EXPLAIN,FIELDS," +
41         "FORCE,FULLTEXT,FUNCTION,GEOMETRY,HASH,HELP,HIGH_PRIORITY," +
42         "HOUR_MINUTE,HOUR_SECOND,IF,IGNORE,INDEX,INFILE,INNODB,KEYS,KILL," +
43         "LIMIT,LINES,LOAD,LOCALTIME,LOCALTIMESTAMP,LOCK,LONG,LONGBLOB," +
44         "LONGTEXT,LOW_PRIORITY,MASTER_SERVER_ID,MEDIUMBLOB,MEDIUMINT," +
45         "MEDIUMTEXT,MIDDLEINT,MINUTE_SECOND,MOD,MRG_MYISAM,OPTIMIZE," +
46         "OPTIONALLY,OUTFILE,PURGE,REGEXP,RENAME,REPLACE,REQUIRE,RETURNS," +
47         "RLIKE,RTREE,SHOW,SONAME,SPATIAL,SQL_BIG_RESULT,SQL_CALC_FOUND_ROWS," +
48         "SQL_SMALL_RESULT,SSL,STARTING,STRAIGHT_JOIN,STRIPED,TABLES," +
49         "TERMINATED,TINYBLOB,TINYINT,TINYTEXT,TYPES,UNLOCK,UNSIGNED,USE," +
50         "USER_RESOURCES,VARBINARY,VARCHARACTER,WARNINGS,XOR,YEAR_MONTH," +
51         "ZEROFILL";
52
53
54     public MySQLAdapter(DatabaseMetaData JavaDoc metadata)
55     {
56         super(metadata);
57
58         keywords.addAll(parseKeywordList(NONSQL92_RESERVED_WORDS));
59     }
60
61     public String JavaDoc getVendorID()
62     {
63         return "mysql";
64     }
65
66     public TableExpression newTableExpression(QueryStatement qs, Table table, SQLIdentifier rangeVar)
67     {
68         return new TableExprAsJoins(qs, table, rangeVar);
69     }
70
71     public TypeInfo newTypeInfo(ResultSet JavaDoc rs)
72     {
73         TypeInfo ti = new MySQLTypeInfo(rs);
74
75         /*
76          * Exclude BINARY and VARBINARY so we don't use them. These equate to
77          * CHAR(m) BINARY and VARCHAR(m) BINARY respectively, which aren't true
78          * binary types (e.g. trailing space characters are stripped).
79          */

80         if (ti.typeName.equalsIgnoreCase("binary") ||
81             ti.typeName.equalsIgnoreCase("varbinary"))
82             return null;
83
84         return ti;
85     }
86
87     public boolean createIndexesBeforeForeignKeys()
88     {
89         return true;
90     }
91
92     public boolean supportsAlterTableDropConstraint()
93     {
94         return false;
95     }
96
97     public boolean supportsDeferredConstraints()
98     {
99         return false;
100     }
101 }
102
Popular Tags