use of org.teiid.metadata.ForeignKey in project teiid by teiid.
the class TestDynamicImportedMetaData method testMultipleFK.
@Test
public void testMultipleFK() throws Exception {
ModelMetaData mmd = new ModelMetaData();
mmd.addSourceMetadata("ddl", "create foreign table x (y integer, z integer, primary key (y, z));" + "create foreign table z (y integer, z integer, y1 integer, z1 integer, foreign key (y, z) references x (y, z), foreign key (y1, z1) references x (y, z))");
mmd.setName("foo");
mmd.addSourceMapping("x", "x", "x");
server.addTranslator("x", new ExecutionFactory());
server.deployVDB("vdb", mmd);
// $NON-NLS-1$
Connection conn = server.createConnection("jdbc:teiid:vdb");
Properties importProperties = new Properties();
importProperties.setProperty("importer.importKeys", "true");
MetadataFactory mf = getMetadata(importProperties, conn);
Table t = mf.asMetadataStore().getSchemas().get("test").getTables().get("vdb.foo.z");
List<ForeignKey> fks = t.getForeignKeys();
assertEquals(2, fks.size());
}
use of org.teiid.metadata.ForeignKey in project teiid by teiid.
the class MongoDBUpdateExecution method removeParentKey.
private void removeParentKey(MongoDocument document, BasicDBObject row) throws TranslatorException {
Table source = document.getTable();
Table target = document.getMergeTable();
for (ForeignKey fk : source.getForeignKeys()) {
if (fk.getReferenceTableName().equals(target.getName())) {
for (int i = 0; i < fk.getColumns().size(); i++) {
if (row != null) {
row.remove(fk.getColumns().get(i).getName());
}
}
}
}
}
use of org.teiid.metadata.ForeignKey in project teiid by teiid.
the class CoherenceUpdateExecution method updateChildObject.
private void updateChildObject(Table t) throws TranslatorException {
List<ForeignKey> fks = t.getForeignKeys();
ForeignKey fk = fks.get(0);
Table parentTable = fk.getParent();
// the name of the method to obtain the collection is the nameInSource of the foreginKey
String parentToChildMethod = fk.getNameInSource();
if (parentToChildMethod == null) {
// $NON-NLS-1$
final String msg = CoherencePlugin.Util.getString("CoherenceUpdateExecution.noNameInSourceForForeingKey", new Object[] { fk.getName() });
throw new TranslatorException(msg);
}
// there must only be 1 column in the primary key
String parentColName = visitor.getNameFromElement(fk.getPrimaryKey().getColumns().get(0));
List<SetClause> updateList = ((Update) command).getChanges();
Condition criteria = ((Update) command).getWhere();
ColumnReference leftElement;
Expression rightExpr;
String nameLeftElement;
Object valueRightExpr;
// API).
for (int i = 0; i < updateList.size(); i++) {
SetClause setClause = updateList.get(i);
// trust that connector API is right and left side
// will always be an IElement
leftElement = setClause.getSymbol();
// call utility method to get NameInSource/Name for element
nameLeftElement = visitor.getNameFromElement(leftElement.getMetadataObject());
// get right expression - if it is not a literal we
// can't handle that so throw an exception
rightExpr = setClause.getValue();
// if (!(rightExpr instanceof Literal)) {
// final String msg = CoherencePlugin.Util.getString("LDAPUpdateExecution.valueNotLiteralError",nameLeftElement); //$NON-NLS-1$
// throw new TranslatorException(msg);
// }
valueRightExpr = ((Literal) rightExpr).getValue();
// add in the modification as a replacement - meaning
// any existing value(s) for this attribute will
// be replaced by the new value. If the attribute
// didn't exist, it will automatically be created
// TODO - since null is a valid attribute
// value, we don't do any special handling of it right
// now. But maybe null should mean to delete an
// attribute?
}
}
use of org.teiid.metadata.ForeignKey in project teiid by teiid.
the class JPAMetadataProcessor method addForeignKey.
private void addForeignKey(MetadataFactory mf, String name, List<String> columnNames, String referenceTable, Table table) throws TranslatorException {
ForeignKey fk = mf.addForeignKey("FK_" + name, columnNames, referenceTable, table);
for (String column : columnNames) {
Column c = table.getColumnByName(column);
c.setProperty(KEY_ASSOSIATED_WITH_FOREIGN_TABLE, mf.getName() + Tokens.DOT + referenceTable);
}
fk.setNameInSource(name);
}
use of org.teiid.metadata.ForeignKey in project teiid by teiid.
the class TestODataMetadataProcessor method testOneToOneAssosiation.
@Test
public void testOneToOneAssosiation() throws Exception {
MetadataFactory mf = oneToOneRelationMetadata(true);
Table g1 = mf.getSchema().getTable("G1");
Table g2 = mf.getSchema().getTable("G2");
ForeignKey fk = g1.getForeignKeys().get(0);
assertEquals("G2_one_2_one", fk.getName());
assertNotNull(fk.getColumnByName("e1"));
fk = g2.getForeignKeys().get(0);
assertEquals("G1_one_2_one", fk.getName());
assertNotNull(fk.getColumnByName("e1"));
mf = oneToOneRelationMetadata(false);
g1 = mf.getSchema().getTable("G1");
g2 = mf.getSchema().getTable("G2");
fk = g1.getForeignKeys().get(0);
assertEquals("G2_one_2_one", fk.getName());
assertNotNull(fk.getColumnByName("e1"));
// TODO: could infer this, but for now it's not in the metadata
assertTrue(g2.getForeignKeys().isEmpty());
}
Aggregations