Search in sources :

Example 1 with SimpleDBAttribute

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

the class SimpleDBMetadataProcessor method process.

/**
 * As SimpleDB does not provide any way to obtain all attribute names for
 * given domain (one can query only attribute names for single item) and
 * querrying all items in domain to get complete set of attribute names
 * would be very slow and resource consuming, this approach has been
 * selected: For each domain only first item is queried for attribute names
 * and metadata are created using this information. Thus first item in
 * domain should have as much attributes as possible.
 * @see org.teiid.translator.MetadataProcessor#process(org.teiid.metadata.MetadataFactory, java.lang.Object)
 */
@Override
public void process(MetadataFactory metadataFactory, SimpleDBConnection connection) throws TranslatorException {
    List<String> domains = connection.getDomains();
    for (String domain : domains) {
        Table table = metadataFactory.addTable(domain);
        table.setSupportsUpdate(true);
        Column itemName = metadataFactory.addColumn(DISPLAY_ITEM_NAME, TypeFacility.RUNTIME_NAMES.STRING, table);
        itemName.setUpdatable(true);
        itemName.setNameInSource(ITEM_NAME);
        itemName.setNullType(NullType.No_Nulls);
        // $NON-NLS-1$
        metadataFactory.addPrimaryKey("PK0", Arrays.asList(DISPLAY_ITEM_NAME), table);
        for (SimpleDBAttribute attribute : connection.getAttributeNames(domain)) {
            Column column = null;
            if (attribute.hasMultipleValues()) {
                // $NON-NLS-1$
                column = metadataFactory.addColumn(attribute.getName(), TypeFacility.RUNTIME_NAMES.STRING + "[]", table);
            } else {
                column = metadataFactory.addColumn(attribute.getName(), TypeFacility.RUNTIME_NAMES.STRING, table);
            }
            column.setUpdatable(true);
            column.setNullType(NullType.Nullable);
        }
    }
}
Also used : SimpleDBAttribute(org.teiid.translator.simpledb.api.SimpleDBConnection.SimpleDBAttribute)

Example 2 with SimpleDBAttribute

use of org.teiid.translator.simpledb.api.SimpleDBConnection.SimpleDBAttribute 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

SimpleDBAttribute (org.teiid.translator.simpledb.api.SimpleDBConnection.SimpleDBAttribute)2 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