use of org.teiid.metadata.MetadataException in project teiid by teiid.
the class DDLFileMetadataRepository method loadMetadata.
@Override
public void loadMetadata(MetadataFactory factory, ExecutionFactory executionFactory, Object connectionFactory, String text) throws TranslatorException {
String ddlFile = factory.getModelProperties().getProperty("ddl-file");
if (ddlFile != null) {
text = ddlFile;
}
if (text != null) {
VDBResource resource = factory.getVDBResources().get(text);
if (resource == null) {
throw new MetadataException(Event.TEIID31137, QueryPlugin.Util.gs(Event.TEIID31137, text));
}
InputStream is;
try {
is = resource.openStream();
} catch (IOException e1) {
throw new MetadataException(e1);
}
try {
// TODO: could allow for a property driven encoding
// $NON-NLS-1$
factory.parse(new InputStreamReader(is, Charset.forName("UTF-8")));
} finally {
try {
is.close();
} catch (IOException e) {
}
}
}
}
use of org.teiid.metadata.MetadataException in project teiid by teiid.
the class TestVisitor method queryMetadataInterface.
private static TransformationMetadata queryMetadataInterface() {
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("couchbase");
CouchbaseMetadataProcessor mp = new CouchbaseMetadataProcessor();
MetadataFactory mf = new MetadataFactory("couchbase", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), mmd);
Table customer = createTable(mf, KEYSPACE, "Customer");
mp.scanRow(KEYSPACE, KEYSPACE_SOURCE, formCustomer(), mf, customer, customer.getName(), false, new Dimension());
Table order = createTable(mf, KEYSPACE, "Oder");
mp.scanRow(KEYSPACE, KEYSPACE_SOURCE, formOder(), mf, order, order.getName(), false, new Dimension());
Table t2 = createTable(mf, "T2", "T2");
mp.scanRow("T2", "`T2`", formDataTypeJson(), mf, t2, t2.getName(), false, new Dimension());
Table t3 = createTable(mf, "T3", "T3");
mp.scanRow("T3", "`T3`", nestedJson(), mf, t3, t3.getName(), false, new Dimension());
mp.scanRow("T3", "`T3`", nestedArray(), mf, t3, t3.getName(), false, new Dimension());
mp.addProcedures(mf, null);
TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x");
ValidatorReport report = new MetadataValidator().validate(tm.getVdbMetaData(), tm.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
return tm;
} catch (MetadataException e) {
throw new RuntimeException(e);
}
}
use of org.teiid.metadata.MetadataException in project teiid by teiid.
the class VDBRepository method getODBCMetadataStore.
private MetadataStore getODBCMetadataStore() {
try {
PgCatalogMetadataStore pg = new PgCatalogMetadataStore(CoreConstants.ODBC_MODEL, getRuntimeTypeMap());
// $NON-NLS-1$
ValidatorReport report = new ValidatorReport("Function Validation");
FunctionMetadataValidator.validateFunctionMethods(pg.getSchema().getFunctions().values(), report);
if (report.hasItems()) {
throw new MetadataException(report.getFailureMessage());
}
return pg.asMetadataStore();
} catch (MetadataException e) {
this.odbcException = e;
LogManager.logError(LogConstants.CTX_DQP, e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40002));
}
return null;
}
use of org.teiid.metadata.MetadataException in project teiid by teiid.
the class TestSQLConversionVisitor method queryMetadataInterface.
private static TransformationMetadata queryMetadataInterface() {
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("prestodbModel");
MetadataFactory mf = new MetadataFactory("prestodb", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), mmd);
mf.setParser(new QueryParser());
mf.parse(new FileReader(UnitTestUtil.getTestDataFile("sample.ddl")));
TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x");
ValidatorReport report = new MetadataValidator().validate(tm.getVdbMetaData(), tm.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
return tm;
} catch (MetadataException | FileNotFoundException e) {
throw new RuntimeException(e);
}
}
use of org.teiid.metadata.MetadataException in project teiid by teiid.
the class SwaggerMetadataProcessor method addProcedureParameters.
private void addProcedureParameters(final MetadataFactory mf, final Swagger swagger, final Procedure procedure, final Operation operation) throws TranslatorException {
for (final Parameter parameter : operation.getParameters()) {
if (parameter instanceof BodyParameter) {
PropertyAction pa = new PropertyAction() {
@Override
public void execute(String name, String nameInSource, Property property, boolean array) {
String type = getPropertyType(property, array);
if (procedure.getParameterByName(nameInSource) == null) {
ProcedureParameter param = mf.addProcedureParameter(name, type, Type.In, procedure);
param.setProperty(PARAMETER_TYPE, parameter.getIn());
if (property != null && !property.getRequired()) {
param.setProperty(BaseColumn.DEFAULT_HANDLING, BaseColumn.OMIT_DEFAULT);
}
param.setNullType(NullType.No_Nulls);
param.setAnnotation(property != null ? property.getDescription() : null);
if (!name.equalsIgnoreCase(nameInSource)) {
param.setNameInSource(nameInSource);
}
}
}
};
Model model = ((BodyParameter) parameter).getSchema();
if (model instanceof RefModel) {
RefModel refModel = (RefModel) model;
if (refModel.getProperties() != null) {
walkProperties(swagger, refModel.getProperties(), null, null, pa);
} else if (refModel.getReference() != null) {
Model m = swagger.getDefinitions().get(refModel.getSimpleRef());
walkProperties(swagger, m.getProperties(), null, null, pa);
}
} else {
if ((model instanceof ModelImpl) && model.getProperties() != null) {
walkProperties(swagger, model.getProperties(), null, null, pa);
} else {
ProcedureParameter p = mf.addProcedureParameter(parameter.getName(), DataTypeManager.DefaultDataTypes.CLOB, Type.In, procedure);
p.setProperty(PARAMETER_TYPE, parameter.getIn());
p.setNullType(NullType.No_Nulls);
p.setAnnotation(parameter.getDescription());
}
}
} else {
String name = parameter.getName();
ProcedureParameter pp = null;
String type = null;
Object defaultValue = null;
String collectionFormat = null;
if (parameter instanceof AbstractSerializableParameter) {
AbstractSerializableParameter p = (AbstractSerializableParameter) parameter;
type = p.getType();
if (p.getType().equalsIgnoreCase("array")) {
Property ap = p.getItems();
type = ap.getType();
}
type = SwaggerTypeManager.teiidType(type, p.getFormat(), p.getItems() != null);
defaultValue = p.getDefaultValue();
collectionFormat = p.getCollectionFormat();
} else {
// $NON-NLS-1$
throw new MetadataException("Unknown property type" + parameter.getClass().getName());
}
pp = mf.addProcedureParameter(name, type, Type.In, procedure);
pp.setProperty(PARAMETER_TYPE, parameter.getIn());
boolean required = parameter.getRequired();
if (!required) {
pp.setProperty(BaseColumn.DEFAULT_HANDLING, BaseColumn.OMIT_DEFAULT);
}
pp.setNullType(NullType.No_Nulls);
pp.setAnnotation(parameter.getDescription());
if (defaultValue != null) {
pp.setDefaultValue(defaultValue.toString());
}
if (collectionFormat != null) {
pp.setProperty(COLLECION_FORMAT, collectionFormat);
}
// extended properties
for (Entry<String, Object> extension : parameter.getVendorExtensions().entrySet()) {
pp.setProperty(extension.getKey(), extension.getValue().toString());
}
}
}
}
Aggregations