fix(manager-api-jpa): update DDL initialiser code
fix(distro-tomcat): ensure Postgres does not autocommit on Tomcat
refactor: prod JPA/SQL bootstrapper early
Fix init issues on Tomcat
MODIFY
distro/data/src/main/resources/ddls/apiman_h2.ddl
distro/data/src/main/resources/ddls/apiman_h2.ddl
-- Update Database Script
-- *********************************************************************
-- Change Log: /Users/msavy/oss/apiman/apiman/distro/ddl/src/main/liquibase/master.xml
--- Ran at: 06/10/2021, 18:44
--- Against: sa@offline:h2?version=1.4.200&caseSensitive=true&changeLogFile=/Users/msavy/oss/apiman/apiman/distro/ddl/target/changelog/h2/databasechangelog.csv
--- Liquibase version: 4.4.3
--- *********************************************************************
-
--- "support" JSON
-CREATE domain IF NOT EXISTS json AS text;
-CREATE domain IF NOT EXISTS jsonb AS other;
-
--- *********************************************************************
--- Update Database Script
--- *********************************************************************
--- Change Log: /Users/msavy/oss/apiman/apiman/distro/ddl/src/main/liquibase/master.xml
--- Ran at: 06/10/2021, 19:01
--- Against: sa@offline:h2?version=1.4.200&caseSensitive=true&changeLogFile=/Users/msavy/oss/apiman/apiman/distro/ddl/target/changelog/h2/databasechangelog.csv
+-- Ran at: 21/10/2021, 17:08
+-- Against: sa@offline:h2?version=1.4.199&caseSensitive=true&changeLogFile=/Users/msavy/oss/apiman/apiman/distro/ddl/target/changelog/h2/databasechangelog.csv
-- Liquibase version: 4.4.3
-- *********************************************************************
@@ -281,6 +268,10 @@ CREATE INDEX IDX_FK_contracts_s ON contracts(apiv_id);
-- Changeset src/main/liquibase/current/200-apiman-manager-api.db.indexes.changelog.xml::createIndex-18::apiman
CREATE INDEX IDX_FK_contracts_a ON contracts(clientv_id);
+-- Changeset src/main/liquibase/current/201-add-json-type.changelog.xml::h2-json-type::msavy marc@blackparrotlabs.io
+-- H2 JSON field (needed for versions older than 1.4.200)
+CREATE domain IF NOT EXISTS json AS other;
+
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::dev-portal-2-initial-changeset-6::msavy marc@blackparrotlabs.io (generated)
CREATE TABLE developer_mappings (developer_id VARCHAR(255) NOT NULL, client_id VARCHAR(255) NOT NULL, organization_id VARCHAR(255) NOT NULL, CONSTRAINT PK_DEVELOPER_MAPPINGS PRIMARY KEY (developer_id, client_id, organization_id));
@@ -348,7 +339,7 @@ ALTER TABLE notification_category_preferences ADD CONSTRAINT FKaq4x0n83d83xevui0
ALTER TABLE developer_mappings ADD CONSTRAINT FKhl2dwc4m0kvisedxfb9crceqd FOREIGN KEY (developer_id) REFERENCES developers (id);
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633441143380-4::msavy (generated)
-CREATE TABLE KeyValueTag (id BIGINT AUTO_INCREMENT NOT NULL, key VARCHAR(255) NOT NULL, value VARCHAR(255), CONSTRAINT KeyValueTagPK PRIMARY KEY (id));
+CREATE TABLE kv_tags (id BIGINT AUTO_INCREMENT NOT NULL, key VARCHAR(255) NOT NULL, value VARCHAR(255), CONSTRAINT kv_tagsPK PRIMARY KEY (id));
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633441143380-5::msavy (generated)
CREATE TABLE api_tag (api_id VARCHAR(255) NOT NULL, org_id VARCHAR(255) NOT NULL, tag_id BIGINT NOT NULL, CONSTRAINT PK_API_TAG PRIMARY KEY (api_id, org_id, tag_id));
@@ -366,7 +357,8 @@ ALTER TABLE blob_store ADD CONSTRAINT UC_BLOB_STOREID_COL UNIQUE (id);
ALTER TABLE blob_store ADD CONSTRAINT UK_4jee67ekw7s4y8spoc58i4dsf UNIQUE (hash, mime_type, name);
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-15::msavy (generated)
-ALTER TABLE api_tag ADD CONSTRAINT FK2h64maqscweorti1hta9josl2 FOREIGN KEY (tag_id) REFERENCES KeyValueTag (id);
+ALTER TABLE api_tag ADD CONSTRAINT FK2h64maqscweorti1hta9josl2 FOREIGN KEY (tag_id) REFERENCES kv_tags (id);
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-16::msavy (generated)
ALTER TABLE api_tag ADD CONSTRAINT FKlpr8yu65omneju5297uqthb6k FOREIGN KEY (api_id, org_id) REFERENCES apis (id, organization_id);
+

