我可以从单个模型描述创建服务器端Java类,OR映射和客户端AS类吗?

时间:2022-07-25 12:16:20

I have a Java server application and a Flex client application. For my data model, I have typical objects, like User etc., that are basically the same in the database, the server-side Java code and the client-side AS code. I. e., the public fields of my AS and Java classes are named identically, and have the same types and values as the respective fields in the database table which has the same name as those classes.

我有一个Java服务器应用程序和一个Flex客户端应用程序。对于我的数据模型,我有典型的对象,如User等,它们在数据库,服务器端Java代码和客户端AS代码中基本相同。例如,我的AS和Java类的公共字段以相同的名称命名,并且具有与数据库表中与这些类具有相同名称的相应字段相同的类型和值。

For the Java classes and the DB tables to match, I can use any ORM. Are there any tools to have the AS classes (and, ideally, the matching Remoting boilerplate code) autogenerated from the Java ones as well? I had a short look at BlazeDS, but it didn't seem to have tools like that, at least I couldn't find anything about it.

要使Java类和DB表匹配,我可以使用任何ORM。是否有任何工具可以从Java自动生成AS类(以及理想情况下,匹配的Remoting样板代码)?我简单地看了一下BlazeDS,但它似乎没有这样的工具,至少我找不到任何关于它的东西。

Of course, in a perfect world, I'd describe my data items once and have the DDL, Java code and AS code all autogenerated. Does such a tool exist, and is it usable enough?

当然,在完美的世界中,我会描述一次我的数据项,并且自动生成DDL,Java代码和AS代码。这样的工具是否存在,是否可以使用?

Oh yeah, and it would be great if the source format could be protobuf files...

哦是的,如果源格式可能是protobuf文件会很棒......

Note: This seems to be the same question as this one. The answers there seem to indicate that at least there's no common tool that "everybody uses" or that has a reputation for high quality.

注意:这似乎与此问题相同。那里的答案似乎表明,至少没有“每个人都使用”或具有高质量声誉的通用工具。

2 个解决方案

#1


You can start here : http://www.graniteds.org/confluence/display/DOC/2.+Gas3+Code+Generator

你可以从这里开始:http://www.graniteds.org/confluence/display/DOC/2.+Gas3+Code+Generator

#2


The only tools that I know of are for generating AS classes from server code are the wizards built into Flex builder for autogenerating AS remote classes from ColdFusion CFC's for use with a ColdFusion based AMF service.

我所知道的唯一用于从服务器代码生成AS类的工具是Flex构建器中内置的向导,用于从ColdFusion CFC自动生成AS远程类,以便与基于ColdFusion的AMF服务一起使用。

What may be useful to remember though is that once the serialized object has been received by Flex and an instance of mx.utils.ObjectProxy has been created for it (this relates to the flex RemoteObject class and AMF based services, but I imagine that a Protocol Buffer extension would follow the same pattern), the process of casting the proxy to an Actionscript class isn't all that complicated. As long as your Actionscript class has properties or accessors with names that match the properties on the serialized object, and an Remote Object alias that matches the type of the serialized object, then you can cast the object proxy to the remote class without having to do any extra work.

但是有一点可能有用的是,一旦Flex接收到序列化对象并且已经为它创建了mx.utils.ObjectProxy实例(这与flex RemoteObject类和基于AMF的服务有关,但我想这是一个协议缓冲区扩展将遵循相同的模式),将代理转换为Actionscript类的过程并不是那么复杂。只要您的Actionscript类具有名称与序列化对象的属性匹配的属性或访问器,以及与序列化对象的类型匹配的远程对象别名,您就可以将对象代理强制转换为远程类而无需执行任何额外的工作。

Like I said, I'm not aware of a tool that does what you want, but It wouldn't be too difficult to create a tool to read the type and public properties from your Java classes, or extract that same metadata from your protocol buffer files, and write some Actionscript code off that Metadata. If you can't find a solution that fits your needs, you might consider writing an Ant task or a script or something to do it for you. Thats what I would do anyway.

就像我说的那样,我不知道有什么工具能够满足您的需求,但是创建一个工具来从Java类中读取类型和公共属性,或者从协议中提取相同的元数据并不困难。缓冲区文件,并从元数据中写下一些Actionscript代码。如果找不到符合您需求的解决方案,您可以考虑编写Ant任务或脚本或其他东西来为您完成。多数民众赞成我会做什么。

#1


You can start here : http://www.graniteds.org/confluence/display/DOC/2.+Gas3+Code+Generator

你可以从这里开始:http://www.graniteds.org/confluence/display/DOC/2.+Gas3+Code+Generator

#2


The only tools that I know of are for generating AS classes from server code are the wizards built into Flex builder for autogenerating AS remote classes from ColdFusion CFC's for use with a ColdFusion based AMF service.

我所知道的唯一用于从服务器代码生成AS类的工具是Flex构建器中内置的向导,用于从ColdFusion CFC自动生成AS远程类,以便与基于ColdFusion的AMF服务一起使用。

What may be useful to remember though is that once the serialized object has been received by Flex and an instance of mx.utils.ObjectProxy has been created for it (this relates to the flex RemoteObject class and AMF based services, but I imagine that a Protocol Buffer extension would follow the same pattern), the process of casting the proxy to an Actionscript class isn't all that complicated. As long as your Actionscript class has properties or accessors with names that match the properties on the serialized object, and an Remote Object alias that matches the type of the serialized object, then you can cast the object proxy to the remote class without having to do any extra work.

但是有一点可能有用的是,一旦Flex接收到序列化对象并且已经为它创建了mx.utils.ObjectProxy实例(这与flex RemoteObject类和基于AMF的服务有关,但我想这是一个协议缓冲区扩展将遵循相同的模式),将代理转换为Actionscript类的过程并不是那么复杂。只要您的Actionscript类具有名称与序列化对象的属性匹配的属性或访问器,以及与序列化对象的类型匹配的远程对象别名,您就可以将对象代理强制转换为远程类而无需执行任何额外的工作。

Like I said, I'm not aware of a tool that does what you want, but It wouldn't be too difficult to create a tool to read the type and public properties from your Java classes, or extract that same metadata from your protocol buffer files, and write some Actionscript code off that Metadata. If you can't find a solution that fits your needs, you might consider writing an Ant task or a script or something to do it for you. Thats what I would do anyway.

就像我说的那样,我不知道有什么工具能够满足您的需求,但是创建一个工具来从Java类中读取类型和公共属性,或者从协议中提取相同的元数据并不困难。缓冲区文件,并从元数据中写下一些Actionscript代码。如果找不到符合您需求的解决方案,您可以考虑编写Ant任务或脚本或其他东西来为您完成。多数民众赞成我会做什么。