Search in sources :

Example 1 with SimpleDBConnection

use of org.teiid.translator.simpledb.api.SimpleDBConnection in project teiid by teiid.

the class TestSimpleDBMetadataProcessor method getDDL.

static String getDDL(Properties props) throws TranslatorException {
    SimpleDBExecutionFactory translator = new SimpleDBExecutionFactory();
    translator.start();
    MetadataFactory mf = new MetadataFactory("vdb", 1, "people", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
    SimpleDBConnection connection = Mockito.mock(SimpleDBConnection.class);
    Mockito.stub(connection.getDomains()).toReturn(Arrays.asList("G1", "G2"));
    HashSet<SimpleDBAttribute> cols = new HashSet<SimpleDBConnection.SimpleDBAttribute>();
    cols.add(new SimpleDBAttribute("e1", false));
    cols.add(new SimpleDBAttribute("e2", false));
    Mockito.stub(connection.getAttributeNames("G1")).toReturn(cols);
    HashSet<SimpleDBAttribute> cols2 = new HashSet<SimpleDBConnection.SimpleDBAttribute>();
    cols2.add(new SimpleDBAttribute("e1", false));
    cols2.add(new SimpleDBAttribute("e2", true));
    Mockito.stub(connection.getAttributeNames("G2")).toReturn(cols2);
    translator.getMetadata(mf, connection);
    TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "vdb", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
    ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
    if (report.hasItems()) {
        throw new RuntimeException(report.getFailureMessage());
    }
    String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
    return ddl;
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) SimpleDBAttribute(org.teiid.translator.simpledb.api.SimpleDBConnection.SimpleDBAttribute) ValidatorReport(org.teiid.query.validator.ValidatorReport) RealMetadataFactory(org.teiid.query.unittest.RealMetadataFactory) MetadataFactory(org.teiid.metadata.MetadataFactory) SimpleDBExecutionFactory(org.teiid.translator.simpledb.SimpleDBExecutionFactory) MetadataValidator(org.teiid.query.metadata.MetadataValidator) SimpleDBConnection(org.teiid.translator.simpledb.api.SimpleDBConnection) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 MetadataFactory (org.teiid.metadata.MetadataFactory)1 FunctionTree (org.teiid.query.function.FunctionTree)1 UDFSource (org.teiid.query.function.UDFSource)1 MetadataValidator (org.teiid.query.metadata.MetadataValidator)1 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)1 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)1 ValidatorReport (org.teiid.query.validator.ValidatorReport)1 SimpleDBExecutionFactory (org.teiid.translator.simpledb.SimpleDBExecutionFactory)1 SimpleDBConnection (org.teiid.translator.simpledb.api.SimpleDBConnection)1 SimpleDBAttribute (org.teiid.translator.simpledb.api.SimpleDBConnection.SimpleDBAttribute)1