提交 c99ad8ad authored 作者: Noel Grandin's avatar Noel Grandin

cleanup

上级 7ec1dbee
...@@ -8,12 +8,12 @@ import org.h2.expression.Expression; ...@@ -8,12 +8,12 @@ import org.h2.expression.Expression;
public class ColumnNamer { public class ColumnNamer {
private static final String DEFAULT_COLUMN_NAME = "DEFAULT"; private static final String DEFAULT_COLUMN_NAME = "DEFAULT";
private ColumnNamerConfiguration configuration; private ColumnNamerConfiguration configuration;
private Session session; private Session session;
private Set<String> existingColumnNames = new HashSet<String>(); private final Set<String> existingColumnNames = new HashSet<>();
public ColumnNamer(Session session) { public ColumnNamer(Session session) {
this.session = session; this.session = session;
...@@ -31,9 +31,8 @@ public class ColumnNamer { ...@@ -31,9 +31,8 @@ public class ColumnNamer {
} }
/** /**
* Create a standardized column name that isn't null and doesn't have a CR/LF in it. * Create a standardized column name that isn't null and doesn't have a CR/LF in it.
* @param columnExp the column expression * @param expr the column expression
* @param indexOfColumn index of column in below array * @param indexOfColumn index of column in below array
* @return
*/ */
public String getColumnName(Expression expr, int indexOfColumn) { public String getColumnName(Expression expr, int indexOfColumn) {
return getColumnName(expr,indexOfColumn,(String) null); return getColumnName(expr,indexOfColumn,(String) null);
...@@ -49,10 +48,10 @@ public class ColumnNamer { ...@@ -49,10 +48,10 @@ public class ColumnNamer {
String columnNameOverride = null; String columnNameOverride = null;
if (columnNameOverides != null && columnNameOverides.length > indexOfColumn){ if (columnNameOverides != null && columnNameOverides.length > indexOfColumn){
columnNameOverride = columnNameOverides[indexOfColumn]; columnNameOverride = columnNameOverides[indexOfColumn];
} }
return getColumnName(columnExp, indexOfColumn, columnNameOverride); return getColumnName(columnExp, indexOfColumn, columnNameOverride);
} }
/** /**
* Create a standardized column name that isn't null and doesn't have a CR/LF in it. * Create a standardized column name that isn't null and doesn't have a CR/LF in it.
* @param columnExp the column expression * @param columnExp the column expression
...@@ -67,11 +66,11 @@ public class ColumnNamer { ...@@ -67,11 +66,11 @@ public class ColumnNamer {
columnName = columnNameOverride; columnName = columnNameOverride;
if(!isAllowableColumnName(columnName)){ if(!isAllowableColumnName(columnName)){
columnName = fixColumnName(columnName); columnName = fixColumnName(columnName);
} }
if(!isAllowableColumnName(columnName)){ if(!isAllowableColumnName(columnName)){
columnName = null; columnName = null;
} }
} }
// try a name from the column alias // try a name from the column alias
if (columnName==null && columnExp.getAlias()!=null && !DEFAULT_COLUMN_NAME.equals(columnExp.getAlias())){ if (columnName==null && columnExp.getAlias()!=null && !DEFAULT_COLUMN_NAME.equals(columnExp.getAlias())){
columnName = columnExp.getAlias(); columnName = columnExp.getAlias();
...@@ -112,22 +111,22 @@ public class ColumnNamer { ...@@ -112,22 +111,22 @@ public class ColumnNamer {
existingColumnNames.add(columnName); existingColumnNames.add(columnName);
return columnName; return columnName;
} }
private String generateUniqueName(String columnName) { private String generateUniqueName(String columnName) {
String newColumnName = columnName; String newColumnName = columnName;
int loopCount = 2; int loopCount = 2;
while(existingColumnNames.contains(newColumnName)){ while(existingColumnNames.contains(newColumnName)){
String loopCountString = "_"+loopCount; String loopCountString = "_"+loopCount;
newColumnName = columnName.substring(0,Math.min(columnName.length(), configuration.getMaxIdentiferLength()-loopCountString.length()))+loopCountString; newColumnName = columnName.substring(0,Math.min(columnName.length(), configuration.getMaxIdentiferLength()-loopCountString.length()))+loopCountString;
loopCount++; loopCount++;
} }
return newColumnName; return newColumnName;
} }
public boolean isAllowableColumnName(String proposedName){ public boolean isAllowableColumnName(String proposedName){
// check null // check null
if (proposedName == null){ if (proposedName == null){
return false; return false;
...@@ -142,21 +141,21 @@ public class ColumnNamer { ...@@ -142,21 +141,21 @@ public class ColumnNamer {
} }
return true; return true;
} }
private String fixColumnName(String proposedName) { private String fixColumnName(String proposedName) {
Matcher match = configuration.getCompiledRegularExpressionMatchDisallowed().matcher(proposedName); Matcher match = configuration.getCompiledRegularExpressionMatchDisallowed().matcher(proposedName);
proposedName = match.replaceAll(""); proposedName = match.replaceAll("");
// check size limits - then truncate // check size limits - then truncate
if (proposedName.length() > configuration.getMaxIdentiferLength()){ if (proposedName.length() > configuration.getMaxIdentiferLength()){
proposedName=proposedName.substring(0, configuration.getMaxIdentiferLength()); proposedName=proposedName.substring(0, configuration.getMaxIdentiferLength());
} }
return proposedName; return proposedName;
} }
public ColumnNamerConfiguration getConfiguration() { public ColumnNamerConfiguration getConfiguration() {
return configuration; return configuration;
} }
} }
...@@ -11,8 +11,6 @@ import java.io.InputStream; ...@@ -11,8 +11,6 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.io.PrintStream; import java.io.PrintStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
...@@ -74,7 +72,7 @@ public class TestScript extends TestBase { ...@@ -74,7 +72,7 @@ public class TestScript extends TestBase {
} }
@Override @Override
public void test() throws Exception { public void test() throws Exception {
if (config.networked && config.big) { if (config.networked && config.big) {
return; return;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论