奥林戈:可以';无法使@EdmFunctionImport工作
我正在与Olingo合作,我想说一切都很好,除了一件事:没有找到一种方法来获取@EdmFunctionImport的函数,正在工作 我使用的是纯注释方法,而不是JPA,因此我没有描述的ODataJPAContext。我假设奥林戈:可以';无法使@EdmFunctionImport工作,function,odata,olingo,Function,Odata,Olingo,我正在与Olingo合作,我想说一切都很好,除了一件事:没有找到一种方法来获取@EdmFunctionImport的函数,正在工作 我使用的是纯注释方法,而不是JPA,因此我没有描述的ODataJPAContext。我假设AnnotationEdmProvider edmProvider=newannotationedmprovider(AnnotationInstances.MODEL_包)应该找到我的函数,用@EdmFunctionImport属性描述 谷歌对此一无所知。可能有人有这样的经验
AnnotationEdmProvider edmProvider=newannotationedmprovider(AnnotationInstances.MODEL_包)代码>应该找到我的函数,用@EdmFunctionImport属性描述
谷歌对此一无所知。可能有人有这样的经验吗?到目前为止,还没有官方支持Olingo注释处理器扩展的函数导入
但是,如果您浏览问题列表,则有一些代码贡献可用,需要对annotation-core.jar进行一些更改以启用函数导入。您可以参考此处的链接:
到目前为止,对于Olingo注释处理器扩展的函数导入还没有任何官方支持
但是,如果您浏览问题列表,则有一些代码贡献可用,需要对annotation-core.jar进行一些更改以启用函数导入。您可以参考此处的链接:
谢谢!我在前面以几乎相同的方式使其工作,但我的代码有点复杂,因为它使用的是返回和参数类型解析。
作为基础,我使用了JPA函数支持的方法。
这是我的代码(按照前面链接的第一部分):
2) 在容器生成器类中添加新方法
public ContainerBuilder addFunctionImport(
final FunctionImport functionImport) {
functionImports.add(functionImport);
return this;
}
3) 在AnnotationEdmProvider类中修改了handleEntityContainer方法,如下所示
private void handleEntityContainer(final Class<?> aClass) {
EdmEntityType entityType = aClass.getAnnotation(EdmEntityType.class);
if (entityType != null) {
FullQualifiedName typeName = createFqnForEntityType(aClass);
String containerName = ANNOTATION_HELPER
.extractContainerName(aClass);
ContainerBuilder builder = containerName2ContainerBuilder
.get(containerName);
if (builder == null) {
builder = ContainerBuilder.init(typeName.getNamespace(),
containerName);
containerName2ContainerBuilder.put(containerName, builder);
}
EdmEntitySet entitySet = aClass.getAnnotation(EdmEntitySet.class);
if (entitySet != null) {
builder.addEntitySet(createEntitySet(typeName, aClass));
}
buildFunctionImports(aClass, builder);
}
}
private void buildFunctionImports(Class aClass, ContainerBuilder builder) {
for (int i = 0; i < aClass.getMethods().length; i++) {
Method method = aClass.getMethods()[i];
EdmFunctionImport edmAnnotationFunctionImport = method
.getAnnotation(EdmFunctionImport.class);
if (edmAnnotationFunctionImport != null
&& edmAnnotationFunctionImport.returnType() != null) {
try {
FunctionImport fi = new FunctionImport();
fi.setEntitySet(edmAnnotationFunctionImport.entitySet());
fi.setHttpMethod(edmAnnotationFunctionImport.httpMethod().name());
fi.setName(edmAnnotationFunctionImport.name());
builder.addFunctionImport(fi);
builder.addFunctionImport(buildEdmFunctionImport(method,
edmAnnotationFunctionImport));
} catch (ODataAnnotationException e) {
}
}
}
}
private FunctionImport buildEdmFunctionImport(final Method method,
final EdmFunctionImport edmAnnotationFunctionImport)
throws ODataAnnotationException {
if (edmAnnotationFunctionImport != null
&& edmAnnotationFunctionImport.returnType() != null) {
FunctionImport functionImport = new FunctionImport();
if (edmAnnotationFunctionImport.name().equals("")) {
functionImport.setName(method.getName());
} else {
functionImport.setName(edmAnnotationFunctionImport.name());
}
functionImport.setHttpMethod(edmAnnotationFunctionImport
.httpMethod().name().toString());
buildEdmReturnType(functionImport, method,
edmAnnotationFunctionImport);
buildEdmParameter(functionImport, method);
return functionImport;
}
return null;
}
private void buildEdmParameter(final FunctionImport functionImport,
final Method method) throws ODataAnnotationException {
Annotation[][] annotations = method.getParameterAnnotations();
Class<?>[] parameterTypes = method.getParameterTypes();
List<FunctionImportParameter> funcImpList = new ArrayList<FunctionImportParameter>();
int j = 0;
for (Annotation[] annotationArr : annotations) {
Class<?> parameterType = parameterTypes[j++];
for (Annotation element : annotationArr) {
if (element instanceof EdmFunctionImportParameter) {
EdmFunctionImportParameter annotation = (EdmFunctionImportParameter) element;
FunctionImportParameter functionImportParameter = new FunctionImportParameter();
if (annotation.name().equals("")) {
throw new ODataAnnotationException(
"annotation.name().equals(\"\")");
} else {
functionImportParameter.setName(annotation.name());
}
functionImportParameter.setType(TypeBuilder
.getEdmSimpleType(parameterType));
Facets facets = new Facets();
if (annotation.facets().maxLength() > 0) {
facets.setMaxLength(annotation.facets().maxLength());
}
if (annotation.facets().nullable() == false) {
facets.setNullable(false);
} else {
facets.setNullable(true);
}
if (annotation.facets().precision() > 0) {
facets.setPrecision(annotation.facets().precision());
}
if (annotation.facets().scale() >= 0) {
facets.setScale(annotation.facets().scale());
}
functionImportParameter.setFacets(facets);
funcImpList.add(functionImportParameter);
}
}
}
if (!funcImpList.isEmpty()) {
functionImport.setParameters(funcImpList);
}
}
private void buildEdmReturnType(final FunctionImport functionImport,
final Method method,
final EdmFunctionImport edmAnnotationFunctionImport)
throws ODataAnnotationException {
ReturnType returnType = edmAnnotationFunctionImport.returnType();
if (returnType != null) {
org.apache.olingo.odata2.api.edm.provider.ReturnType functionReturnType = new org.apache.olingo.odata2.api.edm.provider.ReturnType();
if (returnType.isCollection()) {
functionReturnType.setMultiplicity(EdmMultiplicity.MANY);
} else {
functionReturnType.setMultiplicity(EdmMultiplicity.ONE);
}
if (returnType.type() == ReturnType.Type.ENTITY) {
String entitySet = edmAnnotationFunctionImport.entitySet();
if (entitySet.equals("")) {
throw new ODataAnnotationException("entitySet.equals(\"\")");
}
functionImport.setEntitySet(entitySet);
}
Class<?> methodReturnType = method.getReturnType();
if (methodReturnType == null
|| methodReturnType.getName().equals("void")) {
throw new ODataAnnotationException("Wrong return type");
}
switch (returnType.type()) {
case ENTITY:
EntityType edmEntityType = null;
String returnTypeName = null;
if (returnType.isCollection() == false) {
returnTypeName = methodReturnType.getSimpleName();
} else {
returnTypeName = getReturnTypeSimpleName(method);
}
for (Class<?> clazz : annotatedClasses) {
if (returnTypeName.equals(clazz.getName())) {
edmEntityType = getEntityType(createFqnForEntityType(clazz));
break;
}
}
if (edmEntityType == null) {
throw new ODataAnnotationException(
"Unable to find an entity type");
}
functionReturnType.setTypeName(edmEntityType.getBaseType());
break;
case SIMPLE:
EdmSimpleTypeKind edmSimpleTypeKind = TypeBuilder
.getEdmSimpleType(methodReturnType);
functionReturnType.setTypeName(edmSimpleTypeKind
.getFullQualifiedName());
break;
case COMPLEX:
String embeddableTypeName = null;
ComplexType complexType = null;
boolean exists = false;
if (returnType.isCollection() == false) {
embeddableTypeName = methodReturnType.getName();
} else {
embeddableTypeName = getReturnTypeName(method);
}
FullQualifiedName fqn = null;
for (Class<?> clazz : annotatedClasses) {
if (embeddableTypeName.equals(clazz.getName())) {
fqn = ANNOTATION_HELPER.extractComplexTypeFqn(clazz);
break;
}
}
if (fqn == null) {
throw new ODataAnnotationException(
"Unable to find an complex type");
}
functionReturnType.setTypeName(fqn);
break;
default:
break;
}
functionImport.setReturnType(functionReturnType);
}
}
private String getReturnTypeName(final Method method) {
try {
ParameterizedType pt = (ParameterizedType) method
.getGenericReturnType();
Type t = pt.getActualTypeArguments()[0];
return ((Class<?>) t).getName();
} catch (ClassCastException e) {
return method.getReturnType().getName();
}
}
private String getReturnTypeSimpleName(final Method method) {
try {
ParameterizedType pt = (ParameterizedType) method
.getGenericReturnType();
Type t = pt.getActualTypeArguments()[0];
return ((Class<?>) t).getSimpleName();
} catch (ClassCastException e) {
return method.getReturnType().getSimpleName();
}
}
private void handleEntityContainer(最终类aClass){
EdmEntityType entityType=aClass.getAnnotation(EdmEntityType.class);
if(entityType!=null){
FullQualifiedName typeName=CreateFQNforentyType(aClass);
字符串containerName=注释\辅助对象
.提取容器名称(aClass);
ContainerBuilder=ContainerName2 ContainerBuilder
.获取(容器名称);
if(builder==null){
builder=ContainerBuilder.init(typeName.getNamespace(),
容器名称);
containerName 2 ContainerBuilder.put(containerName,builder);
}
EdmEntitySet-entitySet=aClass.getAnnotation(EdmEntitySet.class);
if(entitySet!=null){
builder.addEntitySet(createEntitySet(typeName,aClass));
}
buildFunctionImports(aClass,builder);
}
}
私有void buildFunctionImports(类aClass,ContainerBuilder builder){
for(int i=0;i0){
setMaxLength(annotation.facets().maxLength());
}
if(annotation.facets().nullable()==false){
面。可设置为空(假);
}否则{
facets.setNullable(true);
}
if(annotation.facets()。