use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class ConnectorHost method readResultsFromExecution.
private List<List> readResultsFromExecution(Execution execution) throws TranslatorException {
List<List> results = new ArrayList<List>();
while (true) {
try {
if (execution instanceof ResultSetExecution) {
ResultSetExecution rs = (ResultSetExecution) execution;
List result = null;
while ((result = rs.next()) != null) {
results.add(result);
}
break;
}
UpdateExecution rs = (UpdateExecution) execution;
int[] result = rs.getUpdateCounts();
for (int i = 0; i < result.length; i++) {
results.add(Arrays.asList(result[i]));
}
break;
} catch (DataNotAvailableException e) {
if (e.getRetryDelay() > 0) {
try {
Thread.sleep(e.getRetryDelay());
} catch (InterruptedException e1) {
throw new TranslatorException(e1);
}
}
}
}
return results;
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class ODataTypeManager method convertToTeiidRuntimeType.
/**
* @param type
* @param value
* @param odataType type hint if the value could be a string containing a literal value of another type
* @return
* @throws TeiidException
*/
public static Object convertToTeiidRuntimeType(Class<?> type, Object value, String odataType) throws TeiidException {
if (value == null) {
return null;
}
if (type.isAssignableFrom(value.getClass())) {
return value;
}
if (value instanceof UUID) {
return value.toString();
}
if (type.isArray() && value instanceof List<?>) {
List<?> list = (List<?>) value;
Class<?> expectedArrayComponentType = type.getComponentType();
Object array = Array.newInstance(type.getComponentType(), list.size());
for (int i = 0; i < list.size(); i++) {
Object arrayItem = convertToTeiidRuntimeType(expectedArrayComponentType, list.get(i), null);
Array.set(array, i, arrayItem);
}
return array;
}
if (odataType != null && value instanceof String) {
try {
value = ODataTypeManager.parseLiteral(odataType, (String) value);
} catch (TeiidException e) {
throw new TranslatorException(e);
}
}
if (value instanceof Geospatial && type == DataTypeManager.DefaultDataClasses.GEOMETRY) {
final Geospatial val = (Geospatial) value;
// if (val.getDimension() == Dimension.GEOMETRY) {
return new GeometryInputSource() {
@Override
public Reader getGml() throws Exception {
AtomGeoValueSerializer serializer = new AtomGeoValueSerializer();
XMLOutputFactory factory = XMLOutputFactory.newInstance();
StringWriter sw = new StringWriter();
final XMLStreamWriter writer = factory.createXMLStreamWriter(sw);
serializer.serialize(writer, val);
writer.close();
return new StringReader(sw.toString());
}
@Override
public Integer getSrid() {
String srid = val.getSrid().toString();
try {
return Integer.parseInt(srid);
} catch (NumberFormatException e) {
return null;
}
}
};
// }
}
if (value instanceof Calendar) {
Calendar calender = (Calendar) value;
if (type.isAssignableFrom(java.sql.Time.class)) {
calender.set(Calendar.YEAR, 1970);
calender.set(Calendar.MONTH, Calendar.JANUARY);
calender.set(Calendar.DAY_OF_MONTH, 1);
calender.set(Calendar.MILLISECOND, 0);
return new Time(calender.getTimeInMillis());
} else if (type.isAssignableFrom(java.sql.Date.class)) {
calender.set(Calendar.HOUR_OF_DAY, 0);
calender.set(Calendar.MINUTE, 0);
calender.set(Calendar.SECOND, 0);
calender.set(Calendar.MILLISECOND, 0);
return new java.sql.Date(calender.getTimeInMillis());
} else if (type.isAssignableFrom(java.sql.Timestamp.class)) {
return new Timestamp(calender.getTimeInMillis());
}
}
Transform transform = DataTypeManager.getTransform(value.getClass(), type);
if (transform != null) {
try {
value = transform.transform(value, type);
} catch (TransformationException e) {
throw new TeiidException(e);
}
}
return value;
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class ODataMetadataProcessor method addEntitySetAsTable.
protected Table addEntitySetAsTable(MetadataFactory mf, EdmEntitySet entitySet) throws TranslatorException {
Table table = buildTable(mf, entitySet);
table.setProperty(ENTITY_TYPE, entitySet.getType().getFullyQualifiedTypeName());
// add columns
for (EdmProperty ep : entitySet.getType().getProperties().toList()) {
if (ep.getType().isSimple() || (ep.getType() instanceof EdmCollectionType && ((EdmCollectionType) ep.getType()).getItemType().isSimple())) {
addPropertyAsColumn(mf, table, ep, entitySet);
} else {
// this is complex type, i.e treat them as embeddable in the same table add all columns.
// Have tried adding this as separate table with 1 to 1 mapping to parent table, however
// that model fails when there are two instances of single complex type as column. This
// creates verbose columns but safe.
EdmComplexType embedded = (EdmComplexType) ep.getType();
for (EdmProperty property : embedded.getProperties().toList()) {
if (property.getType().isSimple() || (property.getType() instanceof EdmCollectionType && ((EdmCollectionType) property.getType()).getItemType().isSimple())) {
Column column = addPropertyAsColumn(mf, table, property, entitySet, ep.getName());
// complex type
column.setProperty(COMPLEX_TYPE, embedded.getFullyQualifiedTypeName());
// name of parent column
column.setProperty(COLUMN_GROUP, ep.getName());
} else {
throw new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17002, entitySet.getName(), ep.getName()));
}
}
}
}
// add PK
// $NON-NLS-1$
mf.addPrimaryKey("PK", entitySet.getType().getKeys(), table);
return table;
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class ODataMetadataProcessor method getEds.
private EdmDataServices getEds(WSConnection conn) throws TranslatorException {
try {
BaseQueryExecution execution = new BaseQueryExecution(ef, null, null, conn);
// $NON-NLS-1$ //$NON-NLS-2$
BinaryWSProcedureExecution call = execution.executeDirect("GET", "$metadata", null, execution.getDefaultHeaders());
if (call.getResponseCode() != Status.OK.getStatusCode()) {
throw execution.buildError(call);
}
Blob out = (Blob) call.getOutputParameterValues().get(0);
EdmDataServices eds = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new InputStreamReader(out.getBinaryStream())));
return eds;
} catch (SQLException e) {
throw new TranslatorException(e);
} catch (Exception e) {
throw new TranslatorException(e);
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class ODataMetadataProcessor method addFunctionImportAsProcedure.
void addFunctionImportAsProcedure(MetadataFactory mf, EdmFunctionImport function) throws TranslatorException {
Procedure procedure = mf.addProcedure(function.getName());
procedure.setProperty(HTTP_METHOD, function.getHttpMethod());
// add parameters
for (EdmFunctionParameter fp : function.getParameters()) {
ProcedureParameter.Type type = ProcedureParameter.Type.In;
if (fp.getMode().equals(EdmFunctionParameter.Mode.InOut)) {
type = ProcedureParameter.Type.InOut;
} else if (fp.getMode().equals(EdmFunctionParameter.Mode.Out)) {
type = ProcedureParameter.Type.Out;
}
mf.addProcedureParameter(fp.getName(), ODataTypeManager.teiidType(fp.getType().getFullyQualifiedTypeName()), type, procedure);
}
// add return type
EdmType returnType = function.getReturnType();
if (returnType != null) {
if (returnType.isSimple()) {
// $NON-NLS-1$
mf.addProcedureParameter("return", ODataTypeManager.teiidType(((EdmSimpleType) returnType).getFullyQualifiedTypeName()), ProcedureParameter.Type.ReturnValue, procedure);
} else if (returnType instanceof EdmComplexType) {
procedure.setProperty(ENTITY_TYPE, function.getReturnType().getFullyQualifiedTypeName());
addProcedureTableReturn(mf, procedure, returnType);
} else if (returnType instanceof EdmEntityType) {
procedure.setProperty(ENTITY_TYPE, function.getReturnType().getFullyQualifiedTypeName());
addProcedureTableReturn(mf, procedure, returnType);
} else if (returnType instanceof EdmCollectionType) {
procedure.setProperty(ENTITY_TYPE, ((EdmCollectionType) returnType).getItemType().getFullyQualifiedTypeName());
addProcedureTableReturn(mf, procedure, ((EdmCollectionType) returnType).getItemType());
} else {
throw new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17005, function.getName(), returnType.getFullyQualifiedTypeName()));
}
}
}
Aggregations