001package io.ebean.config.dbplatform.oracle; 002 003import io.ebean.BackgroundExecutor; 004import io.ebean.Query; 005import io.ebean.annotation.Platform; 006import io.ebean.config.dbplatform.BasicSqlAnsiLimiter; 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.PlatformIdGenerator; 012import io.ebean.config.dbplatform.SqlErrorCodes; 013 014import javax.sql.DataSource; 015import java.sql.Types; 016 017/** 018 * Oracle specific platform. 019 */ 020public class OraclePlatform extends DatabasePlatform { 021 022 public OraclePlatform() { 023 super(); 024 this.platform = Platform.ORACLE; 025 this.columnAliasPrefix = "c"; 026 this.supportsDeleteTableAlias = true; 027 this.maxTableNameLength = 30; 028 this.maxConstraintNameLength = 30; 029 this.dbEncrypt = new OracleDbEncrypt(); 030 this.sqlLimiter = new OracleAnsiSqlRowsLimiter(); 031 this.basicSqlLimiter = new BasicSqlAnsiLimiter(); 032 this.historySupport = new OracleDbHistorySupport(); 033 this.truncateTable = "truncate table %s cascade"; 034 dbIdentity.setIdType(IdType.IDENTITY); 035 dbIdentity.setSupportsSequence(true); 036 dbIdentity.setSupportsIdentity(true); 037 dbIdentity.setSupportsGetGeneratedKeys(true); 038 039 this.dbDefaultValue.setFalse("0"); 040 this.dbDefaultValue.setTrue("1"); 041 this.dbDefaultValue.setNow("current_timestamp"); 042 043 this.treatEmptyStringsAsNull = true; 044 this.likeClauseRaw = "like ?"; 045 046 this.exceptionTranslator = 047 new SqlErrorCodes() 048 //.addAcquireLock("") 049 .addDuplicateKey("1") 050 .addDataIntegrity("2291") 051 .addSerializableConflict("72000") 052 .build(); 053 054 this.openQuote = "\""; 055 this.closeQuote = "\""; 056 057 booleanDbType = Types.INTEGER; 058 dbTypeMap.put(DbType.BOOLEAN, new DbPlatformType("number(1)")); 059 060 dbTypeMap.put(DbType.INTEGER, new DbPlatformType("number", 10)); 061 dbTypeMap.put(DbType.BIGINT, new DbPlatformType("number", 19)); 062 dbTypeMap.put(DbType.REAL, new DbPlatformType("number", 19, 4)); 063 dbTypeMap.put(DbType.DOUBLE, new DbPlatformType("number", 19, 4)); 064 dbTypeMap.put(DbType.SMALLINT, new DbPlatformType("number", 5)); 065 dbTypeMap.put(DbType.TINYINT, new DbPlatformType("number", 3)); 066 dbTypeMap.put(DbType.DECIMAL, new DbPlatformType("number", 16, 3)); 067 dbTypeMap.put(DbType.VARCHAR, new DbPlatformType("varchar2", 255)); 068 069 dbTypeMap.put(DbType.LONGVARBINARY, new DbPlatformType("blob")); 070 dbTypeMap.put(DbType.LONGVARCHAR, new DbPlatformType("clob")); 071 dbTypeMap.put(DbType.VARBINARY, new DbPlatformType("raw", 255)); 072 dbTypeMap.put(DbType.BINARY, new DbPlatformType("raw", 255)); 073 074 dbTypeMap.put(DbType.TIME, new DbPlatformType("timestamp")); 075 } 076 077 @Override 078 public PlatformIdGenerator createSequenceIdGenerator(BackgroundExecutor be, DataSource ds, int stepSize, String seqName) { 079 return new OracleSequenceIdGenerator(be, ds, seqName, sequenceBatchSize); 080 } 081 082 @Override 083 protected String withForUpdate(String sql, Query.LockWait lockWait, Query.LockType lockType) { 084 switch (lockWait) { 085 case SKIPLOCKED: 086 return sql + " for update skip locked"; 087 case NOWAIT: 088 return sql + " for update nowait"; 089 default: 090 return sql + " for update"; 091 } 092 } 093 094}