MODIFY
distro/data/src/main/resources/ddls/apiman_mssql15.ddl
distro/data/src/main/resources/ddls/apiman_mssql15.ddl
-- Update Database Script
-- *********************************************************************
-- Change Log: /Users/msavy/oss/apiman/apiman/distro/ddl/src/main/liquibase/master.xml
--- Ran at: 21/10/2021, 12:57
+-- Ran at: 21/10/2021, 17:08
-- Against: apiman@offline:mssql?version=15&caseSensitive=true&catalog=apiman&changeLogFile=/Users/msavy/oss/apiman/apiman/distro/ddl/target/changelog/mssql/databasechangelog.csv
-- Liquibase version: 4.4.3
-- *********************************************************************
@@ -443,7 +443,7 @@ ALTER TABLE developer_mappings ADD CONSTRAINT FKhl2dwc4m0kvisedxfb9crceqd FOREIG
GO
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633441143380-4::msavy (generated)
-CREATE TABLE KeyValueTag (id bigint IDENTITY (1, 1) NOT NULL, [key] varchar(255) NOT NULL, value varchar(255), CONSTRAINT KeyValueTagPK PRIMARY KEY (id))
+CREATE TABLE kv_tags (id bigint IDENTITY (1, 1) NOT NULL, [key] varchar(255) NOT NULL, value varchar(255), CONSTRAINT kv_tagsPK PRIMARY KEY (id))
GO
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633441143380-5::msavy (generated)
@@ -467,7 +467,7 @@ ALTER TABLE blob_store ADD CONSTRAINT UK_4jee67ekw7s4y8spoc58i4dsf UNIQUE (hash,
GO
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-15::msavy (generated)
-ALTER TABLE api_tag ADD CONSTRAINT FK2h64maqscweorti1hta9josl2 FOREIGN KEY (tag_id) REFERENCES KeyValueTag (id)
+ALTER TABLE api_tag ADD CONSTRAINT FK2h64maqscweorti1hta9josl2 FOREIGN KEY (tag_id) REFERENCES kv_tags (id)
GO
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-16::msavy (generated)

MODIFY
distro/data/src/main/resources/ddls/apiman_mysql8.ddl
distro/data/src/main/resources/ddls/apiman_mysql8.ddl
-- Update Database Script
-- *********************************************************************
-- Change Log: /Users/msavy/oss/apiman/apiman/distro/ddl/src/main/liquibase/master.xml
--- Ran at: 21/10/2021, 13:43
+-- Ran at: 21/10/2021, 17:09
-- Against: apiman@offline:mysql?version=8&caseSensitive=true&catalog=apiman&changeLogFile=/Users/msavy/oss/apiman/apiman/distro/ddl/target/changelog/mysql/databasechangelog.csv
-- Liquibase version: 4.4.3
-- *********************************************************************
@@ -337,7 +337,7 @@ ALTER TABLE notification_category_preferences ADD CONSTRAINT FKaq4x0n83d83xevui0
ALTER TABLE developer_mappings ADD CONSTRAINT FKhl2dwc4m0kvisedxfb9crceqd FOREIGN KEY (developer_id) REFERENCES developers (id);
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633441143380-4::msavy (generated)
-CREATE TABLE KeyValueTag (id BIGINT AUTO_INCREMENT NOT NULL, `key` VARCHAR(255) NOT NULL, value VARCHAR(255) NULL, CONSTRAINT KeyValueTagPK PRIMARY KEY (id));
+CREATE TABLE kv_tags (id BIGINT AUTO_INCREMENT NOT NULL, `key` VARCHAR(255) NOT NULL, value VARCHAR(255) NULL, CONSTRAINT kv_tagsPK PRIMARY KEY (id));
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633441143380-5::msavy (generated)
CREATE TABLE api_tag (api_id VARCHAR(255) NOT NULL, org_id VARCHAR(255) NOT NULL, tag_id BIGINT NOT NULL, CONSTRAINT PK_API_TAG PRIMARY KEY (api_id, org_id, tag_id));
@@ -355,7 +355,7 @@ ALTER TABLE blob_store ADD CONSTRAINT UC_BLOB_STOREID_COL UNIQUE (id);
ALTER TABLE blob_store ADD CONSTRAINT UK_4jee67ekw7s4y8spoc58i4dsf UNIQUE (hash, mime_type, name);
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-15::msavy (generated)
-ALTER TABLE api_tag ADD CONSTRAINT FK2h64maqscweorti1hta9josl2 FOREIGN KEY (tag_id) REFERENCES KeyValueTag (id);
+ALTER TABLE api_tag ADD CONSTRAINT FK2h64maqscweorti1hta9josl2 FOREIGN KEY (tag_id) REFERENCES kv_tags (id);
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-16::msavy (generated)
ALTER TABLE api_tag ADD CONSTRAINT FKlpr8yu65omneju5297uqthb6k FOREIGN KEY (api_id, org_id) REFERENCES apis (id, organization_id);

MODIFY
distro/data/src/main/resources/ddls/apiman_oracle19.ddl
distro/data/src/main/resources/ddls/apiman_oracle19.ddl
-- Update Database Script
-- *********************************************************************
-- Change Log: /Users/msavy/oss/apiman/apiman/distro/ddl/src/main/liquibase/master.xml
--- Ran at: 21/10/2021, 12:57
+-- Ran at: 21/10/2021, 17:08
-- Against: apiman@offline:oracle?version=19&caseSensitive=true&changeLogFile=/Users/msavy/oss/apiman/apiman/distro/ddl/target/changelog/oracle/databasechangelog.csv
-- Liquibase version: 4.4.3
-- *********************************************************************
@@ -332,7 +332,7 @@ ALTER TABLE notification_category_preferences ADD CONSTRAINT FKaq4x0n83d83xevui0
ALTER TABLE developer_mappings ADD CONSTRAINT FKhl2dwc4m0kvisedxfb9crceqd FOREIGN KEY (developer_id) REFERENCES developers (id);
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633441143380-4::msavy (generated)
-CREATE TABLE KeyValueTag (id NUMBER(38, 0) GENERATED BY DEFAULT AS IDENTITY NOT NULL, key VARCHAR2(255) NOT NULL, value VARCHAR2(255), CONSTRAINT KeyValueTagPK PRIMARY KEY (id));
+CREATE TABLE kv_tags (id NUMBER(38, 0) GENERATED BY DEFAULT AS IDENTITY NOT NULL, key VARCHAR2(255) NOT NULL, value VARCHAR2(255), CONSTRAINT kv_tagsPK PRIMARY KEY (id));
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633441143380-5::msavy (generated)
CREATE TABLE api_tag (api_id VARCHAR2(255) NOT NULL, org_id VARCHAR2(255) NOT NULL, tag_id NUMBER(38, 0) NOT NULL, CONSTRAINT PK_API_TAG PRIMARY KEY (api_id, org_id, tag_id));
@@ -350,7 +350,7 @@ ALTER TABLE blob_store ADD CONSTRAINT UC_BLOB_STOREID_COL UNIQUE (id);
ALTER TABLE blob_store ADD CONSTRAINT UK_4jee67ekw7s4y8spoc58i4dsf UNIQUE (hash, mime_type, name);
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-15::msavy (generated)
-ALTER TABLE api_tag ADD CONSTRAINT FK2h64maqscweorti1hta9josl2 FOREIGN KEY (tag_id) REFERENCES KeyValueTag (id);
+ALTER TABLE api_tag ADD CONSTRAINT FK2h64maqscweorti1hta9josl2 FOREIGN KEY (tag_id) REFERENCES kv_tags (id);
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-16::msavy (generated)
ALTER TABLE api_tag ADD CONSTRAINT FKlpr8yu65omneju5297uqthb6k FOREIGN KEY (api_id, org_id) REFERENCES apis (id, organization_id);

MODIFY
distro/data/src/main/resources/ddls/apiman_postgresql9.ddl
distro/data/src/main/resources/ddls/apiman_postgresql9.ddl
-- Update Database Script
-- *********************************************************************
-- Change Log: /Users/msavy/oss/apiman/apiman/distro/ddl/src/main/liquibase/master.xml
--- Ran at: 21/10/2021, 12:57
+-- Ran at: 21/10/2021, 17:08
-- Against: apiman@offline:postgresql?version=9.6.23&caseSensitive=true&changeLogFile=/Users/msavy/oss/apiman/apiman/distro/ddl/target/changelog/postgresql/databasechangelog.csv
-- Liquibase version: 4.4.3
-- *********************************************************************
@@ -335,11 +335,29 @@ ALTER TABLE notification_category_preferences ADD CONSTRAINT "FKaq4x0n83d83xevui
ALTER TABLE developer_mappings ADD CONSTRAINT "FKhl2dwc4m0kvisedxfb9crceqd" FOREIGN KEY (developer_id) REFERENCES developers (id);
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633441143380-4::msavy (generated)
-CREATE TABLE "KeyValueTag" (id BIGSERIAL NOT NULL, key VARCHAR(255) NOT NULL, value VARCHAR(255), CONSTRAINT "KeyValueTagPK" PRIMARY KEY (id));
+CREATE TABLE kv_tags (id BIGSERIAL NOT NULL, key VARCHAR(255) NOT NULL, value VARCHAR(255), CONSTRAINT "kv_tagsPK" PRIMARY KEY (id));
-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633441143380-5::msavy (generated)
CREATE TABLE api_tag (api_id VARCHAR(255) NOT NULL, org_id VARCHAR(255) NOT NULL, tag_id BIGINT NOT NULL, CONSTRAINT api_tag_pkey PRIMARY KEY (api_id, org_id, tag_id));
+-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-6::msavy (generated)
+CREATE TABLE blob_store (id VARCHAR(255) NOT NULL, mrblobby OID NOT NULL, created_on TIMESTAMP WITHOUT TIME ZONE NOT NULL, hash BIGINT NOT NULL, mime_type VARCHAR(255) NOT NULL, modified_on TIMESTAMP WITHOUT TIME ZONE NOT NULL, name VARCHAR(255) NOT NULL, "references" INTEGER NOT NULL, CONSTRAINT "blob_storePK" PRIMARY KEY (id));
+
+-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-7::msavy (generated)
+CREATE TABLE outbox (id BIGSERIAL NOT NULL, event_version BIGINT NOT NULL, payload BYTEA NOT NULL, source VARCHAR(255) NOT NULL, subject VARCHAR(255) NOT NULL, time TIMESTAMP WITHOUT TIME ZONE NOT NULL, type VARCHAR(255) NOT NULL, CONSTRAINT "outboxPK" PRIMARY KEY (id));
+
+-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-8::msavy (generated)
+ALTER TABLE blob_store ADD CONSTRAINT UC_BLOB_STOREID_COL UNIQUE (id);
+
+-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-10::msavy (generated)
+ALTER TABLE blob_store ADD CONSTRAINT "UK_4jee67ekw7s4y8spoc58i4dsf" UNIQUE (hash, mime_type, name);
+
+-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-15::msavy (generated)
+ALTER TABLE api_tag ADD CONSTRAINT "FK2h64maqscweorti1hta9josl2" FOREIGN KEY (tag_id) REFERENCES kv_tags (id);
+
+-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-16::msavy (generated)
+ALTER TABLE api_tag ADD CONSTRAINT "FKlpr8yu65omneju5297uqthb6k" FOREIGN KEY (api_id, org_id) REFERENCES apis (id, organization_id);
+
-- Manual bits
CREATE OR REPLACE FUNCTION inttobool(num int, val bool) RETURNS bool AS '
BEGIN
@@ -375,21 +393,4 @@ CREATE OPERATOR = (
procedure = inttobool,
commutator = =,
negator = !=
-);-- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-6::msavy (generated)
-CREATE TABLE blob_store (id VARCHAR(255) NOT NULL, mrblobby OID NOT NULL, created_on TIMESTAMP WITHOUT TIME ZONE NOT NULL, hash BIGINT NOT NULL, mime_type VARCHAR(255) NOT NULL, modified_on TIMESTAMP WITHOUT TIME ZONE NOT NULL, name VARCHAR(255) NOT NULL, "references" INTEGER NOT NULL, CONSTRAINT "blob_storePK" PRIMARY KEY (id));
-
--- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-7::msavy (generated)
-CREATE TABLE outbox (id BIGSERIAL NOT NULL, event_version BIGINT NOT NULL, payload BYTEA NOT NULL, source VARCHAR(255) NOT NULL, subject VARCHAR(255) NOT NULL, time TIMESTAMP WITHOUT TIME ZONE NOT NULL, type VARCHAR(255) NOT NULL, CONSTRAINT "outboxPK" PRIMARY KEY (id));
-
--- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-8::msavy (generated)
-ALTER TABLE blob_store ADD CONSTRAINT UC_BLOB_STOREID_COL UNIQUE (id);
-
--- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-10::msavy (generated)
-ALTER TABLE blob_store ADD CONSTRAINT "UK_4jee67ekw7s4y8spoc58i4dsf" UNIQUE (hash, mime_type, name);
-
--- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-15::msavy (generated)
-ALTER TABLE api_tag ADD CONSTRAINT "FK2h64maqscweorti1hta9josl2" FOREIGN KEY (tag_id) REFERENCES "KeyValueTag" (id);
-
--- Changeset src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml::1633542267834-16::msavy (generated)
-ALTER TABLE api_tag ADD CONSTRAINT "FKlpr8yu65omneju5297uqthb6k" FOREIGN KEY (api_id, org_id) REFERENCES apis (id, organization_id);
-
+);
\ No newline at end of file

