Skip to content

Commit

Permalink
TEIID-2950 not qualifying references from the current schema
Browse files Browse the repository at this point in the history
Conflicts:

	engine/src/main/java/org/teiid/query/metadata/DDLStringVisitor.java
  • Loading branch information
shawkins committed May 8, 2014
1 parent 962d414 commit 8b65647
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Expand Up @@ -281,8 +281,12 @@ private void buildContraints(Table table) {
ForeignKey key = table.getForeignKeys().get(i);
addConstraint("FK" + i, FOREIGN_KEY, key, false); //$NON-NLS-1$
append(SPACE).append(REFERENCES);
if (key.getPrimaryKey() != null) {
append(SPACE).append(new GroupSymbol(key.getPrimaryKey().getParent().getFullName()));
if (key.getReferenceKey() != null) {
if (key.getReferenceKey().getParent().getParent().equals(key.getParent().getParent())) {
append(SPACE).append(new GroupSymbol(key.getReferenceKey().getParent().getName()));
} else {
append(SPACE).append(new GroupSymbol(key.getReferenceKey().getParent().getFullName()));
}
} else if (key.getReferenceTableName() != null) {
append(SPACE).append(new GroupSymbol(key.getReferenceTableName()));
}
Expand Down
Expand Up @@ -1131,7 +1131,7 @@ public boolean isVariadic(Object metadataID) {
}

@Override
public Object getModelID(String modelName) throws TeiidComponentException,
public Schema getModelID(String modelName) throws TeiidComponentException,
QueryMetadataException {
Schema s = this.getMetadataStore().getSchema(modelName);
if (s == null) {
Expand Down
Expand Up @@ -35,6 +35,7 @@
import org.teiid.metadata.Schema;
import org.teiid.metadata.Table;
import org.teiid.query.parser.TestDDLParser;
import org.teiid.query.unittest.RealMetadataFactory;

@SuppressWarnings("nls")
public class TestDDLStringVisitor {
Expand Down Expand Up @@ -128,7 +129,7 @@ public void testConstraints2() throws Exception {
public void testFK() throws Exception {
String ddl = "CREATE FOREIGN TABLE G1(\"g1-e1\" integer, g1e2 varchar, PRIMARY KEY(\"g1-e1\", g1e2));\n" +
"CREATE FOREIGN TABLE G2( g2e1 integer, g2e2 varchar, " +
"FOREIGN KEY (g2e1, g2e2) REFERENCES G1 (g1e1, g1e2))";
"FOREIGN KEY (g2e1, g2e2) REFERENCES G1 (\"g1-e1\", g1e2))";

String expected = "CREATE FOREIGN TABLE G1 (\n" +
" \"g1-e1\" integer,\n" +
Expand All @@ -139,10 +140,13 @@ public void testFK() throws Exception {
"CREATE FOREIGN TABLE G2 (\n" +
" g2e1 integer,\n" +
" g2e2 string,\n" +
" FOREIGN KEY(g2e1, g2e2) REFERENCES G1 (g1e1, g1e2)\n" +
" FOREIGN KEY(g2e1, g2e2) REFERENCES G1 (\"g1-e1\", g1e2)\n" +
");";

helpTest(ddl, expected);
TransformationMetadata vdb = RealMetadataFactory.fromDDL(ddl, "x", "y");
Schema s = vdb.getModelID("y");
String metadataDDL = DDLStringVisitor.getDDLString(s, null, null);
assertEquals(expected, metadataDDL);
}

@Test
Expand Down

0 comments on commit 8b65647

Please sign in to comment.