node.get(MODEL_NAME).set(model.getName()); if (model.getDescription() != null) { node.get(DESCRIPTION).set(model.getDescription()); node.get(VISIBLE).set(model.isVisible()); node.get(MODEL_TYPE).set(model.getModelType().toString()); if (model.getPath() != null) { node.get(MODELPATH).set(model.getPath()); Collection<SourceMappingMetadata> sources = model.getSourceMappings(); if (sources != null && !sources.isEmpty()) { ModelNode sourceMappingNode = node.get(SOURCE_MAPPINGS); List<Message> errors = model.getMessages(); if (errors != null && !errors.isEmpty()) { ModelNode errorsNode = node.get(VALIDITY_ERRORS); if (!model.getSourceMetadataType().isEmpty()) { ModelNode metadataNodes = node.get(METADATAS); for (int i = 0; i < model.getSourceMetadataType().size(); i++) { ModelNode metadataNode = new ModelNode(); metadataNode.get(METADATA_TYPE).set(model.getSourceMetadataType().get(i)); String text = model.getSourceMetadataText().get(i); if (text != null) { metadataNode.get(METADATA).set(text); node.get(METADATA_STATUS).set(model.getMetadataStatus().name()); return node;
ModelMetaData model = new ModelMetaData(); if (node.has(MODEL_NAME)) { model.setName(node.get(MODEL_NAME).asString()); model.setDescription(node.get(DESCRIPTION).asString()); model.setVisible(node.get(VISIBLE).asBoolean()); model.setModelType(node.get(MODEL_TYPE).asString()); model.setPath(node.get(MODELPATH).asString()); String[] prop = PropertyMetaDataMapper.INSTANCE.unwrap(propNode); if (prop != null) { model.addProperty(prop[0], prop[1]); SourceMappingMetadata source = SourceMappingMetadataMapper.INSTANCE.unwrap(sourceMapping); if (source != null) { model.addSourceMapping(source); Message error = ValidationErrorMapper.INSTANCE.unwrap(errorNode); if (error != null) { model.addMessage(error); model.addSourceMetadata(type, text); model.setMetadataStatus(node.get(METADATA_STATUS).asString());
public MetadataFactory(String vdbName, Object vdbVersion, Map<String, Datatype> runtimeTypes, ModelMetaData model) { this(vdbName, vdbVersion, model.getName(), runtimeTypes, model.getProperties(), model.getSchemaText()); this.model = model; }
public static Map<String, String> getMultiSourceModels(VDBMetaData vdb) { HashMap<String, String> result = new HashMap<String, String>(); for (ModelMetaData mmd : vdb.getModelMetaDatas().values()) { if (!mmd.isSupportsMultiSourceBindings()) { continue; } String columnName = mmd.getPropertyValue(MULTISOURCE_COLUMN_NAME); if (columnName == null) { columnName = MultiSourceElement.DEFAULT_MULTI_SOURCE_ELEMENT_NAME; } result.put(mmd.getName(), columnName); } return result; }
ModelMetaData buildModel(String name) { ModelMetaData model = new ModelMetaData(); model.setName(name); model.setModelType(Model.Type.PHYSICAL); model.setVisible(true); return model; }
ModelMetaData mmd = new ModelMetaData(); mmd.setName(schema.getName()); mmd.setDescription(schema.getAnnotation()); mmd.setVisible(Boolean.valueOf(schema.isVisible())); mmd.getPropertiesMap().putAll(schema.getProperties()); if (schema.isPhysical()) { mmd.setModelType(Model.Type.PHYSICAL); connectionName = server.getName(); mmd.addSourceMapping(server.getName(), server.getDataWrapper(), connectionName); mmd.setModelType(Model.Type.VIRTUAL);
private static void parseModel(XMLStreamReader reader, ModelMetaData model) throws XMLStreamException { Properties props = getAttributes(reader); model.setName(props.getProperty(Element.NAME.getLocalName())); model.setModelType(props.getProperty(Element.TYPE.getLocalName(), "PHYSICAL")); model.setVisible(Boolean.parseBoolean(props.getProperty(Element.VISIBLE.getLocalName(), "true"))); model.setPath(props.getProperty(Element.PATH.getLocalName())); switch (element) { case DESCRIPTION: model.setDescription(reader.getElementText()); break; case PROPERTY: String translatorName = sourceProps.getProperty(Element.SOURCE_TRANSLATOR_NAME_ATTR.getLocalName()); String connectionName = sourceProps.getProperty(Element.SOURCE_CONNECTION_JNDI_NAME_ATTR.getLocalName()); model.addSourceMapping(name, translatorName, connectionName); ignoreTillEnd(reader); break; Message ve = new Message(Severity.valueOf(severity), msg); ve.setPath(path); model.addMessage(ve); break; case METADATA: String type = metdataProps.getProperty(Element.TYPE.getLocalName(), "DDL"); String text = reader.getElementText(); model.addSourceMetadata(type, text); break; default:
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 testSchemaProperties() { ModelMetaData mmd = new ModelMetaData(); mmd.setName("foo"); mmd.addProperty("teiid_rel:data-ttl", "1"); MetadataFactory mf = new MetadataFactory("x", 1, Collections.EMPTY_MAP, mmd); Schema s = mf.getSchema(); assertEquals("foo", s.getName()); String val = s.getProperty(DataModifiable.DATA_TTL, false); assertEquals("1", val); }
private MetadataFactory loadSchema(VDBMetaData vdb, Properties p, String name, QueryParser parser) { ModelMetaData mmd = new ModelMetaData(); mmd.setName(name); vdb.addModel(mmd); InputStream is = SystemMetadata.class.getClassLoader().getResourceAsStream("org/teiid/metadata/"+name+".sql"); //$NON-NLS-1$ //$NON-NLS-2$ try { MetadataFactory factory = new MetadataFactory(vdb.getName(), vdb.getVersion(), name, typeMap, p, null); parser.parseDDL(factory, new InputStreamReader(is, Charset.forName("UTF-8"))); //$NON-NLS-1$ for (Table t : factory.getSchema().getTables().values()) { t.setSystem(true); } return factory; } finally { try { is.close(); } catch (IOException e) { throw new TeiidRuntimeException(e); } } }
assertEquals("model-one", modelOne.getName()); //$NON-NLS-1$ assertEquals("s1", modelOne.getSourceNames().get(0)); //$NON-NLS-1$ assertEquals(Model.Type.PHYSICAL, modelOne.getModelType()); assertEquals("model-value-override", modelOne.getPropertyValue("model-prop")); //$NON-NLS-1$ //$NON-NLS-2$ assertFalse(modelOne.isVisible()); assertEquals("model description", modelOne.getDescription()); assertEquals("DDL", modelOne.getSourceMetadataType().get(0)); assertEquals("DDL Here", modelOne.getSourceMetadataText().get(0)); assertEquals("OTHER", modelOne.getSourceMetadataType().get(1)); assertEquals("other text", modelOne.getSourceMetadataText().get(1)); assertEquals("model-two", modelTwo.getName()); //$NON-NLS-1$ assertTrue(modelTwo.getSourceNames().contains("s1")); //$NON-NLS-1$ assertTrue(modelTwo.getSourceNames().contains("s2")); //$NON-NLS-1$ assertEquals(Model.Type.VIRTUAL, modelTwo.getModelType()); // this is not persisted in the XML assertEquals("model-value", modelTwo.getPropertyValue("model-prop")); //$NON-NLS-1$ //$NON-NLS-2$ assertEquals("DDL", modelTwo.getSourceMetadataType().get(0)); assertEquals("DDL Here", modelTwo.getSourceMetadataText().get(0));
protected void assignMetadataRepositories(VDBMetaData deployment, MetadataRepository<?, ?> defaultRepo) throws VirtualDatabaseException { for (ModelMetaData model:deployment.getModelMetaDatas().values()) { if (model.getModelType() != Type.OTHER && (model.getName() == null || model.getName().indexOf('.') >= 0) || model.getName().equalsIgnoreCase(CoreConstants.SYSTEM_MODEL) || model.getName().equalsIgnoreCase(CoreConstants.SYSTEM_ADMIN_MODEL) || model.getName().equalsIgnoreCase(CoreConstants.ODBC_MODEL)) { throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40121, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40121, model.getName(), deployment.getName(), deployment.getVersion())); } if (model.isSource() && model.getSourceNames().isEmpty()) { throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40093, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40093, model.getName(), deployment.getName(), deployment.getVersion())); } if (model.getModelType() == Type.FUNCTION || model.getModelType() == Type.OTHER) { continue; } MetadataRepository<?, ?> repo = getMetadataRepository(deployment, model, defaultRepo); //handle multi-source column creation if (model.isSupportsMultiSourceBindings() && Boolean.valueOf(model.getPropertyValue("multisource.addColumn"))) { //$NON-NLS-1$ List<MetadataRepository<?, ?>> repos = new ArrayList<MetadataRepository<?, ?>>(2); repos.add(repo); String columnName = model.getPropertyValue(MultiSourceMetadataWrapper.MULTISOURCE_COLUMN_NAME); repos.add(new MultiSourceMetadataRepository(columnName==null?MultiSourceElement.DEFAULT_MULTI_SOURCE_ELEMENT_NAME:columnName)); repo = new ChainingMetadataRepository(repos); } model.addAttchment(MetadataRepository.class, repo); } }
public String toString() { return getName() + this.sources; }
public void createConnectorManagers(VDBMetaData deployment, ExecutionFactoryProvider provider) throws ConnectorManagerException { for (ModelMetaData model : deployment.getModelMetaDatas().values()) { List<String> sourceNames = model.getSourceNames(); if (sourceNames.size() != new HashSet<String>(sourceNames).size()) { throw new ConnectorManagerException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31101, model.getName(), deployment.getName(), deployment.getVersion())); } if (sourceNames.size() > 1 && !model.isSupportsMultiSourceBindings()) { throw new ConnectorManagerException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31102, model.getName(), deployment.getName(), deployment.getVersion())); } for (SourceMappingMetadata source : model.getSourceMappings()) { createConnectorManager(deployment, provider, source, false); } } }
if (t.isPhysical() && !model.isSource()) { metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31075, t.getFullName(), model.getName())); if (!p.isVirtual() && !model.isSource()) { metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31077, p.getFullName(), model.getName())); if (func.getPushdown().equals(FunctionMethod.PushDown.MUST_PUSHDOWN) && !model.isSource()) { metadataValidator.log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31078, func.getFullName(), model.getName()));
Schema schema = metadataStore.getSchema(m.getName()); if (m.isSource()){ Collection<SourceMappingMetadata> sources = m.getSourceMappings();
private MetadataRepository<?, ?> getMetadataRepository(VDBMetaData vdb, ModelMetaData model, MetadataRepository<?, ?> defaultRepo) throws VirtualDatabaseException { if (model.getSourceMetadataType().isEmpty()) { if (defaultRepo != null) { return defaultRepo; if (model.isSource()) { return new ChainingMetadataRepository(Arrays.asList(new NativeMetadataRepository(), new DirectQueryMetadataRepository())); throw new VirtualDatabaseException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40094, model.getName(), vdb.getName(), vdb.getVersion(), null)); for (int i = 0; i < model.getSourceMetadataType().size(); i++) { String schemaTypes = model.getSourceMetadataType().get(i); MetadataRepository<?, ?> current = getMetadataRepository(repoType); if (current == null) { throw new VirtualDatabaseException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40094, model.getName(), vdb.getName(), vdb.getVersion(), repoType)); if (model.getSourceMetadataText().size() > i) { current = new MetadataRepositoryWrapper(current, model.getSourceMetadataText().get(i)); if (model.getModelType() == ModelMetaData.Type.PHYSICAL) { repos.add(new DirectQueryMetadataRepository()); if (model.getModelType() == ModelMetaData.Type.VIRTUAL) { repos.add(new MaterializationMetadataRepository());
for (ModelMetaData m:modelMetaDatas.values()) { Schema schema = new Schema(); schema.setName(m.getName()); schema.setAnnotation(m.getDescription()); schema.setVisible(m.isVisible()); schema.setPhysical(m.isSource()); schema.setProperties(m.getPropertiesMap()); metadataStore.addSchema(schema);
@Test public void testModelType() { ModelMetaData model = new ModelMetaData(); model.setModelType("physical"); assertTrue(model.getModelType() == Model.Type.PHYSICAL); assertTrue(model.isSource()); model.modelType = "VIRTUAL"; assertTrue(model.getModelType() == Model.Type.VIRTUAL); model.modelType = "TYPE"; assertTrue(model.getModelType() == Model.Type.OTHER); assertTrue(!model.isSource()); }
@Test public void testSupportMultiSource() { ModelMetaData model = new ModelMetaData(); assertFalse(model.isSupportsMultiSourceBindings()); model.setSupportsMultiSourceBindings(true); assertTrue(model.isSupportsMultiSourceBindings()); model.setModelType(Type.VIRTUAL); assertFalse(model.isSupportsMultiSourceBindings()); assertTrue(!model.getProperties().isEmpty()); }