mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1243 - Add IDENTITY support for Oracle platform (since 12c Oracle supports auto generated identity)
This commit is contained in:
@@ -10,12 +10,13 @@ import io.ebean.config.dbplatform.DbType;
|
||||
import io.ebean.config.dbplatform.IdType;
|
||||
import io.ebean.config.dbplatform.PlatformIdGenerator;
|
||||
import io.ebean.config.dbplatform.RownumSqlLimiter;
|
||||
import io.ebean.config.dbplatform.SqlErrorCodes;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Types;
|
||||
|
||||
/**
|
||||
* Oracle10 and greater specific platform.
|
||||
* Oracle specific platform.
|
||||
*/
|
||||
public class OraclePlatform extends DatabasePlatform {
|
||||
|
||||
@@ -29,17 +30,23 @@ public class OraclePlatform extends DatabasePlatform {
|
||||
this.basicSqlLimiter = new BasicSqlAnsiLimiter();
|
||||
this.historySupport = new OracleDbHistorySupport();
|
||||
|
||||
// Not using getGeneratedKeys as instead we will
|
||||
// batch load sequences which enables JDBC batch execution
|
||||
dbIdentity.setSupportsGetGeneratedKeys(false);
|
||||
dbIdentity.setIdType(IdType.SEQUENCE);
|
||||
dbIdentity.setSupportsSequence(true);
|
||||
dbIdentity.setSupportsIdentity(true);
|
||||
dbIdentity.setSupportsGetGeneratedKeys(true);
|
||||
|
||||
this.treatEmptyStringsAsNull = true;
|
||||
|
||||
this.likeClause = "like ? escape '|'";
|
||||
this.specialLikeCharacters = new char[] { '%', '_', '|' };
|
||||
|
||||
|
||||
this.exceptionTranslator =
|
||||
new SqlErrorCodes()
|
||||
//.addAcquireLock("")
|
||||
.addDuplicateKey("1")
|
||||
.addDataIntegrity("2291")
|
||||
.build();
|
||||
|
||||
this.openQuote = "\"";
|
||||
this.closeQuote = "\"";
|
||||
|
||||
@@ -81,7 +88,7 @@ public class OraclePlatform extends DatabasePlatform {
|
||||
return sql + " for update";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void escapeLikeCharacter(char ch, StringBuilder sb) {
|
||||
sb.append('|').append(ch);
|
||||
|
||||
@@ -19,6 +19,7 @@ public class Oracle10Ddl extends PlatformDdl {
|
||||
this.columnSetNotnull = "not null";
|
||||
this.columnSetNull = "null";
|
||||
this.columnSetDefault = "default";
|
||||
this.identitySuffix = " generated always as identity";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -4,10 +4,10 @@ import io.ebean.Ebean;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import io.ebean.config.dbplatform.IdType;
|
||||
import io.ebean.config.dbplatform.h2.H2Platform;
|
||||
import io.ebean.config.dbplatform.sqlserver.SqlServerPlatform;
|
||||
import io.ebean.config.dbplatform.mysql.MySqlPlatform;
|
||||
import io.ebean.config.dbplatform.oracle.OraclePlatform;
|
||||
import io.ebean.config.dbplatform.postgres.PostgresPlatform;
|
||||
import io.ebean.config.dbplatform.sqlserver.SqlServerPlatform;
|
||||
import io.ebeaninternal.dbmigration.migration.AlterColumn;
|
||||
import io.ebeaninternal.dbmigration.migration.IdentityType;
|
||||
import io.ebeaninternal.server.core.PlatformDdlBuilder;
|
||||
@@ -222,7 +222,7 @@ public class PlatformDdl_AlterColumnTest {
|
||||
|
||||
assertEquals(oraDdl.useIdentityType(null), IdType.SEQUENCE);
|
||||
assertEquals(oraDdl.useIdentityType(IdentityType.SEQUENCE), IdType.SEQUENCE);
|
||||
assertEquals(oraDdl.useIdentityType(IdentityType.IDENTITY), IdType.SEQUENCE);
|
||||
assertEquals(oraDdl.useIdentityType(IdentityType.IDENTITY), IdType.IDENTITY);
|
||||
assertEquals(oraDdl.useIdentityType(IdentityType.GENERATOR), IdType.GENERATOR);
|
||||
assertEquals(oraDdl.useIdentityType(IdentityType.EXTERNAL), IdType.EXTERNAL);
|
||||
}
|
||||
|
||||
@@ -3,25 +3,46 @@ package org.tests.transaction;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Transaction;
|
||||
|
||||
|
||||
import io.ebean.annotation.IgnorePlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.ESimple;
|
||||
|
||||
/**
|
||||
* This test tests a strange bug in the 6.2.0. sqlserver JDBC driver.
|
||||
* (Version 6.1.7.jre8-preview works)
|
||||
*
|
||||
*
|
||||
* https://github.com/Microsoft/mssql-jdbc/pull/374
|
||||
*
|
||||
*
|
||||
* @author Roland Praml, FOCONIS AG
|
||||
*/
|
||||
public class TestSqlServerBatch extends BaseTestCase {
|
||||
|
||||
@IgnorePlatform(value = Platform.SQLSERVER)
|
||||
@Test
|
||||
public void testAggressiveBatch() throws InterruptedException {
|
||||
public void testBasicIdentityBatch() {
|
||||
|
||||
Transaction txn = Ebean.beginTransaction();
|
||||
try {
|
||||
txn.setBatchMode(true);
|
||||
txn.setBatchSize(3);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
ESimple model = new ESimple();
|
||||
model.setName("baz "+i);
|
||||
Ebean.save(model);
|
||||
}
|
||||
|
||||
txn.commit();
|
||||
|
||||
} finally {
|
||||
txn.end();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAggressiveBatch() {
|
||||
|
||||
|
||||
Transaction txn = Ebean.beginTransaction();
|
||||
try {
|
||||
txn.setBatchMode(true);
|
||||
|
||||
@@ -111,9 +111,9 @@ datasource.mysql.databaseUrl=jdbc:mysql://127.0.0.1:3306/unit
|
||||
datasource.mysql.databaseDriver=com.mysql.jdbc.Driver
|
||||
|
||||
|
||||
datasource.ora.username=unit
|
||||
datasource.ora.password=unit
|
||||
datasource.ora.databaseUrl=jdbc:oracle:thin:@127.0.0.1:1521:xe
|
||||
datasource.ora.username=test_user
|
||||
datasource.ora.password=test
|
||||
datasource.ora.databaseUrl=jdbc:oracle:thin:@127.0.0.1:1521:XE
|
||||
datasource.ora.databaseDriver=oracle.jdbc.driver.OracleDriver
|
||||
|
||||
## set this to use timestamp rather than timestamptz
|
||||
|
||||
Reference in New Issue
Block a user