View Javadoc
1   package edu.internet2.middleware.grouper.ext.org.apache.ddlutils.platform.mysql;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.sql.Types;
23  
24  import edu.internet2.middleware.grouper.ext.org.apache.ddlutils.PlatformInfo;
25  import edu.internet2.middleware.grouper.ext.org.apache.ddlutils.platform.PlatformImplBase;
26  
27  /**
28   * The platform implementation for MySQL.
29   * 
30   * @version $Revision: 231306 $
31   */
32  public class MySqlPlatform extends PlatformImplBase
33  {
34      /** Database name of this platform. */
35      public static final String DATABASENAME     = "MySQL";
36      /** The standard MySQL jdbc driver. */
37      public static final String JDBC_DRIVER      = "com.mysql.cj.jdbc.Driver";
38      /** The old MySQL jdbc driver. */
39      public static final String JDBC_DRIVER_OLD  = "org.gjt.mm.mysql.Driver";
40      /** The subprotocol used by the standard MySQL driver. */
41      public static final String JDBC_SUBPROTOCOL = "mysql";
42  
43      /**
44       * Creates a new platform instance.
45       */
46      public MySqlPlatform()
47      {
48          PlatformInfo info = getPlatformInfo();
49  
50          info.setMaxIdentifierLength(64);
51          info.setNullAsDefaultValueRequired(true);
52          info.setDefaultValuesForLongTypesSupported(false);
53          // see http://dev.mysql.com/doc/refman/4.1/en/example-auto-increment.html
54          info.setNonPKIdentityColumnsSupported(false);
55          // MySql returns synthetic default values for pk columns
56          info.setSyntheticDefaultValueForRequiredReturned(true);
57          info.setCommentPrefix("#");
58          // Double quotes are only allowed for delimiting identifiers if the server SQL mode includes ANSI_QUOTES 
59          info.setDelimiterToken("`");
60  
61          info.addNativeTypeMapping(Types.ARRAY,         "LONGBLOB",          Types.LONGVARBINARY);
62          info.addNativeTypeMapping(Types.BIT,           "TINYINT(1)");
63          info.addNativeTypeMapping(Types.BLOB,          "LONGBLOB",          Types.LONGVARBINARY);
64          info.addNativeTypeMapping(Types.CLOB,          "LONGTEXT",          Types.LONGVARCHAR);
65          info.addNativeTypeMapping(Types.DISTINCT,      "LONGBLOB",          Types.LONGVARBINARY);
66          info.addNativeTypeMapping(Types.FLOAT,         "DOUBLE",            Types.DOUBLE);
67          info.addNativeTypeMapping(Types.JAVA_OBJECT,   "LONGBLOB",          Types.LONGVARBINARY);
68          info.addNativeTypeMapping(Types.LONGVARBINARY, "MEDIUMBLOB");
69          info.addNativeTypeMapping(Types.LONGVARCHAR,   "MEDIUMTEXT");
70          info.addNativeTypeMapping(Types.NULL,          "MEDIUMBLOB",        Types.LONGVARBINARY);
71          info.addNativeTypeMapping(Types.NUMERIC,       "DECIMAL",           Types.DECIMAL);
72          info.addNativeTypeMapping(Types.OTHER,         "LONGBLOB",          Types.LONGVARBINARY);
73          info.addNativeTypeMapping(Types.REAL,          "FLOAT");
74          info.addNativeTypeMapping(Types.REF,           "MEDIUMBLOB",        Types.LONGVARBINARY);
75          info.addNativeTypeMapping(Types.STRUCT,        "LONGBLOB",          Types.LONGVARBINARY);
76          // Since TIMESTAMP is not a stable datatype yet, and does not support a higher precision
77          // than DATETIME (year to seconds) as of MySQL 5, we map the JDBC type here to DATETIME
78          // TODO: Make this configurable
79          info.addNativeTypeMapping(Types.TIMESTAMP,     "DATETIME");
80          // In MySql, TINYINT has only a range of -128 to 127
81          info.addNativeTypeMapping(Types.TINYINT,       "SMALLINT",          Types.SMALLINT);
82          info.addNativeTypeMapping("BOOLEAN",  "TINYINT(1)", "BIT");
83          info.addNativeTypeMapping("DATALINK", "MEDIUMBLOB", "LONGVARBINARY");
84  
85          info.setDefaultSize(Types.CHAR,      254);
86          info.setDefaultSize(Types.VARCHAR,   254);
87          info.setDefaultSize(Types.BINARY,    254);
88          info.setDefaultSize(Types.VARBINARY, 254);
89          
90          setSqlBuilder(new MySqlBuilder(this));
91          setModelReader(new MySqlModelReader(this));
92      }
93  
94      /**
95       * {@inheritDoc}
96       */
97      public String getName()
98      {
99          return DATABASENAME;
100     }
101 }