use of org.teiid.metadata.Schema 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.Schema in project teiid by teiid.
the class AccessInfo method restore.
/**
* Restore reconnects to the live metadata objects
* @throws TeiidComponentException
* @throws TeiidProcessingException
*/
void restore() throws TeiidComponentException, TeiidProcessingException {
if (this.objectsAccessed != null) {
return;
}
VDBMetaData vdb = DQPWorkContext.getWorkContext().getVDB();
TransformationMetadata tm = vdb.getAttachment(TransformationMetadata.class);
GlobalTableStore globalStore = vdb.getAttachment(GlobalTableStore.class);
if (!externalNames.isEmpty()) {
this.objectsAccessed = new HashSet<Object>(externalNames.size());
for (List<String> key : this.externalNames) {
if (key.size() == 1) {
String matTableName = key.get(0);
TempMetadataID id = globalStore.getGlobalTempTableMetadataId(matTableName);
if (id == null) {
// if the id is null, then create a local instance
String viewFullName = matTableName.substring(RelationalPlanner.MAT_PREFIX.length());
id = globalStore.getGlobalTempTableMetadataId(tm.getGroupID(viewFullName));
}
this.objectsAccessed.add(id);
} else {
Schema s = tm.getMetadataStore().getSchema(key.get(0));
Modifiable m = s.getTables().get(key.get(1));
if (m == null) {
m = s.getProcedures().get(key.get(1));
}
if (m != null) {
this.objectsAccessed.add(m);
}
}
}
} else {
this.objectsAccessed = Collections.emptySet();
}
this.externalNames = null;
}
use of org.teiid.metadata.Schema in project teiid by teiid.
the class TestDDLStringVisitor method testFK.
@Test
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 (\"g1-e1\", g1e2))";
String expected = "CREATE FOREIGN TABLE G1 (\n" + " \"g1-e1\" integer,\n" + " g1e2 string,\n" + " PRIMARY KEY(\"g1-e1\", g1e2)\n" + ");\n" + "\n" + "CREATE FOREIGN TABLE G2 (\n" + " g2e1 integer,\n" + " g2e2 string,\n" + " FOREIGN KEY(g2e1, g2e2) REFERENCES G1 (\"g1-e1\", g1e2)\n" + ");";
TransformationMetadata vdb = RealMetadataFactory.fromDDL(ddl, "x", "y");
Schema s = vdb.getModelID("y");
String metadataDDL = DDLStringVisitor.getDDLString(s, null, null);
assertEquals(expected, metadataDDL);
}
use of org.teiid.metadata.Schema in project teiid by teiid.
the class EvaluatorIterator method createTransformationMetadata.
public static TransformationMetadata createTransformationMetadata(String ddl) {
MetadataStore mds = new MetadataStore();
MetadataFactory mf = new MetadataFactory("vdb", 1, IMPLICIT_MODEL_NAME, SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
QueryParser.getQueryParser().parseDDL(mf, ddl);
mf.mergeInto(mds);
CompositeMetadataStore store = new CompositeMetadataStore(mds);
VDBMetaData vdbMetaData = new VDBMetaData();
// $NON-NLS-1$
vdbMetaData.setName("vdb");
vdbMetaData.setVersion(1);
List<FunctionTree> udfs = new ArrayList<FunctionTree>();
for (Schema schema : store.getSchemas().values()) {
vdbMetaData.addModel(createModel(schema.getName(), schema.isPhysical()));
}
TransformationMetadata metadata = new TransformationMetadata(vdbMetaData, store, null, SFM.getSystemFunctions(), udfs);
vdbMetaData.addAttchment(TransformationMetadata.class, metadata);
vdbMetaData.addAttchment(QueryMetadataInterface.class, metadata);
return metadata;
}
use of org.teiid.metadata.Schema in project teiid by teiid.
the class MarshallerBuilder method getWireMap.
public static TreeMap<Integer, TableWireFormat> getWireMap(Table parentTbl, RuntimeMetadata metadata) throws TranslatorException {
TreeMap<Integer, TableWireFormat> wireMap = buildWireMap(parentTbl, false, metadata);
Schema schema = parentTbl.getParent();
for (Table table : schema.getTables().values()) {
if (table.equals(parentTbl)) {
continue;
}
String mergeName = ProtobufMetadataProcessor.getMerge(table);
if (mergeName != null && mergeName.equals(parentTbl.getFullName())) {
// one 2 many relation
int parentTag = ProtobufMetadataProcessor.getParentTag(table);
String childName = ProtobufMetadataProcessor.getMessageName(table);
TableWireFormat child = new TableWireFormat(childName, parentTag);
wireMap.put(child.getReadTag(), child);
TreeMap<Integer, TableWireFormat> childWireMap = buildWireMap(table, true, metadata);
for (TableWireFormat twf : childWireMap.values()) {
child.addNested(twf);
}
}
}
return wireMap;
}
Aggregations