use of org.teiid.core.TeiidException in project teiid by teiid.
the class MetadataValidator method validate.
private void validate(VDBMetaData vdb, ModelMetaData model, AbstractMetadataRecord record, ValidatorReport report, QueryMetadataInterface metadata, MetadataFactory mf) {
ValidatorReport resolverReport = null;
try {
if (record instanceof Procedure) {
Procedure p = (Procedure) record;
Command command = parser.parseProcedure(p.getQueryPlan(), false);
validateNoReferences(command, report, model);
QueryResolver.resolveCommand(command, new GroupSymbol(p.getFullName()), Command.TYPE_STORED_PROCEDURE, metadata, false);
resolverReport = Validator.validate(command, metadata);
determineDependencies(p, command);
} else if (record instanceof Table) {
Table t = (Table) record;
GroupSymbol symbol = new GroupSymbol(t.getFullName());
ResolverUtil.resolveGroup(symbol, metadata);
String selectTransformation = t.getSelectTransformation();
QueryNode node = null;
if (t.isVirtual()) {
QueryCommand command = (QueryCommand) parser.parseCommand(selectTransformation);
validateNoReferences(command, report, model);
QueryResolver.resolveCommand(command, metadata);
resolverReport = Validator.validate(command, metadata);
if (!resolverReport.hasItems() && (t.getColumns() == null || t.getColumns().isEmpty())) {
List<Expression> symbols = command.getProjectedSymbols();
for (Expression column : symbols) {
try {
addColumn(Symbol.getShortName(column), column.getType(), t, mf);
} catch (TranslatorException e) {
log(report, model, e.getMessage());
}
}
}
node = QueryResolver.resolveView(symbol, new QueryNode(selectTransformation), SQLConstants.Reserved.SELECT, metadata, true);
if (t.getColumns() != null && !t.getColumns().isEmpty()) {
determineDependencies(t, command);
if (t.getInsertPlan() != null && t.isInsertPlanEnabled()) {
validateUpdatePlan(model, report, metadata, t, t.getInsertPlan(), Command.TYPE_INSERT);
}
if (t.getUpdatePlan() != null && t.isUpdatePlanEnabled()) {
validateUpdatePlan(model, report, metadata, t, t.getUpdatePlan(), Command.TYPE_UPDATE);
}
if (t.getDeletePlan() != null && t.isDeletePlanEnabled()) {
validateUpdatePlan(model, report, metadata, t, t.getDeletePlan(), Command.TYPE_DELETE);
}
}
}
boolean addCacheHint = false;
if (t.isVirtual() && t.isMaterialized() && t.getMaterializedTable() == null) {
List<KeyRecord> fbis = t.getFunctionBasedIndexes();
List<GroupSymbol> groups = Arrays.asList(symbol);
if (fbis != null && !fbis.isEmpty()) {
for (KeyRecord fbi : fbis) {
for (int j = 0; j < fbi.getColumns().size(); j++) {
Column c = fbi.getColumns().get(j);
if (c.getParent() != fbi) {
continue;
}
String exprString = c.getNameInSource();
try {
Expression ex = parser.parseExpression(exprString);
validateNoReferences(ex, report, model);
ResolverVisitor.resolveLanguageObject(ex, groups, metadata);
if (!ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(ex).isEmpty()) {
log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31114, exprString, fbi.getFullName()));
}
EvaluatableVisitor ev = new EvaluatableVisitor();
PreOrPostOrderNavigator.doVisit(ex, ev, PreOrPostOrderNavigator.PRE_ORDER);
if (ev.getDeterminismLevel().compareTo(Determinism.VDB_DETERMINISTIC) < 0) {
log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31115, exprString, fbi.getFullName()));
}
} catch (QueryResolverException e) {
log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31116, exprString, fbi.getFullName(), e.getMessage()));
}
}
}
}
} else {
addCacheHint = true;
}
if (node != null && addCacheHint && t.isMaterialized()) {
CacheHint cacheHint = node.getCommand().getCacheHint();
Long ttl = -1L;
if (cacheHint != null) {
if (cacheHint.getTtl() != null && t.getProperty(MaterializationMetadataRepository.MATVIEW_TTL, false) == null) {
ttl = cacheHint.getTtl();
t.setProperty(MaterializationMetadataRepository.MATVIEW_TTL, String.valueOf(ttl));
}
if (cacheHint.getUpdatable() != null && t.getProperty(MaterializationMetadataRepository.MATVIEW_UPDATABLE, false) == null) {
t.setProperty(MaterializationMetadataRepository.MATVIEW_UPDATABLE, String.valueOf(cacheHint.getUpdatable()));
}
if (cacheHint.getPrefersMemory() != null && t.getProperty(MaterializationMetadataRepository.MATVIEW_PREFER_MEMORY, false) == null) {
t.setProperty(MaterializationMetadataRepository.MATVIEW_PREFER_MEMORY, String.valueOf(cacheHint.getPrefersMemory()));
}
if (cacheHint.getScope() != null && t.getProperty(MaterializationMetadataRepository.MATVIEW_SHARE_SCOPE, false) == null) {
log(report, model, Severity.WARNING, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31252, t.getName(), cacheHint.getScope().name()));
t.setProperty(MaterializationMetadataRepository.MATVIEW_SHARE_SCOPE, MaterializationMetadataRepository.Scope.IMPORTED.name());
}
}
}
}
processReport(model, record, report, resolverReport);
} catch (TeiidException e) {
log(report, model, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31080, record.getFullName(), e.getMessage()));
}
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class EmbeddedServer method deployVDB.
protected void deployVDB(VDBMetaData vdb, VDBResources resources) throws ConnectorManagerException, VirtualDatabaseException, TranslatorException {
checkStarted();
if (!vdb.getOverrideTranslators().isEmpty() && !allowOverrideTranslators()) {
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40106, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40106, vdb.getName()));
}
vdb.addAttchment(ClassLoader.class, Thread.currentThread().getContextClassLoader());
try {
createPreParser(vdb);
} catch (TeiidException e1) {
throw new VirtualDatabaseException(e1);
}
cmr.createConnectorManagers(vdb, this);
MetadataStore metadataStore = new MetadataStore();
UDFMetaData udfMetaData = new UDFMetaData();
udfMetaData.setFunctionClassLoader(Thread.currentThread().getContextClassLoader());
MetadataRepository<?, ?> defaultRepo = null;
LinkedHashMap<String, VDBResources.Resource> visibilityMap = null;
if (resources != null) {
// that index is the default metadata repo
for (String s : resources.getEntriesPlusVisibilities().keySet()) {
if (s.endsWith(VDBResources.INDEX_EXT)) {
defaultRepo = new IndexMetadataRepository();
break;
}
}
visibilityMap = resources.getEntriesPlusVisibilities();
} else {
visibilityMap = new LinkedHashMap<String, VDBResources.Resource>();
}
this.assignMetadataRepositories(vdb, defaultRepo);
repo.addVDB(vdb, metadataStore, visibilityMap, udfMetaData, cmr);
try {
this.loadMetadata(vdb, cmr, metadataStore, resources);
} catch (VDBValidationError e) {
throw new VirtualDatabaseException(RuntimePlugin.Event.valueOf(e.getCode()), e.getMessage());
}
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class TranslatorUtil method getExecutionFactory.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static ExecutionFactory<Object, Object> getExecutionFactory(String name, TranslatorRepository vdbRepo, TranslatorRepository repo, VDBMetaData deployment, IdentityHashMap<Translator, ExecutionFactory<Object, Object>> map, HashSet<String> building) throws ConnectorManagerException {
if (!building.add(name)) {
throw new ConnectorManagerException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40138, building));
}
VDBTranslatorMetaData translator = vdbRepo.getTranslatorMetaData(name);
if (translator == null) {
translator = repo.getTranslatorMetaData(name);
}
if (translator == null) {
return null;
}
ExecutionFactory<Object, Object> ef = map.get(translator);
if (ef == null) {
try {
ef = TranslatorUtil.buildExecutionFactory(translator);
} catch (TeiidException e) {
throw new ConnectorManagerException(e);
}
if (ef instanceof DelegatingExecutionFactory) {
DelegatingExecutionFactory delegator = (DelegatingExecutionFactory) ef;
String delegateName = delegator.getDelegateName();
if (delegateName != null) {
ExecutionFactory<Object, Object> delegate = getExecutionFactory(delegateName, vdbRepo, repo, deployment, map, building);
if (delegate == null) {
if (deployment != null) {
throw new ConnectorManagerException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31146, deployment.getName(), deployment.getVersion(), delegateName));
}
throw new ConnectorManagerException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40136, delegateName));
}
((DelegatingExecutionFactory<Object, Object>) ef).setDelegate(delegate);
}
}
map.put(translator, ef);
}
return ef;
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class ODataUpdateExecution method addAutoGeneretedKeys.
private void addAutoGeneretedKeys(Table table, Entity entity) throws TranslatorException {
int cols = table.getPrimaryKey().getColumns().size();
Class<?>[] columnDataTypes = new Class<?>[cols];
String[] columnNames = new String[cols];
String[] odataTypes = new String[cols];
// we may eventual need the type logic off of the metadata importer
for (int i = 0; i < cols; i++) {
columnDataTypes[i] = table.getPrimaryKey().getColumns().get(i).getJavaType();
columnNames[i] = table.getPrimaryKey().getColumns().get(i).getName();
odataTypes[i] = ODataMetadataProcessor.getNativeType(table.getPrimaryKey().getColumns().get(i));
}
GeneratedKeys generatedKeys = this.executionContext.getCommandContext().returnGeneratedKeys(columnNames, columnDataTypes);
List<Object> vals = new ArrayList<Object>(columnDataTypes.length);
for (int i = 0; i < columnDataTypes.length; i++) {
Property prop = entity.getProperty(columnNames[i]);
Object value;
try {
value = ODataTypeManager.convertToTeiidRuntimeType(columnDataTypes[i], prop.getValue(), odataTypes[i]);
} catch (TeiidException e) {
throw new TranslatorException(e);
}
vals.add(value);
}
generatedKeys.addKey(vals);
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class BaseQueryExecution method buildRow.
@SuppressWarnings("unchecked")
List<?> buildRow(List<Column> columns, boolean isMapResponse, Class<?>[] expectedType, Map<String, Object> values) throws TranslatorException {
List<Object> results = new ArrayList<Object>();
for (int i = 0; i < columns.size(); i++) {
Column column = columns.get(i);
String colName = column.getName();
if (column.getNameInSource() != null) {
colName = column.getNameInSource();
}
int arrayIndex = colName.indexOf("[]/");
if (arrayIndex != -1) {
colName = colName.substring(0, arrayIndex) + colName.substring(colName.indexOf("/", arrayIndex + 3));
}
Object value;
try {
if (isMapResponse) {
if (colName.equals(SwaggerMetadataProcessor.KEY_NAME)) {
value = values.keySet().iterator().next();
} else if (colName.equals(SwaggerMetadataProcessor.KEY_VALUE)) {
value = values.values().iterator().next();
} else {
value = values.get(colName);
}
} else {
value = values.get(colName);
}
value = SwaggerTypeManager.convertTeiidRuntimeType(value, expectedType[i]);
} catch (TeiidException e) {
throw new TranslatorException(e);
}
results.add(value);
}
return results;
}
Aggregations