use of org.teiid.metadata.Table in project teiid by teiid.
the class PrestoDBMetadataProcessor method addTable.
private void addTable(String tableName, Connection conn, String catalog, String schema, MetadataFactory metadataFactory) throws SQLException {
Table table = addTable(metadataFactory, null, null, tableName, null, tableName);
if (table == null) {
return;
}
// $NON-NLS-1$ //$NON-NLS-2$
String nis = catalog + "." + schema + "." + tableName;
table.setNameInSource(nis);
Statement stmt = conn.createStatement();
// $NON-NLS-1$
ResultSet rs = stmt.executeQuery("SHOW COLUMNS FROM " + nis);
while (rs.next()) {
String name = rs.getString(1);
if (this.trimColumnNames) {
name = name.trim();
}
String type = rs.getString(2);
if (type != null) {
type = type.trim();
}
String runtimeType = getRuntimeType(type);
NullType nt = Boolean.valueOf(rs.getString(3)) ? NullType.Nullable : NullType.No_Nulls;
Column column = metadataFactory.addColumn(name, runtimeType, table);
column.setNameInSource(name);
column.setUpdatable(true);
column.setNullType(nt);
}
rs.close();
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class JPAMetadataProcessor method addSingularAttributes.
private void addSingularAttributes(MetadataFactory mf, Metamodel model, ManagedType<?> entity, Table entityTable) throws TranslatorException {
for (Attribute<?, ?> attr : entity.getAttributes()) {
if (!attr.isCollection()) {
boolean simpleType = isSimpleType(attr.getJavaType());
if (simpleType) {
Column column = addColumn(mf, attr.getName(), TypeFacility.getDataTypeName(getJavaDataType(attr.getJavaType())), entityTable);
if (((SingularAttribute) attr).isOptional()) {
column.setDefaultValue(null);
}
} else {
boolean classFound = false;
// this tables columns
for (EmbeddableType<?> embeddable : model.getEmbeddables()) {
if (embeddable.getJavaType().equals(attr.getJavaType())) {
addSingularAttributes(mf, model, embeddable, entityTable);
classFound = true;
break;
}
}
if (!classFound) {
// table, then add that column as FK
for (EntityType et : model.getEntities()) {
if (et.getJavaType().equals(attr.getJavaType())) {
Table attributeTable = addEntity(mf, model, et);
KeyRecord pk = attributeTable.getPrimaryKey();
if (pk != null) {
// TODO: entities must have PK, so this check is not needed.
ArrayList<String> keys = new ArrayList<String>();
for (Column column : pk.getColumns()) {
addColumn(mf, column.getName(), column.getDatatype().getRuntimeTypeName(), entityTable);
keys.add(column.getName());
}
if (!foreignKeyExists(keys, entityTable)) {
addForeignKey(mf, attr.getName(), keys, attributeTable.getName(), entityTable);
}
} else {
throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14001, attributeTable.getName()));
}
classFound = true;
break;
}
}
}
if (!classFound) {
throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14002, attr.getName()));
}
}
}
}
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class JPAMetadataProcessor method addEntity.
private Table addEntity(MetadataFactory mf, Metamodel model, EntityType<?> entity) throws TranslatorException {
Table table = mf.getSchema().getTable(entity.getName());
if (table == null) {
table = mf.addTable(entity.getName());
table.setSupportsUpdate(true);
table.setProperty(ENTITYCLASS, entity.getJavaType().getCanonicalName());
addPrimaryKey(mf, model, entity, table);
addSingularAttributes(mf, model, entity, table);
}
return table;
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class TestCreateDrop method testForeignTemp.
@Test
public void testForeignTemp() {
Create create = new Create();
// $NON-NLS-1$
create.setTable(new GroupSymbol("tempTable"));
create.setOn("source");
Table t = new Table();
t.setName("tempTable");
t.setUUID("tid:0");
Column c = new Column();
c.setName("x");
c.setUUID("tid:0");
Datatype string = SystemMetadata.getInstance().getRuntimeTypeMap().get("string");
c.setDatatype(string, true, 0);
t.addColumn(c);
c = new Column();
c.setName("y");
c.setUUID("tid:0");
Datatype decimal = SystemMetadata.getInstance().getRuntimeTypeMap().get("decimal");
c.setDatatype(decimal, true, 0);
t.addColumn(c);
t.setCardinality(10000);
create.setTableMetadata(t);
// $NON-NLS-1$ //$NON-NLS-2$
helpTest("create foreign temporary table tempTable (x string, y decimal) options (cardinality 10000) on source", "CREATE FOREIGN TEMPORARY TABLE tempTable (\n x string,\n y bigdecimal\n) OPTIONS (CARDINALITY 10000) ON 'source'", create);
}
use of org.teiid.metadata.Table in project teiid by teiid.
the class CoherenceUpdateExecution method executeUpdate.
// Private method to actually do an update operation.
private void executeUpdate() throws TranslatorException {
Update ucommand = (Update) command;
Table t = metadata.getTable(ucommand.getTable().getMetadataObject().getFullName());
// if the table has a foreign key, its must be a child (contained) object in the root
if (t.getForeignKeys() != null && t.getForeignKeys().size() > 0) {
updateChildObject(t);
return;
}
}
Aggregations