001package com.avaje.ebean.config.dbplatform;
002
003import com.avaje.ebean.BackgroundExecutor;
004import com.avaje.ebean.dbmigration.ddlgeneration.platform.H2Ddl;
005
006import javax.sql.DataSource;
007
008/**
009 * H2 specific platform.
010 */
011public class H2Platform extends DatabasePlatform {
012
013  public H2Platform() {
014    super();
015    this.name = "h2";
016    this.dbEncrypt = new H2DbEncrypt();
017    this.platformDdl = new H2Ddl(this.dbTypeMap, dbIdentity);
018    this.historySupport = new H2HistorySupport();
019    this.nativeUuidType = true;
020
021    // only support getGeneratedKeys with non-batch JDBC
022    // so generally use SEQUENCE instead of IDENTITY for H2
023    this.dbIdentity.setIdType(IdType.SEQUENCE);
024    this.dbIdentity.setSupportsGetGeneratedKeys(true);
025    this.dbIdentity.setSupportsSequence(true);
026    this.dbIdentity.setSupportsIdentity(true);
027
028    // like ? escape'' not working in the latest version H2 so just using no
029    // escape clause for now noting that backslash is an escape char for like in H2
030    this.likeClause = "like ?";
031
032    // H2 data types match default JDBC types
033    // so no changes to dbTypeMap required
034  }
035
036  /**
037   * Return a H2 specific sequence IdGenerator that supports batch fetching
038   * sequence values.
039   */
040  @Override
041  public IdGenerator createSequenceIdGenerator(BackgroundExecutor be, DataSource ds,
042      String seqName, int batchSize) {
043
044    return new H2SequenceIdGenerator(be, ds, seqName, batchSize);
045  }
046
047  @Override
048  protected String withForUpdate(String sql) {
049    return sql + " for update";
050  }
051}