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);
}
}
}
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;
}
Aggregations