001package io.ebean.config.dbplatform.nuodb;
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 * NuoDb specific platform.
017 */
018public class NuoDbPlatform extends DatabasePlatform {
019
020  public NuoDbPlatform() {
021    super();
022    this.platform = Platform.NUODB;
023    this.idInExpandedForm = true;
024    this.supportsResultSetConcurrencyModeUpdatable = false;
025    this.supportsDeleteTableAlias = true;
026    this.likeClauseRaw = "like ?";
027    this.historySupport = new NuoDbHistorySupport();
028    //this.dbEncrypt = ...
029    dbIdentity.setIdType(IdType.IDENTITY);
030    dbIdentity.setSupportsIdentity(true);
031    dbIdentity.setSupportsSequence(true);
032    dbIdentity.setSupportsGetGeneratedKeys(true);
033
034    // No referential integrity exception to map
035    this.exceptionTranslator =
036      new SqlErrorCodes()
037        //.addAcquireLock("")
038        .addDuplicateKey("23000")
039        .addSerializableConflict("40002")
040        .build();
041
042    dbTypeMap.put(DbType.INTEGER, new DbPlatformType("integer", false));
043  }
044
045  @Override
046  public PlatformIdGenerator createSequenceIdGenerator(BackgroundExecutor be, DataSource ds, int stepSize, String seqName) {
047    return new NuoDbSequence(be, ds, seqName, stepSize);
048  }
049
050  @Override
051  protected String withForUpdate(String sql, Query.LockWait lockWait, Query.LockType lockType) {
052    switch (lockWait) {
053      case NOWAIT:
054        return sql + " for update nowait";
055      case SKIPLOCKED:
056      default:
057        return sql + " for update";
058    }
059  }
060
061}