001package com.avaje.ebean.config.dbplatform; 002 003import com.avaje.ebean.BackgroundExecutor; 004import com.avaje.ebean.dbmigration.ddlgeneration.platform.MySqlDdl; 005 006import javax.sql.DataSource; 007import java.sql.Types; 008 009/** 010 * MySQL specific platform. 011 * <p> 012 * <ul> 013 * <li>supportsGetGeneratedKeys = true</li> 014 * <li>Uses LIMIT OFFSET clause</li> 015 * <li>Uses ` for quoted identifiers</li> 016 * </ul> 017 * </p> 018 */ 019public class MySqlPlatform extends DatabasePlatform { 020 021 public MySqlPlatform() { 022 super(); 023 this.name = "mysql"; 024 this.useExtraTransactionOnIterateSecondaryQueries = true; 025 this.likeClause = "like ? escape''"; 026 this.selectCountWithAlias = true; 027 this.dbEncrypt = new MySqlDbEncrypt(); 028 this.platformDdl = new MySqlDdl(this); 029 this.historySupport = new MySqlHistorySupport(); 030 031 this.dbIdentity.setIdType(IdType.IDENTITY); 032 this.dbIdentity.setSupportsGetGeneratedKeys(true); 033 this.dbIdentity.setSupportsIdentity(true); 034 this.dbIdentity.setSupportsSequence(false); 035 036 this.openQuote = "`"; 037 this.closeQuote = "`"; 038 039 this.forwardOnlyHintOnFindIterate = true; 040 this.booleanDbType = Types.BIT; 041 042 dbTypeMap.put(Types.BIT, new DbType("tinyint(1) default 0")); 043 dbTypeMap.put(Types.BOOLEAN, new DbType("tinyint(1) default 0")); 044 dbTypeMap.put(Types.TIMESTAMP, new DbType("datetime(6)")); 045 dbTypeMap.put(Types.CLOB, new MySqlClob()); 046 dbTypeMap.put(Types.BLOB, new MySqlBlob()); 047 dbTypeMap.put(Types.BINARY, new DbType("binary", 255)); 048 dbTypeMap.put(Types.VARBINARY, new DbType("varbinary", 255)); 049 } 050 051 /** 052 * Return null in case there is a sequence annotation. 053 */ 054 @Override 055 public PlatformIdGenerator createSequenceIdGenerator(BackgroundExecutor be, 056 DataSource ds, String seqName, int batchSize) { 057 058 return null; 059 } 060 061 @Override 062 protected String withForUpdate(String sql) { 063 return sql + " for update"; 064 } 065}