intershop - Intershop7: How to use NumberSequenceProvider correctly -
i working on latest , greatest intershop 7.8.0.3 , trying implement new functionality generates unique, human readable sku. first idea use numberseriesprovider implement functionality. however, unfortunately class marked deprecated , replaced numbersequenceprovider. there unfortunately huge documentation gap feature.
so far good. numbersequenceprovider provides method nextvalue(sequenceid) provide next sequence entry. problem how define sequenceid. have seen there method createsequence(...) can used so. method adds sequence database , stores sequenceid in local sequencenumbergenerators cache. without calling createsequence(...) method sequence - far can see - never available nextvalue(sequenceid) method , therefore call method result in error.
i not understand how supposed work in production scenario multiple application servers. need call createsequence(...) method on every server start make sequence available in local sequencenumbergenerators cache. approach try create sequence in database which, results in catched exception if sequence created on previous start or parallel application server.
is how supposed work?
thank , best regards
afaik once created - programmatically or via dbinit - sequence persisted in database. represented oracle sequence , row in basicseriesentry
table. sequence available after server restart again , there won't need recreate it.
a call next val on server reserve "series" of numbers. happen within synchronized method - e.g. numbers 50 till 100 reserved , kept in memory (sychronized) until interval exhausted generator. after server attempt request series database. optimization rather ancient times aims decrease number of database calls. on each server restart database called again new series reserved.
here how server(s) behave in cases, when, example orders created sequence number generator.
scenario 1: single server - 3 orders created, server restarted, 3 new orders created.
possible result: order numbers might 50,51,52, 100, 101, 102
scenario 2: parallel servers create orders.
possible results in time: order numbers might 100, 101, 50, 102, 51, 52
note may have 1 n appservers single db manages sequence.
update sample usage:
step 1) create sequence
@inject private numbersequenceprovider nsp; public void createseq() { nsp.createsequence( "so_1234567890", "0000000", "abc", 1, 1, long.max_value, 1, false, false, 50 ); }
here happened in db:
select * basicseriesentry identifier = 'so_1234567890' identifier numberpattern sequencename oca --------------- ---------------- ------------------------------ ---------------------- so_1234567890 0000000 abc 0 select * user_sequences sequence_name = 'abc'; sequence_name min_value max_value increment_by cycle_flag order_flag cache_size last_number ------------------------------ ---------------------- ---------------------- ---------------------- ---------- ---------- ---------------------- ---------------------- abc 1 9223372036854775807 1 n n 50 1
step 2) restart server
step 3) try out
string seq = stream. generate(() -> nsp.nextvalue("so_1234567890")). limit(5). collect(collectors.joining(", ")); system.out.println("sequence: " + seq);
output:
sequence: 0000001, 0000002, 0000003, 0000004, 0000005
troubleshooting:
1) numbersequenceprovider
nasty quite when comes reporting oracle errors. please check error log errors like: ora-04006: start cannot less minvalue
2) activate debug log provider implementation , check related debug messages (see comments).
Comments
Post a Comment