Each table in the JBPM database has a primary key-ID (long type). This ID can be generated by the user, or it can be generated by JBPM. This value is unique in the ID of all tables. The user setting the class generated by the user by setting the jbpm.id.generator property.
(1) JBPM ID generation basic principles and functions
The basic principles generated by the ID in JBPM are: Store the currently available ID value using the table JBPM_SEQUENCEBLOCK. When the JBPM needs to use the ID, obtain this ID from the database, then increase the number of amounts as the currently available ID value and store it in the database. JBPM ID can be used for server clusters. The function of the ID generated in Hibernate is similar to the JBPM generates ID, but cannot be applied to the cluster.
The JBPM_SEQUENCEBLOCK table has two field IDs and nextid, the former is the primary key, indicating the ID number of the current node in the cluster, which can use the minimum number of data segments for the current node. The table is represented by class org.jbpm.persistence.hibernate.sequence, org.jbpm.Persistence.hibernate.sequenceBolckIdgenerator maintenance.
SequenceBolckidGenerator main function:
(1) Public sequenceblockidgenerator (JBPMConfiguration JBPMConfiguration)
Initialization, including initializing the NodeID and BlockSize variables. NodeID indicates the ID number (0-65535) of the current node in the cluster (0-65535), and the user can set up JBPM.ID.NodeID, the default value is 0. Blocksize indicates a data block size of the current node using long plastics, and the user can set up JBPM.ID.BOLCKSIZE, the default value is 100.
(2) Public long getnextid () // Get the currently available ID, JBPM uses it to get ID
{
Return GetNextId (sessionFactory, NodeID, blocksize);
}
(3) Public Static Synchronized long getnextid (sessionFactory SessionFactory,
Long NodeID, long blocksize
The most important function is used to calculate the currently available ID.
(2) ID generation algorithm
Basic Ideas: Segment 1-long.maxvalue range, according to size blocksize * max no, then divide each paragraph to divide the blocksize block into the MAXNODES block, each node is used in accordance with the node number, such as the node number 0 can only Using the first block, the second piece of the node number 1 is used, and the second block is used. MAXNODES is the total number of nodes in the current cluster, with 65535.
Value algorithm:
(1) Remove the first number of numbers (minimum number of blocks) that can be used (minimum)
(2) The first number blocksize × nodeid (node number, 0-65535) is the ID (NextID) that can be used;
(3) NEXTID BlockSize-1 When the last ID (4) (4) (4) that is currently available, nextId <= lastid, returns NextID, then NEXTID ; otherwise take the next data block 1-3 calculation.
Description:
(1) Read a database, you can use the BlockSize ID, you don't have to read a database each time you use the ID.
(2) The NEXTID field of the table is stored in the currently available block instead of the first number of blocks. The first number of each node uses the block by the node number separately.
(3) For each number, each node uses only one of the (first blocksize × nodeid) - (the first blocksize × (NodeID 1) -1), ensuring that the ID value used by each node is The database is unique.
(3) Database connection session
In order to ensure the uniqueness of the ID, JBPM requires database session to operate on table JBPM_SEQUENCEBLOCK must be independent and cannot be used for other database operations. If JBPM uses a database connection pool, you must set the jbpm.id.generator.configuration property, and provide the Hibernate configuration file that is directly connected to the database. By default, JBPM uses a global static session in addition to JBPM_SEQUENCEBLOCK, and session for the JBPM_SEQUENCEBLOCK table is temporarily established when the class sequencebolckidgenerator is initialized. .