mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-25 23:59:38 +00:00
Refactor tidy ModelBuildPropertyVisitor - no functional change
This commit is contained in:
+22
-29
@@ -78,7 +78,7 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
||||
private String uniqueConstraintName(IndexDefinition index) {
|
||||
String uqName = index.getName();
|
||||
if (uqName == null || uqName.trim().isEmpty()) {
|
||||
return determineUniqueConstraintName(index.getColumns());
|
||||
return uniqueConstraintName(index.getColumns());
|
||||
}
|
||||
return uqName;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
||||
private String indexName(IndexDefinition index) {
|
||||
String idxName = index.getName();
|
||||
if (idxName == null || idxName.trim().isEmpty()) {
|
||||
idxName = determineIndexName(index.getColumns());
|
||||
idxName = indexName(index.getColumns());
|
||||
}
|
||||
return idxName;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
||||
public void visitEnd() {
|
||||
|
||||
// set the primary key name
|
||||
table.setPkName(determinePrimaryKeyName());
|
||||
table.setPkName(primaryKeyName());
|
||||
|
||||
// check if indexes on foreign keys should be suppressed
|
||||
for (MColumn column : table.allColumns()) {
|
||||
@@ -162,7 +162,7 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
||||
if (cols.size() == 2) {
|
||||
// always the second column that we put the unique constraint on
|
||||
MColumn col = new ArrayList<>(cols).get(1);
|
||||
col.setUnique(determineUniqueConstraintName(col.getName()));
|
||||
col.setUnique(uniqueConstraintName(col.getName()));
|
||||
}
|
||||
}
|
||||
} else if (p.isElementCollection()) {
|
||||
@@ -199,8 +199,8 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
||||
if (columns.length > 1) {
|
||||
// compound foreign key
|
||||
String refTable = p.getTargetDescriptor().getBaseTable();
|
||||
String fkName = determineForeignKeyConstraintName(p.getName());
|
||||
String fkIndex = determineForeignKeyIndexName(p.getName());
|
||||
String fkName = foreignKeyConstraintName(p.getName());
|
||||
String fkIndex = foreignKeyIndexName(p.getName());
|
||||
compoundKey = new MCompoundForeignKey(fkName, refTable, fkIndex);
|
||||
table.addForeignKey(compoundKey);
|
||||
}
|
||||
@@ -227,9 +227,9 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
||||
refTable = p.getTargetDescriptor().getBaseTable();
|
||||
}
|
||||
col.setReferences(refTable + "." + refColumn);
|
||||
col.setForeignKeyName(determineForeignKeyConstraintName(col.getName()));
|
||||
col.setForeignKeyName(foreignKeyConstraintName(col.getName()));
|
||||
if (p.hasForeignKeyIndex()) {
|
||||
col.setForeignKeyIndex(determineForeignKeyIndexName(col.getName()));
|
||||
col.setForeignKeyIndex(foreignKeyIndexName(col.getName()));
|
||||
}
|
||||
PropertyForeignKey foreignKey = p.getForeignKey();
|
||||
if (foreignKey != null) {
|
||||
@@ -248,11 +248,11 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
||||
if (modelColumns.size() == 1) {
|
||||
MColumn col = modelColumns.get(0);
|
||||
indexSetAdd(col.getName());
|
||||
col.setUniqueOneToOne(determineUniqueConstraintName(col.getName()));
|
||||
col.setUniqueOneToOne(uniqueConstraintName(col.getName()));
|
||||
|
||||
} else {
|
||||
String[] cols = indexSetAdd(toColumnNames(modelColumns));
|
||||
String uqName = determineUniqueConstraintName(p.getName());
|
||||
String uqName = uniqueConstraintName(p.getName());
|
||||
table.addUniqueConstraint(new MCompoundUniqueConstraint(cols, uqName));
|
||||
}
|
||||
}
|
||||
@@ -284,7 +284,7 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
||||
if (foreignKey == null || !foreignKey.isNoConstraint()) {
|
||||
TableJoinColumn[] columns = primaryKeyJoin.columns();
|
||||
col.setReferences(primaryKeyJoin.getTable() + "." + columns[0].getForeignDbColumn());
|
||||
col.setForeignKeyName(determineForeignKeyConstraintName(col.getName()));
|
||||
col.setForeignKeyName(foreignKeyConstraintName(col.getName()));
|
||||
if (foreignKey != null) {
|
||||
col.setForeignKeyModes(foreignKey.getOnDelete(), foreignKey.getOnUpdate());
|
||||
}
|
||||
@@ -300,7 +300,7 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
||||
col.setDbMigrationInfos(p.getDbMigrationInfos());
|
||||
|
||||
if (p.isUnique() && !p.isId()) {
|
||||
col.setUnique(determineUniqueConstraintName(col.getName()));
|
||||
col.setUnique(uniqueConstraintName(col.getName()));
|
||||
indexSetAdd(col.getName());
|
||||
}
|
||||
Set<String> checkConstraintValues = p.getDbCheckConstraintValues();
|
||||
@@ -310,7 +310,7 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
||||
inheritInfo.appendCheckConstraintValues(p.getName(), checkConstraintValues);
|
||||
}
|
||||
col.setCheckConstraint(buildCheckConstraint(p.getDbColumn(), checkConstraintValues));
|
||||
col.setCheckConstraintName(determineCheckConstraintName(col.getName()));
|
||||
col.setCheckConstraintName(checkConstraintName(col.getName()));
|
||||
}
|
||||
|
||||
lastColumn = col;
|
||||
@@ -354,61 +354,54 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
||||
/**
|
||||
* Return the primary key constraint name.
|
||||
*/
|
||||
protected String determinePrimaryKeyName() {
|
||||
protected String primaryKeyName() {
|
||||
return ctx.primaryKeyName(table.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the foreign key constraint name given a single column foreign key.
|
||||
*/
|
||||
protected String determineForeignKeyConstraintName(String columnName) {
|
||||
protected String foreignKeyConstraintName(String columnName) {
|
||||
return ctx.foreignKeyConstraintName(table.getName(), columnName, ++countForeignKey);
|
||||
}
|
||||
|
||||
protected String determineForeignKeyIndexName(String column) {
|
||||
protected String foreignKeyIndexName(String column) {
|
||||
String[] cols = {column};
|
||||
return determineForeignKeyIndexName(cols);
|
||||
return foreignKeyIndexName(cols);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the foreign key constraint name given a single column foreign key.
|
||||
*/
|
||||
protected String determineForeignKeyIndexName(String[] columns) {
|
||||
protected String foreignKeyIndexName(String[] columns) {
|
||||
return ctx.foreignKeyIndexName(table.getName(), columns, ++countIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the index name given a single column foreign key.
|
||||
*/
|
||||
protected String determineIndexName(String column) {
|
||||
return ctx.indexName(table.getName(), column, ++countIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the index name given multiple columns.
|
||||
*/
|
||||
protected String determineIndexName(String[] columns) {
|
||||
protected String indexName(String[] columns) {
|
||||
return ctx.indexName(table.getName(), columns, ++countIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the unique constraint name.
|
||||
*/
|
||||
protected String determineUniqueConstraintName(String columnName) {
|
||||
protected String uniqueConstraintName(String columnName) {
|
||||
return ctx.uniqueConstraintName(table.getName(), columnName, ++countUnique);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the unique constraint name.
|
||||
*/
|
||||
protected String determineUniqueConstraintName(String[] columnNames) {
|
||||
protected String uniqueConstraintName(String[] columnNames) {
|
||||
return ctx.uniqueConstraintName(table.getName(), columnNames, ++countUnique);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the constraint name.
|
||||
*/
|
||||
protected String determineCheckConstraintName(String columnName) {
|
||||
protected String checkConstraintName(String columnName) {
|
||||
return ctx.checkConstraintName(table.getName(), columnName, ++countCheck);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user