001package io.ebean.config.dbplatform.h2;
002
003import io.ebean.BackgroundExecutor;
004import io.ebean.Query;
005import io.ebean.annotation.Platform;
006import io.ebean.config.dbplatform.DatabasePlatform;
007import io.ebean.config.dbplatform.DbPlatformType;
008import io.ebean.config.dbplatform.DbType;
009import io.ebean.config.dbplatform.IdType;
010import io.ebean.config.dbplatform.PlatformIdGenerator;
011import io.ebean.config.dbplatform.SqlErrorCodes;
012
013import javax.sql.DataSource;
014
015/**
016 * H2 specific platform.
017 */
018public class H2Platform extends DatabasePlatform {
019
020  public H2Platform() {
021    super();
022    this.platform = Platform.H2;
023    this.dbEncrypt = new H2DbEncrypt();
024    this.historySupport = new H2HistorySupport();
025    this.nativeUuidType = true;
026    this.supportsDeleteTableAlias = true;
027    this.inlineSqlUpdateLimit = true;
028    this.dbDefaultValue.setNow("now()");
029    this.exceptionTranslator =
030      new SqlErrorCodes()
031        .addAcquireLock("50200","HYT00")
032        .addDuplicateKey("23001","23505")
033        .addDataIntegrity("22001","22003","22012","22018","22025","23000","23002","23003","23502","23503","23506","23507","23513")
034        .build();
035
036    this.dbIdentity.setIdType(IdType.IDENTITY);
037    this.dbIdentity.setSupportsGetGeneratedKeys(true);
038    this.dbIdentity.setSupportsSequence(true);
039    this.dbIdentity.setSupportsIdentity(true);
040
041    dbTypeMap.put(DbType.UUID, new DbPlatformType("uuid", false));
042  }
043
044  /**
045   * Return a H2 specific sequence IdGenerator that supports batch fetching
046   * sequence values.
047   */
048  @Override
049  public PlatformIdGenerator createSequenceIdGenerator(BackgroundExecutor be, DataSource ds, int stepSize, String seqName) {
050    return new H2SequenceIdGenerator(be, ds, seqName, sequenceBatchSize);
051  }
052
053  @Override
054  protected String withForUpdate(String sql, Query.LockWait lockWait, Query.LockType lockType) {
055    // NOWAIT and SKIP LOCKED currently not supported with H2
056    return sql + " for update";
057  }
058}