use of org.teiid.metadata.KeyRecord in project teiid by teiid.
the class TestODataMetadataProcessor method testKeyMaytches.
@Test
public void testKeyMaytches() {
Column c1 = new Column();
c1.setName("one");
Column c2 = new Column();
c2.setName("two");
KeyRecord record = new KeyRecord(Type.Primary);
record.addColumn(c1);
record.addColumn(c2);
ODataMetadataProcessor p = new ODataMetadataProcessor();
assertTrue(p.keyMatches(Arrays.asList("one", "one"), record));
assertTrue(p.keyMatches(Arrays.asList("two", "one"), record));
}
use of org.teiid.metadata.KeyRecord in project teiid by teiid.
the class TestODataMetadataProcessor method testAssosiationWithReferentialContriant.
@Test
public void testAssosiationWithReferentialContriant() throws Exception {
ODataMetadataProcessor processor = new ODataMetadataProcessor();
MetadataFactory mf = new MetadataFactory("vdb", 1, "northwind", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
EdmEntityType.Builder g1Entity = entityType("g1");
g1Entity.addProperties(EdmProperty.newBuilder("g2e2").setType(EdmSimpleType.STRING).setNullable(false));
EdmEntityType.Builder g2Entity = entityType("g2");
EdmAssociationEnd.Builder aend1 = EdmAssociationEnd.newBuilder().setRole("source").setType(g1Entity).setMultiplicity(EdmMultiplicity.ONE);
EdmAssociationEnd.Builder aend2 = EdmAssociationEnd.newBuilder().setRole("target").setType(g2Entity).setMultiplicity(EdmMultiplicity.ONE);
EdmReferentialConstraint.Builder refContraint = EdmReferentialConstraint.newBuilder().addPrincipalReferences("g2e2").setPrincipalRole("source").addDependentReferences("e1").setDependentRole("target");
EdmAssociation.Builder assocition = EdmAssociation.newBuilder().setNamespace("namspace").setName("one_2_one").setEnds(aend2, aend1).setRefConstraint(refContraint);
EdmNavigationProperty.Builder navigation = EdmNavigationProperty.newBuilder("g1").setFromTo(aend2, aend1).setFromToName("source", "target").setRelationship(assocition);
g2Entity.addNavigationProperties(navigation);
EdmEntitySet g1Set = EdmEntitySet.newBuilder().setName("G1").setEntityType(g1Entity).build();
EdmEntitySet g2Set = EdmEntitySet.newBuilder().setName("G2").setEntityType(g2Entity).build();
Table t1 = processor.addEntitySetAsTable(mf, g1Set);
Table t2 = processor.addEntitySetAsTable(mf, g2Set);
KeyRecord record = new KeyRecord(Type.Unique);
record.addColumn(t1.getColumnByName("g2e2"));
t1.setUniqueKeys(Arrays.asList(record));
processor.addNavigationRelations(mf, "G2", g2Entity.build());
Table g1 = mf.getSchema().getTable("G1");
Table g2 = mf.getSchema().getTable("G2");
assertNotNull(g1);
assertNotNull(g2);
ForeignKey fk = g1.getForeignKeys().get(0);
assertEquals("one_2_one", fk.getName());
assertNotNull(fk.getColumnByName("g2e2"));
assertEquals("e1", fk.getReferenceColumns().get(0));
}
use of org.teiid.metadata.KeyRecord in project teiid by teiid.
the class SalesForceMetadataProcessor method addRelationships.
private void addRelationships() {
for (Map.Entry<String, ChildRelationship[]> entry : this.relationships.entrySet()) {
for (ChildRelationship relationship : entry.getValue()) {
if (relationship.getRelationshipName() == null) {
// not queryable
continue;
}
if (!isModelAuditFields() && isAuditField(relationship.getField())) {
continue;
}
Table parent = tableMap.get(entry.getKey());
KeyRecord pk = parent.getPrimaryKey();
if (null == pk) {
// $NON-NLS-1$
throw new RuntimeException("ERROR !!primary key column not found!!");
}
Table child = tableMap.get(relationship.getChildSObject());
if (child == null) {
// child must have been excluded
continue;
}
Column col = null;
columns = child.getColumns();
for (Iterator<Column> colIter = columns.iterator(); colIter.hasNext(); ) {
Column column = colIter.next();
if (column.getNameInSource().equals(relationship.getField())) {
col = column;
}
}
if (null == col) {
throw new RuntimeException(// $NON-NLS-1$
"ERROR !!foreign key column not found!! " + child.getName() + relationship.getField());
}
// $NON-NLS-1$ //$NON-NLS-2$
String name = "FK_" + parent.getName() + "_" + col.getName();
ArrayList<String> columnNames = new ArrayList<String>();
columnNames.add(col.getName());
ForeignKey fk = metadataFactory.addForeignKey(name, columnNames, parent.getName(), child);
// TODO: only needed for custom relationships
fk.setNameInSource(relationship.getRelationshipName());
}
}
}
use of org.teiid.metadata.KeyRecord in project teiid by teiid.
the class TestCoherenceTranslator method getTradeTranslationUtility.
/**
* this is used as an alternative to loading the vdb
* @return
*/
private TranslationUtility getTradeTranslationUtility() {
MetadataStore metadataStore = new MetadataStore();
// Create TRADE
// $NON-NLS-1$
Schema trading = RealMetadataFactory.createPhysicalModel("Trade_Object", metadataStore);
// Create physical groups
// $NON-NLS-1$
Table trade = RealMetadataFactory.createPhysicalGroup("TRADE", trading);
trade.setNameInSource("org.teiid.translator.coherence.Trade");
// Create physical elements
String[] elemNames = new String[] { // $NON-NLS-1$ //$NON-NLS-2$
"NAME", // $NON-NLS-1$ //$NON-NLS-2$
"TRADEID" };
String[] elemTypes = new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.LONG };
List<Column> cols = RealMetadataFactory.createElements(trade, elemNames, elemTypes);
// Set name in source on each column
String[] nameInSource = new String[] { "Name", "TradeId" };
for (int i = 0; i < nameInSource.length; i++) {
cols.get(i).setNameInSource(nameInSource[i]);
}
List<Column> keys = new ArrayList(1);
keys.add(cols.get(1));
KeyRecord trade_pk = RealMetadataFactory.createKey(Type.Primary, "TradeID_PK", trade, keys);
// LEG
// $NON-NLS-1$
Table leg = RealMetadataFactory.createPhysicalGroup("LEG", trading);
leg.setNameInSource("org.teiid.translator.coherence.Leg");
// Create physical elements
String[] legNames = new String[] { // $NON-NLS-1$ //$NON-NLS-2$
"LEGID", // $NON-NLS-1$ //$NON-NLS-2$
"NOTATIONAL", // $NON-NLS-1$ //$NON-NLS-2$
"NAME", // $NON-NLS-1$ //$NON-NLS-2$
"TRADEID" };
String[] legTypes = new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.DOUBLE, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.LONG };
List<Column> legcols = RealMetadataFactory.createElements(leg, legNames, legTypes);
// Set name in source on each column
String[] legnameInSource = new String[] { "LegId", "Notational", "Name", "TradeId" };
for (int i = 0; i < legnameInSource.length; i++) {
legcols.get(i).setNameInSource(legnameInSource[i]);
}
legcols.get(3).setSelectable(false);
legcols.get(3).setUpdatable(false);
List<Column> legkeys = new ArrayList(1);
keys.add(legcols.get(0));
RealMetadataFactory.createKey(Type.Primary, "Leg_ID_PK", leg, legkeys);
List<Column> foreignkey = new ArrayList(1);
foreignkey.add(legcols.get(3));
ForeignKey fk = RealMetadataFactory.createForeignKey("TRADE_FK", leg, foreignkey, trade_pk);
fk.setNameInSource("Legs");
fk.setParent(trade);
// Set column-specific properties
// cols.get(0).setSelectable(false);
// cols.get(0).setSearchType(SearchType.Unsearchable);
Schema tradeview = RealMetadataFactory.createVirtualModel("Trade_View", metadataStore);
QueryNode qn = new QueryNode("SELECT Trade_Object.Trade.TradeID, Trade_Object.Trade.Name, Trade_Object.Leg.LegID, Trade_Object.Leg.Notational, Trade_Object.Leg.Name AS LegName " + " FROM Trade_Object.Trade, Trade_Object.Leg " + "WHERE Trade_Object.Trade.TradeID = Trade_Object.Leg.TradeID " + "SELECT * FROM Trade.Trad " + " WHERE Trade.Trade.TradeID = Trade.Trade.TradeID");
Table trades = RealMetadataFactory.createVirtualGroup("Trades", tradeview, qn);
return new TranslationUtility(RealMetadataFactory.createTransformationMetadata(metadataStore, "Trade"));
}
use of org.teiid.metadata.KeyRecord in project teiid by teiid.
the class SolrUpdateExecution method buildSelectQuery.
private Select buildSelectQuery(Insert insert) throws TranslatorException {
Table table = insert.getTable().getMetadataObject();
KeyRecord pk = table.getPrimaryKey();
final String id = getRecordName(pk.getColumns().get(0));
NamedTable g = insert.getTable();
List<DerivedColumn> symbols = new ArrayList<DerivedColumn>();
for (Column column : table.getColumns()) {
String columnName = getRecordName(column);
symbols.add(new DerivedColumn(columnName, new ColumnReference(g, columnName, column, column.getJavaType())));
}
List groups = new ArrayList();
groups.add(g);
ColumnReference idCol = new ColumnReference(g, id, table.getColumnByName(id), table.getColumnByName(id).getJavaType());
Comparison cc = new Comparison(idCol, getPKValue(id, insert), Operator.EQ);
Select q = new Select(symbols, false, groups, cc, null, null, null);
return q;
}
Aggregations