Skip to content

Commit

Permalink
TEIID-5404 correcting the import test with name in source
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Jul 3, 2018
1 parent 9bde56a commit 2171af8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
Expand Up @@ -24,12 +24,23 @@
import java.util.LinkedList;
import java.util.concurrent.atomic.AtomicInteger;

import org.teiid.language.*;
import org.teiid.language.ColumnReference;
import org.teiid.language.Comparison;
import org.teiid.language.Condition;
import org.teiid.language.Function;
import org.teiid.language.Join;
import org.teiid.language.Join.JoinType;
import org.teiid.language.NamedTable;
import org.teiid.language.SQLConstants.Tokens;
import org.teiid.language.Select;
import org.teiid.language.TableReference;
import org.teiid.language.visitor.HierarchyVisitor;
import org.teiid.language.visitor.SQLStringVisitor;
import org.teiid.metadata.*;
import org.teiid.metadata.AbstractMetadataRecord;
import org.teiid.metadata.Column;
import org.teiid.metadata.ForeignKey;
import org.teiid.metadata.RuntimeMetadata;
import org.teiid.metadata.Table;
import org.teiid.translator.TranslatorException;
/**
* This visitor converts the Teiid command into JPQL string
Expand Down Expand Up @@ -424,12 +435,8 @@ public void visit(ColumnReference column) {
if (record != null) {
String name = record.getProperty(JPAMetadataProcessor.KEY_ASSOSIATED_WITH_FOREIGN_TABLE, false);
if (name == null) {
/*
* The fallback to getName() is really there just to save me
* the trouble of updating the test data in sakila.ddl.
*/
buffer.append(column.getTable().getCorrelationName()).append(Tokens.DOT)
.append(record.getNameInSource() != null ? column.getMetadataObject().getNameInSource() : record.getName());
.append(record.getSourceName());
}
else {
String attrName = record.getProperty(JPAMetadataProcessor.RELATION_PROPERTY, false);
Expand Down
Expand Up @@ -59,10 +59,10 @@ public static void setUp() throws TranslatorException {
assertEquals("SET NAMESPACE 'http://www.teiid.org/translator/jpa/2014' AS teiid_jpa;\n" +
"\n" +
"CREATE FOREIGN TABLE Marketdata (\n" +
"\tid string,\n" +
"\tprice bigdecimal,\n" +
"\texchange_name string OPTIONS (\"teiid_jpa:assosiated_with_table\" 'market.Exchange', \"teiid_jpa:relation_key\" 'name', \"teiid_jpa:relation_property\" 'exchange'),\n" +
"\tstock_id string OPTIONS (\"teiid_jpa:assosiated_with_table\" 'market.Stock', \"teiid_jpa:relation_key\" 'id', \"teiid_jpa:relation_property\" 'stock'),\n" +
"\tid string OPTIONS (NAMEINSOURCE 'id'),\n" +
"\tprice bigdecimal OPTIONS (NAMEINSOURCE 'price'),\n" +
"\texchange_name string OPTIONS (NAMEINSOURCE 'name', \"teiid_jpa:assosiated_with_table\" 'market.Exchange', \"teiid_jpa:relation_key\" 'name', \"teiid_jpa:relation_property\" 'exchange'),\n" +
"\tstock_id string OPTIONS (NAMEINSOURCE 'id', \"teiid_jpa:assosiated_with_table\" 'market.Stock', \"teiid_jpa:relation_key\" 'id', \"teiid_jpa:relation_property\" 'stock'),\n" +
"\tCONSTRAINT PK_Marketdata PRIMARY KEY(id),\n" +
"\tCONSTRAINT FK_exchange FOREIGN KEY(exchange_name) REFERENCES Exchange OPTIONS (NAMEINSOURCE 'exchange'),\n" +
"\tCONSTRAINT FK_stock FOREIGN KEY(stock_id) REFERENCES Stock OPTIONS (NAMEINSOURCE 'stock')\n" +
Expand All @@ -72,17 +72,17 @@ public static void setUp() throws TranslatorException {
assertEquals("SET NAMESPACE 'http://www.teiid.org/translator/jpa/2014' AS teiid_jpa;\n" +
"\n" +
"CREATE FOREIGN TABLE Stock (\n" +
"\tid string,\n" +
"\tsymbol string,\n" +
"\tcompanyName string,\n" +
"\tid string OPTIONS (NAMEINSOURCE 'id'),\n" +
"\tsymbol string OPTIONS (NAMEINSOURCE 'symbol'),\n" +
"\tcompanyName string OPTIONS (NAMEINSOURCE 'companyName'),\n" +
"\tCONSTRAINT PK_Stock PRIMARY KEY(id)\n" +
") OPTIONS (UPDATABLE TRUE, \"teiid_jpa:entity_class\" 'org.teiid.translator.jpa.model.Stock');", ddl);

ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, "Exchange");
assertEquals("SET NAMESPACE 'http://www.teiid.org/translator/jpa/2014' AS teiid_jpa;\n" +
"\n" +
"CREATE FOREIGN TABLE Exchange (\n" +
"\tname string,\n" +
"\tname string OPTIONS (NAMEINSOURCE 'name'),\n" +
"\tCONSTRAINT PK_Exchange PRIMARY KEY(name)\n" +
") OPTIONS (UPDATABLE TRUE, \"teiid_jpa:entity_class\" 'org.teiid.translator.jpa.model.Exchange');", ddl);
}
Expand Down

0 comments on commit 2171af8

Please sign in to comment.