如何为持久性 class 创建非持久性抽象 superclass
How to create a not persistent abstract superclass for a persistent class
我想为我的持久性 classes 创建一个抽象超级 class,它提供了一些函数来查询任何其他持久性 class 的成员 class =].
所以我尝试将这个摘要 class 添加为 superclass,但出现以下错误:
The superclass of a persistent class must be persistent
Message no. OO629
有什么好的解决方法吗? (我的意思是不同于制作接口并将函数复制粘贴到每个子class)
这里有一些额外的信息:
Here is what I want to do (Try IE if it does not work with chrome or friefox
简短摘要:
- (我在
user
工作)
- 创建一个通用函数来查询每个键。
- 使用通用函数创建更具体的函数以查询来自联接 table(
user_has_tag
) 的所有“链接”,将它们填充到属性中
- 再次使用通用函数查询另一个外键(
tag
)。
这里是我的抽象superclass(具有通用函数QUERY_BY_UUID
:
CLASS zcl_ps_hrmobject DEFINITION
PUBLIC
ABSTRACT
CREATE PUBLIC .
PUBLIC SECTION.
METHODS get_uuid
RETURNING
VALUE(ro_uuid) TYPE uuid .
PROTECTED SECTION.
METHODS query_by_uuid
IMPORTING
!ir_agent TYPE REF TO object
RETURNING
VALUE(rt_entries) TYPE osreftab
RAISING
cx_os_object_not_found
cx_os_query_error .
METHODS get_query
RETURNING
VALUE(rr_query) TYPE REF TO if_os_query .
PRIVATE SECTION.
CONSTANTS lc_query_method_name TYPE string VALUE 'IF_OS_CA_PERSISTENCY~GET_PERSISTENT_BY_QUERY'. "#EC NOTEXT
DATA mlr_query TYPE REF TO if_os_query .
ENDCLASS.
CLASS zcl_ps_hrmobject IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Protected Method ZCL_PS_HRMOBJECT->GET_QUERY
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RR_QUERY TYPE REF TO IF_OS_QUERY
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD get_query.
rr_query = me->mlr_query.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_HRMOBJECT->GET_UUID
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RO_UUID TYPE UUID
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD get_uuid.
* must be implemented in subclass
RAISE EXCEPTION TYPE cx_os_no_implementation
* EXPORTING
* textid =
* previous =
.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Protected Method ZCL_PS_HRMOBJECT->QUERY_BY_UUID
* +-------------------------------------------------------------------------------------------------+
* | [--->] IR_AGENT TYPE REF TO OBJECT
* | [<-()] RT_ENTRIES TYPE OSREFTAB
* | [!CX!] CX_OS_OBJECT_NOT_FOUND
* | [!CX!] CX_OS_QUERY_ERROR
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD query_by_uuid.
DATA: lr_query TYPE REF TO if_os_query,
lr_uuid TYPE uuid.
lr_query = me->get_query( ).
lr_uuid = me->get_uuid( ).
*TRY.
CALL METHOD ir_agent->(lc_query_method_name)
EXPORTING
i_query = lr_query
* i_parameter_tab =
i_par1 = lr_uuid
* i_par2 =
* i_par3 =
* i_subclasses = OSCON_FALSE
* i_upto = 0
* i_options = IF_OS_QUERY_OPTIONS=>DEFAULT_OPTIONS
RECEIVING
result = rt_entries.
* CATCH cx_os_object_not_found .
* CATCH cx_os_query_error .
*ENDTRY.
ENDMETHOD.
ENDCLASS.
没有。不过,您的描述听起来您可能想仔细查看生成的代理 类 和查询服务提供的方法。
我用一个接口和一个静态辅助类解决了这个问题。
接口强制执行三个 getter:
get_uuid ( )
get_query ( )
get_query_method_name ( )
现在每个元素都实现了这个接口。
在 helperclass 中,我现在有我想要继承的 Query_by_uuid 函数,它获取该接口的实例类型 (ir_root_instance
)。
这里是函数
METHOD QUERY_BY_UUID.
DATA: lr_query TYPE REF TO if_os_query,
lr_uuid TYPE uuid,
lv_query_method_name TYPE string.
lr_query = ir_root_instance->get_query( ).
lr_uuid = ir_root_instance->get_uuid( ).
lv_query_method_name = ir_root_instance->get_query_method_name( ).
*TRY.
CALL METHOD ir_agent->(lv_query_method_name)
EXPORTING
i_query = lr_query
* i_parameter_tab =
i_par1 = lr_uuid
* i_par2 =
* i_par3 =
* i_subclasses = OSCON_FALSE
* i_upto = 0
* i_options = IF_OS_QUERY_OPTIONS=>DEFAULT_OPTIONS
RECEIVING
result = rt_entry.
* CATCH cx_os_object_not_found .
* CATCH cx_os_query_error .
*ENDTRY.
ENDMETHOD.
我想为我的持久性 classes 创建一个抽象超级 class,它提供了一些函数来查询任何其他持久性 class 的成员 class =].
所以我尝试将这个摘要 class 添加为 superclass,但出现以下错误:
The superclass of a persistent class must be persistent
Message no. OO629
有什么好的解决方法吗? (我的意思是不同于制作接口并将函数复制粘贴到每个子class)
这里有一些额外的信息:
Here is what I want to do (Try IE if it does not work with chrome or friefox
简短摘要:
- (我在
user
工作) - 创建一个通用函数来查询每个键。
- 使用通用函数创建更具体的函数以查询来自联接 table(
user_has_tag
) 的所有“链接”,将它们填充到属性中 - 再次使用通用函数查询另一个外键(
tag
)。
这里是我的抽象superclass(具有通用函数QUERY_BY_UUID
:
CLASS zcl_ps_hrmobject DEFINITION
PUBLIC
ABSTRACT
CREATE PUBLIC .
PUBLIC SECTION.
METHODS get_uuid
RETURNING
VALUE(ro_uuid) TYPE uuid .
PROTECTED SECTION.
METHODS query_by_uuid
IMPORTING
!ir_agent TYPE REF TO object
RETURNING
VALUE(rt_entries) TYPE osreftab
RAISING
cx_os_object_not_found
cx_os_query_error .
METHODS get_query
RETURNING
VALUE(rr_query) TYPE REF TO if_os_query .
PRIVATE SECTION.
CONSTANTS lc_query_method_name TYPE string VALUE 'IF_OS_CA_PERSISTENCY~GET_PERSISTENT_BY_QUERY'. "#EC NOTEXT
DATA mlr_query TYPE REF TO if_os_query .
ENDCLASS.
CLASS zcl_ps_hrmobject IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Protected Method ZCL_PS_HRMOBJECT->GET_QUERY
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RR_QUERY TYPE REF TO IF_OS_QUERY
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD get_query.
rr_query = me->mlr_query.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_HRMOBJECT->GET_UUID
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RO_UUID TYPE UUID
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD get_uuid.
* must be implemented in subclass
RAISE EXCEPTION TYPE cx_os_no_implementation
* EXPORTING
* textid =
* previous =
.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Protected Method ZCL_PS_HRMOBJECT->QUERY_BY_UUID
* +-------------------------------------------------------------------------------------------------+
* | [--->] IR_AGENT TYPE REF TO OBJECT
* | [<-()] RT_ENTRIES TYPE OSREFTAB
* | [!CX!] CX_OS_OBJECT_NOT_FOUND
* | [!CX!] CX_OS_QUERY_ERROR
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD query_by_uuid.
DATA: lr_query TYPE REF TO if_os_query,
lr_uuid TYPE uuid.
lr_query = me->get_query( ).
lr_uuid = me->get_uuid( ).
*TRY.
CALL METHOD ir_agent->(lc_query_method_name)
EXPORTING
i_query = lr_query
* i_parameter_tab =
i_par1 = lr_uuid
* i_par2 =
* i_par3 =
* i_subclasses = OSCON_FALSE
* i_upto = 0
* i_options = IF_OS_QUERY_OPTIONS=>DEFAULT_OPTIONS
RECEIVING
result = rt_entries.
* CATCH cx_os_object_not_found .
* CATCH cx_os_query_error .
*ENDTRY.
ENDMETHOD.
ENDCLASS.
没有。不过,您的描述听起来您可能想仔细查看生成的代理 类 和查询服务提供的方法。
我用一个接口和一个静态辅助类解决了这个问题。
接口强制执行三个 getter:
get_uuid ( )
get_query ( )
get_query_method_name ( )
现在每个元素都实现了这个接口。
在 helperclass 中,我现在有我想要继承的 Query_by_uuid 函数,它获取该接口的实例类型 (ir_root_instance
)。
这里是函数
METHOD QUERY_BY_UUID.
DATA: lr_query TYPE REF TO if_os_query,
lr_uuid TYPE uuid,
lv_query_method_name TYPE string.
lr_query = ir_root_instance->get_query( ).
lr_uuid = ir_root_instance->get_uuid( ).
lv_query_method_name = ir_root_instance->get_query_method_name( ).
*TRY.
CALL METHOD ir_agent->(lv_query_method_name)
EXPORTING
i_query = lr_query
* i_parameter_tab =
i_par1 = lr_uuid
* i_par2 =
* i_par3 =
* i_subclasses = OSCON_FALSE
* i_upto = 0
* i_options = IF_OS_QUERY_OPTIONS=>DEFAULT_OPTIONS
RECEIVING
result = rt_entry.
* CATCH cx_os_object_not_found .
* CATCH cx_os_query_error .
*ENDTRY.
ENDMETHOD.