use of org.teiid.metadata.Table in project teiid by teiid.
the class SchemaToProtobufProcessor method processFKTable.
// Find FK to this table, and add the column
private void processFKTable(Table table) {
int increment = 1;
for (Table t : schema.getTables().values()) {
if (table == t) {
continue;
}
if (!t.getForeignKeys().isEmpty()) {
List<ForeignKey> fks = t.getForeignKeys();
for (ForeignKey fk : fks) {
if (fk.getReferenceTableName().equals(table.getName())) {
addTab();
String messageName = ProtobufMetadataProcessor.getMessageName(t);
if (messageName == null) {
messageName = table.getName();
} else {
messageName = messageName.substring(messageName.lastIndexOf('.') + 1);
}
String columnName = ProtobufMetadataProcessor.getParentColumnName(t);
if (columnName == null) {
columnName = t.getName().toLowerCase();
}
int tag = ProtobufMetadataProcessor.getParentTag(t);
if (tag == -1) {
tag = table.getColumns().size() + increment;
increment++;
}
buffer.append("repeated ");
buffer.append(messageName).append(SPACE).append(columnName);
buffer.append(" = ").append(tag).append(SEMICOLON).append(NL);
}
}
}
}
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class IckleConversionVisitor method visit.
@Override
public void visit(NamedTable obj) {
this.queriedTable = obj;
if (obj.getCorrelationName() == null) {
obj.setCorrelationName(obj.getMetadataObject().getName().toLowerCase() + "_" + aliasCounter.getAndIncrement());
}
if (this.rootNode == null) {
String messageName = null;
String aliasName = null;
String mergedTableName = ProtobufMetadataProcessor.getMerge(obj.getMetadataObject());
if (mergedTableName == null) {
aliasName = obj.getCorrelationName();
messageName = getMessageName(obj.getMetadataObject());
this.parentTable = obj;
this.rootNode = new DocumentNode(obj.getMetadataObject(), true);
this.joinedNode = this.rootNode;
// check to see if there is one-2-one rows
Set<String> tags = new HashSet<>();
for (Column column : obj.getMetadataObject().getColumns()) {
if (ProtobufMetadataProcessor.getParentTag(column) != -1) {
String childMessageName = ProtobufMetadataProcessor.getMessageName(column);
if (!tags.contains(childMessageName)) {
tags.add(childMessageName);
// TODO: DocumentNode needs to be refactored to just take name, not table
Table t = new Table();
t.setName(childMessageName);
this.joinedNode = this.rootNode.joinWith(JoinType.INNER_JOIN, new DocumentNode(t, false));
}
}
}
} else {
try {
Table mergedTable = this.metadata.getTable(mergedTableName);
messageName = getMessageName(mergedTable);
aliasName = mergedTable.getName().toLowerCase() + "_" + aliasCounter.getAndIncrement();
this.parentTable = new NamedTable(mergedTable.getName(), aliasName, mergedTable);
this.rootNode = new DocumentNode(mergedTable, true);
this.joinedNode = this.rootNode.joinWith(JoinType.INNER_JOIN, new DocumentNode(obj.getMetadataObject(), true));
this.nested = true;
} catch (TranslatorException e) {
this.exceptions.add(e);
}
}
buffer.append(messageName);
if (aliasName != null) {
buffer.append(Tokens.SPACE);
buffer.append(aliasName);
}
if (this.includePK) {
KeyRecord pk = this.parentTable.getMetadataObject().getPrimaryKey();
if (pk != null) {
for (Column column : pk.getColumns()) {
projectedExpressions.add(new ColumnReference(obj, column.getName(), column, column.getJavaType()));
}
}
}
}
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class IckleConversionVisitor method visit.
@Override
public void visit(Join obj) {
Condition cond = null;
if (obj.getLeftItem() instanceof Join) {
cond = obj.getCondition();
append(obj.getLeftItem());
Table right = ((NamedTable) obj.getRightItem()).getMetadataObject();
this.joinedNode.joinWith(obj.getJoinType(), new DocumentNode(right, true));
} else if (obj.getRightItem() instanceof Join) {
cond = obj.getCondition();
append(obj.getRightItem());
Table left = ((NamedTable) obj.getLeftItem()).getMetadataObject();
this.joinedNode.joinWith(obj.getJoinType(), new DocumentNode(left, true));
} else {
cond = obj.getCondition();
append(obj.getLeftItem());
this.queriedTable = (NamedTable) obj.getRightItem();
Table right = ((NamedTable) obj.getRightItem()).getMetadataObject();
this.joinedNode.joinWith(obj.getJoinType(), new DocumentNode(right, true));
}
if (cond != null) {
append(cond);
}
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class InfinispanDirectQueryExecution method clearContents.
private void clearContents(BasicCache<String, String> aliasCache, String tableName) throws TranslatorException {
tableName = getAliasName(context, aliasCache, tableName);
Table table = metadata.getTable(tableName);
String cacheName = ProtobufMetadataProcessor.getCacheName(table);
BasicCache<Object, Object> cache = connection.getCacheFactory().getCache(cacheName);
if (cache == null) {
throw new TranslatorException(InfinispanPlugin.Event.TEIID25014, InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25014, tableName));
}
cache.clear();
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class InfinispanExecutionFactory method getMetadata.
@Override
public void getMetadata(MetadataFactory metadataFactory, InfinispanConnection conn) throws TranslatorException {
ProtobufMetadataProcessor metadataProcessor = (ProtobufMetadataProcessor) getMetadataProcessor();
// $NON-NLS-1$
PropertiesUtils.setBeanProperties(metadataProcessor, metadataFactory.getModelProperties(), "importer");
// This block is only invoked when NATIVE metadata is defined, by the time code got here if we have
// tables already in schema, then user defined through other metadata repositories. In this case,
// a .proto file need to be generated based on schema, then use that to generate final metadata and
// register the .proto with the Infinispan
Schema schema = metadataFactory.getSchema();
ProtobufResource resource = null;
ArrayList<Table> removedTables = new ArrayList<>();
if (schema.getTables() != null && !schema.getTables().isEmpty()) {
SchemaToProtobufProcessor stpp = new SchemaToProtobufProcessor();
stpp.setIndexMessages(true);
resource = stpp.process(metadataFactory, conn);
metadataProcessor.setProtobufResource(resource);
ArrayList<Table> tables = new ArrayList<>(schema.getTables().values());
for (Table t : tables) {
// remove the previous tables, as we want to introduce them with necessary
// extension metadata generated with generated .proto file. As some of the default
// extension metadata can be added.
removedTables.add(schema.removeTable(t.getName()));
}
}
metadataProcessor.process(metadataFactory, conn);
// may be not carried forward, we need to make sure we copy those back.
for (Table oldT : removedTables) {
Table newT = schema.getTable(oldT.getName());
Map<String, String> properties = oldT.getProperties();
for (Map.Entry<String, String> entry : properties.entrySet()) {
newT.setProperty(entry.getKey(), entry.getValue());
}
newT.setSupportsUpdate(oldT.supportsUpdate());
if (oldT.getAnnotation() != null) {
newT.setAnnotation(oldT.getAnnotation());
}
List<Column> columns = oldT.getColumns();
for (Column c : columns) {
Column newCol = newT.getColumnByName(c.getName());
if (newCol != null) {
Map<String, String> colProperties = c.getProperties();
for (Map.Entry<String, String> entry : colProperties.entrySet()) {
newCol.setProperty(entry.getKey(), entry.getValue());
}
newCol.setUpdatable(c.isUpdatable());
if (c.getAnnotation() != null) {
newCol.setAnnotation(c.getAnnotation());
}
}
}
}
resource = metadataProcessor.getProtobufResource();
if (resource == null) {
SchemaToProtobufProcessor stpp = new SchemaToProtobufProcessor();
resource = stpp.process(metadataFactory, conn);
}
// register protobuf
if (resource != null) {
conn.registerProtobufFile(resource);
}
}
Aggregations