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