MODIFY
distro/ddl/src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml
distro/ddl/src/main/liquibase/current/20211002-154432-apiman3-dev-portal-2-initial.changelog.xml
</changeSet>
<!-- tagging bits -->
<changeSet author="msavy (generated)" id="1633441143380-4">
- <createTable tableName="KeyValueTag">
+ <createTable tableName="kv_tags">
<column autoIncrement="true" name="id" type="BIGINT">
- <constraints nullable="false" primaryKey="true" primaryKeyName="KeyValueTagPK"/>
+ <constraints nullable="false" primaryKey="true" primaryKeyName="kv_tagsPK"/>
</column>
<column name="key" type="VARCHAR(255)">
<constraints nullable="false"/>
<addUniqueConstraint columnNames="hash, mime_type, name" constraintName="UK_4jee67ekw7s4y8spoc58i4dsf" tableName="blob_store"/>
</changeSet>
<changeSet author="msavy (generated)" id="1633542267834-15">
- <addForeignKeyConstraint baseColumnNames="tag_id" baseTableName="api_tag" constraintName="FK2h64maqscweorti1hta9josl2" deferrable="false" initiallyDeferred="false" referencedColumnNames="id" referencedTableName="KeyValueTag" validate="true"/>
+ <addForeignKeyConstraint baseColumnNames="tag_id" baseTableName="api_tag" constraintName="FK2h64maqscweorti1hta9josl2" deferrable="false" initiallyDeferred="false" referencedColumnNames="id" referencedTableName="kv_tags" validate="true"/>
</changeSet>
<changeSet author="msavy (generated)" id="1633542267834-16">
<addForeignKeyConstraint baseColumnNames="api_id,org_id" baseTableName="api_tag" constraintName="FKlpr8yu65omneju5297uqthb6k" deferrable="false" initiallyDeferred="false" referencedColumnNames="id,organization_id" referencedTableName="apis" validate="true"/>

