private static boolean hasStream(List<CsdlProperty> properties) { for (CsdlProperty p : properties) { if (p.getType().equals(EdmPrimitiveTypeKind.Binary.getFullQualifiedName())) { return true; } } return false; }
@Override public String getTypeName() { return typeKind.getFullQualifiedName().toString(); }
FullQualifiedName getSimpleType() throws ODataJPAModelException { Class<?> javaType = null; if (valueConverter != null) { javaType = dbType; } else { javaType = entityType; } return JPATypeConvertor.convertToEdmSimpleType(javaType, jpaAttribute) .getFullQualifiedName(); }
@Override public String getTypeName() { return typeKind.getFullQualifiedName().toString(); }
private <T extends Number> FullQualifiedName determineUnderlyingType() throws ODataJPAModelException { if (javaEnum.getEnumConstants().length == 0) return EdmPrimitiveTypeKind.Int32.getFullQualifiedName(); final T value = valueOf(javaEnum.getEnumConstants()[0].toString()); final EdmPrimitiveTypeKind type = JPATypeConvertor.convertToEdmSimpleType(value.getClass()); if (isValidType(type)) return type.getFullQualifiedName(); // Enumeration '%1$s' has the unsupported type '%2$s'. throw new ODataJPAModelException(MessageKeys.ENUMERATION_UNSUPPORTED_TYPE, javaEnum.getName(), type .getFullQualifiedName().getFullQualifiedNameAsString()); }
private String odataType(String type, String runtimeType) { if (type == null) { type = ODataTypeManager.odataType(runtimeType) .getFullQualifiedName().getFullQualifiedNameAsString(); } return type; }
@Override public FullQualifiedName getTypeFQN() throws ODataJPAModelException { return JPATypeConvertor.convertToEdmSimpleType(jpaParameter.type()).getFullQualifiedName(); }
@Override protected FullQualifiedName determineParameterType(final Class<?> type, final EdmParameter definedParameter) throws ODataJPAModelException { final EdmPrimitiveTypeKind edmType = JPATypeConvertor.convertToEdmSimpleType(type); if (edmType != null) return edmType.getFullQualifiedName(); else { final IntermediateEnumerationType enumType = schema.getEnumerationType(type); if (enumType != null) { return enumType.getExternalFQN(); } else throw new ODataJPAModelException(ODataJPAModelException.MessageKeys.FUNC_PARAM_ONLY_PRIMITIVE, javaFunction .getDeclaringClass().getName(), javaFunction.getName(), definedParameter.name()); } } }
static String getQueryParameters(Call obj) throws EdmPrimitiveTypeException { StringBuilder sb = new StringBuilder(); final List<Argument> params = obj.getArguments(); if (params != null && params.size() != 0) { Argument param = null; for (int i = 0; i < params.size(); i++) { param = params.get(i); if (param.getDirection() == Direction.IN || param.getDirection() == Direction.INOUT) { if (i != 0) { sb.append("&"); //$NON-NLS-1$ } sb.append(WSUtil.httpURLEncode(param.getMetadataObject().getName())); sb.append(Tokens.EQ); sb.append(WSUtil.httpURLEncode(ODataTypeManager.convertToODataURIValue(param.getArgumentValue().getValue(), ODataTypeManager.odataType(param.getType()).getFullQualifiedName() .getFullQualifiedNameAsString()))); } } } return sb.toString(); }
static FullQualifiedName determineReturnType(final ReturnType definedReturnType, final Class<?> declairedReturnType, final IntermediateSchema schema, final String operationName) throws ODataJPAModelException { IntermediateStructuredType structuredType = schema.getStructuredType(declairedReturnType); if (structuredType != null) return structuredType.getExternalFQN(); else { final IntermediateEnumerationType enumType = schema.getEnumerationType(declairedReturnType); if (enumType != null) { return enumType.getExternalFQN(); } else { final EdmPrimitiveTypeKind edmType = JPATypeConvertor.convertToEdmSimpleType(declairedReturnType); if (edmType == null) throw new ODataJPAModelException(MessageKeys.FUNC_RETURN_TYPE_INVALID, definedReturnType.type().getName(), declairedReturnType.getName(), operationName); return edmType.getFullQualifiedName(); } } } }
protected FullQualifiedName determineTypeByPersistanceType(Enum<?> persistanceType) throws ODataJPAModelException { if (persistanceType == PersistentAttributeType.BASIC || persistanceType == PersistenceType.BASIC) { final IntermediateModelElement odataType = getODataPrimitiveType(); if (odataType == null) { return getSimpleType(); } else return odataType.getExternalFQN(); } if (persistanceType == PersistentAttributeType.EMBEDDED || persistanceType == PersistenceType.EMBEDDABLE) return nameBuilder.buildFQN(type.getExternalName()); else return EdmPrimitiveTypeKind.Boolean.getFullQualifiedName(); }
private void annotation(final XMLStreamWriter writer, final Annotation annotation, final String target) throws XMLStreamException, EdmPrimitiveTypeException { writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ANNOTATION, Constants.NS_METADATA); writer.writeAttribute(Constants.ATOM_ATTR_TERM, annotation.getTerm()); if (target != null) { writer.writeAttribute(Constants.ATTR_TARGET, target); } EdmTypeInfo typeInfo = null; if (annotation.getType() != null) { typeInfo = new EdmTypeInfo.Builder().setTypeExpression(annotation.getType()).build(); if (!EdmPrimitiveTypeKind.String.getFullQualifiedName().toString().equals(typeInfo.internal())) { writer.writeAttribute(Constants.PREFIX_METADATA, Constants.NS_METADATA, Constants.ATTR_TYPE, typeInfo.external()); } } value(writer, annotation.getValueType(), typeInfo == null ? EdmTypeInfo.determineTypeKind(annotation.getValue()) : typeInfo.getPrimitiveTypeKind(), annotation.getValue()); writer.writeEndElement(); }
private void annotation(final XMLStreamWriter writer, final Annotation annotation, final String target) throws XMLStreamException, EdmPrimitiveTypeException { writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ANNOTATION, Constants.NS_METADATA); writer.writeAttribute(Constants.ATOM_ATTR_TERM, annotation.getTerm()); if (target != null) { writer.writeAttribute(Constants.ATTR_TARGET, target); } EdmTypeInfo typeInfo = null; if (annotation.getType() != null) { typeInfo = new EdmTypeInfo.Builder().setTypeExpression(annotation.getType()).build(); if (!EdmPrimitiveTypeKind.String.getFullQualifiedName().toString().equals(typeInfo.internal())) { writer.writeAttribute(Constants.PREFIX_METADATA, Constants.NS_METADATA, Constants.ATTR_TYPE, typeInfo.external()); } } value(writer, annotation.getValueType(), typeInfo == null ? EdmTypeInfo.determineTypeKind(annotation.getValue()) : typeInfo.getPrimitiveTypeKind(), annotation.getValue()); writer.writeEndElement(); }
@Override protected FullQualifiedName determineParameterType(final Class<?> type, final EdmParameter definedParameter) throws ODataJPAModelException { final EdmPrimitiveTypeKind edmType = JPATypeConvertor.convertToEdmSimpleType(definedParameter.type()); if (edmType != null) return edmType.getFullQualifiedName(); else { final IntermediateEnumerationType enumType = schema.getEnumerationType(definedParameter.type()); if (enumType != null) { return enumType.getExternalFQN(); } else throw new ODataJPAModelException(ODataJPAModelException.MessageKeys.FUNC_CONV_ERROR); } }
@Override public void visit(Update obj) { this.operationType = OperationType.UPDATE; visitNode(obj.getTable()); this.odataQuery.setCondition(obj.getWhere()); try { // read the properties int elementCount = obj.getChanges().size(); for (int i = 0; i < elementCount; i++) { Column column = obj.getChanges().get(i).getSymbol().getMetadataObject(); String type = ODataTypeManager.odataType(column) .getFullQualifiedName().getFullQualifiedNameAsString(); Expression expr = obj.getChanges().get(i).getValue(); Object value = resolveExpressionValue(expr); this.odataQuery.addUpdateProperty(column, type, value); } } catch (TranslatorException e) { this.exceptions.add(e); } }
protected void valuable(final JsonGenerator jgen, final Valuable valuable, final String name) throws IOException, EdmPrimitiveTypeException { if (!Constants.VALUE.equals(name) && !(valuable instanceof Annotation) && !(valuable.isComplex() && !valuable.isCollection())) { String type = valuable.getType(); if ((!valuable.isCollection() && (type == null || type.isEmpty()) && valuable.isPrimitive()) || valuable.isNull()) { type = EdmPrimitiveTypeKind.String.getFullQualifiedName().toString(); } if (type != null && !type.isEmpty() && isODataMetadataFull) { jgen.writeStringField( name + Constants.JSON_TYPE, new EdmTypeInfo.Builder().setTypeExpression(type).build().external()); } } for (Annotation annotation : ((Annotatable) valuable).getAnnotations()) { valuable(jgen, annotation, name + "@" + annotation.getTerm()); } jgen.writeFieldName(name); value(jgen, valuable.getType(), valuable); }
protected void valuable(final JsonGenerator jgen, final Valuable valuable, final String name) throws IOException, EdmPrimitiveTypeException { if (!Constants.VALUE.equals(name) && !(valuable instanceof Annotation) && !(valuable.isComplex() && !valuable.isCollection())) { String type = valuable.getType(); if ((!valuable.isCollection() && (type == null || type.isEmpty()) && valuable.isPrimitive()) || valuable.isNull()) { type = EdmPrimitiveTypeKind.String.getFullQualifiedName().toString(); } if (type != null && !type.isEmpty() && isODataMetadataFull) { jgen.writeStringField( name + Constants.JSON_TYPE, new EdmTypeInfo.Builder().setTypeExpression(type).build().external()); } } for (Annotation annotation : ((Annotatable) valuable).getAnnotations()) { valuable(jgen, annotation, name + "@" + annotation.getTerm()); } jgen.writeFieldName(name); value(jgen, valuable.getType(), valuable); }
private EdmTypeInfo buildTypeInfo(final FullQualifiedName typeName, final String propertyType) { EdmTypeInfo typeInfo = null; if (typeName == null) { if (propertyType != null) { typeInfo = new EdmTypeInfo.Builder().setTypeExpression(propertyType).build(); } } else { if (propertyType == null || propertyType.equals(EdmPrimitiveTypeKind.String.getFullQualifiedName().toString())) { typeInfo = new EdmTypeInfo.Builder().setTypeExpression(typeName.toString()).build(); } else if(isPrimiteveType(typeName)) { // Inheritance is not allowed for primitive types, so we use the type given by the EDM. typeInfo = new EdmTypeInfo.Builder().setTypeExpression(typeName.toString()).build(); } else { typeInfo = new EdmTypeInfo.Builder().setTypeExpression(propertyType).build(); } } return typeInfo; }
private EdmTypeInfo buildTypeInfo(final FullQualifiedName typeName, final String propertyType) { EdmTypeInfo typeInfo = null; if (typeName == null) { if (propertyType != null) { typeInfo = new EdmTypeInfo.Builder().setTypeExpression(propertyType).build(); } } else { if (propertyType == null || propertyType.equals(EdmPrimitiveTypeKind.String.getFullQualifiedName().toString())) { typeInfo = new EdmTypeInfo.Builder().setTypeExpression(typeName.toString()).build(); } else if(isPrimiteveType(typeName)) { // Inheritance is not allowed for primitive types, so we use the type given by the EDM. typeInfo = new EdmTypeInfo.Builder().setTypeExpression(typeName.toString()).build(); } else { typeInfo = new EdmTypeInfo.Builder().setTypeExpression(propertyType).build(); } } return typeInfo; }
private void odataAnnotations(final Annotatable annotatable, final ClientAnnotatable odataAnnotatable) { for (Annotation annotation : annotatable.getAnnotations()) { FullQualifiedName fqn = null; if (client instanceof EdmEnabledODataClient) { final EdmTerm term = ((EdmEnabledODataClient) client).getCachedEdm(). getTerm(new FullQualifiedName(annotation.getTerm())); if (term != null) { fqn = term.getType().getFullQualifiedName(); } } if (fqn == null && annotation.getType() != null) { final EdmTypeInfo typeInfo = new EdmTypeInfo.Builder().setTypeExpression(annotation.getType()).build(); if (typeInfo.isPrimitiveType()) { fqn = typeInfo.getPrimitiveTypeKind().getFullQualifiedName(); } } final ClientAnnotation odataAnnotation = new ClientAnnotationImpl(annotation.getTerm(), getODataValue(fqn, annotation, null, null)); odataAnnotatable.getAnnotations().add(odataAnnotation); } }