001package com.avaje.ebean.config.dbplatform; 002 003import com.avaje.ebean.BackgroundExecutor; 004import com.avaje.ebean.config.ServerConfig; 005import com.avaje.ebean.dbmigration.ddlgeneration.platform.H2Ddl; 006 007import javax.sql.DataSource; 008import java.util.Properties; 009 010/** 011 * H2 specific platform. 012 */ 013public class H2Platform extends DatabasePlatform { 014 015 public H2Platform() { 016 super(); 017 this.name = "h2"; 018 this.dbEncrypt = new H2DbEncrypt(); 019 this.platformDdl = new H2Ddl(this); 020 this.historySupport = new H2HistorySupport(); 021 this.nativeUuidType = true; 022 this.dbDefaultValue.setNow("now()"); 023 024 this.dbIdentity.setIdType(IdType.IDENTITY); 025 this.dbIdentity.setSupportsGetGeneratedKeys(true); 026 this.dbIdentity.setSupportsSequence(true); 027 this.dbIdentity.setSupportsIdentity(true); 028 029 // like ? escape'' not working in the latest version H2 so just using no 030 // escape clause for now noting that backslash is an escape char for like in H2 031 this.likeClause = "like ?"; 032 033 // H2 data types match default JDBC types 034 // so no changes to dbTypeMap required 035 } 036 037 @Override 038 public void configure(ServerConfig serverConfig) { 039 super.configure(serverConfig); 040 Properties properties = serverConfig.getProperties(); 041 if (properties != null) { 042 String idType = properties.getProperty("ebean.h2.idtype"); 043 if (idType != null) { 044 this.dbIdentity.setIdType(IdType.valueOf(idType)); 045 } 046 } 047 } 048 049 /** 050 * Return a H2 specific sequence IdGenerator that supports batch fetching 051 * sequence values. 052 */ 053 @Override 054 public PlatformIdGenerator createSequenceIdGenerator(BackgroundExecutor be, DataSource ds, 055 String seqName, int batchSize) { 056 057 return new H2SequenceIdGenerator(be, ds, seqName, batchSize); 058 } 059 060 @Override 061 protected String withForUpdate(String sql) { 062 return sql + " for update"; 063 } 064}