mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-14 06:45:21 +00:00
DDL generation fixes fpr oracle platform (fix drop default, do "drop if exists" with error handlers)
This commit is contained in:
1 parent
897a97d415
commit
e0669e9a9f
11 files changed
+350
-46
No files matched your search
+34
@@ -20,6 +20,8 @@ public class OracleDdl extends PlatformDdl {
|
||||
this.columnSetNotnull = "not null";
|
||||
this.columnSetNull = "null";
|
||||
this.columnSetDefault = "default";
|
||||
this.columnDropDefault = "default null"; // dropping default is not supported. See:
|
||||
// https://stackoverflow.com/questions/8481532/how-do-i-remove-the-default-value-from-a-column-in-oracle
|
||||
this.identitySuffix = " generated by default as identity";
|
||||
}
|
||||
|
||||
@@ -33,6 +35,21 @@ public class OracleDdl extends PlatformDdl {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String dropSequence(String sequenceName) {
|
||||
return ignoreError(-2289, super.dropSequence(sequenceName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String alterTableDropConstraint(String tableName, String constraintName) {
|
||||
return ignoreError(-2443, super.alterTableDropConstraint(tableName, constraintName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String alterTableDropUniqueConstraint(String tableName, String uniqueConstraintName) {
|
||||
return ignoreError(-2443, super.alterTableDropUniqueConstraint(tableName, uniqueConstraintName));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendForeignKeyOnUpdate(StringBuilder buffer, ConstraintMode mode) {
|
||||
// do nothing, no on update clause for oracle
|
||||
@@ -57,4 +74,21 @@ public class OracleDdl extends PlatformDdl {
|
||||
return asIdentityStandardOptions(columnDefn, identity);
|
||||
}
|
||||
|
||||
/**
|
||||
* generates anonymous pl/sql block that catches expected error so that we can
|
||||
* effectively do a 'drop if exists'
|
||||
*/
|
||||
private String ignoreError(int errorNr, String statement) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("delimiter $$\n")
|
||||
.append("declare\n")
|
||||
.append(" expected_error exception;\n")
|
||||
.append(" pragma exception_init(expected_error, ").append(errorNr).append(");\n")
|
||||
.append("begin\n")
|
||||
.append(" execute immediate '").append(statement).append("';\n")
|
||||
.append("exception\n")
|
||||
.append(" when expected_error then null;\n")
|
||||
.append("end;\n$$");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user