use of org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException in project teiid by teiid.
the class AtomGeoValueSerializer method points.
private void points(final XMLStreamWriter writer, final Iterator<Point> itor, final boolean wrap) throws XMLStreamException {
while (itor.hasNext()) {
final Point point = itor.next();
if (wrap) {
writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POINT, Constants.NS_GML);
}
writer.writeStartElement(Constants.PREFIX_GML, Constants.ELEM_POS, Constants.NS_GML);
try {
writer.writeCharacters(EdmDouble.getInstance().valueToString(point.getX(), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null) + " " + EdmDouble.getInstance().valueToString(point.getY(), null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null));
} catch (EdmPrimitiveTypeException e) {
throw new XMLStreamException("While serializing point coordinates as double", e);
}
writer.writeEndElement();
if (wrap) {
writer.writeEndElement();
}
}
}
use of org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException in project teiid by teiid.
the class ODataTypeManager method parseLiteral.
public static Object parseLiteral(String odataType, String value) throws TeiidException {
EdmPrimitiveType primitiveType = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.valueOf(odataType.substring(4)));
int maxLength = DataTypeManager.MAX_STRING_LENGTH;
if (primitiveType instanceof EdmBinary || primitiveType instanceof EdmStream) {
maxLength = DataTypeManager.MAX_VARBINARY_BYTES;
}
int precision = 4;
int scale = 3;
if (primitiveType instanceof EdmDecimal) {
precision = 38;
scale = 9;
}
Class<?> expectedClass = primitiveType.getDefaultType();
try {
if (EdmString.getInstance().equals(primitiveType)) {
value = EdmString.getInstance().fromUriLiteral(value);
}
Object converted = primitiveType.valueOfString(value, false, maxLength, precision, scale, true, expectedClass);
if (primitiveType instanceof EdmTimeOfDay) {
Calendar ts = (Calendar) converted;
return new Time(ts.getTimeInMillis());
} else if (primitiveType instanceof EdmDate) {
Calendar ts = (Calendar) converted;
return new Date(ts.getTimeInMillis());
}
return converted;
} catch (EdmPrimitiveTypeException e) {
throw new TeiidException(e);
}
}
use of org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException in project teiid by teiid.
the class ODataProcedureExecution method execute.
@Override
public void execute() throws TranslatorException {
try {
String parameters = getQueryParameters(this.command);
InputStream response = null;
Procedure procedure = this.command.getMetadataObject();
if (isFunction(procedure)) {
String URI = buildFunctionURL(this.command, parameters);
response = executeQuery("GET", URI, null, null, new HttpStatusCode[] { HttpStatusCode.OK });
handleResponse(procedure, URI, response);
} else {
String URI = this.command.getProcedureName();
response = executeQuery("POST", URI, parameters, null, new HttpStatusCode[] { HttpStatusCode.OK });
handleResponse(procedure, URI, response);
}
} catch (ODataDeserializerException e) {
throw new TranslatorException(e);
} catch (EdmPrimitiveTypeException e) {
throw new TranslatorException(e);
}
}
use of org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException in project teiid by teiid.
the class ODataTypeManager method convertToODataURIValue.
public static String convertToODataURIValue(Object val, String odataType) throws EdmPrimitiveTypeException {
if (val == null) {
// is this correct? //$NON-NLS-1$
return "null";
}
if (odataType.startsWith("Edm.")) {
// $NON-NLS-1$
odataType = odataType.substring(4);
}
if (val instanceof GeometryType) {
Geometry g;
try {
g = GeometryUtils.getGeometry((GeometryType) val);
} catch (FunctionExecutionException e1) {
throw new EdmPrimitiveTypeException(e1.getMessage(), e1);
}
StringWriter sw = new StringWriter();
// $NON-NLS-1$
sw.write("geometry'SRID=");
sw.write(String.valueOf(g.getSRID()));
// $NON-NLS-1$
sw.write(";");
ODataWKTWriter writer = new ODataWKTWriter();
try {
writer.write(g, sw);
} catch (IOException e) {
throw new TeiidRuntimeException(e);
}
// $NON-NLS-1$
sw.write("'");
return sw.toString();
}
EdmPrimitiveTypeKind kind = EdmPrimitiveTypeKind.valueOf(odataType);
String value = EdmPrimitiveTypeFactory.getInstance(kind).valueToString(val, true, null, null, Integer.MAX_VALUE, true);
if (kind == EdmPrimitiveTypeKind.String) {
return EdmString.getInstance().toUriLiteral(value);
}
return value;
}
use of org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException 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
}
}
}
}
Aggregations