mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Merge pull request #2604 from FOCONIS/remove-lowertablename2
Remove LowerTableName
This commit is contained in:
@@ -184,17 +184,4 @@ public class DbConstraintNaming {
|
||||
return normalise.normaliseColumn(tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lower case the table name checking for quoted identifiers.
|
||||
*/
|
||||
public String lowerTableName(String tableName) {
|
||||
return normalise.lowerTableName(tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lower case the column name checking for quoted identifiers.
|
||||
*/
|
||||
public String lowerColumnName(String name) {
|
||||
return normalise.lowerColumnName(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,26 +55,6 @@ public class DbConstraintNormalise {
|
||||
return value.replace("(","").replace(")","");
|
||||
}
|
||||
|
||||
/**
|
||||
* Lower case the table name checking for quoted identifiers.
|
||||
*/
|
||||
public String lowerTableName(String tableName) {
|
||||
if (lowerCaseTables && notQuoted(tableName)) {
|
||||
return tableName.toLowerCase();
|
||||
}
|
||||
return tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lower case the column name checking for quoted identifiers.
|
||||
*/
|
||||
public String lowerColumnName(String name) {
|
||||
if (lowerCaseColumns && notQuoted(name)) {
|
||||
return name.toLowerCase();
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim off the platform quoted identifier quotes like [ ' and ".
|
||||
*/
|
||||
|
||||
+4
-18
@@ -204,7 +204,7 @@ public class BaseTableDdl implements TableDdl {
|
||||
public void generate(DdlWrite writer, CreateTable createTable) {
|
||||
reset();
|
||||
|
||||
String tableName = lowerTableName(createTable.getName());
|
||||
String tableName = createTable.getName();
|
||||
List<Column> columns = createTable.getColumn();
|
||||
List<Column> pk = determinePrimaryKeyColumns(columns);
|
||||
|
||||
@@ -398,7 +398,7 @@ public class BaseTableDdl implements TableDdl {
|
||||
|
||||
protected void writeForeignKey(DdlWrite writer, WriteForeignKey request) {
|
||||
DdlBuffer fkeyBuffer = writer.applyForeignKeys();
|
||||
String tableName = lowerTableName(request.table());
|
||||
String tableName = request.table();
|
||||
if (request.indexName() != null) {
|
||||
// no matching unique constraint so add the index
|
||||
fkeyBuffer.appendStatement(platformDdl.createIndex(new WriteCreateIndex(request.indexName(), tableName, request.cols(), false)));
|
||||
@@ -423,7 +423,7 @@ public class BaseTableDdl implements TableDdl {
|
||||
if (i > 0) {
|
||||
buffer.append(",");
|
||||
}
|
||||
buffer.append(lowerColumnName(columns[i].trim()));
|
||||
buffer.append(columns[i].trim());
|
||||
}
|
||||
buffer.append(")");
|
||||
}
|
||||
@@ -490,7 +490,7 @@ public class BaseTableDdl implements TableDdl {
|
||||
buffer.append(",").newLine();
|
||||
buffer.append(" constraint ").append(uqName).append(" unique ");
|
||||
buffer.append("(");
|
||||
buffer.append(lowerColumnName(column.getName()));
|
||||
buffer.append(column.getName());
|
||||
buffer.append(")");
|
||||
}
|
||||
|
||||
@@ -514,20 +514,6 @@ public class BaseTableDdl implements TableDdl {
|
||||
return cols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the table lower case.
|
||||
*/
|
||||
protected String lowerTableName(String name) {
|
||||
return naming.lowerTableName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the column name to lower case.
|
||||
*/
|
||||
protected String lowerColumnName(String name) {
|
||||
return naming.lowerColumnName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of columns that make the primary key.
|
||||
*/
|
||||
|
||||
+3
-2
@@ -95,9 +95,10 @@ public class DB2Ddl extends PlatformDdl {
|
||||
.append("begin\n")
|
||||
.append("if exists (select constname from syscat.tabconst where tabschema = current_schema and constname = '")
|
||||
.append(maxConstraintName(constraintName).toUpperCase())
|
||||
.append("' and tabname = '").append(lowerTableName(tableName).toUpperCase()).append("') then\n")
|
||||
|
||||
.append(" prepare stmt from 'alter table ").append(lowerTableName(tableName))
|
||||
.append("' and tabname = '").append(naming.normaliseTable(tableName).toUpperCase()).append("') then\n")
|
||||
|
||||
.append(" prepare stmt from 'alter table ").append(tableName)
|
||||
.append(" drop constraint ").append(maxConstraintName(constraintName)).append("';\n")
|
||||
|
||||
.append(" execute stmt;\n")
|
||||
|
||||
+1
-1
@@ -120,7 +120,7 @@ public class Db2HistoryDdl implements PlatformHistoryDdl {
|
||||
protected void writeColumnDefinition(DdlBuffer buffer, String columnName, String type, boolean isNotNull) {
|
||||
|
||||
String platformType = platformDdl.convert(type);
|
||||
buffer.append(" ").append(platformDdl.lowerColumnName(columnName));
|
||||
buffer.append(" ").append(columnName);
|
||||
buffer.append(" ").append(platformType);
|
||||
if (isNotNull) {
|
||||
buffer.append(" not null");
|
||||
|
||||
+1
-1
@@ -195,7 +195,7 @@ public abstract class DbTriggerBasedHistoryDdl implements PlatformHistoryDdl {
|
||||
|
||||
String platformType = platformDdl.convert(type);
|
||||
buffer.append(" ");
|
||||
buffer.append(platformDdl.lowerColumnName(columnName), 29);
|
||||
buffer.append(columnName, 29);
|
||||
buffer.append(platformType);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@ public class HanaHistoryDdl implements PlatformHistoryDdl {
|
||||
boolean isNotNull, String generated) {
|
||||
|
||||
String platformType = platformDdl.convert(type);
|
||||
buffer.append(" ").append(platformDdl.lowerColumnName(columnName));
|
||||
buffer.append(" ").append(columnName);
|
||||
buffer.append(" ").append(platformType);
|
||||
if (defaultValue != null) {
|
||||
buffer.append(" default ").append(defaultValue);
|
||||
|
||||
+5
-25
@@ -258,7 +258,7 @@ public class PlatformDdl {
|
||||
}
|
||||
|
||||
buffer.append(" ");
|
||||
buffer.append(lowerColumnName(column.getName()), 29);
|
||||
buffer.append(column.getName(), 29);
|
||||
buffer.append(columnDefn);
|
||||
if (!Boolean.TRUE.equals(column.isPrimaryKey())) {
|
||||
String defaultValue = convertDefaultValue(column.getDefaultValue());
|
||||
@@ -435,7 +435,7 @@ public class PlatformDdl {
|
||||
StringBuilder buffer = new StringBuilder(90);
|
||||
buffer.append("foreign key");
|
||||
appendColumns(request.cols(), buffer);
|
||||
buffer.append(" references ").append(lowerTableName(request.refTable()));
|
||||
buffer.append(" references ").append(request.refTable());
|
||||
appendColumns(request.refCols(), buffer);
|
||||
appendForeignKeySuffix(request, buffer);
|
||||
return buffer.toString();
|
||||
@@ -448,13 +448,13 @@ public class PlatformDdl {
|
||||
|
||||
StringBuilder buffer = new StringBuilder(90);
|
||||
buffer
|
||||
.append("alter table ").append(lowerTableName(request.table()))
|
||||
.append("alter table ").append(request.table())
|
||||
.append(" add constraint ").append(maxConstraintName(request.fkName()))
|
||||
.append(" foreign key");
|
||||
appendColumns(request.cols(), buffer);
|
||||
buffer
|
||||
.append(" references ")
|
||||
.append(lowerTableName(request.refTable()));
|
||||
.append(request.refTable());
|
||||
appendColumns(request.refCols(), buffer);
|
||||
appendForeignKeySuffix(request, buffer);
|
||||
if (options.isForeignKeySkipCheck()) {
|
||||
@@ -665,31 +665,11 @@ public class PlatformDdl {
|
||||
if (i > 0) {
|
||||
buffer.append(",");
|
||||
}
|
||||
buffer.append(lowerColumnName(columns[i].trim()));
|
||||
buffer.append(columns[i].trim());
|
||||
}
|
||||
buffer.append(")");
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the table to lower case.
|
||||
* <p>
|
||||
* Override as desired. Generally lower case with underscore is a good cross database
|
||||
* choice for column/table names.
|
||||
*/
|
||||
protected String lowerTableName(String name) {
|
||||
return naming.lowerTableName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the column name to lower case.
|
||||
* <p>
|
||||
* Override as desired. Generally lower case with underscore is a good cross database
|
||||
* choice for column/table names.
|
||||
*/
|
||||
protected String lowerColumnName(String name) {
|
||||
return naming.lowerColumnName(name);
|
||||
}
|
||||
|
||||
public DatabasePlatform getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
+8
-8
@@ -1,11 +1,11 @@
|
||||
create table persons (
|
||||
id bigint generated by default as identity (start with 1000 increment by 40) not null,
|
||||
surname varchar(64) not null,
|
||||
name varchar(64) not null,
|
||||
constraint pk_persons primary key (id)
|
||||
create table PERSONS (
|
||||
ID bigint generated by default as identity (start with 1000 increment by 40) not null,
|
||||
SURNAME varchar(64) not null,
|
||||
NAME varchar(64) not null,
|
||||
constraint pk_persons primary key (ID)
|
||||
);
|
||||
|
||||
create table phones (
|
||||
create table PHONES (
|
||||
id bigint generated by default as identity not null,
|
||||
phone_number varchar(7) not null,
|
||||
person_id bigint not null,
|
||||
@@ -14,6 +14,6 @@ create table phones (
|
||||
);
|
||||
|
||||
-- foreign keys and indices
|
||||
create index ix_phones_person_id on phones (person_id);
|
||||
alter table phones add constraint fk_phones_person_id foreign key (person_id) references persons (id) on delete restrict on update restrict;
|
||||
create index ix_phones_person_id on PHONES (person_id);
|
||||
alter table PHONES add constraint fk_phones_person_id foreign key (person_id) references PERSONS (ID) on delete restrict on update restrict;
|
||||
|
||||
|
||||
+8
-8
@@ -1,11 +1,11 @@
|
||||
create table persons (
|
||||
id bigint generated by default as identity (start with 1000 increment by 40) not null,
|
||||
surname varchar(64) not null,
|
||||
name varchar(64) not null,
|
||||
constraint pk_persons primary key (id)
|
||||
create table PERSONS (
|
||||
ID bigint generated by default as identity (start with 1000 increment by 40) not null,
|
||||
SURNAME varchar(64) not null,
|
||||
NAME varchar(64) not null,
|
||||
constraint pk_persons primary key (ID)
|
||||
);
|
||||
|
||||
create table phones (
|
||||
create table PHONES (
|
||||
id bigint generated by default as identity not null,
|
||||
phone_number varchar(7) not null,
|
||||
person_id bigint not null,
|
||||
@@ -14,6 +14,6 @@ create table phones (
|
||||
);
|
||||
|
||||
-- foreign keys and indices
|
||||
create index ix_phones_person_id on phones (person_id);
|
||||
alter table phones add constraint fk_phones_person_id foreign key (person_id) references persons (id) on delete restrict on update restrict not valid;
|
||||
create index ix_phones_person_id on PHONES (person_id);
|
||||
alter table PHONES add constraint fk_phones_person_id foreign key (person_id) references PERSONS (ID) on delete restrict on update restrict not valid;
|
||||
|
||||
|
||||
@@ -33,10 +33,6 @@ public class DbConstraintNamingTest {
|
||||
@Test
|
||||
public void testDefaultToLower() {
|
||||
assertThat(naming.normaliseTable("SCH.FOO_BAR]")).isEqualTo("foo_bar");
|
||||
assertThat(naming.lowerTableName("SCH.FOO_BAR]")).isEqualTo("SCH.FOO_BAR]");
|
||||
assertThat(naming.lowerTableName("SCH.FOO_BAR")).isEqualTo("sch.foo_bar");
|
||||
assertThat(naming.lowerColumnName("SCH.FOO_BAR]")).isEqualTo("SCH.FOO_BAR]");
|
||||
assertThat(naming.lowerColumnName("SCH.FOO_BAR")).isEqualTo("sch.foo_bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -44,11 +40,7 @@ public class DbConstraintNamingTest {
|
||||
DbConstraintNaming naming = new DbConstraintNaming(false, true);
|
||||
assertThat(naming.normaliseTable("SCH.FOO_BAR]")).isEqualTo("FOO_BAR");
|
||||
assertThat(naming.normaliseColumn("SCH.FOO_BAR]")).isEqualTo("sch.foo_bar");
|
||||
assertThat(naming.lowerTableName("SCH.FOO_BAR]")).isEqualTo("SCH.FOO_BAR]");
|
||||
// table name not lowered
|
||||
assertThat(naming.lowerTableName("SCH.FOO_BAR")).isEqualTo("SCH.FOO_BAR");
|
||||
assertThat(naming.lowerColumnName("SCH.FOO_BAR]")).isEqualTo("SCH.FOO_BAR]");
|
||||
assertThat(naming.lowerColumnName("SCH.FOO_BAR")).isEqualTo("sch.foo_bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,11 +48,7 @@ public class DbConstraintNamingTest {
|
||||
DbConstraintNaming naming = new DbConstraintNaming(true, false);
|
||||
assertThat(naming.normaliseTable("SCH.FOO_BAR]")).isEqualTo("foo_bar");
|
||||
assertThat(naming.normaliseColumn("SCH.FOO_BAR]")).isEqualTo("SCH.FOO_BAR");
|
||||
assertThat(naming.lowerTableName("SCH.FOO_BAR]")).isEqualTo("SCH.FOO_BAR]");
|
||||
assertThat(naming.lowerTableName("SCH.FOO_BAR")).isEqualTo("sch.foo_bar");
|
||||
assertThat(naming.lowerColumnName("SCH.FOO_BAR]")).isEqualTo("SCH.FOO_BAR]");
|
||||
// column name not lowered
|
||||
assertThat(naming.lowerColumnName("SCH.FOO_BAR")).isEqualTo("SCH.FOO_BAR");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user