From 21351e3affc630126f3815756299ece68e8e1613 Mon Sep 17 00:00:00 2001 From: Joze RIHTARSIC <joze.RIHTARSIC@ext.ec.europa.eu> Date: Thu, 28 Apr 2022 09:59:48 +0200 Subject: [PATCH] set native database ID generator --- .../ec/edelivery/smp/data/model/DBDomain.java | 5 +- .../smp/data/model/DBRevisionLog.java | 6 +-- .../smp/data/model/DBServiceGroup.java | 7 +-- .../smp/data/model/DBServiceGroupDomain.java | 5 +- .../smp/data/model/DBServiceMetadata.java | 5 +- .../ec/edelivery/smp/data/model/DBUser.java | 5 +- .../mysql-4.1_integration_test_data.sql | 6 --- .../database-scripts/mysql5innodb-data.sql | 4 +- .../database-scripts/mysql5innodb-drop.ddl | 12 ----- .../database-scripts/mysql5innodb.ddl | 48 +++---------------- .../smp-setup/database-scripts/oracle10g.ddl | 2 +- 11 files changed, 27 insertions(+), 78 deletions(-) diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBDomain.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBDomain.java index c12b28f0c..d13a33738 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBDomain.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBDomain.java @@ -14,6 +14,7 @@ package eu.europa.ec.edelivery.smp.data.model; import eu.europa.ec.edelivery.smp.data.dao.utils.ColumnDescription; +import org.hibernate.annotations.GenericGenerator; import org.hibernate.envers.Audited; import javax.persistence.*; @@ -53,8 +54,8 @@ import javax.persistence.*; public class DBDomain extends BaseEntity { @Id - @SequenceGenerator(name = "domain_generator", sequenceName = "SMP_DOMAIN_SEQ", allocationSize = 1) - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "domain_generator") + @GeneratedValue(strategy = GenerationType.AUTO, generator = "SMP_DOMAIN_SEQ") + @GenericGenerator(name = "SMP_DOMAIN_SEQ", strategy = "native") @Column(name = "ID") @ColumnDescription(comment = "Unique domain id") Long id; diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBRevisionLog.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBRevisionLog.java index ed0cc45e3..a69d8b00b 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBRevisionLog.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBRevisionLog.java @@ -2,6 +2,7 @@ package eu.europa.ec.edelivery.smp.data.model; import eu.europa.ec.edelivery.smp.data.dao.SMPRevisionListener; +import org.hibernate.annotations.GenericGenerator; import org.hibernate.envers.RevisionEntity; import org.hibernate.envers.RevisionNumber; import org.hibernate.envers.RevisionTimestamp; @@ -20,10 +21,9 @@ import java.time.LocalDateTime; @RevisionEntity(SMPRevisionListener.class) public class DBRevisionLog { - @Id - @SequenceGenerator(name="revision_generator", sequenceName = "SMP_REVISION_SEQ", allocationSize = 1) - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "revision_generator") + @GeneratedValue(strategy = GenerationType.AUTO, generator = "SMP_REVISION_SEQ") + @GenericGenerator(name = "SMP_REVISION_SEQ", strategy = "native") @RevisionNumber private long id; diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroup.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroup.java index 2f67ecaa6..f277f8dfb 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroup.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroup.java @@ -14,6 +14,7 @@ package eu.europa.ec.edelivery.smp.data.model; import eu.europa.ec.edelivery.smp.data.dao.utils.ColumnDescription; import org.apache.commons.lang3.StringUtils; +import org.hibernate.annotations.GenericGenerator; import org.hibernate.envers.Audited; import javax.persistence.*; @@ -42,10 +43,10 @@ import java.util.*; public class DBServiceGroup extends BaseEntity { @Id - @SequenceGenerator(name = "sg_generator", sequenceName = "SMP_SERVICE_GROUP_SEQ", allocationSize = 1) - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sg_generator") + @GeneratedValue(strategy = GenerationType.AUTO, generator = "SMP_SERVICE_GROUP_SEQ") + @GenericGenerator(name = "SMP_SERVICE_GROUP_SEQ", strategy = "native") @Column(name = "ID") - @ColumnDescription(comment = "Unique Servicegroup id") + @ColumnDescription(comment = "Unique ServiceGroup id") Long id; diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroupDomain.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroupDomain.java index 77274937b..e2fb66467 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroupDomain.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceGroupDomain.java @@ -1,5 +1,6 @@ package eu.europa.ec.edelivery.smp.data.model; +import org.hibernate.annotations.GenericGenerator; import org.hibernate.envers.Audited; import javax.persistence.*; @@ -33,8 +34,8 @@ import java.util.Objects; public class DBServiceGroupDomain extends BaseEntity { @Id - @SequenceGenerator(name = "sgd_generator", sequenceName = "SMP_SERVICE_GROUP_DOMAIN_SEQ", allocationSize = 1) - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sgd_generator") + @GeneratedValue(strategy = GenerationType.AUTO, generator = "SMP_SERVICE_GROUP_DOMAIN_SEQ") + @GenericGenerator(name = "SMP_SERVICE_GROUP_DOMAIN_SEQ", strategy = "native") @Column(name = "ID") Long id; diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceMetadata.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceMetadata.java index 620409647..289fcd5a9 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceMetadata.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBServiceMetadata.java @@ -14,6 +14,7 @@ package eu.europa.ec.edelivery.smp.data.model; import eu.europa.ec.edelivery.smp.data.dao.utils.ColumnDescription; +import org.hibernate.annotations.GenericGenerator; import org.hibernate.envers.Audited; import javax.persistence.*; @@ -44,8 +45,8 @@ import java.util.Objects; public class DBServiceMetadata extends BaseEntity { @Id - @SequenceGenerator(name = "sgmd_generator", sequenceName = "SMP_SERVICE_METADATA_SEQ",allocationSize = 1) - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sgmd_generator") + @GeneratedValue(strategy = GenerationType.AUTO, generator = "SMP_SERVICE_METADATA_SEQ") + @GenericGenerator(name = "SMP_SERVICE_METADATA_SEQ", strategy = "native") @Column(name = "ID") @ColumnDescription(comment = "Shared primary key with master table SMP_SERVICE_METADATA") Long id; diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBUser.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBUser.java index 31e4480bc..14594696b 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBUser.java +++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/data/model/DBUser.java @@ -14,6 +14,7 @@ package eu.europa.ec.edelivery.smp.data.model; import eu.europa.ec.edelivery.smp.data.dao.utils.ColumnDescription; import org.apache.commons.lang3.StringUtils; +import org.hibernate.annotations.GenericGenerator; import org.hibernate.envers.Audited; import javax.persistence.*; @@ -52,8 +53,8 @@ import java.util.Objects; public class DBUser extends BaseEntity { @Id - @SequenceGenerator(name = "usr_generator", sequenceName = "SMP_USER_SEQ", allocationSize = 1) - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "usr_generator") + @GeneratedValue(strategy = GenerationType.AUTO, generator = "SMP_USER_SEQ") + @GenericGenerator(name = "SMP_USER_SEQ", strategy = "native") @Column(name = "ID") @ColumnDescription(comment = "Unique user id") Long id; diff --git a/smp-soapui-tests/groovy/mysql-4.1_integration_test_data.sql b/smp-soapui-tests/groovy/mysql-4.1_integration_test_data.sql index cfdd660d6..b2cf07e7f 100644 --- a/smp-soapui-tests/groovy/mysql-4.1_integration_test_data.sql +++ b/smp-soapui-tests/groovy/mysql-4.1_integration_test_data.sql @@ -43,9 +43,6 @@ insert into SMP_CERTIFICATE (ID, CERTIFICATE_ID, VALID_FROM, VALID_TO, CREATED_O insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE, CREATED_ON, LAST_UPDATED_ON) values (21, 'blue_gw', '', 'SERVICE_GROUP_ADMIN', 1, NOW(), NOW()); insert into SMP_CERTIFICATE (ID, CERTIFICATE_ID, VALID_FROM, VALID_TO, CREATED_ON, LAST_UPDATED_ON) values (21, 'CN=blue_gw,O=eDelivery,C=BE:e07b6b956330a19a', null,null, NOW(), NOW()); -update SMP_USER_SEQ set next_val=100 where next_val=1; - - -- insert domain insert into SMP_DOMAIN (ID, DOMAIN_CODE, SML_SUBDOMAIN, SML_SMP_ID, SIGNATURE_KEY_ALIAS, SML_CLIENT_KEY_ALIAS, SML_BLUE_COAT_AUTH,SML_REGISTERED, CREATED_ON, LAST_UPDATED_ON, SML_CLIENT_CERT_HEADER) values (1, 'domain','','CEF-SMP-002', 'sample_key','sample_key', 1,0, NOW(), NOW(),'sno=1&subject=CN=SMP_TEST-PRE-SET-EXAMPLE, OU=eDelivery, O=DIGITAL, C=BE&validfrom=Dec 6 17:41:42 2016 GMT&validto=Jul 9 23:59:00 2050 GMT&issuer=CN=rootCNTest,OU=B4,O=DIGIT,L=Brussels,ST=BE,C=BE'); @@ -62,6 +59,3 @@ insert into SMP_DOMAIN (ID, DOMAIN_CODE, SML_SUBDOMAIN, SML_SMP_ID, SIGNATURE_KE insert into SMP_DOMAIN (ID, DOMAIN_CODE, SML_SUBDOMAIN, SML_SMP_ID, SIGNATURE_KEY_ALIAS, SML_BLUE_COAT_AUTH,SML_REGISTERED, CREATED_ON, LAST_UPDATED_ON) values (11, 'domainK','subdomain011', 'CEF-SMP-011','sample_key',1,0,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); insert into SMP_DOMAIN (ID, DOMAIN_CODE, SML_SUBDOMAIN, SML_SMP_ID, SIGNATURE_KEY_ALIAS, SML_BLUE_COAT_AUTH,SML_REGISTERED, CREATED_ON, LAST_UPDATED_ON) values (12, 'domainL','subdomain012', 'CEF-SMP-012','sample_key',1,0,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); - -insert into SMP_ALERT (ID, DOMAIN_CODE, SML_SUBDOMAIN, SML_SMP_ID, SIGNATURE_KEY_ALIAS, SML_BLUE_COAT_AUTH,SML_REGISTERED, CREATED_ON, LAST_UPDATED_ON) values (12, 'domainL','subdomain012', 'CEF-SMP-012','sample_key',1,0,CURRENT_TIMESTAMP(),CURRENT_TIMESTAMP()); - diff --git a/smp-webapp/src/main/smp-setup/database-scripts/mysql5innodb-data.sql b/smp-webapp/src/main/smp-setup/database-scripts/mysql5innodb-data.sql index b1b95b8a3..6fa387b1f 100644 --- a/smp-webapp/src/main/smp-setup/database-scripts/mysql5innodb-data.sql +++ b/smp-webapp/src/main/smp-setup/database-scripts/mysql5innodb-data.sql @@ -2,9 +2,7 @@ insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE, CREATED_ON, LAST_UPD insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE, CREATED_ON, LAST_UPDATED_ON) values (2, 'smp', '$2a$06$FDmjewn/do3C219uysNm9.XG8mIn.ubHnMydAzC8lsv61HsRpOR36', 'SMP_ADMIN', 1, NOW(), NOW()); insert into SMP_USER (ID, USERNAME, PASSWORD, ROLE, ACTIVE, CREATED_ON, LAST_UPDATED_ON) values (3, 'user', '$2a$06$FDmjewn/do3C219uysNm9.XG8mIn.ubHnMydAzC8lsv61HsRpOR36', 'SERVICE_GROUP_ADMIN', 1, NOW(), NOW()); -update SMP_USER_SEQ set next_val=4; - -- insert domain insert into SMP_DOMAIN (ID, DOMAIN_CODE, SML_SUBDOMAIN, SML_SMP_ID, SIGNATURE_KEY_ALIAS, SML_BLUE_COAT_AUTH,SML_REGISTERED, CREATED_ON, LAST_UPDATED_ON) values (1, 'testDomain','test','CEF-SMP-002', 'sample_key', 1,0, NOW(), NOW()); -update SMP_USER_SEQ set next_val=2; + diff --git a/smp-webapp/src/main/smp-setup/database-scripts/mysql5innodb-drop.ddl b/smp-webapp/src/main/smp-setup/database-scripts/mysql5innodb-drop.ddl index 19447e569..7c739984e 100644 --- a/smp-webapp/src/main/smp-setup/database-scripts/mysql5innodb-drop.ddl +++ b/smp-webapp/src/main/smp-setup/database-scripts/mysql5innodb-drop.ddl @@ -95,16 +95,12 @@ drop table if exists SMP_DOMAIN_AUD; - drop table if exists SMP_DOMAIN_SEQ; - drop table if exists SMP_OWNERSHIP; drop table if exists SMP_OWNERSHIP_AUD; drop table if exists SMP_REV_INFO; - drop table if exists SMP_REVISION_SEQ; - drop table if exists SMP_SERVICE_GROUP; drop table if exists SMP_SERVICE_GROUP_AUD; @@ -113,16 +109,10 @@ drop table if exists SMP_SERVICE_GROUP_DOMAIN_AUD; - drop table if exists SMP_SERVICE_GROUP_DOMAIN_SEQ; - - drop table if exists SMP_SERVICE_GROUP_SEQ; - drop table if exists SMP_SERVICE_METADATA; drop table if exists SMP_SERVICE_METADATA_AUD; - drop table if exists SMP_SERVICE_METADATA_SEQ; - drop table if exists SMP_SERVICE_METADATA_XML; drop table if exists SMP_SERVICE_METADATA_XML_AUD; @@ -134,5 +124,3 @@ drop table if exists SMP_USER; drop table if exists SMP_USER_AUD; - - drop table if exists SMP_USER_SEQ; diff --git a/smp-webapp/src/main/smp-setup/database-scripts/mysql5innodb.ddl b/smp-webapp/src/main/smp-setup/database-scripts/mysql5innodb.ddl index f3dca1661..1cdebaab3 100644 --- a/smp-webapp/src/main/smp-setup/database-scripts/mysql5innodb.ddl +++ b/smp-webapp/src/main/smp-setup/database-scripts/mysql5innodb.ddl @@ -84,7 +84,7 @@ ) ENGINE=InnoDB DEFAULT CHARSET=utf8; create table SMP_DOMAIN ( - ID bigint not null comment 'Unique domain id', + ID bigint not null auto_increment comment 'Unique domain id', CREATED_ON datetime not null, LAST_UPDATED_ON datetime not null, DOMAIN_CODE varchar(256) CHARACTER SET utf8 COLLATE utf8_bin not null comment 'Domain code used as http parameter in rest webservices', @@ -117,12 +117,6 @@ primary key (ID, REV) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - create table SMP_DOMAIN_SEQ ( - next_val bigint - ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - - insert into SMP_DOMAIN_SEQ values ( 1 ); - create table SMP_OWNERSHIP ( FK_SG_ID bigint not null, FK_USER_ID bigint not null, @@ -138,21 +132,15 @@ ) ENGINE=InnoDB DEFAULT CHARSET=utf8; create table SMP_REV_INFO ( - id bigint not null, + id bigint not null auto_increment, REVISION_DATE datetime, timestamp bigint not null, USERNAME varchar(255) CHARACTER SET utf8 COLLATE utf8_bin, primary key (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - create table SMP_REVISION_SEQ ( - next_val bigint - ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - - insert into SMP_REVISION_SEQ values ( 1 ); - create table SMP_SERVICE_GROUP ( - ID bigint not null comment 'Unique Servicegroup id', + ID bigint not null auto_increment comment 'Unique ServiceGroup id', CREATED_ON datetime not null, LAST_UPDATED_ON datetime not null, PARTICIPANT_IDENTIFIER varchar(256) CHARACTER SET utf8 COLLATE utf8_bin not null, @@ -172,7 +160,7 @@ ) ENGINE=InnoDB DEFAULT CHARSET=utf8; create table SMP_SERVICE_GROUP_DOMAIN ( - ID bigint not null, + ID bigint not null auto_increment, CREATED_ON datetime not null, LAST_UPDATED_ON datetime not null, SML_REGISTERED bit not null, @@ -193,20 +181,8 @@ primary key (ID, REV) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - create table SMP_SERVICE_GROUP_DOMAIN_SEQ ( - next_val bigint - ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - - insert into SMP_SERVICE_GROUP_DOMAIN_SEQ values ( 1 ); - - create table SMP_SERVICE_GROUP_SEQ ( - next_val bigint - ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - - insert into SMP_SERVICE_GROUP_SEQ values ( 1 ); - create table SMP_SERVICE_METADATA ( - ID bigint not null comment 'Shared primary key with master table SMP_SERVICE_METADATA', + ID bigint not null auto_increment comment 'Shared primary key with master table SMP_SERVICE_METADATA', CREATED_ON datetime not null, LAST_UPDATED_ON datetime not null, DOCUMENT_IDENTIFIER varchar(500) CHARACTER SET utf8 COLLATE utf8_bin not null, @@ -227,12 +203,6 @@ primary key (ID, REV) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - create table SMP_SERVICE_METADATA_SEQ ( - next_val bigint - ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - - insert into SMP_SERVICE_METADATA_SEQ values ( 1 ); - create table SMP_SERVICE_METADATA_XML ( ID bigint not null, CREATED_ON datetime not null, @@ -270,7 +240,7 @@ ) ENGINE=InnoDB DEFAULT CHARSET=utf8; create table SMP_USER ( - ID bigint not null comment 'Unique user id', + ID bigint not null auto_increment comment 'Unique user id', CREATED_ON datetime not null, LAST_UPDATED_ON datetime not null, ACCESS_TOKEN varchar(256) CHARACTER SET utf8 COLLATE utf8_bin comment 'BCrypted personal access token', @@ -315,12 +285,6 @@ primary key (ID, REV) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - create table SMP_USER_SEQ ( - next_val bigint - ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - - insert into SMP_USER_SEQ values ( 1 ); - alter table SMP_CERTIFICATE add constraint UK_3x3rvf6hkim9fg16caurkgg6f unique (CERTIFICATE_ID); diff --git a/smp-webapp/src/main/smp-setup/database-scripts/oracle10g.ddl b/smp-webapp/src/main/smp-setup/database-scripts/oracle10g.ddl index d160ce5e2..3a4dac348 100644 --- a/smp-webapp/src/main/smp-setup/database-scripts/oracle10g.ddl +++ b/smp-webapp/src/main/smp-setup/database-scripts/oracle10g.ddl @@ -240,7 +240,7 @@ create sequence SMP_USER_SEQ start with 1 increment by 1; 'Service group data - Identifier and scheme'; comment on column SMP_SERVICE_GROUP.ID is - 'Unique Servicegroup id'; + 'Unique ServiceGroup id'; create table SMP_SERVICE_GROUP_AUD ( ID number(19,0) not null, -- GitLab