提交 d1eda2f4 authored 作者: Thomas Mueller's avatar Thomas Mueller

Reorder, formatting, javadocs

上级 26a94693
......@@ -23,6 +23,34 @@ public class DbColumn {
private final String dataType;
private int position;
public DbColumn(DbContents contents, ResultSet rs) throws SQLException {
name = rs.getString("COLUMN_NAME");
quotedName = contents.quoteIdentifier(name);
String type = rs.getString("TYPE_NAME");
// A procedures column size is identified by PRECISION, for table this is COLUMN_SIZE
int precisionColumnIndex = DbContents.findColumn(rs, "PRECISION", 0);
int size;
if (precisionColumnIndex == 0) {
size = rs.getInt(DbContents.findColumn(rs, "COLUMN_SIZE", 7));
} else {
size = rs.getInt(precisionColumnIndex);
}
position = rs.getInt("ORDINAL_POSITION");
boolean isSQLite = contents.isSQLite();
if (size > 0 && !isSQLite) {
type += "(" + size;
int prec = rs.getInt(DbContents.findColumn(rs, "DECIMAL_DIGITS", 9));
if (prec > 0) {
type += ", " + prec;
}
type += ")";
}
if (rs.getInt("NULLABLE") == DatabaseMetaData.columnNoNulls) {
type += " NOT NULL";
}
dataType = type;
}
/**
* @return The data type name (including precision and the NOT NULL flag if
......@@ -53,31 +81,4 @@ public class DbColumn {
return position;
}
public DbColumn(DbContents contents, ResultSet rs) throws SQLException {
name = rs.getString("COLUMN_NAME");
quotedName = contents.quoteIdentifier(name);
String type = rs.getString("TYPE_NAME");
// A procedures column size is identified by PRECISION, for table this is COLUMN_SIZE
int precisionColumnIndex = DbContents.findColumn(rs, "PRECISION", 0);
int size;
if( precisionColumnIndex == 0 ){
size = rs.getInt(DbContents.findColumn(rs, "COLUMN_SIZE", 7));
} else {
size = rs.getInt(precisionColumnIndex);
}
position = rs.getInt("ORDINAL_POSITION");
boolean isSQLite = contents.isSQLite();
if (size > 0 && !isSQLite) {
type += "(" + size;
int prec = rs.getInt(DbContents.findColumn(rs, "DECIMAL_DIGITS", 9));
if (prec > 0) {
type += ", " + prec;
}
type += ")";
}
if (rs.getInt("NULLABLE") == DatabaseMetaData.columnNoNulls) {
type += " NOT NULL";
}
dataType = type;
}
}
......@@ -36,7 +36,13 @@ public class DbContextRule implements Rule {
/**
* BNF terminal rule Constructor
* @param contents Extract rule from this component
* @param type Rule type, one of {@link DbContextRule#COLUMN,DbContextRule#TABLE,DbContextRule#TABLE_ALIAS,DbContextRule#NEW_TABLE_ALIAS,DbContextRule#COLUMN_ALIAS,DbContextRule#SCHEMA}
* @param type Rule type, one of
* {@link DbContextRule#COLUMN},
* {@link DbContextRule#TABLE},
* {@link DbContextRule#TABLE_ALIAS},
* {@link DbContextRule#NEW_TABLE_ALIAS},
* {@link DbContextRule#COLUMN_ALIAS},
* {@link DbContextRule#SCHEMA}
*/
public DbContextRule(DbContents contents, int type) {
this.contents = contents;
......@@ -182,8 +188,10 @@ public class DbContextRule implements Rule {
continue;
}
for (DbColumn column : table.getColumns()) {
String name = StringUtils.toUpperEnglish(column.getName());
if(columnType == null || column.getDataType().contains(columnType)) {
String name = StringUtils.toUpperEnglish(column
.getName());
if (columnType == null
|| column.getDataType().contains(columnType)) {
if (up.startsWith(name)) {
String b = s.substring(name.length());
if (best == null || b.length() < best.length()) {
......@@ -225,7 +233,7 @@ public class DbContextRule implements Rule {
}
String incompleteSentence = sentence.getQueryUpper();
String incompleteFunctionName = incompleteSentence;
if(incompleteSentence.contains("(")) {
if (incompleteSentence.contains("(")) {
incompleteFunctionName = incompleteSentence.substring(0, incompleteSentence.indexOf('(')).trim();
}
......@@ -235,26 +243,29 @@ public class DbContextRule implements Rule {
RuleElement comma = new RuleElement(",", "Function");
// Fetch all elements
for(DbProcedure procedure : schema.getProcedures()) {
for (DbProcedure procedure : schema.getProcedures()) {
final String procName = procedure.getName();
if(procName.startsWith(incompleteFunctionName)) {
if (procName.startsWith(incompleteFunctionName)) {
// That's it, build a RuleList from this function
RuleElement procedureElement = new RuleElement(procName, "Function");
RuleElement procedureElement = new RuleElement(procName,
"Function");
RuleList rl = new RuleList(procedureElement, openBracket, false);
// Go further only if the user use open bracket
if(incompleteSentence.contains("(")) {
for(DbColumn parameter : procedure.getParameters()) {
if(parameter.getPosition() > 1) {
if (incompleteSentence.contains("(")) {
for (DbColumn parameter : procedure.getParameters()) {
if (parameter.getPosition() > 1) {
rl = new RuleList(rl, comma, false);
}
DbContextRule columnRule = new DbContextRule(contents, COLUMN);
DbContextRule columnRule = new DbContextRule(contents,
COLUMN);
String parameterType = parameter.getDataType();
// Remove precision
if(parameterType.contains("(")) {
parameterType = parameterType.substring(0, parameterType.indexOf('('));
if (parameterType.contains("(")) {
parameterType = parameterType.substring(0,
parameterType.indexOf('('));
}
columnRule.setColumnType(parameterType);
rl = new RuleList(rl, columnRule , false);
rl = new RuleList(rl, columnRule, false);
}
rl = new RuleList(rl, closeBracket , false);
}
......
......@@ -77,16 +77,18 @@ public class DbProcedure {
ArrayList<DbColumn> list = New.arrayList();
while (rs.next()) {
DbColumn column = new DbColumn(schema.getContents(), rs);
if(column.getPosition()>0) { //Not the return type
if (column.getPosition() > 0) {
// Not the return type
list.add(column);
}
}
rs.close();
parameters = new DbColumn[list.size()];
// Store the parameter in the good position [1-n]
for(int i=0;i<parameters.length;i++) {
for (int i = 0; i < parameters.length; i++) {
DbColumn column = list.get(i);
if(column.getPosition()>0 && column.getPosition() <= parameters.length) {
if (column.getPosition() > 0
&& column.getPosition() <= parameters.length) {
parameters[column.getPosition() - 1] = column;
}
}
......
......@@ -34,11 +34,6 @@ public class DbSchema {
*/
public static final int MAX_PROCEDURES_LIST_COLUMNS = 500;
/**
* The database content container.
*/
private final DbContents contents;
/**
* The schema name.
*/
......@@ -59,6 +54,11 @@ public class DbSchema {
*/
public final String quotedName;
/**
* The database content container.
*/
private final DbContents contents;
/**
* The table list.
*/
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论