Author: shawkins
Date: 2012-10-02 11:05:22 -0400 (Tue, 02 Oct 2012)
New Revision: 4503
Modified:
trunk/api/src/main/java/org/teiid/metadata/Column.java
trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java
trunk/engine/src/main/java/org/teiid/query/metadata/DDLStringVisitor.java
trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java
Log:
TEIID-2236 fix for searchable parsing
Modified: trunk/api/src/main/java/org/teiid/metadata/Column.java
===================================================================
--- trunk/api/src/main/java/org/teiid/metadata/Column.java 2012-10-02 14:09:05 UTC (rev
4502)
+++ trunk/api/src/main/java/org/teiid/metadata/Column.java 2012-10-02 15:05:22 UTC (rev
4503)
@@ -113,6 +113,10 @@
}
return searchType;
}
+
+ public boolean isSearchTypeSet() {
+ return searchType != null;
+ }
public String getFormat() {
return format;
Modified: trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java 2012-10-02
14:09:05 UTC (rev 4502)
+++ trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java 2012-10-02
15:05:22 UTC (rev 4503)
@@ -998,4 +998,18 @@
return true;
}
+ public static <T extends Enum<T>> T caseInsensitiveValueOf(Class<T>
enumType, String name) {
+ try {
+ return Enum.valueOf(enumType, name);
+ } catch (IllegalArgumentException e) {
+ T[] vals = enumType.getEnumConstants();
+ for (T t : vals) {
+ if (name.equalsIgnoreCase(t.name())) {
+ return t;
+ }
+ }
+ throw e;
+ }
+ }
+
}
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/DDLStringVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/DDLStringVisitor.java 2012-10-02
14:09:05 UTC (rev 4502)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/DDLStringVisitor.java 2012-10-02
15:05:22 UTC (rev 4503)
@@ -419,7 +419,7 @@
}
// by default the search type is default data type search, so avoid it.
- if (column.getSearchType() != null &&
!column.getSearchType().equals(column.getDatatype().getSearchType())) {
+ if (column.getSearchType() != null &&
(!column.getSearchType().equals(column.getDatatype().getSearchType()) ||
column.isSearchTypeSet())) {
addOption(options, SEARCHABLE, column.getSearchType().name());
}
Modified: trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2012-10-02
14:09:05 UTC (rev 4502)
+++ trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2012-10-02
15:05:22 UTC (rev 4503)
@@ -367,7 +367,7 @@
v = props.remove(DDLConstants.SEARCHABLE);
if (v != null) {
- c.setSearchType(SearchType.valueOf(v.toUpperCase()));
+ c.setSearchType(StringUtil.caseInsensitiveValueOf(SearchType.class, v));
}
v = props.remove(DDLConstants.MIN_VALUE);
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java 2012-10-02
14:09:05 UTC (rev 4502)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java 2012-10-02
15:05:22 UTC (rev 4503)
@@ -31,6 +31,7 @@
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.metadata.*;
import org.teiid.metadata.BaseColumn.NullType;
+import org.teiid.metadata.Column.SearchType;
import org.teiid.query.metadata.MetadataValidator;
import org.teiid.query.metadata.SystemMetadata;
import org.teiid.query.validator.ValidatorReport;
@@ -48,7 +49,7 @@
"e1 integer primary key,\n" +
"e2 varchar(10) unique,\n" +
"e3 date not null unique,\n" +
- "e4 decimal(12,3),\n" +
+ "e4 decimal(12,3) options (searchable 'unsearchable'),\n" +
"e5 integer auto_increment INDEX OPTIONS (UUID 'uuid', NAMEINSOURCE
'nis', SELECTABLE 'NO'),\n" +
"e6 varchar index default 'hello')\n" +
"OPTIONS (CARDINALITY 12, UUID 'uuid2', UPDATABLE 'true', FOO
'BAR', ANNOTATION 'Test Table')";
@@ -101,6 +102,7 @@
assertEquals(false, e4.isAutoIncremented());
assertEquals(12, e4.getPrecision());
assertEquals(3, e4.getScale());
+ assertEquals(SearchType.Unsearchable, e4.getSearchType());
assertEquals("e5", e5.getName());
assertEquals("int", e5.getDatatype().getName());
Show replies by date