use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class JPAMetadataProcessor method addSingularAttributes.
private void addSingularAttributes(MetadataFactory mf, Metamodel model, ManagedType<?> entity, Table entityTable) throws TranslatorException {
for (Attribute<?, ?> attr : entity.getAttributes()) {
if (!attr.isCollection()) {
boolean simpleType = isSimpleType(attr.getJavaType());
if (simpleType) {
Column column = addColumn(mf, attr.getName(), TypeFacility.getDataTypeName(getJavaDataType(attr.getJavaType())), entityTable);
if (((SingularAttribute) attr).isOptional()) {
column.setDefaultValue(null);
}
} else {
boolean classFound = false;
// this tables columns
for (EmbeddableType<?> embeddable : model.getEmbeddables()) {
if (embeddable.getJavaType().equals(attr.getJavaType())) {
addSingularAttributes(mf, model, embeddable, entityTable);
classFound = true;
break;
}
}
if (!classFound) {
// table, then add that column as FK
for (EntityType et : model.getEntities()) {
if (et.getJavaType().equals(attr.getJavaType())) {
Table attributeTable = addEntity(mf, model, et);
KeyRecord pk = attributeTable.getPrimaryKey();
if (pk != null) {
// TODO: entities must have PK, so this check is not needed.
ArrayList<String> keys = new ArrayList<String>();
for (Column column : pk.getColumns()) {
addColumn(mf, column.getName(), column.getDatatype().getRuntimeTypeName(), entityTable);
keys.add(column.getName());
}
if (!foreignKeyExists(keys, entityTable)) {
addForeignKey(mf, attr.getName(), keys, attributeTable.getName(), entityTable);
}
} else {
throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14001, attributeTable.getName()));
}
classFound = true;
break;
}
}
}
if (!classFound) {
throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14002, attr.getName()));
}
}
}
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class JPQLDirectQueryExecution method execute.
@Override
public void execute() throws TranslatorException {
if (query.length() < 7) {
throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14008));
}
String firstToken = query.substring(0, 7);
String jpql = query.substring(7);
// $NON-NLS-1$
LogManager.logTrace(LogConstants.CTX_CONNECTOR, "JPA Source-Query:", jpql);
if (firstToken.equalsIgnoreCase("search;")) {
// //$NON-NLS-1$
StringBuilder buffer = new StringBuilder();
SQLStringVisitor.parseNativeQueryParts(jpql, arguments, buffer, new SQLStringVisitor.Substitutor() {
@Override
public void substitute(Argument arg, StringBuilder builder, int index) {
Literal argumentValue = arg.getArgumentValue();
builder.append(argumentValue);
}
});
jpql = buffer.toString();
Query queryCommand = this.enityManager.createQuery(jpql);
List<?> results = queryCommand.getResultList();
this.resultsIterator = results.iterator();
} else if (firstToken.equalsIgnoreCase("create;")) {
// //$NON-NLS-1$
Object entity = arguments.get(0).getArgumentValue().getValue();
this.enityManager.merge(entity);
this.resultsIterator = Arrays.asList(1).iterator();
} else if (firstToken.equalsIgnoreCase("update;") || firstToken.equalsIgnoreCase("delete;")) {
// //$NON-NLS-1$ //$NON-NLS-2$
Query queryCmd = this.enityManager.createQuery(jpql);
this.resultsIterator = Arrays.asList(queryCmd.executeUpdate()).iterator();
} else {
throw new TranslatorException(JPAPlugin.Util.gs(JPAPlugin.Event.TEIID14008));
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class ExpressionEvaluator method visit.
@Override
public void visit(In obj) {
try {
Object o1 = getRowValue(obj.getLeftExpression());
ArrayList<Object> values = new ArrayList<Object>();
for (int i = 0; i < obj.getRightExpressions().size(); i++) {
values.add(getLiteralValue(obj.getRightExpressions().get(i)));
}
if (obj.isNegated()) {
this.match.push(!values.contains(o1));
} else {
this.match.push(values.contains(o1));
}
} catch (TranslatorException e) {
this.exceptions.add(e);
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class ExpressionEvaluator method visit.
@Override
public void visit(Comparison obj) {
try {
Object o1 = getRowValue(obj.getLeftExpression());
Object o2 = getLiteralValue(obj.getRightExpression());
int compare = ((Comparable<Object>) o1).compareTo(o2);
switch(obj.getOperator()) {
case EQ:
this.match.push(Boolean.valueOf(compare == 0));
break;
case NE:
this.match.push(Boolean.valueOf(compare != 0));
break;
case LT:
this.match.push(Boolean.valueOf(compare < 0));
break;
case LE:
this.match.push(Boolean.valueOf(compare <= 0));
break;
case GT:
this.match.push(Boolean.valueOf(compare > 0));
break;
case GE:
this.match.push(Boolean.valueOf(compare >= 0));
break;
}
} catch (TranslatorException e) {
this.exceptions.add(e);
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class BinaryWSProcedureExecution method execute.
public void execute() throws TranslatorException {
List<Argument> arguments = this.procedure.getArguments();
String method = (String) arguments.get(0).getArgumentValue().getValue();
Object payload = arguments.get(1).getArgumentValue().getValue();
String endpoint = (String) arguments.get(2).getArgumentValue().getValue();
try {
Dispatch<DataSource> dispatch = this.conn.createDispatch(HTTPBinding.HTTP_BINDING, endpoint, DataSource.class, Mode.MESSAGE);
if (method == null) {
// $NON-NLS-1$
method = "POST";
}
dispatch.getRequestContext().put(MessageContext.HTTP_REQUEST_METHOD, method);
if (payload != null && !"POST".equalsIgnoreCase(method) && !"PUT".equalsIgnoreCase(method) && !"PATCH".equalsIgnoreCase(method)) {
// $NON-NLS-1$
throw new WebServiceException(WSExecutionFactory.UTIL.getString("http_usage_error"));
}
Map<String, List<String>> httpHeaders = (Map<String, List<String>>) dispatch.getRequestContext().get(MessageContext.HTTP_REQUEST_HEADERS);
if (customHeaders != null) {
httpHeaders.putAll(customHeaders);
}
if (arguments.size() > 5 && // designer modeled the return value as an out, which will add an argument in the 5th position that is an out
this.procedure.getMetadataObject() != null && (this.procedure.getMetadataObject().getParameters().get(0).getType() == Type.ReturnValue || arguments.get(5).getMetadataObject().getSourceName().equalsIgnoreCase("headers"))) {
// $NON-NLS-1$
Clob headers = (Clob) arguments.get(5).getArgumentValue().getValue();
if (headers != null) {
parseHeader(httpHeaders, headers);
}
}
dispatch.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, httpHeaders);
DataSource ds = null;
if (payload instanceof String) {
ds = new InputStreamFactory.ClobInputStreamFactory(new ClobImpl((String) payload));
} else if (payload instanceof SQLXML) {
ds = new InputStreamFactory.SQLXMLInputStreamFactory((SQLXML) payload);
} else if (payload instanceof Clob) {
ds = new InputStreamFactory.ClobInputStreamFactory((Clob) payload);
} else if (payload instanceof Blob) {
ds = new InputStreamFactory.BlobInputStreamFactory((Blob) payload);
}
this.returnValue = dispatch.invoke(ds);
Map<String, Object> rc = dispatch.getResponseContext();
this.responseCode = (Integer) rc.get(WSConnection.STATUS_CODE);
if (this.useResponseContext) {
// it's presumed that the caller will handle the response codes
this.responseContext = rc;
} else {
// TODO: may need to add logic around some 200/300 codes - cxf should at least be logging this
if (this.responseCode >= 400) {
String message = conn.getStatusMessage(this.responseCode);
throw new TranslatorException(WSExecutionFactory.Event.TEIID15005, WSExecutionFactory.UTIL.gs(WSExecutionFactory.Event.TEIID15005, this.responseCode, message));
}
}
} catch (WebServiceException e) {
throw new TranslatorException(e);
} catch (ParseException e) {
throw new TranslatorException(e);
} catch (IOException e) {
throw new TranslatorException(e);
} catch (SQLException e) {
throw new TranslatorException(e);
}
}
Aggregations