From bba240f1d44cd57b9240465f66260a6b19bb5f80 Mon Sep 17 00:00:00 2001 From: Joerg Hohwiller Date: Thu, 16 Aug 2018 17:31:45 +0200 Subject: [PATCH 1/3] #671: add support for hana as dbType --- .../resources/archetype-resources/core/pom.xml | 4 ++++ .../src/main/resources/application.properties | 4 ++++ .../resources/config/application.properties | 3 +++ .../db/type/hana/V0001__Create_Sequence.sql | 18 ++++++++++++++++++ .../db/type/hana/V0002__Create_RevInfo.sql | 7 +++++++ .../type/hana/V0003__Create_BinaryObject.sql | 9 +++++++++ 6 files changed, 45 insertions(+) create mode 100644 templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/type/hana/V0001__Create_Sequence.sql create mode 100644 templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/type/hana/V0002__Create_RevInfo.sql create mode 100644 templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/type/hana/V0003__Create_BinaryObject.sql diff --git a/templates/server/src/main/resources/archetype-resources/core/pom.xml b/templates/server/src/main/resources/archetype-resources/core/pom.xml index b688a8246..780651f02 100644 --- a/templates/server/src/main/resources/archetype-resources/core/pom.xml +++ b/templates/server/src/main/resources/archetype-resources/core/pom.xml @@ -143,6 +143,10 @@ org.mariadb.jdbc mariadb-java-client 1.5.4 +#elseif ($dbType == 'hana') + com.sap.cloud.db.jdbc + ngdbc + 2.3.48 #elseif ($dbType == 'oracle') com.oracle.jdbc ojdbc8 diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties index ae4cfce1b..e30756442 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties @@ -39,6 +39,10 @@ spring.datasource.username=${rootArtifactId} # spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect # spring.datasource.driver-class-name=org.mariadb.jdbc.Driver spring.datasource.username=${rootArtifactId} +#elseif ($dbType == 'hana') +# spring.jpa.database-platform=org.hibernate.dialect.HANAColumnStoreDialect +# spring.datasource.driver-class-name=com.sap.db.jdbc.Driver +spring.datasource.username=${rootArtifactId} #elseif ($dbType == 'oracle') # spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect # spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties index 6518f5fbd..5a32027ce 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties @@ -27,6 +27,9 @@ spring.datasource.url=jdbc:mysql://address=(protocol=tcp)(host=localhost)(port=3 #elseif ($dbType == 'mariadb') spring.datasource.password=todo spring.datasource.url=jdbc:mariadb://localhost:3306/db +#elseif ($dbType == 'hana') +spring.datasource.password=todo +spring.datasource.url=jdbc:sap://localhost:39015 #elseif ($dbType == 'oracle') spring.datasource.password=todo spring.datasource.url=jdbc:oracle:thin:@localhost:1521/XE diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/type/hana/V0001__Create_Sequence.sql b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/type/hana/V0001__Create_Sequence.sql new file mode 100644 index 000000000..49953d2cc --- /dev/null +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/type/hana/V0001__Create_Sequence.sql @@ -0,0 +1,18 @@ +-- Leave a large ID space reserved for master-data and test-data +CREATE SEQUENCE HIBERNATE_SEQUENCE START WITH 1000000; + +-- hana does not support Dateadd function out of the box so we add it here to be able to use it for master-data SQLs +CREATE FUNCTION DATEADD(IN DATETYPE NVARCHAR(256), IN NUMBER INTEGER, IN TS TIMESTAMP) +RETURNS TSADD TIMESTAMP +AS +BEGIN + IF :DATETYPE = 'DAY' + THEN + TSADD = ADD_DAYS(:TS, :NUMBER); + ELSEIF :DATETYPE = 'HOUR' + THEN + TSADD = ADD_SECONDS(:TS, :NUMBER * 3600); + ELSE + SIGNAL SQL_ERROR_CODE 10000 SET MESSAGE_TEXT = 'Unsupported date type: ' || :DATETYPE; + END IF; +END; \ No newline at end of file diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/type/hana/V0002__Create_RevInfo.sql b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/type/hana/V0002__Create_RevInfo.sql new file mode 100644 index 000000000..38b650b38 --- /dev/null +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/type/hana/V0002__Create_RevInfo.sql @@ -0,0 +1,7 @@ +-- *** RevInfo (Commit log for envers audit trail) *** +CREATE COLUMN TABLE RevInfo( + id BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1), + "timestamp" BIGINT NOT NULL, + userLogin VARCHAR(255), + PRIMARY KEY (ID) +); diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/type/hana/V0003__Create_BinaryObject.sql b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/type/hana/V0003__Create_BinaryObject.sql new file mode 100644 index 000000000..b00b7863a --- /dev/null +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/type/hana/V0003__Create_BinaryObject.sql @@ -0,0 +1,9 @@ +-- *** BinaryObject (BLOBs) *** +CREATE TABLE BinaryObject ( + id BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY, + modificationCounter INTEGER NOT NULL, + content CLOB, + filesize BIGINT NOT NULL, + mimeType VARCHAR(255), + CONSTRAINT PK_BinaryObject_id PRIMARY KEY(ID) +); From a1c84e33c74b4329bb0a2708642ae2f7fced779b Mon Sep 17 00:00:00 2001 From: Joerg Hohwiller Date: Mon, 20 Aug 2018 14:26:57 +0200 Subject: [PATCH 2/3] #671: rewview rework --- .../resources/db/type/hana/V0003__Create_BinaryObject.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/type/hana/V0003__Create_BinaryObject.sql b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/type/hana/V0003__Create_BinaryObject.sql index b00b7863a..6463189dd 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/type/hana/V0003__Create_BinaryObject.sql +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/db/type/hana/V0003__Create_BinaryObject.sql @@ -1,8 +1,8 @@ -- *** BinaryObject (BLOBs) *** -CREATE TABLE BinaryObject ( +CREATE COLUMN TABLE BinaryObject ( id BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY, modificationCounter INTEGER NOT NULL, - content CLOB, + content BLOB, filesize BIGINT NOT NULL, mimeType VARCHAR(255), CONSTRAINT PK_BinaryObject_id PRIMARY KEY(ID) From 0e8b401ff1b1a0176f7cc2e6a4b216031400f767 Mon Sep 17 00:00:00 2001 From: Joerg Hohwiller Date: Tue, 11 Sep 2018 09:32:17 +0200 Subject: [PATCH 3/3] #671: included review improvement suggestions --- .../core/src/main/resources/application.properties | 4 ++++ .../core/src/main/resources/config/application.properties | 1 + 2 files changed, 5 insertions(+) diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties index e30756442..7f8510eb9 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/application.properties @@ -16,6 +16,10 @@ spring.jpa.hibernate.ddl-auto=validate # https://github.com/spring-projects/spring-boot/blob/d3c34ee3d1bfd3db4a98678c524e145ef9bca51c/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DatabaseDriver.java #if ($dbType == 'mariadb') spring.jpa.database=mysql +#elseif ($dbType == 'hana') +# Requires spring 5.1 - see https://jira.spring.io/browse/SPR-16460 +#spring.jpa.database=hana +spring.jpa.database=default #else spring.jpa.database=${dbType} #end diff --git a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties index 5a32027ce..44692641a 100644 --- a/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties +++ b/templates/server/src/main/resources/archetype-resources/core/src/main/resources/config/application.properties @@ -29,6 +29,7 @@ spring.datasource.password=todo spring.datasource.url=jdbc:mariadb://localhost:3306/db #elseif ($dbType == 'hana') spring.datasource.password=todo +# https://help.sap.com/viewer/0eec0d68141541d1b07893a39944924e/latest/en-US/b250e7fef8614ea0a0973d58eb73bda8.html spring.datasource.url=jdbc:sap://localhost:39015 #elseif ($dbType == 'oracle') spring.datasource.password=todo