Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new sample: sticky session with locking and rollback #373

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions src/z2ui5_cl_demo_app_135.clas.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
CLASS z2ui5_cl_demo_app_135 DEFINITION
PUBLIC
CREATE PUBLIC .

PUBLIC SECTION.

INTERFACES if_serializable_object .
INTERFACES z2ui5_if_app .

DATA lock_counter TYPE i READ-ONLY .
DATA check_initialized TYPE abap_bool READ-ONLY .
DATA session_is_stateful TYPE abap_bool READ-ONLY .
DATA session_text TYPE string READ-ONLY .
DATA lock_text TYPE string READ-ONLY .
DATA:
BEGIN OF error READ-ONLY,
text TYPE string,
flag TYPE abap_bool,
END OF error.

PROTECTED SECTION.
PRIVATE SECTION.

METHODS initialize_view
IMPORTING
client TYPE REF TO z2ui5_if_client.

METHODS on_event
IMPORTING
client TYPE REF TO z2ui5_if_client.

METHODS set_session_stateful
IMPORTING
client TYPE REF TO z2ui5_if_client
stateful TYPE abap_bool.

METHODS update_lock_counter.

ENDCLASS.



CLASS z2ui5_cl_demo_app_135 IMPLEMENTATION.

METHOD initialize_view.
set_session_stateful( client = client stateful = abap_true ).

DATA(view) = z2ui5_cl_xml_view=>factory( ).

DATA(page) = view->shell( )->page(
title = `abap2UI5 - Sample: Sticky Session with locks`
navbuttonpress = client->_event( 'BACK' )
shownavbutton = xsdbool( client->get( )-s_draft-id_prev_app_stack IS NOT INITIAL ) ).

page->message_strip(
text = client->_bind( error-text )
type = 'Error'
visible = client->_bind( error-flag ) ).

DATA(vbox) = page->vbox( ).

DATA(hbox) = vbox->hbox( alignitems = 'Center' ).

hbox->info_label( text = client->_bind( session_text ) ).

hbox->button(
text = 'End session'
press = client->_event( 'END_SESSION' ) ).

hbox->button(
text = 'Start session again'
press = client->_event( 'START_SESSION' ) ).

hbox = vbox->hbox( alignitems = 'Center' ).
hbox->label( text = 'press button to create lock entry (SM12) in backend session' class = 'sapUiTinyMarginEnd' ).
hbox->button(
text = 'Lock'
press = client->_event( 'LOCK' )
type = 'Emphasized' ).

hbox = vbox->hbox( ).

hbox->button(
text = 'Refresh lock counter'
press = client->_event( 'REFRESH' ) ).

hbox->button(
text = 'Rollback Work'
press = client->_event( 'ROLLBACK' ) ).

vbox->hbox( )->info_label( client->_bind( lock_text ) ).

client->view_display( view->stringify( ) ).
ENDMETHOD.


METHOD on_event.
CASE client->get( )-event.
WHEN 'BACK'.
client->nav_app_leave( ).
WHEN 'LOCK'.
lcl_locking=>acquire_lock( ).
client->message_toast_display( `Lock acquired. Press 'Refresh lock counter'` ).
client->view_model_update( ).
WHEN 'END_SESSION'.
set_session_stateful( client = client stateful = abap_false ).
WHEN 'START_SESSION'.
set_session_stateful( client = client stateful = abap_true ).
WHEN 'REFRESH'.
update_lock_counter( ).
client->view_model_update( ).
WHEN 'ROLLBACK'.
ROLLBACK WORK.
client->message_toast_display( |ROLLBACK WORK done, { lock_counter } locks released. Press 'Refresh lock counter'| ).
ENDCASE.
ENDMETHOD.


METHOD set_session_stateful.
client->set_session_stateful( stateful ).
session_is_stateful = stateful.
IF stateful = abap_true.
session_text = 'Session ON (stateful)'.
ELSE.
session_text = 'Session OFF (stateless)'.
ENDIF.
client->view_model_update( ).
ENDMETHOD.


METHOD z2ui5_if_app~main.

CLEAR error.

IF check_initialized = abap_false.
check_initialized = abap_true.
update_lock_counter( ).
initialize_view( client ).
ENDIF.

TRY.
on_event( client ).
CATCH z2ui5_cx_util_error INTO DATA(x_error).
error-text = x_error->get_text( ).
error-flag = abap_true.
client->view_model_update( ).
ENDTRY.

ENDMETHOD.


METHOD update_lock_counter.

