cancel
Showing results for 
Search instead for 
Did you mean: 

How To Implement Sequence ID In the Alfresco

mohammed_amr
Champ in-the-making
Champ in-the-making
Dear Gurus,

I'm working on the alfresco and i need to implement a sequence of ids, so can you please give me a way to implement a sequence.

Exactly, let we have a type and that type has id and may be exist in the repository multiple instance of that type and all of every instance must has id as a unique identifier and that id must be recognized as this equation:

sequence no + date as example.

How can i implement something like this

Thanks
Mohammed Amr
Senior System Developer.
Digital Series Co.
5 REPLIES 5

mrogers
Star Contributor
Star Contributor
Sequences are surprisingly tricky. :roll:   And can you allow gaps within your sequence?   No gaps makes things far harder :!:

Each node already has a DBID and a NodeRef.  Those are the "unique keys" that are already available.   I suggest you use these first.

If you really do want a sequence then you will need to write some sort of sequence generator.   It could be as simple as a five line class with a synchronized counter, although that would need initialising and would not work clustered.  

Another approach sometimes used is to put attributes or properties onto a node that gets incremented with each new addition.  Or you could use a sequence if you have a database that supports sequences.

Either way you call your sequence generator in an on create policy handler for the specified type.

mohammed_amr
Champ in-the-making
Champ in-the-making
Another approach sometimes used is to put attributes or properties onto a node that gets incremented with each new addition. Or you could use a sequence if you have a database that supports sequences.

let i used the above scenario, is this scenario support clustered ?

FYI, i use the already built-in alfresco database and it is MYSQL, and i think it is capable to handle the sequences.

mrogers
Star Contributor
Star Contributor
Yes both those approaches would work clustered.

mohammed_amr
Champ in-the-making
Champ in-the-making
let i will go through this scenario

i have a node A with property a, once i create the node B the property a within node A will be incremented by one.

pseudopod for this

Assumption:
getIncrement() {return a + 1}; // where a is the sequence

Begin:

Node B = new Node(); // new node
Node A = getNodeA(); // sequence node

lock(A); // lock the sequence node by LockService
int incremenntByOne = A.getIncrement();  // increment the sequence within A by one and return it back to variable incrementByOne
B.setId(incrementByOne); // set the new sequence into the new node.
unlock(A); // unlock sequence node to allow another to gain it

end;

- Is this scenario supported by clustered environment ?
- should i use the lockService  ? or there is another service will be used ?

Thanks In Advance
Mohammed Amr.
Senior System Developer
Digital Series Co.

mrogers
Star Contributor
Star Contributor
Yes that should work in a clustered enviornment.      You probably want to use the JobLockService rather than the LockService.

Another approach is just to run the update in a read/write transaction.   Should more than one tran attempt to update the same property at the same time then the database will conflict so the looser will rollback.   If you use the RetryingTransactionHelper then it will retry for you.
Welcome to the new Hyland Connect. Get started or submit feedback.