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.supportsDeleteTableAlias = true; 026 this.maxInBinding = 1000; 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 this.dbDefaultValue.setFalse("0"); 039 this.dbDefaultValue.setTrue("1"); 040 this.dbDefaultValue.setNow("current_timestamp"); 041 this.treatEmptyStringsAsNull = true; 042 this.likeClauseRaw = "like ?"; 043 044 this.exceptionTranslator = 045 new SqlErrorCodes() 046 //.addAcquireLock("") 047 .addDuplicateKey("1") 048 .addDataIntegrity("2291") 049 .addSerializableConflict("72000") 050 .build(); 051 052 this.openQuote = "\""; 053 this.closeQuote = "\""; 054 055 booleanDbType = Types.INTEGER; 056 dbTypeMap.put(DbType.BOOLEAN, new DbPlatformType("number(1)")); 057 dbTypeMap.put(DbType.INTEGER, new DbPlatformType("number", 10)); 058 dbTypeMap.put(DbType.BIGINT, new DbPlatformType("number", 19)); 059 dbTypeMap.put(DbType.REAL, new DbPlatformType("number", 19, 4)); 060 dbTypeMap.put(DbType.DOUBLE, new DbPlatformType("number", 19, 4)); 061 dbTypeMap.put(DbType.SMALLINT, new DbPlatformType("number", 5)); 062 dbTypeMap.put(DbType.TINYINT, new DbPlatformType("number", 3)); 063 dbTypeMap.put(DbType.DECIMAL, new DbPlatformType("number", 16, 3)); 064 dbTypeMap.put(DbType.VARCHAR, new DbPlatformType("varchar2", 255)); 065 dbTypeMap.put(DbType.LONGVARBINARY, new DbPlatformType("blob")); 066 dbTypeMap.put(DbType.LONGVARCHAR, new DbPlatformType("clob")); 067 dbTypeMap.put(DbType.VARBINARY, new DbPlatformType("raw", 255)); 068 dbTypeMap.put(DbType.BINARY, new DbPlatformType("raw", 255)); 069 dbTypeMap.put(DbType.TIME, new DbPlatformType("timestamp")); 070 } 071 072 @Override 073 public PlatformIdGenerator createSequenceIdGenerator(BackgroundExecutor be, DataSource ds, int stepSize, String seqName) { 074 return new OracleSequenceIdGenerator(be, ds, seqName, sequenceBatchSize); 075 } 076 077 @Override 078 protected String withForUpdate(String sql, Query.LockWait lockWait, Query.LockType lockType) { 079 switch (lockWait) { 080 case SKIPLOCKED: 081 return sql + " for update skip locked"; 082 case NOWAIT: 083 return sql + " for update nowait"; 084 default: 085 return sql + " for update"; 086 } 087 } 088 089}