MODIFY
distro/tomcat/src/main/resources/overlay/conf/server.xml
distro/tomcat/src/main/resources/overlay/conf/server.xml
maxWaitMillis="10000"/>
</GlobalNamingResources>
+ <!-- Example PostgreSQL config
+ <Resource
+ name="apiman/datasources/apiman-manager"
+ url="jdbc:postgresql://localhost:5432/postgres"
+ username="postgres"
+ password="apiman-is-super-cool"
+ type="javax.sql.DataSource"
+ driverClassName="org.postgresql.Driver"
+ defaultAutoCommit="false"
+ maxTotal="100"
+ maxIdle="30"
+ maxWaitMillis="10000"/>
+ </GlobalNamingResources>
+ -->
+
<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.

MODIFY
manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/KeyValueTag.java
manager/api/beans/src/main/java/io/apiman/manager/api/beans/apis/KeyValueTag.java
@@ -6,6 +6,7 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+import javax.persistence.Table;
import org.hibernate.Hibernate;
import org.hibernate.annotations.NaturalId;
@@ -14,6 +15,7 @@ import org.hibernate.annotations.NaturalId;
* Simple tag with value.
*/
@Entity
+@Table(name = "kv_tags")
public class KeyValueTag {
@Id
@GeneratedValue

RENAME
manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/ApimanMySQL5Dialect.java
manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/ApimanMySQL8Dialect.java
@@ -17,7 +17,7 @@ package io.apiman.manager.api.jpa;
import java.sql.Types;
-import org.hibernate.dialect.MySQL5Dialect;
+import org.hibernate.dialect.MySQL8Dialect;
/**
* A custom mysql dialect to convert BOOLEAN to BIT(1). This is done automatically
@@ -25,12 +25,12 @@ import org.hibernate.dialect.MySQL5Dialect;
*
* @author eric.wittmann@redhat.com
*/
-public class ApimanMySQL5Dialect extends MySQL5Dialect {
+public class ApimanMySQL8Dialect extends MySQL8Dialect {
/**
* Constructor.
*/
- public ApimanMySQL5Dialect() {
+ public ApimanMySQL8Dialect() {
registerColumnType(Types.BOOLEAN, "BIT(1)"); //$NON-NLS-1$
}

RENAME
manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/ApimanOracle12Dialect.java
manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/ApimanOracle19Dialect.java
@@ -26,12 +26,12 @@ import org.hibernate.dialect.Oracle10gDialect;
* @author eric.wittmann@redhat.com
*/
@SuppressWarnings("nls")
-public class ApimanOracle12Dialect extends Oracle10gDialect {
+public class ApimanOracle19Dialect extends Oracle10gDialect {
/**
* Constructor.
*/
- public ApimanOracle12Dialect() {
+ public ApimanOracle19Dialect() {
}
/**

MODIFY
manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/ApimanPostgreSQLDialect.java
manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/ApimanPostgreSQLDialect.java
*/
package io.apiman.manager.api.jpa;
-import org.hibernate.dialect.PostgreSQL82Dialect;
+import org.hibernate.dialect.PostgreSQL95Dialect;
/**
* For consistency, a postgresql dialect in the same package as our H2 and MySQL
@@ -23,7 +23,7 @@ import org.hibernate.dialect.PostgreSQL82Dialect;
*
* @author eric.wittmann@redhat.com
*/
-public class ApimanPostgreSQLDialect extends PostgreSQL82Dialect {
+public class ApimanPostgreSQLDialect extends PostgreSQL95Dialect {
/**
* Constructor.

MODIFY
manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/EntityManagerFactoryAccessor.java
manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/EntityManagerFactoryAccessor.java
@@ -63,19 +63,20 @@ public class EntityManagerFactoryAccessor implements IEntityManagerFactoryAccess
}
// Get two specific properties from the System (for backward compatibility only)
- String s = properties.get("hibernate.hbm2ddl.auto"); //$NON-NLS-1$
+ String s = properties.get("hibernate.hbm2ddl.auto");
if (s == null) {
- s = "validate"; //$NON-NLS-1$
+ s = "validate";
}
- String autoValue = System.getProperty("apiman.hibernate.hbm2ddl.auto", s); //$NON-NLS-1$
- s = properties.get("hibernate.dialect"); //$NON-NLS-1$
+ String autoValue = System.getProperty("apiman.hibernate.hbm2ddl.auto", s);
+ s = properties.get("hibernate.dialect");
if (s == null) {
- s = "org.hibernate.dialect.H2Dialect"; //$NON-NLS-1$
+ s = "org.hibernate.dialect.H2Dialect";
}
- String dialect = System.getProperty("apiman.hibernate.dialect", s); //$NON-NLS-1$
- properties.put("hibernate.hbm2ddl.auto", autoValue); //$NON-NLS-1$
- properties.put("hibernate.dialect", dialect); //$NON-NLS-1$
- properties.put("hibernate.connection.handling_mode", "DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT");
+ String dialect = System.getProperty("apiman.hibernate.dialect", s);
+ properties.put("hibernate.hbm2ddl.auto", autoValue);
+ properties.put("hibernate.dialect", dialect);
+ properties.put("hibernate.globally_quoted_identifiers", "true");
+ //properties.put("hibernate.connection.handling_mode", "DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT");
// properties.put("hibernate.transaction.jta.platform", "com.atomikos.icatch.jta.hibernate4.AtomikosPlatform");
// First try using standard JPA to load the persistence unit. If that fails, then
@@ -87,10 +88,10 @@ public class EntityManagerFactoryAccessor implements IEntityManagerFactoryAccess
}
try {
- emf = Persistence.createEntityManagerFactory("apiman-manager-api-jpa", properties); //$NON-NLS-1$
+ emf = Persistence.createEntityManagerFactory("apiman-manager-api-jpa", properties);
} catch (Throwable t1) {
try {
- emf = new HibernatePersistenceProvider().createEntityManagerFactory("apiman-manager-api-jpa", properties); //$NON-NLS-1$
+ emf = new HibernatePersistenceProvider().createEntityManagerFactory("apiman-manager-api-jpa", properties);
} catch (Throwable t3) {
throw t1;
}

MODIFY
manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/JpaStorageInitializer.java
manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/JpaStorageInitializer.java
@@ -27,6 +27,7 @@ import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import javax.naming.InitialContext;
import javax.sql.DataSource;
@@ -49,6 +50,7 @@ import org.hibernate.dialect.PostgreSQL9Dialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.dialect.SQLServer2012Dialect;
import org.hibernate.dialect.SQLServerDialect;
+import org.jdbi.v3.core.Jdbi;
/**
* Initializes the database by installing the appropriate DDL for the database in
@@ -64,13 +66,17 @@ public class JpaStorageInitializer {
DB_TYPE_MAP.put(ApimanH2Dialect.class.getName(), "h2");
DB_TYPE_MAP.put(H2Dialect.class.getName(), "h2");
+ DB_TYPE_MAP.put("io.apiman.manager.api.jpa.ApimanMySQL5Dialect", "mysql8"); // compatibility but might need to drop this
+ DB_TYPE_MAP.put(ApimanMySQL8Dialect.class.getName(), "mysql8"); // Hmm
DB_TYPE_MAP.put(MySQLDialect.class.getName(), "mysql8");
DB_TYPE_MAP.put(MySQL8Dialect.class.getName(), "mysql8");
+ DB_TYPE_MAP.put(ApimanOracle19Dialect.class.getName(), "oracle19");
DB_TYPE_MAP.put(OracleDialect.class.getName(), "oracle19");
DB_TYPE_MAP.put(Oracle8iDialect.class.getName(), "oracle19");
DB_TYPE_MAP.put(Oracle9iDialect.class.getName(), "oracle19");
+ DB_TYPE_MAP.put(ApimanPostgreSQLDialect.class.getName(), "postgresql9");
DB_TYPE_MAP.put(PostgreSQLDialect.class.getName(), "postgresql9");
DB_TYPE_MAP.put(PostgreSQL81Dialect.class.getName(), "postgresql9");
DB_TYPE_MAP.put(PostgreSQL82Dialect.class.getName(), "postgresql9");
@@ -98,8 +104,6 @@ public class JpaStorageInitializer {
}
ds = lookupDS(dsJndiLocation);
-
-
dbType = DB_TYPE_MAP.get(hibernateDialect);
if (dbType == null) {
throw new RuntimeException("Unknown hibernate dialect configured: " + hibernateDialect);
@@ -134,8 +138,6 @@ public class JpaStorageInitializer {
Boolean isInitialized;
try {
- //ds.getConnection().setAutoCommit(false);
-
isInitialized = run.query("SELECT * FROM apis", new ResultSetHandler<Boolean>() {
@Override
public Boolean handle(ResultSet rs) throws SQLException {
@@ -143,7 +145,7 @@ public class JpaStorageInitializer {
}
});
} catch (SQLException e) {
- LOGGER.error(e);
+ LOGGER.trace("Is initialised error: {0}", e);
isInitialized = false;
}
@@ -156,18 +158,23 @@ public class JpaStorageInitializer {
ClassLoader cl = JpaStorageInitializer.class.getClassLoader();
URL resource = cl.getResource("ddls/apiman_" + dbType + ".ddl");
+ Objects.requireNonNull(resource, "DDLs are missing");
+ try {
try (InputStream is = resource.openStream()) {
LOGGER.info("=======================================");
LOGGER.info("Initializing Apiman Manager database. " + resource.getPath());
DdlParser ddlParser = new DdlParser();
List<String> statements = ddlParser.parse(is);
+ Jdbi jdbi = Jdbi.create(ds);
for (String sql : statements) {
LOGGER.info(sql);
- run.update(sql);
+ jdbi.useHandle(h -> {
+ h.createUpdate(sql).execute();
+ h.commit();
+ });
}
LOGGER.info("=======================================");
- //run.getDataSource().getConnection().commit();
-
+ }
} catch (Exception e) {
throw new RuntimeException(e);
}

MODIFY
manager/api/war/src/main/java/io/apiman/manager/api/war/WarApiManagerBootstrapperServlet.java
manager/api/war/src/main/java/io/apiman/manager/api/war/WarApiManagerBootstrapperServlet.java
@@ -18,6 +18,7 @@ package io.apiman.manager.api.war;
import io.apiman.common.config.ConfigFactory;
import io.apiman.common.logging.ApimanLoggerFactory;
import io.apiman.common.logging.IApimanLogger;
+import io.apiman.manager.api.core.IStorage;
import io.apiman.manager.api.exportimport.json.JsonImportReader;
import io.apiman.manager.api.exportimport.manager.StorageImportDispatcher;
import io.apiman.manager.api.exportimport.read.IImportReader;
@@ -49,6 +50,9 @@ public class WarApiManagerBootstrapperServlet extends HttpServlet {
@Inject
private StorageImportDispatcher importer;
+ @Inject
+ private IStorage storage;
+
private static Configuration config;
static {
config = ConfigFactory.createConfig();
@@ -59,6 +63,7 @@ public class WarApiManagerBootstrapperServlet extends HttpServlet {
*/
@Override
public void init() throws ServletException {
+ storage.toString();
Thread t = new Thread(() -> {
if (isImportEnabled()){
File dataDir = getDataDir();

fix(manager-api-jpa): update DDL initialiser code

fix(distro-tomcat): ensure Postgres does not autocommit on Tomcat

refactor: prod JPA/SQL bootstrapper early

Fix init issues on Tomcat