lock_counter = lcl_locking=>get_lock_counter( ).
lock_text = |There are { lock_counter } SM12 locks|.

ENDMETHOD.

ENDCLASS.

55 changes: 55 additions & 0 deletions src/z2ui5_cl_demo_app_135.clas.locals_imp.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
CLASS lcl_locking DEFINITION CREATE PRIVATE FINAL.
PUBLIC SECTION.
CLASS-METHODS acquire_lock.
CLASS-METHODS get_lock_counter
RETURNING
VALUE(result) TYPE i.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.

CLASS lcl_locking IMPLEMENTATION.

METHOD acquire_lock.

CALL FUNCTION 'ENQUEUE_E_TABLE'

Check failure on line 15 in src/z2ui5_cl_demo_app_135.clas.locals_imp.abap

View check run for this annotation

abaplint / abaplint / abap_cloud_readiness

Function module "ENQUEUE_E_TABLE" not found/released

https://rules.abaplint.org/check_syntax
EXPORTING
tabname = 'ZTEST'
varkey = 'Z100'
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO DATA(error_text).
RAISE EXCEPTION TYPE z2ui5_cx_util_error EXPORTING val = error_text.
ENDIF.

ENDMETHOD.


METHOD get_lock_counter.
DATA: enqueue_table TYPE STANDARD TABLE OF seqg3.

Check failure on line 32 in src/z2ui5_cl_demo_app_135.clas.locals_imp.abap

View check run for this annotation

abaplint / abaplint

Variable "ENQUEUE_TABLE" contains unknown: SEQG3 not found, lookup

https://rules.abaplint.org/unknown_types

Check failure on line 32 in src/z2ui5_cl_demo_app_135.clas.locals_imp.abap

View check run for this annotation

abaplint / abaplint / abap_cloud_readiness

Variable "ENQUEUE_TABLE" contains unknown: SEQG3 not found, lookup

https://rules.abaplint.org/unknown_types

DATA(argument) = CONV eqegraarg( |ZTEST Z100*| ).

Check failure on line 34 in src/z2ui5_cl_demo_app_135.clas.locals_imp.abap

View check run for this annotation

abaplint / abaplint

EQEGRAARG not found, lookup

https://rules.abaplint.org/unknown_types

Check failure on line 34 in src/z2ui5_cl_demo_app_135.clas.locals_imp.abap

View check run for this annotation

abaplint / abaplint

Variable "ARGUMENT" contains unknown: EQEGRAARG not found, lookup

https://rules.abaplint.org/unknown_types

Check failure on line 34 in src/z2ui5_cl_demo_app_135.clas.locals_imp.abap

View check run for this annotation

abaplint / abaplint / abap_cloud_readiness

EQEGRAARG not found, lookup

https://rules.abaplint.org/unknown_types

Check failure on line 34 in src/z2ui5_cl_demo_app_135.clas.locals_imp.abap

View check run for this annotation

abaplint / abaplint / abap_cloud_readiness

Variable "ARGUMENT" contains unknown: EQEGRAARG not found, lookup

https://rules.abaplint.org/unknown_types

CALL FUNCTION 'ENQUEUE_READ'

Check failure on line 36 in src/z2ui5_cl_demo_app_135.clas.locals_imp.abap

View check run for this annotation

abaplint / abaplint / abap_cloud_readiness

Function module "ENQUEUE_READ" not found/released

https://rules.abaplint.org/check_syntax
EXPORTING
garg = argument
guname = sy-uname
TABLES
enq = enqueue_table
EXCEPTIONS
communication_failure = 1
system_failure = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO DATA(error_text).
RAISE EXCEPTION TYPE z2ui5_cx_util_error EXPORTING val = error_text.
ENDIF.

result = VALUE #( enqueue_table[ 1 ]-gusevb OPTIONAL ).

Check failure on line 51 in src/z2ui5_cl_demo_app_135.clas.locals_imp.abap

View check run for this annotation

abaplint / abaplint

Not a structure, type unknown, FieldChain

https://rules.abaplint.org/check_syntax

Check failure on line 51 in src/z2ui5_cl_demo_app_135.clas.locals_imp.abap

View check run for this annotation

abaplint / abaplint / abap_cloud_readiness

Not a structure, type unknown, FieldChain

https://rules.abaplint.org/check_syntax

ENDMETHOD.

ENDCLASS.
16 changes: 16 additions & 0 deletions src/z2ui5_cl_demo_app_135.clas.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>Z2UI5_CL_DEMO_APP_135</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>Sticky session with locking</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>
Loading