How does Active Objects know the next primary key value?

MattS
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 28, 2015

I'm moving data from one JIRA to another and I know about the sequence_value_item table that contains the next primary ids to use for each kind of table and its data.

I'm looking for something similar in Active Objects. For example when you add a new column to a board, the info is recorded in AO_60DB71_COLUMN. But how did AO know what primary key value to use - did it keep the last used value somewhere, or did it dynamically find the highest primary key for each table at startup?

5 answers

1 accepted

0 votes
Answer accepted
MattS
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 20, 2016

I have added more info to https://developer.atlassian.com/jiradev/jira-platform/jira-architecture/database-schema#Databaseschema-ChangeHistory about this.

Basically, it's pretty easy in MySQL 5.6 since you can override autoincrement with an INSERT, but it's harder in Oracle 11g. With Oracle you have to disable a trigger, hack a sequence to increment it, reenable the trigger. Apparently Oracle 12 has autoincrement built in.

1 vote
Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 28, 2015

It is using DB feature for auto-increment keys

from https://developer.atlassian.com/docs/atlassian-platform-common-components/active-objects/developing-your-plugin-with-active-objects/the-active-objects-library/creating-entities

public interface Entity extends RawEntity<Integer>
{
	@AutoIncrement
	@NotNull
	@PrimaryKey("ID")
	public int getID();
}

So, by default, all your entities are using this scheme

But simple google search shows that you can use some custom ones, as well

http://www.codecommit.com/blog/java/custom-primary-keys-with-activeobjects

However, I suggest to think twice, before using this approach and the main reason I see is that it can get pretty complex when you consider backup and restore functionality and your "custom functionality"

0 votes
MattS
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 11, 2016

ActiveObjects uses the AUTOINCREMENT column attribute for the primary key (id) column in MySQL. In Oracle 11 it uses a sequence and a trigger to do the same thing

Sushanth Kumar Jayanthi April 10, 2018

AO crates a new sequence when i create a table, can I use the existing sequence instead?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 10, 2018

No, it needs to be unarguably unique, so it uses autoincrement.

Sushanth Kumar Jayanthi April 10, 2018

but I am using Oracle 11 it uses a sequence for same thing, Can you help me with how to use my custom sequence?

I have existing sequence "SEARCHACTIVITYID", I am creating the new table using AO where the primary key column should use this same sequence("SEARCHACTIVITYID") , how can i do this? 

 

Thanks

0 votes
Vasiliy Zverev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 28, 2015

As SQL developer I can assume that usually every database provide next id. There are two major options: incremental and random id. It is commonly is configured into Database settings.

MattS
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 29, 2015

That's not how JIRA does it. It stores the next id in the sequence_value_item table.

0 votes
MattS
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 28, 2015

Perhaps the id field once known is just autoincremented by the database?

Suggest an answer

Log in or Sign up to answer