EJB的继承和多态 [www.theserverside.com]

【进阶EJB】深入探讨三种Bean(二)——Entity Bean 通过上一篇文章,我们介绍了【进阶EJB】深入探讨三种Bean(一)——Session Bean,这篇文章继续介绍EJB的三种Bean,今天我们重点介绍一下Entity Bean。Entity Bean,通过名字我们就知道是实体Bean是存放数据的。Entity Bean是持久化的数据组件,代表持久存储的商业实体对象。通常情况下,每个Entity Bean对应于关系数据库中的单张表,Entity Bean的单个实例对应于表中的某一条数据。上篇文章中说的Session Bean可作为Entity Bean的客户 阅读详情
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> Introduction One of the most common criticisms of entity EJBs is that they don't support inheritance or polymorphism. If this were true, it would be a serious complaint for two reasons. First, entity beans are intended to provide an object-oriented view of information in a persistent store, and inheritance and polymorphism are key aspects of the object-oriented programming paradigm. Second, many bean developers are using relational database schemas that essentially implement a form of inheritance, and they need to be able to operate on these schemas with their EJBs. However, in practice, entity EJBs are capable of meeting these requirements. In this article I'm going to show how to implement entity bean inheritance with three CMP EJBs: a "base class" PARTY EJB and two "derived class" EJBs: PERSON and CORPORATION. (This is a common design in relational database schemas.) Furthermore, I'll demonstrate a polymorphic finder query and a couple of polymorphic method calls. The beans I produce will be absolutely portable according to the EJB 2.0 specification. I'll also show how these container-managed persistence beans can be mapped to a standard relational database schema for this type of data. The EJB specification does not require particular object/relational mapping capabilities from an EJB container's CMP engine. It does not even require that the container be able to use relational databases at all, so the ability to map to a particular schema is not portable. However, I am the author of a pluggable CMP engine that provides this capability (the MVCSoft Persistence Manager). We'll look at how this engine is able to make the sometimes-difficult translation from EJB objects and relationships to database tables, and what is involved from the user's point of view in using this particular mapping. Some Distinctions It's important to be clear exactly what we mean when we talk about inheritance. In this case there are three possibilities, and this article is mostly about a single one of these possibilities. First, there is the language inheritance with which every competent Java programmer is familiar. The Java language allows a class to extend a single immediate base class, which can in its turn extend another single base class, until the universal base class of java.lang.Object is reached. It also allows an interface to extend one or more interfaces. Finally, it allows a class to implement any number of interfaces. The EJB specification allows for any of the interfaces or implementation classes associated with a bean (remote home and component interfaces, local home and component interfaces, primary key class, and bean implementation class) to take advantage of these Java language features. (There are a few caveats, such as requirements for the return types from create methods.) Second, there is an amorphous concept called "component inheritance." Although frequently used (even once in the EJB spec itself), there is no generally accepted definition of the term in this context. It would probably include (1) the ability to extend an existing entity without modifying the base component or even having the source code; (2) the ability to compare component interfaces of different types for equality; and (3) the ability to return different component interfaces from a single finder or ejbSelect method. Third, there is "data model inheritance." This is the ability to model an inheritance hierarchy of business objects (and their polymorphic behavior) using entity EJBs. It is this last type of inheritance that this article addresses. Note that whereas language inheritance and component inheritance might be considered "implementation details," data model inheritance directly affects what can and cannot be accomplished using EJBs. Why the Criticism? If entity EJBs are capable of inheritance and polymorphism, why do people frequently say they are not? One source for this criticism can be found right in the EJB 2.0 specification. Section 11.2.11 says, "The data model for container-managed persistence does not currently support inheritance. Therefore, entity objects or value classes of different types cannot be compared. EJB QL queries that contain such comparisons are invalid." Furthermore, the list of features deferred to future releases includes "support for component-level inheritance." In fact, there is no framework support in the EJB spec for inheritance and polymorphism. This has consequences for all three types of inheritance discussed above. It makes component inheritance--by any reasonable definition--impossible. It places limitations on how language inheritance is used. It requires the bean developer to implement data model inheritance on his or her own, while being mindful of the limitations of the EJB component model. This lack of framework support, and the consequences, are the issues that ultimately generate the criticism. But that's a far cry from saying that entity EJBs are incapable of representing an inheritance hierarchy, or polymorphic behavior, in a data model. When enterprise software developers hear about the lack of inheritance in EJBs, they most likely assume that EJBs cannot work with their existing schema. But they can, and this is the important point by far. In practice, it's not that significant that you don't have "black box" component-level inheritance for EJBs. What's important is that you can represent your complete existing enterprise schema using EJBs. How to Do It It's not complicated to implement a schema incorporating inheritance. The fundamental technique is called "containment." This just means that your base EJB component will have a reference to its derived class or classes, and will delegate calls as appropriate. The base class will need some way of determining how to delegate the call to a related "derived" class. Typically, there will be a field (called a discriminator) that establishes the type of the base class. In its simplest form, a business method would check this discriminator, retrieve the appropriate related entity component interface from a cmr field, and delegate the call to this interface. For example, a business method call on a PARTY component interface would be translated by the container to a call on the PARTY implementation class. The PARTY implementation class might check a discriminator CMP field, and depending on the result, delegate the business method call to the PERSON cmr field or the CORPORATION cmr field. Polymorphic relationships between entities will actually be between base EJB components, and polymorphic EJB-QL queries will return references to the base EJB component. For instance, if there were an ORDER component, it might have a relationship to a PARTY bean, rather than either a PERSON or CORPORATION bean. Or if you called a finder that retrieved all the orders in Ohio, you would query on the PARTY bean rather than the PERSON or CORPORATION bean. It is possible that there might be methods defined on a subclass component interface that aren't defined on the base component interface. You can't use Java language casting to downcast from the base interface to the subclass interface...but you could implement a business method that returned the desired derived component interface. An elegant signature might be EJBLocalObject dynamicCast( String type ). The example code for this article implements four EJBs: a session bean façade and the three entity EJBs (PARTY, PERSON, and CORPORATION). A client will ask the session bean façade to create some sample data: three people and three corporations. It will then execute a findAll() query that returns all six of these EJBs in a single result set. It will call two polymorphic business methods, one getting a display name and one getting a credit rating. There is nothing special about any of the code, but I'll review the parts that are relevant to inheritance or polymorphism. First, I have provided a business interface from which every local component interface in the inheritance hierarchy derives. (See [url=http://www.theserverside.com/resources/articles/EJBInheritance/ejbInheritance.zip]PartyIntf.java[/url].) This is not a requirement, but it allows us to treat any local component interface in the hierarchy as a single type with polymorhic methods. If I had not done this, the business methods of all three of the component interfaces would still function correctly, but the client would not be able to treat a party component interface, a person component interface, and a corporation component interface as the same type. Really, this is just syntactic sugar. In this example, the polymorphic behavior is implemented entirely in the PARTY bean implementation class. (See PartyBean.java.) There is a cmp field "typeCode" that indicates the derived type of the entity. There are also two cmr fields to contain the derived instance: corporation and person. In this example, they are mutually exclusive and one of them will be null, but this is not a fundamental requirement. (In other words, you can implement multiple inheritance if your schema requires it.) There are two business methods: getDisplayName() and getCreditLimitCode(). When either of the business methods is called, the typeCode cmp field is checked and the business method is delegated appropriately. For example: public String getDisplayName() { String code = getTypeCode(); if (code.equals("I")) return getPerson().getDisplayName(); else if (code.equals("C")) return getCorporation().getDisplayName(); throw new EJBException( "Unknown type" ); } You could make a case that the typeCode is redundant and it should be possible to check which relationship is not null. But if the cmr field is being lazily loaded by the EJB container, this could result in unnecessary database I/O. The findAll() query (used by the session bean façade and called by the client) is defined on the PARTY local home interface. Of course, it is only returning component interfaces for the PARTY EJB, but these represent both PERSON instances and CORPORATION instances. It is defined in the deployment descriptor as a query returning PARTY instances, as follows: findAll select object(pb) from PartyBean pb The last interesting pieces of code from this example are the ejbCreate and ejbPostCreate methods for the CORPORATION and PERSON beans. As well as creating the corporation or person instance, respectively, these methods need to create the corresponding PARTY instance and establish a one-one relationship between the two. You might wonder if any special technique is required, considering that the relationship between a PARTY instance and a CORPORATION or PERSON instance is likely implied by a migrated key, rather than being explicitly stored in a separate foreign key. But this is a detail of the object/relational mapping, and doesn't enter into consideration when you are coding your component. Let's take a look at [url=http://www.theserverside.com/resources/articles/EJBInheritance/ejbInheritance.zip]CorporationBean.java's[/url] ejbCreate method: public Integer ejbCreate( ViewCorporation view ) throws CreateException { getPartyLocalHome().create(new ViewParty(view.getId(), "C")); setViewCorporation( view ); return null; } This is just one possible implementation, but the basic steps will usually be the same. In the ejbCreate method, we create an instance of the PARTY base component, and initialize the cmp fields for this component. Then in the ejbPostCreate method, we establish the relationship between the two: public void ejbPostCreate( ViewCorporation view ) throws CreateException { try { PartyLocal party = getPartyLocalHome().findByPrimaryKey(view.getId()); setParty( party ); } catch (FinderException e) { throw new EJBException( "Party not created" ); } } Object/Relational Mapping For most enterprise developers, modeling inheritance and polymorphic behavior in EJBs is just half the battle. The other half is working with an existing schema. The code with this article should work with any EJB container, but there are no requirements in the EJB spec for any set of mapping capabilities. In practice, you'll find that there is substantial variation in capabilities between implementations, and there are three potential trouble spots here. First, the most common database schema for this model will have a migrated primary key that establishes the relationship between the base and derived entities. In the EJB world, primary keys and relationships are completely unrelated. The persistence mechanism for your EJB container must be smart enough to realize that in this case, the primary key and relationship information in the persistent store are conflated. Second, the typical database schema for this model will have foreign-key constraints on the migrated primary key. This requires that the database inserts take place in the correct order (to not violate these constraints). If the EJB container triggers the insert statements immediately on return from ejbCreate, you must make sure that your code is ordered correctly. The persistence manager I wrote (the MVCSoft Persistence Manager) can cache the data and write it out to the database at the end of the transaction, dynamically reordering the database i/o so as to not violate any constraints. Finally, if your EJB container is lazily-loading relationships for large result sets, it can lead to unacceptable performance. In our example, each call from the PARTY bean to getCorporation() or getPerson() might result in a select query to the database to get the information. There are several possible solutions to this problem. For example, the MVCSoft Persistence Manager allows you to define a "fault group" for a query that defines the information you will need during the transaction, and this fault group can extend to related information. The runtime will eagerly load the required data using a minimum number of queries. If you issued a finder query that returned a hundred results and called a polymorphic method on each instance, a properly configured runtime will issue three queries, rather than 101 queries as in the lazy loading case. Conclusion Despite what you may have heard, entity EJBs can be used effectively to represent business objects with inheritance and polymorphic behavior. There is no support for this functionality in the EJB component model, but one simple technique--called containment--is to delegate polymorphic business method calls to appropriate "derived" component instances. The EJB specification does not mandate specific object/relational mapping functionality, but there are products that can work with your existing relational database schema.
YOLO26算法人物面部性别识别目标检测+训练好的模型+2000张数据集+pyqt可视化界面.zip 附训练好的 YOLO 权重与 PyQt 可视化检测界面,页面底部含可视化效果预览,毕设/课设开箱即用。 【数据集概况】 · 检测类别(中文):[女性(female), 男性(male)] · 总计:2000 张 · 测试集:0 张 · 验证集:0 张 · 训练集:2000 张 【训练曲线与评估图】 【模型训练配置】 参数 | 值 模型 | yolo26n 训练轮数 | 100 epochs 输入尺寸 | 640x640 批次大小 | 24 优化器 | auto 初始学习率 | 0.01 训练设备 【关键指标汇总】 训练了 100 个 epoch,最终轮指标: 指标 | 数值 mAP50 | **0.9372** mAP50-95 | 0.8835 Precision | 0.8383 Recall | 0.9027 train/box_loss | 0.1385 train/cls_loss | 0.1134 val/box_loss | 0.3528 val/cls_loss | 0.3538 【训练过程分析】 在训练初期,模型的box_loss和cls_loss迅速下降,到了第50轮已经趋于平稳。这轮训练中,我们使用的yolo26n算法在前50轮内收敛速度相当快,这意味着我们的优化器在早期阶段调整权重时非常高效。训练集上的l1_loss也表现出类似的下降趋势,在前50轮内迅速下降,此后趋于稳定。在第100轮的训练过程中,loss值保持了较好的收敛性,没有明显的过拟合迹象。尽管模型在训练过程中表现平稳,但在第70轮后,我们观察到整体的mAP50略有下降,但mAP50-95持续稳定上升,分别达到了0.9372和0.8835,这意味着模型在不同置信度下的检测能力有了提了一截。然而,这轮曲线的最后几轮训练显得... 使用场景:毕业设计、课程设计、深度学习入门、工业场景落地验证。 立即下载

相关推荐

夏BC1850年世界历史地图矢量文件SHP格式.zip

本资源为《夏BC1850年世界历史地图矢量文件SHP格式》压缩包,文件大小约 17.69 MB,便于集中下载、整理和使用。具体内容请结合压缩包内的实际文件与说明查看。 在当前可读取的目录中,可见属性表(.dbf)、投影说明文件(.prj)、Shapefile 主文件(.shp)、Shapefile 索引(.shx)。建议解压后保持原有目录结构,先浏览文件清单与说明,再选择需要的资料进行加载或整理。 应用方面,可根据实际资料用于学习练习、资料检索、研究整理或项目参考。使用时可先确定所需内容,建立清晰的文件分类,再按项目要求进行筛选、转换与汇总。 使用 Shapefile 数据时,请把实际配套的 .shp、.shx、.dbf 等文件保存在同一目录,并保持同名关联;加载后再检查坐标系与中文字段显示。如需叠加其它数据,请先统一坐标与字段口径。 数据来源、时间范围、坐标系、字段定义、精度和使用条件,请以实际文件及原始说明为准。本介绍不对文件名之外尚未核实的信息作额外承诺。

设置ODBC的自定义类CSetODBC

何志丹一,功能描述用于配置数据源用户名及密码.1,可以得到连接串,此串可用于CMyRecordset(派生于CRecordset)的GetDefaultConnect(),也可以用干CDataBase类OpenEx.2,如果用户配置正确,只需要配置一次,相关信息记录在文件.3,可以指定存储信息的文件名.因为有可能几个程序共用一个数据源.4,用户可以重新配置数据5,可以得到当前数据的类型.6

闻缺陷则喜何志丹 3202

技术转移从业人员在寻找共建研发机构合作伙伴时,使用哪类垂直行业平台能获取最精准的需求和供给信息?.docx

科易网基于行业知识库+行业大数据+科技资源要素+AI模型,以AI,赋能技术转移、成果转化、技术经理人培训、知识产权管理、区域产业分析与布局、地方科技招商、创新创业大赛等场景,推出科技创新领域的AI工具、场景化服务和数智化解决方案,推动科技创新与产业创新智能化发展。

PS 2023.exe.part003

PS 2023.exe.part003

传统园区物理空间租赁模式与现代数智化孵化器的区别是什么?.docx

传统园区物理空间租赁模式与现代数智化孵化器的区别是什么?

linux相同wifi下固定ip

linux相同wifi下固定ip

科研院所牵头组建基础科学创新联合体,有哪些平台能支持海量实验数据的共享?.docx

科易网基于行业知识库+行业大数据+科技资源要素+AI模型,以AI,赋能技术转移、成果转化、技术经理人培训、知识产权管理、区域产业分析与布局、地方科技招商、创新创业大赛等场景,推出科技创新领域的AI工具、场景化服务和数智化解决方案,推动科技创新与产业创新智能化发展。

【运维自动化】基于Zabbix的Java服务监控与自启系统:利用zabbix实现宕机检测及远程命令自动恢复服务

内容概要:本文介绍了如何利用Zabbix监控Java服务并实现服务宕机后的自动重启。通过Zabbix Agent检测Java进程状态,当发现服务停止时触发告警,并借助Zabbix的Action功能执行远程命令自动启动服务。具体步骤包括:创建自定义监控项`java.status[*]`检测指定Java进程是否存在;设置触发器判断服务是否宕机;配置Action在问题发生时通过SSH执行启动脚本恢复服务,从而实现无人值守的自动化运维机制。; 适合人群:具备Linux系统操作、Shell脚本基础及Zabbix监控平台使用经验的运维工程师或DevOps人员,尤其适用于管理Java应用服务的技术人员。; 使用场景及目标:①对关键Java服务进行高可用监控,避免因服务崩溃导致业务中断;②实现故障自愈,减少人工干预,提升系统稳定性与响应效率;③结合邮件、企业微信等通知方式完善告警体系。; 阅读建议:实际部署前需确保Zabbix Agent正常运行,SSH免密或密码认证配置正确,且启动脚本具有可执行权限。建议先在测试环境验证脚本逻辑与Action执行效果,再上线至生产环境。

【视觉目标跟踪】视觉目标跟踪中摄像机的运动与被跟踪对象的运动之间存在因果关系研究(Matlab代码实现)

内容概要:本文聚焦于视觉目标跟踪中摄像机运动与被跟踪对象运动之间的因果关系,采用Matlab作为仿真工具,构建动态响应模型以探究二者在复杂环境下的交互机制。通过设计并实现因果推理算法,深入分析目标运动特征如何驱动摄像机的实时调整,进而提升跟踪系统的鲁棒性与精确度。文中提供了完整的Matlab代码实现流程,涵盖运动建模、数据采集与预处理、因果关系量化分析、控制器设计及可视化展示等关键环节,具有较强的工程实践价值和理论研究意义。; 适合人群:具备一定Matlab编程能力与信号处理基础,从事计算机视觉、智能监控、自动驾驶或机器人导航等相关领域的科研人员、高校研究生及工程技术开发者。; 使用场景及目标:①应用于智能安防系统中实现对移动目标的稳定主动跟踪;②服务于无人机、无人船及自动驾驶平台的视觉伺服控制系统,优化动态目标跟随性能;③为学术研究提供可复现的因果建模方法与算法验证框架,支撑高水平论文撰写与实验对比分析。; 阅读建议:建议读者结合文中Matlab代码逐模块运行调试,深入理解各函数的设计逻辑与参数调优策略,同时可进一步拓展至多传感器融合、深度学习结合等方向,开展更复杂的实际应用场景研究。

从语言完成的图书管理系统,cc

从语言完成的图书管理系统,cc

国内领先的科技创新孵化器有哪些典型的成功运营案例?.docx

国内领先的科技创新孵化器有哪些典型的成功运营案例?

复现基于李雅普诺夫的多个欠驱动无人船协同路径跟踪Matlab仿真

内容概要:本文围绕基于李雅普诺夫稳定性理论的多个欠驱动无人船协同路径跟踪控制问题展开,通过Matlab仿真复现相关研究工作。系统阐述了欠驱动无人船的动力学建模方法、编队控制架构设计以及基于李雅普诺夫方法的控制器稳定性分析过程。研究设计了多种仿真工况,涵盖不含避碰机制的编队跟踪、引入避碰成本项的协同控制,以及结合扩展状态观测器(ESO)的动态线性模型预测控制(DLMPC)对正弦轨迹的跟踪控制,全面验证了所复现控制策略的有效性、鲁棒性及抗干扰能力。同时深入探讨了系统稳定性条件与控制方法的应用边界,明确了其在复杂海洋环境下的局限性与改进方向。; 适合人群:具备自动控制理论基础、海洋工程或机器人方向的研究生及科研人员,熟悉Matlab/Simulink仿真工具且对多智能体协同控制、非线性系统稳定性分析有兴趣的研发人员。; 使用场景及目标:①学习欠驱动船舶路径跟踪控制的经典方法实现路径;②掌握李雅普诺夫函数在多船协同控制系统稳定性证明中的应用技巧;③理解ESO与MPC结合在处理外部扰动与模型不确定性方面的优势;④为无人船编队控制算法开发提供可复现的仿真基准与代码参考。; 阅读建议:建议读者结合文中提供的Matlab代码与详细说明文档,逐步运行并调试不同工况下的仿真程序,重点关注控制器设计与稳定性分析部分的数学推导,深入理解李雅普诺夫方法在实际控制系统中的工程化实现路径。

智慧市政智慧路灯物联网建设方案.pptx

智慧市政智慧路灯物联网建设方案.pptx

组播测试工具,可以专门针对IGMP V2/V3、MLD V1/V2协议测试

此工具包含组播成员和组播源模式,组播源负责推送视频流量,成员模式负责发送组播加入报告并接入视频流量最终呈现画面和声音,组播加入报告属于工具自行构造,不依赖电脑系统注册表,这一点vlc工具做不到,适用于Win10和Win11,需管理员权限运行,此工具就是解决vlc不能自定义加入报文的协议版本而开发。

智慧市政桥梁信息化管理系统解决方案.pptx

智慧市政桥梁信息化管理系统解决方案.pptx

凯云科技的实时仿真软件SimuRTS 使用教程

凯云科技的实时仿真软件,对标 NI VeriStand / dSPACE / SpeedGoat 的国产替代:把 Simulink、MWorks 等环境的模型装进实时仿真机,通过 AD/DA/CAN/1553B 等物理通道与真实设备闭环——覆盖快速控制原型(RCP)、半实物仿真(HIL)与自动化测试。本教程基于官网产品页与公开白皮书拆解整理,全部来源见文末。

高校院所牵头组建创新联合体,分散科研设备如何实现高效共享?.docx

科易网基于行业知识库+行业大数据+科技资源要素+AI模型,以AI,赋能技术转移、成果转化、技术经理人培训、知识产权管理、区域产业分析与布局、地方科技招商、创新创业大赛等场景,推出科技创新领域的AI工具、场景化服务和数智化解决方案,推动科技创新与产业创新智能化发展。

组建创新联合体时,政府、高校和企业各自扮演什么角色?.docx

组建创新联合体时,政府、高校和企业各自扮演什么角色?

上一篇: 实现 Java 平台的三种方式
下一篇: 理解J2ME平台
java169
博客等级 码龄19年 27粉丝 2568原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址