use of org.teiid.core.TeiidException in project teiid by teiid.
the class ODataSQLBuilder method visit.
@Override
public void visit(UriInfoCrossjoin info) {
for (String name : info.getEntitySetNames()) {
EdmEntitySet entitySet = this.serviceMetadata.getEdm().getEntityContainer().getEntitySet(name);
EdmEntityType entityType = entitySet.getEntityType();
CrossJoinNode resource = null;
try {
boolean hasExpand = hasExpand(entitySet.getName(), info.getExpandOption());
resource = CrossJoinNode.buildCrossJoin(entityType, null, this.metadata, this.odata, this.nameGenerator, this.aliasedGroups, getUriInfo(), this.parseService, hasExpand);
resource.addAllColumns(!hasExpand);
if (this.context == null) {
this.context = resource;
this.orderBy = this.context.addDefaultOrderBy();
} else {
this.context.addSibiling(resource);
OrderBy orderby = resource.addDefaultOrderBy();
int index = orderby.getVariableCount();
for (int i = 0; i < index; i++) {
this.orderBy.addVariable(orderby.getVariable(i));
}
}
} catch (TeiidException e) {
this.exceptions.add(e);
}
}
super.visit(info);
// the expand behavior is handled above with selection of the columns
this.expandOption = null;
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class ReferenceUpdateSQLBuilder method updateReference.
public Update updateReference(URI referenceId, boolean prepared, boolean delete) throws SQLException {
try {
if (referenceId != null) {
UriInfo uriInfo = ODataSQLBuilder.buildUriInfo(referenceId, this.baseURI, this.serviceMetadata, this.odata);
UriResourceEntitySet uriEnitytSet = (UriResourceEntitySet) uriInfo.asUriInfoResource().getUriResourceParts().get(0);
if (this.collection) {
this.updateTable.setKeyPredicates(uriEnitytSet.getKeyPredicates());
} else {
this.referenceTable.setKeyPredicates(uriEnitytSet.getKeyPredicates());
}
}
} catch (UriParserException e) {
throw new SQLException(e);
} catch (URISyntaxException e) {
throw new SQLException(e);
} catch (UriValidationException e) {
throw new SQLException(e);
}
try {
Update update = new Update();
update.setGroup(this.updateTable.getGroupSymbol());
List<String> columnNames = DocumentNode.getColumnNames(this.updateTable.getFk().getColumns());
for (int i = 0; i < columnNames.size(); i++) {
Column column = this.updateTable.getFk().getColumns().get(i);
String columnName = columnNames.get(i);
ElementSymbol symbol = new ElementSymbol(columnName, this.updateTable.getGroupSymbol());
EdmEntityType entityType = this.updateTable.getEdmEntityType();
EdmProperty edmProperty = (EdmProperty) entityType.getProperty(columnName);
// reference table keys will be null for delete scenario
Object value = null;
if (!delete) {
UriParameter parameter = getParameter(this.updateTable.getFk().getReferenceColumns().get(i), this.referenceTable.getKeyPredicates());
value = ODataTypeManager.parseLiteral(edmProperty, column.getJavaType(), parameter.getText());
}
if (prepared) {
update.addChange(symbol, new Reference(i++));
this.params.add(ODataSQLBuilder.asParam(edmProperty, value));
} else {
update.addChange(symbol, new Constant(ODataSQLBuilder.asParam(edmProperty, value).getValue()));
}
}
Criteria criteria = DocumentNode.buildEntityKeyCriteria(this.updateTable, null, this.metadata, this.odata, null, null);
update.setCriteria(criteria);
return update;
} catch (TeiidException e) {
throw new SQLException(e);
}
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class TeiidServiceHandler method createEntity.
@Override
public void createEntity(DataRequest request, Entity entity, EntityResponse response) throws ODataLibraryException, ODataApplicationException {
EdmEntityType entityType = request.getEntitySet().getEntityType();
String txn;
try {
txn = getClient().startTransaction();
} catch (SQLException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
}
boolean success = false;
try {
List<ExpandNode> expands = new ArrayList<TeiidServiceHandler.ExpandNode>();
int insertDepth = insertDepth(entityType, entity);
// don't count the root
ODataSQLBuilder.checkExpandLevel(insertDepth - 1);
UpdateResponse updateResponse = performDeepInsert(request.getODataRequest().getRawBaseUri(), request.getUriInfo(), entityType, entity, expands);
if (updateResponse != null && updateResponse.getUpdateCount() == 1) {
ODataSQLBuilder visitor = new ODataSQLBuilder(this.odata, getClient().getMetadataStore(), true, false, request.getODataRequest().getRawBaseUri(), this.serviceMetadata);
Query query = visitor.selectWithEntityKey(entityType, entity, updateResponse.getGeneratedKeys(), expands);
// $NON-NLS-1$ //$NON-NLS-2$
LogManager.logDetail(LogConstants.CTX_ODATA, null, "created entity = ", entityType.getName(), " with key=", query.getCriteria().toString());
EntityCollectionResponse result = new EntityCollectionResponse(request.getODataRequest().getRawBaseUri(), visitor.getContext());
getClient().executeSQL(query, visitor.getParameters(), false, null, null, null, 1, result);
if (!result.getEntities().isEmpty()) {
entity = result.getEntities().get(0);
String location = EntityResponse.buildLocation(request.getODataRequest().getRawBaseUri(), entity, request.getEntitySet().getName(), entityType);
entity.setId(new URI(location));
}
response.writeCreatedEntity(request.getEntitySet(), entity);
} else {
response.writeNotModified();
}
getClient().commit(txn);
success = true;
} catch (EdmPrimitiveTypeException | TeiidException | SQLException | URISyntaxException e) {
throw new ODataApplicationException(e.getMessage(), HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), Locale.getDefault(), e);
} finally {
if (!success) {
try {
getClient().rollback(txn);
} catch (SQLException e1) {
// ignore
}
}
}
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class TranslatorUtil method buildDelegateAwareExecutionFactory.
public static ExecutionFactory<Object, Object> buildDelegateAwareExecutionFactory(VDBTranslatorMetaData translator, ExecutionFactoryProvider provider) throws ConnectorManagerException {
ExecutionFactory<Object, Object> ef = null;
try {
ef = 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 = provider.getExecutionFactory(delegateName);
if (delegate == null) {
throw new ConnectorManagerException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40155, delegateName));
}
((DelegatingExecutionFactory<Object, Object>) ef).setDelegate(delegate);
}
}
return ef;
}
use of org.teiid.core.TeiidException in project teiid by teiid.
the class TranslatorUtil method buildExecutionFactory.
public static ExecutionFactory buildExecutionFactory(VDBTranslatorMetaData data) throws TeiidException {
ExecutionFactory executionFactory;
try {
Class<?> executionClass = data.getExecutionFactoryClass();
Object o = executionClass.newInstance();
if (!(o instanceof ExecutionFactory)) {
throw new TeiidException(RuntimePlugin.Event.TEIID40024, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40024, executionClass));
}
executionFactory = (ExecutionFactory) o;
synchronized (executionFactory) {
injectProperties(executionFactory, data);
ClassLoader orginalCL = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(executionFactory.getClass().getClassLoader());
executionFactory.start();
} finally {
Thread.currentThread().setContextClassLoader(orginalCL);
}
}
return executionFactory;
} catch (InvocationTargetException e) {
throw new TeiidException(RuntimePlugin.Event.TEIID40025, e);
} catch (IllegalAccessException e) {
throw new TeiidException(RuntimePlugin.Event.TEIID40026, e);
} catch (InstantiationException e) {
throw new TeiidException(CorePlugin.Event.TEIID10036, e);
}
}
Aggregations