Skip to content

Commit

Permalink
Fixes resulting from running unit tests
Browse files Browse the repository at this point in the history
* DataTypeManagerService
 * List of enum values should be cached to help performance since the
   reflection used in checking the annotations is slow, adding a considerable
   overhead

* Insert | Query
 * Relax the teiid version constraint since the change is designer to work
   with all 8+ teiid releases

* AbstractTest[QueryParser]
 * Parser tests should not be in AbstractTest since they are executed by
   all its child classes.
  • Loading branch information
Paul Richardson committed Apr 2, 2014
1 parent 9fb51ae commit 8f6452d
Show file tree
Hide file tree
Showing 7 changed files with 4,464 additions and 4,446 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ public enum DefaultDataTypes {

@Since("8.0.0")
VARBINARY ("varbinary", DataTypeName.VARBINARY, BinaryType.class); //$NON-NLS-1$


private static Map<ITeiidServerVersion, List<DefaultDataTypes>> valueCache = new HashMap<ITeiidServerVersion, List<DefaultDataTypes>>();

private String id;

private DataTypeName dataTypeName;
Expand Down Expand Up @@ -228,17 +230,27 @@ public static boolean isLOB(String type) {
* Use instead of values() since it will only return the enumerated values
* that conform to the given teiid version.
*
* This is going to be used an awful lot so reduce the need to call on
* {@link AnnotationUtils} which contains reflection code which is slow
* by caching the results.
*
* @param teiidVersion
*
* @return set of values for teiid version
*/
public static List<DefaultDataTypes> getValues(ITeiidServerVersion teiidVersion) {
List<DefaultDataTypes> appDataTypes = new ArrayList<DefaultDataTypes>();
for (DefaultDataTypes dataType : DefaultDataTypes.values()) {
if (! AnnotationUtils.isApplicable(dataType, teiidVersion))
continue;
List<DefaultDataTypes> appDataTypes = valueCache.get(teiidVersion);

if (appDataTypes == null) {
appDataTypes = new ArrayList<DefaultDataTypes>();
for (DefaultDataTypes dataType : DefaultDataTypes.values()) {
if (! AnnotationUtils.isApplicable(dataType, teiidVersion))
continue;

appDataTypes.add(dataType);
}

appDataTypes.add(dataType);
valueCache.put(teiidVersion, appDataTypes);
}

return appDataTypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.LinkedList;
import java.util.List;
import org.teiid.designer.query.sql.lang.IInsert;
import org.teiid.designer.runtime.version.spi.TeiidServerVersion.Version;
import org.teiid.query.parser.LanguageVisitor;
import org.teiid.query.parser.TeiidParser;
import org.teiid.query.sql.symbol.ElementSymbol;
Expand Down Expand Up @@ -143,7 +142,14 @@ public QueryCommand getQueryExpression() {
* @param query
*/
public void setQueryExpression( QueryCommand query ) {
if (isTeiidVersionOrGreater(Version.TEIID_8_6) && query instanceof Query) {
if (isTeiid8OrGreater() && query instanceof Query) {
/*
* Modified in Teiid 8.6 due to TEIID-2698.
* This moves the addition of values from the parser to here
* and is backward compatible with all previous version 8+ parsers.
* However, the Teiid 7 parser will continue to do its own thing
* so should not come through here.
*/
Query expr = (Query)query;
//a singl row constructor query is the same as values
if (expr.isRowConstructor()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void addDependentGroup(String group, MakeDep makedep) {
}
if(this.makeDependentGroups == null) {
this.makeDependentGroups = new ArrayList<String>();
this.makeDependentOptions = new ArrayList<MakeDep>();
}
this.makeDependentGroups.add(group);
this.makeDependentOptions.add(makedep);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ public class Query extends QueryCommand
/** xml projected symbols */
private List<Expression> selectList;

/*
* Added in Teiid 8.6 but backward-compatible with all
* Teiid 8+ parsers.
*/
@Since("8.6.0")
/** currently set by parser, but can be derived */
private boolean isRowConstructor;

/**
Expand Down Expand Up @@ -217,18 +220,20 @@ public void setIsXML(boolean isXML) {
* @return row constructor flag
*/
public boolean isRowConstructor() {
if (isTeiidVersionOrGreater(Version.TEIID_8_6))
return isRowConstructor;
if (isLessThanTeiidVersion(Version.TEIID_8_0))
return false;

return false;
return isRowConstructor;
}

/**
* @param isRowConstructor
*/
public void setRowConstructor(boolean isRowConstructor) {
if (isTeiidVersionOrGreater(Version.TEIID_8_6))
this.isRowConstructor = isRowConstructor;
if (isLessThanTeiidVersion(Version.TEIID_8_0))
return;

this.isRowConstructor = isRowConstructor;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ protected boolean isTeiidVersionOrGreater(Version teiidVersion) {
return minVersion.equals(teiidVersion.get()) || minVersion.isGreaterThan(teiidVersion.get());
}

protected boolean isLessThanTeiidVersion(Version teiidVersion) {
ITeiidServerVersion maxVersion = getTeiidVersion().getMaximumVersion();
return maxVersion.isLessThan(teiidVersion.get());
}

protected boolean isTeiid8OrGreater() {
return isTeiidVersionOrGreater(Version.TEIID_8_0);
}
Expand Down

0 comments on commit 8f6452d

Please sign in to comment.