use of org.teiid.core.TeiidException in project teiid by teiid.
the class TranslatorUtil method injectProperties.
private static void injectProperties(ExecutionFactory ef, final VDBTranslatorMetaData data) throws InvocationTargetException, IllegalAccessException, TeiidException {
Map<Method, TranslatorProperty> props = TranslatorUtil.getTranslatorProperties(ef.getClass());
Map<String, String> p = data.getPropertiesMap();
TreeMap<String, String> caseInsensitiveProps = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
/*
VDBTranslatorMetaData parent = data.getParent();
while (parent != null) {
for (Map.Entry<String, String> entry : parent.getPropertiesMap().entrySet()) {
if (!caseInsensitiveProps.containsKey(entry.getKey()) && entry.getValue() != null) {
caseInsensitiveProps.put(entry.getKey(), entry.getValue());
}
}
parent = parent.getParent();
}
*/
synchronized (p) {
caseInsensitiveProps.putAll(p);
}
caseInsensitiveProps.remove(DEPLOYMENT_NAME);
for (Method method : props.keySet()) {
TranslatorProperty tp = props.get(method);
String propertyName = getPropertyName(method);
String value = caseInsensitiveProps.remove(propertyName);
if (value != null) {
Method setterMethod = getSetter(ef.getClass(), method);
setterMethod.invoke(ef, convert(value, method.getReturnType()));
} else if (tp.required()) {
throw new TeiidException(RuntimePlugin.Event.TEIID40027, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40027, tp.display()));
}
}
caseInsensitiveProps.remove(Translator.EXECUTION_FACTORY_CLASS);
if (!caseInsensitiveProps.isEmpty()) {
LogManager.logWarning(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40001, caseInsensitiveProps.keySet(), data.getName()));
}
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class VDBStatusChecker method updateSource.
/**
* @return true if the datasource is new to the vdb
* @throws AdminProcessingException
*/
public boolean updateSource(String vdbName, String vdbVersion, SourceMappingMetadata mapping, boolean replace) throws AdminProcessingException {
String dsName = stripContext(mapping.getConnectionJndiName());
VDBMetaData vdb = getVDBRepository().getLiveVDB(vdbName, vdbVersion);
if (vdb == null || vdb.getStatus() == Status.FAILED) {
return false;
}
synchronized (vdb) {
ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
ConnectorManager existing = cmr.getConnectorManager(mapping.getName());
try {
cmr.createConnectorManager(vdb, cmr.getProvider(), mapping, replace);
} catch (TeiidException e) {
throw new AdminProcessingException(RuntimePlugin.Event.TEIID40033, e);
}
if (mapping.getConnectionJndiName() != null && (existing == null || !dsName.equals(existing.getConnectionName()))) {
List<Runnable> runnables = new ArrayList<Runnable>();
resourceAdded(dsName, runnables, vdb);
return true;
}
return false;
}
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class DocumentNode method buildEntityKeyCriteria.
static Criteria buildEntityKeyCriteria(DocumentNode resource, UriInfo uriInfo, MetadataStore store, OData odata, UniqueNameGenerator nameGenerator, URLParseService parseService) throws TeiidException {
List<Column> pk = getPKColumns(resource.getTable());
if (resource.getKeyPredicates().size() == 1) {
if (pk.size() != 1) {
throw new TeiidException(ODataPlugin.Event.TEIID16015, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16015, resource.getTable().getFullName()));
}
Column column = pk.get(0);
ODataExpressionToSQLVisitor visitor = new ODataExpressionToSQLVisitor(resource, false, uriInfo, store, odata, nameGenerator, null, parseService);
UriParameter key = resource.getKeyPredicates().get(0);
org.apache.olingo.server.api.uri.queryoption.expression.Expression expr = getKeyPredicateExpression(key, odata, column);
return new CompareCriteria(new ElementSymbol(column.getName(), resource.getGroupSymbol()), CompareCriteria.EQ, visitor.getExpression(expr));
}
// complex (multi-keyed)
List<Criteria> critList = new ArrayList<Criteria>();
if (pk.size() != resource.getKeyPredicates().size()) {
throw new TeiidException(ODataPlugin.Event.TEIID16015, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16015, resource.getTable().getFullName()));
}
for (UriParameter key : resource.getKeyPredicates()) {
Column column = findColumn(resource.getTable(), key.getName());
ODataExpressionToSQLVisitor visitor = new ODataExpressionToSQLVisitor(resource, false, uriInfo, store, odata, nameGenerator, null, parseService);
org.apache.olingo.server.api.uri.queryoption.expression.Expression expr = getKeyPredicateExpression(key, odata, column);
critList.add(new CompareCriteria(new ElementSymbol(column.getName(), resource.getGroupSymbol()), CompareCriteria.EQ, visitor.getExpression(expr)));
}
return new CompoundCriteria(CompoundCriteria.AND, critList);
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class ODataExpressionToSQLVisitor method visit.
@Override
public void visit(UriResourceNavigation info) {
try {
DocumentNode navigationResource = DocumentNode.build((EdmEntityType) info.getType(), info.getKeyPredicates(), this.metadata, this.odata, this.nameGenerator, true, getUriInfo(), this.parseService);
Query query = new Query();
query.setSelect(new Select(Arrays.asList(new AggregateSymbol(AggregateSymbol.Type.COUNT.name(), false, null))));
query.setFrom(new From(Arrays.asList(navigationResource.getFromClause())));
Criteria criteria = this.ctxQuery.buildJoinCriteria(navigationResource, info.getProperty());
if (criteria == null) {
throw new TeiidException(ODataPlugin.Event.TEIID16037, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16037));
}
query.setCriteria(criteria);
this.stack.add(new ScalarSubquery(query));
} catch (TeiidException e) {
throw new TeiidRuntimeException(e);
}
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class TeiidServiceHandler method updateEntity.
@Override
public void updateEntity(DataRequest request, Entity entity, boolean merge, String entityETag, EntityResponse response) throws ODataLibraryException, ODataApplicationException {
// TODO: need to match entityETag.
checkETag(entityETag);
UpdateResponse updateResponse = null;
if (merge) {
try {
ODataSQLBuilder visitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), this.prepared, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
visitor.visit(request.getUriInfo());
EdmEntityType entityType = request.getEntitySet().getEntityType();
Update update = visitor.update(entityType, entity, this.prepared);
updateResponse = getClient().executeUpdate(update, visitor.getParameters());
} catch (SQLException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
} catch (TeiidException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
}
} else {
// delete, then insert
String txn = startTransaction();
boolean success = false;
try {
// build insert first as it could fail to validate
ODataSQLBuilder visitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), this.prepared, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
visitor.visit(request.getUriInfo());
EdmEntityType entityType = request.getEntitySet().getEntityType();
List<UriParameter> keys = request.getKeyPredicates();
Insert command = visitor.insert(entityType, entity, keys, this.prepared);
// run delete
ODataSQLBuilder deleteVisitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), this.prepared, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
deleteVisitor.visit(request.getUriInfo());
Delete delete = deleteVisitor.delete();
updateResponse = getClient().executeUpdate(delete, deleteVisitor.getParameters());
// run insert
updateResponse = getClient().executeUpdate(command, visitor.getParameters());
commit(txn);
success = true;
} catch (SQLException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
} catch (TeiidException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
} finally {
if (!success) {
rollback(txn);
}
}
}
if (updateResponse != null && updateResponse.getUpdateCount() > 0) {
response.writeUpdatedEntity();
} else {
response.writeNotModified();
}
}
Aggregations