001package io.ebean.config.dbplatform.hana;
002
003import io.ebean.Query.ForUpdate;
004import io.ebean.annotation.PersistBatch;
005import io.ebean.annotation.Platform;
006import io.ebean.config.PlatformConfig;
007import io.ebean.config.dbplatform.DatabasePlatform;
008import io.ebean.config.dbplatform.DbPlatformType;
009import io.ebean.config.dbplatform.DbType;
010import io.ebean.config.dbplatform.IdType;
011import io.ebean.config.dbplatform.SqlErrorCodes;
012
013public class HanaPlatform extends DatabasePlatform {
014
015  public HanaPlatform() {
016    this.platform = Platform.HANA;
017    this.sqlLimiter = new HanaSqlLimiter();
018    this.persistBatchOnCascade = PersistBatch.NONE;
019    this.supportsResultSetConcurrencyModeUpdatable = false;
020    this.columnAliasPrefix = null;
021
022    this.historySupport = new HanaHistorySupport();
023    this.basicSqlLimiter = new HanaBasicSqlLimiter();
024
025    this.likeClauseRaw = "like ?";
026    this.maxConstraintNameLength = 127;
027    this.maxTableNameLength = 127;
028
029    this.dbDefaultValue.setNow("current_timestamp");
030
031    this.exceptionTranslator = new SqlErrorCodes().addAcquireLock("131", "133", "146")
032      .addDataIntegrity("130", "429", "461", "462").addDuplicateKey("144", "301", "349").build();
033
034    this.dbIdentity.setIdType(IdType.IDENTITY);
035    this.dbIdentity.setSelectLastInsertedIdTemplate("select current_identity_value() from sys.dummy");
036    this.dbIdentity.setSupportsGetGeneratedKeys(false);
037    this.dbIdentity.setSupportsIdentity(true);
038
039    this.dbTypeMap.put(DbType.BIGINT, new DbPlatformType("bigint", false));
040    this.dbTypeMap.put(DbType.BINARY, new DbPlatformType("varbinary", 255));
041    this.dbTypeMap.put(DbType.BIT, new DbPlatformType("smallint", false));
042    this.dbTypeMap.put(DbType.BLOB, new DbPlatformType("blob", false));
043    this.dbTypeMap.put(DbType.CHAR, new DbPlatformType("nvarchar", 255));
044    this.dbTypeMap.put(DbType.CLOB, new DbPlatformType("nclob", false));
045    this.dbTypeMap.put(DbType.INTEGER, new DbPlatformType("integer", false));
046    this.dbTypeMap.put(DbType.JSONVARCHAR, new DbPlatformType("nvarchar", 255));
047    this.dbTypeMap.put(DbType.LINESTRING, new DbPlatformType("st_geometry"));
048    this.dbTypeMap.put(DbType.LONGVARBINARY, new DbPlatformType("blob", false));
049    this.dbTypeMap.put(DbType.LONGVARCHAR, new DbPlatformType("nclob", false));
050    this.dbTypeMap.put(DbType.MULTILINESTRING, new DbPlatformType("st_geometry"));
051    this.dbTypeMap.put(DbType.MULTIPOINT, new DbPlatformType("st_geometry"));
052    this.dbTypeMap.put(DbType.MULTIPOLYGON, new DbPlatformType("st_geometry"));
053    this.dbTypeMap.put(DbType.POINT, new DbPlatformType("st_point"));
054    this.dbTypeMap.put(DbType.POLYGON, new DbPlatformType("st_geometry"));
055    this.dbTypeMap.put(DbType.SMALLINT, new DbPlatformType("smallint", false));
056    this.dbTypeMap.put(DbType.TINYINT, new DbPlatformType("smallint", false));
057    this.dbTypeMap.put(DbType.UUID, new DbPlatformType("varchar", 40));
058    this.dbTypeMap.put(DbType.VARBINARY, new DbPlatformType("varbinary", 255));
059    this.dbTypeMap.put(DbType.VARCHAR, new DbPlatformType("nvarchar", 255));
060  }
061
062  @Override
063  protected void addGeoTypes(int srid) {
064    this.dbTypeMap.put(DbType.LINESTRING, new DbPlatformType("st_geometry(" + srid + ")", false));
065    this.dbTypeMap.put(DbType.MULTILINESTRING, new DbPlatformType("st_geometry(" + srid + ")", false));
066    this.dbTypeMap.put(DbType.MULTIPOINT, new DbPlatformType("st_geometry(" + srid + ")", false));
067    this.dbTypeMap.put(DbType.MULTIPOLYGON, new DbPlatformType("st_geometry(" + srid + ")", false));
068    this.dbTypeMap.put(DbType.POINT, new DbPlatformType("st_point(" + srid + ")", false));
069    this.dbTypeMap.put(DbType.POLYGON, new DbPlatformType("st_geometry(" + srid + ")", false));
070  }
071
072  @Override
073  protected String withForUpdate(String sql, ForUpdate forUpdateMode) {
074    switch (forUpdateMode) {
075      case BASE:
076        return sql + " for update";
077      case NOWAIT:
078        return sql + " for update nowait";
079      case SKIPLOCKED:
080        return sql + " for update ignore locked";
081      default:
082        throw new IllegalArgumentException("Unknown update mode: " + forUpdateMode.name());
083    }
084  }
085
086  @Override
087  protected void configure(PlatformConfig config, boolean allQuotedIdentifiers) {
088    super.configure(config, allQuotedIdentifiers);
089    if (config.getDbUuid().useBinary()) {
090      this.dbTypeMap.put(DbType.UUID, new DbPlatformType("varbinary", 16));
091    } else {
092      this.dbTypeMap.put(DbType.UUID, new DbPlatformType("varchar", 40));
093    }
094  }
095
096}