private Column addColumn(MetadataFactory mf, String name, String type, Table entityTable) throws TranslatorException { if (!columnExists(name, entityTable)) { Column c = mf.addColumn(name, type, entityTable); c.setUpdatable(true); return c; } return entityTable.getColumnByName(name); }
private List<String> addLinkTableColumns(MetadataFactory mf, Table table, List<String> columnNames, Table linkTable) throws TranslatorException { if (columnNames != null) { for (String columnName:columnNames) { Column column = table.getColumnByName(columnName); if (column == null) { throw new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17003, columnName, table.getName())); } column = mf.addColumn(column.getName(), column.getRuntimeType(), linkTable); column.setProperty(JOIN_COLUMN, String.valueOf(true)); } } else { columnNames = new ArrayList<String>(); for (Column column :table.getPrimaryKey().getColumns()) { columnNames.add(column.getName()); if (linkTable.getColumnByName(column.getName()) == null) { column = mf.addColumn(column.getName(), column.getRuntimeType(), linkTable); } column.setProperty(JOIN_COLUMN, String.valueOf(true)); } } return columnNames; }
private Column addColumn(String name, Class<?> type, Table table, MetadataFactory mf) throws TranslatorException { if (type == null) { throw new TranslatorException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31086, name, table.getFullName())); } Column column = mf.addColumn(name, DataTypeManager.getDataTypeName(type), table); column.setUpdatable(table.supportsUpdate()); return column; }
table.setSupportsUpdate(true); Column itemName = metadataFactory.addColumn(DISPLAY_ITEM_NAME, TypeFacility.RUNTIME_NAMES.STRING, table); itemName.setUpdatable(true); itemName.setNameInSource(ITEM_NAME); Column column = null; if (attribute.hasMultipleValues()) { column = metadataFactory.addColumn(attribute.getName(), TypeFacility.RUNTIME_NAMES.STRING+"[]", table); //$NON-NLS-1$ column = metadataFactory.addColumn(attribute.getName(), TypeFacility.RUNTIME_NAMES.STRING, table);
@SuppressWarnings("unused") protected Column buildColumn(MetadataFactory mf, Table table, EdmProperty ep, EdmEntitySet entitySet, String prefix) { String columnName = ep.getName(); if (prefix != null) { columnName = prefix+"_"+columnName; //$NON-NLS-1$ } Column c = mf.addColumn(columnName, ODataTypeManager.teiidType(ep.getType().getFullyQualifiedTypeName()), table); c.setNameInSource(ep.getName()); c.setUpdatable(true); return c; }
private ModelMetaData buildSourceTableWithPK() { ModelMetaData model = new ModelMetaData(); model.setName("source"); model.setModelType(Model.Type.PHYSICAL); MetadataFactory target = new MetadataFactory(VDBNAME, VDBVERSION, SystemMetadata.getInstance().getRuntimeTypeMap(), model); Table t = target.addTable("Person"); target.addColumn("id", "integer", t); target.addColumn("name", "string", t); target.addColumn("dob", "date", t); target.addPrimaryKey("PK", Arrays.asList("id"), t); Table addr = target.addTable("address"); target.addColumn("id", "integer", addr); target.addColumn("street", "string", addr); target.addColumn("pid", "integer", addr); target.addPrimaryKey("PK", Arrays.asList("id"), addr); target.addForeignKey("FK", Arrays.asList("pid"), Arrays.asList("id"), "Person", addr); String ddl = DDLStringVisitor.getDDLString(target.getSchema(), null, null); model.addSourceMetadata("ddl", ddl); model.addAttchment(MetadataFactory.class, target); return model; }
@Override public void loadMetadata(MetadataFactory factory, ExecutionFactory<Object, Object> executionFactory, Object connectionFactory) throws TranslatorException { Schema s = factory.getSchema(); for (Table t : s.getTables().values()) { if (!t.isPhysical()) { continue; } Column c = t.getColumnByName(multiSourceColumnName); if (c == null) { c = factory.addColumn(multiSourceColumnName, DataTypeManager.DefaultDataTypes.STRING, t); MultiSourceMetadataWrapper.setMultiSourceElementMetadata(c); } } outer: for (Procedure p : s.getProcedures().values()) { if (p.isVirtual()) { continue; } for (ProcedureParameter pp : p.getParameters()) { if (multiSourceColumnName.equalsIgnoreCase(pp.getName())) { continue outer; } } ProcedureParameter pp = factory.addProcedureParameter(multiSourceColumnName, DataTypeManager.DefaultDataTypes.STRING, Type.In, p); pp.setNullType(NullType.Nullable); } }
/** * Add a procedure resultset column to the given procedure. * @param name * @param type should be one of {@link TypeFacility.RUNTIME_NAMES} * @param procedure * @return * @throws MetadataException */ public Column addProcedureResultSetColumn(String name, String type, Procedure procedure) { if (procedure.getResultSet() == null) { ColumnSet<Procedure> resultSet = new ColumnSet<Procedure>(); resultSet.setParent(procedure); resultSet.setName("RSParam"); //$NON-NLS-1$ setUUID(resultSet); procedure.setResultSet(resultSet); } return addColumn(name, type, procedure.getResultSet()); }
private Column addColumn(Expression toCopy, Table table, MetadataFactory mf, QueryMetadataInterface metadata) throws TranslatorException, QueryMetadataException, TeiidComponentException { String name = Symbol.getShortName(toCopy); Class<?> type = toCopy.getType(); if (type == null) { throw new TranslatorException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31086, name, table.getFullName())); } Column column = mf.addColumn(name, DataTypeManager.getDataTypeName(type), table); column.setUpdatable(table.supportsUpdate()); copyExpressionMetadata(toCopy, metadata, column); return column; }
private Column addColumn(Expression toCopy, Table table, MetadataFactory mf, QueryMetadataInterface metadata) throws TranslatorException, QueryMetadataException, TeiidComponentException { String name = Symbol.getShortName(toCopy); Class<?> type = toCopy.getType(); if (type == null) { throw new TranslatorException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31086, name, table.getFullName())); } Column column = mf.addColumn(name, DataTypeManager.getDataTypeName(type), table); column.setUpdatable(table.supportsUpdate()); copyExpressionMetadata(toCopy, metadata, column); return column; }
private ModelMetaData buildSourceTableWithCompositePK() { ModelMetaData model = new ModelMetaData(); model.setName("source"); model.setModelType(Model.Type.PHYSICAL); MetadataFactory target = new MetadataFactory(VDBNAME, VDBVERSION, SystemMetadata.getInstance().getRuntimeTypeMap(), model); Table t = target.addTable("Person"); target.addColumn("id", "integer", t); target.addColumn("name", "string", t); target.addColumn("dob", "date", t); target.addPrimaryKey("PK", Arrays.asList("id", "name"), t); String ddl = DDLStringVisitor.getDDLString(target.getSchema(), null, null); model.addSourceMetadata("ddl", ddl); model.addAttchment(MetadataFactory.class, target); return model; }
private ModelMetaData buildSourceTable() { ModelMetaData model = new ModelMetaData(); model.setName("source"); model.setModelType(Model.Type.PHYSICAL); MetadataFactory target = new MetadataFactory(VDBNAME, VDBVERSION, SystemMetadata.getInstance().getRuntimeTypeMap(), model); Table t = target.addTable("Person"); target.addColumn("id", "integer", t); target.addColumn("name", "string", t); target.addColumn("dob", "date", t); model.addAttchment(MetadataFactory.class, target); String ddl = DDLStringVisitor.getDDLString(target.getSchema(), null, null); model.addSourceMetadata("ddl", ddl); return model; }
@Test public void testCorrectName() { ModelMetaData mmd = new ModelMetaData(); mmd.setName("foo"); HashMap<String, Datatype> types = new HashMap<String, Datatype>(); Datatype value = new Datatype(); value.setName("string"); types.put("string", value); MetadataFactory factory = new MetadataFactory("x", 1, types, mmd); Table x = factory.addTable("x"); Column c = factory.addColumn("a.b", "string", x); assertEquals("a_b", c.getName()); }
private Column buildColumn(MetadataFactory mf, Table table, CsdlProperty property) { String columnName = property.getName(); Column c = mf.addColumn(columnName, ODataTypeManager.teiidType(property.getType(), property.isCollection()), table); handleGeometryTypes(property.getSrid(), property.getType(), c); if(property.isCollection()) { c.setSearchType(SearchType.Unsearchable); } c.setUpdatable(true); return c; }
private Table addNavigationAsTable(MetadataFactory mf, XMLMetadata metadata, Table fromTable, CsdlNavigationProperty property) throws TranslatorException { String name = join(fromTable.getName(), NAME_SEPARATOR, property.getName()); Table toTable = addTable(mf, name, property.getType(), property.isCollection()?ODataType.NAVIGATION_COLLECTION:ODataType.NAVIGATION, metadata); toTable.setNameInSource(property.getName()); KeyRecord pk = fromTable.getPrimaryKey(); List<String> columnNames = new ArrayList<String>(); for (Column c : pk.getColumns()) { String columnName = join(fromTable.getName(), NAME_SEPARATOR, c.getName()); Column column = mf.addColumn(columnName, c.getRuntimeType(), toTable); column.setProperty(PSEUDO, String.valueOf(Boolean.TRUE)); columnNames.add(columnName); } mf.addForeignKey("FK0", columnNames, getColumnNames(pk.getColumns()), fromTable.getFullName(), toTable); return toTable; }
@Test public void testDuplicateColumns() { ModelMetaData mmd = new ModelMetaData(); mmd.setName("foo"); mmd.addProperty("importer.renameDuplicateColumns", "true"); HashMap<String, Datatype> types = new HashMap<String, Datatype>(); Datatype value = new Datatype(); value.setName("string"); types.put("string", value); MetadataFactory factory = new MetadataFactory("x", 1, types, mmd); Table x = factory.addTable("x"); Column c = factory.addColumn("a_b", "string", x); assertEquals("a_b", c.getName()); c = factory.addColumn("a_B", "string", x); assertEquals("a_B_1", c.getName()); }
@Test public void testTypeCorrection() throws Exception { MetadataFactory mf = new MetadataFactory(null, 1, "x", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null); //$NON-NLS-1$ Table t = mf.addTable("y"); //$NON-NLS-1$ mf.addColumn("test", "string", t); mf.addColumn("array", "string[]", t); Datatype unknown = new Datatype(); unknown.setName("unknown"); Column col = mf.addColumn("arg", "string", t); col.setDatatype(unknown, false, 0); MetadataFactory mf1 = UnitTestUtil.helpSerialize(mf); Column column = mf1.getSchema().getTable("y").getColumns().get(0); Datatype dt = column.getDatatype(); assertNotSame(mf.getDataTypes().get(dt.getName()), column.getDatatype()); assertEquals(1, mf1.getSchema().getTable("y").getColumns().get(1).getArrayDimensions()); mf1.correctDatatypes(mf.getDataTypes()); assertSame(mf.getDataTypes().get(dt.getName()), column.getDatatype()); assertEquals(1, mf1.getSchema().getTable("y").getColumns().get(1).getArrayDimensions()); }
mf.addColumn("col", DataTypeManager.DefaultDataTypes.STRING, t);
private Column addColumn(MetadataFactory mf, Table table, Column property, String newName) { Column c = mf.addColumn(newName, property.getRuntimeType(),table); c.setUpdatable(true); c.setNullType(property.getNullType()); c.setLength(property.getLength()); c.setPrecision(property.getPrecision()); c.setScale(property.getScale()); c.setDefaultValue(property.getDefaultValue()); c.setProperty("MIME-TYPE", c.getProperty("MIME-TYPE", false)); c.setProperty(BaseColumn.SPATIAL_SRID, property.getProperty(BaseColumn.SPATIAL_SRID, false)); c.setProperty("NATIVE_TYPE", property.getProperty("NATIVE_TYPE", false)); return c; }
@Test public void testSkipDocumentModel() throws Exception { ModelMetaData model = new ModelMetaData(); model.setName("xmlstuff"); model.setModelType(Model.Type.VIRTUAL); vdb.addModel(model); MetadataFactory mf = new MetadataFactory("myVDB",1, "xmlstuff", TestDDLParser.getDataTypes(), new Properties(), null); mf.getSchema().setPhysical(false); Table t = mf.addTable("xmldoctable"); t.setTableType(Table.Type.Document); mf.addColumn("c1", "string", t); t.setSelectTransformation("some dummy stuff, should not be validated"); t.setVirtual(true); Table t2 = mf.addTable("xmldoctable2"); t2.setTableType(Table.Type.XmlMappingClass); mf.addColumn("c1", "string", t2); t2.setSelectTransformation("some dummy stuff, should not be validated"); t2.setVirtual(true); mf.mergeInto(store); buildTransformationMetadata(); ValidatorReport report = new MetadataValidator().validate(this.vdb, this.store); assertFalse(printError(report), report.hasItems()); }