From 7f6616e5d7e2759bc21fad0e363e4e356a8ec8f9 Mon Sep 17 00:00:00 2001 From: Jessica Wagantall Date: Fri, 6 Nov 2020 10:20:47 -0800 Subject: Move cps files to root dir Issue-ID: CIMAN-33 Signed-off-by: Jessica Wagantall --- cps-ri/lombok.config | 2 + cps-ri/pom.xml | 40 +++++++++++ .../java/org/onap/cps/spi/entities/Dataspace.java | 62 ++++++++++++++++ .../java/org/onap/cps/spi/entities/Fragment.java | 76 ++++++++++++++++++++ .../org/onap/cps/spi/entities/JsonDataEntity.java | 54 ++++++++++++++ .../org/onap/cps/spi/entities/ModuleEntity.java | 84 ++++++++++++++++++++++ .../cps/spi/impl/DataPersistencyServiceImpl.java | 69 ++++++++++++++++++ .../cps/spi/impl/ModelPersistencyServiceImpl.java | 57 +++++++++++++++ .../onap/cps/spi/repository/DataRepository.java | 28 ++++++++ .../cps/spi/repository/DataspaceRepository.java | 32 +++++++++ .../onap/cps/spi/repository/ModuleRepository.java | 29 ++++++++ cps-ri/src/main/resources/hibernate.properties | 1 + cps-ri/src/main/resources/logback-spring.xml | 48 +++++++++++++ cps-ri/src/main/resources/schema.sql | 63 ++++++++++++++++ 14 files changed, 645 insertions(+) create mode 100644 cps-ri/lombok.config create mode 100644 cps-ri/pom.xml create mode 100644 cps-ri/src/main/java/org/onap/cps/spi/entities/Dataspace.java create mode 100644 cps-ri/src/main/java/org/onap/cps/spi/entities/Fragment.java create mode 100644 cps-ri/src/main/java/org/onap/cps/spi/entities/JsonDataEntity.java create mode 100644 cps-ri/src/main/java/org/onap/cps/spi/entities/ModuleEntity.java create mode 100644 cps-ri/src/main/java/org/onap/cps/spi/impl/DataPersistencyServiceImpl.java create mode 100644 cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistencyServiceImpl.java create mode 100644 cps-ri/src/main/java/org/onap/cps/spi/repository/DataRepository.java create mode 100644 cps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java create mode 100644 cps-ri/src/main/java/org/onap/cps/spi/repository/ModuleRepository.java create mode 100644 cps-ri/src/main/resources/hibernate.properties create mode 100644 cps-ri/src/main/resources/logback-spring.xml create mode 100644 cps-ri/src/main/resources/schema.sql (limited to 'cps-ri') diff --git a/cps-ri/lombok.config b/cps-ri/lombok.config new file mode 100644 index 000000000..a23edb413 --- /dev/null +++ b/cps-ri/lombok.config @@ -0,0 +1,2 @@ +config.stopBubbling = true +lombok.addLombokGeneratedAnnotation = true \ No newline at end of file diff --git a/cps-ri/pom.xml b/cps-ri/pom.xml new file mode 100644 index 000000000..2c28212af --- /dev/null +++ b/cps-ri/pom.xml @@ -0,0 +1,40 @@ + + 4.0.0 + + org.onap.cps + cps-parent + 0.0.1-SNAPSHOT + ../cps-parent/pom.xml + + cps-ri + + + + ${project.groupId} + cps-service + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-validation + + + org.postgresql + postgresql + + + + com.vladmihalcea + hibernate-types-52 + + + org.projectlombok + lombok + + + diff --git a/cps-ri/src/main/java/org/onap/cps/spi/entities/Dataspace.java b/cps-ri/src/main/java/org/onap/cps/spi/entities/Dataspace.java new file mode 100644 index 000000000..627a14467 --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/entities/Dataspace.java @@ -0,0 +1,62 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi.entities; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + + +/** + * Entity to store a dataspace. + */ +@Getter +@Setter +@Entity +@AllArgsConstructor +@NoArgsConstructor +@Table(name = "dataspace") +public class Dataspace { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @NotNull + @Column(columnDefinition = "text") + private String name; + + /** + * Initialize a Dataspace . + * + * @param name the Dataspace name. + */ + public Dataspace(String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/cps-ri/src/main/java/org/onap/cps/spi/entities/Fragment.java b/cps-ri/src/main/java/org/onap/cps/spi/entities/Fragment.java new file mode 100644 index 000000000..12422dc5f --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/entities/Fragment.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi.entities; + +import com.vladmihalcea.hibernate.type.json.JsonBinaryType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToOne; +import javax.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.hibernate.annotations.Type; +import org.hibernate.annotations.TypeDef; +import org.hibernate.annotations.TypeDefs; + +/** + * Entity to store a fragment. + */ +@Getter +@Setter +@Entity +@AllArgsConstructor +@NoArgsConstructor +@TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)}) +public class Fragment { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @NotNull + @Column(columnDefinition = "text") + private String xpath; + + @Type(type = "jsonb") + @Column(columnDefinition = "jsonb") + private String attributes; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "dataspace_id") + private Dataspace dataspace; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "anchor_id") + private Fragment anchorFragment; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "parent_id") + private Fragment parentFragment; +} diff --git a/cps-ri/src/main/java/org/onap/cps/spi/entities/JsonDataEntity.java b/cps-ri/src/main/java/org/onap/cps/spi/entities/JsonDataEntity.java new file mode 100644 index 000000000..413362e38 --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/entities/JsonDataEntity.java @@ -0,0 +1,54 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi.entities; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/** + * Entity to store a JSON data structure. + */ +@Getter +@Setter +@Entity +@AllArgsConstructor +@NoArgsConstructor +@Table(name = "JsonData") +public class JsonDataEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @Column + private String jsonStructure; + + public JsonDataEntity(String jsonStructure) { + this.jsonStructure = jsonStructure; + } +} diff --git a/cps-ri/src/main/java/org/onap/cps/spi/entities/ModuleEntity.java b/cps-ri/src/main/java/org/onap/cps/spi/entities/ModuleEntity.java new file mode 100644 index 000000000..d2130aeec --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/entities/ModuleEntity.java @@ -0,0 +1,84 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi.entities; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + + +/** + * Entity to store a yang module. + */ +@Getter +@Setter +@Entity +@AllArgsConstructor +@NoArgsConstructor +@Table(name = "module") +public class ModuleEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @NotNull + @Column + private String moduleContent; + + @NotNull + @Column + private String revision; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "dataspace_id", referencedColumnName = "ID") + private Dataspace dataspace; + + @NotNull + @Column + private String namespace; + + /** + * Initialize a module entity. + * + * @param namespace the module namespace. + * @param moduleContent the module content. + * @param revision the revision number of the module. + * @param dataspace the dataspace related to the module. + */ + public ModuleEntity(String namespace, String moduleContent, String revision, Dataspace dataspace) { + this.namespace = namespace; + this.moduleContent = moduleContent; + this.revision = revision; + this.dataspace = dataspace; + } +} \ No newline at end of file diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/DataPersistencyServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/DataPersistencyServiceImpl.java new file mode 100644 index 000000000..2b4f1357d --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/DataPersistencyServiceImpl.java @@ -0,0 +1,69 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi.impl; + +import org.onap.cps.spi.DataPersistencyService; +import org.onap.cps.spi.entities.JsonDataEntity; +import org.onap.cps.spi.repository.DataRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + + +@Component +public class DataPersistencyServiceImpl implements DataPersistencyService { + + @Autowired + private DataRepository dataRepository; + + /** + * Method to store a JSON data structure in the database. + * + * @param jsonStructure the JSON data structure. + * @return the entity identifier. + */ + @Override + public final Integer storeJsonStructure(final String jsonStructure) { + final JsonDataEntity jsonDataEntity = new JsonDataEntity(jsonStructure); + dataRepository.save(jsonDataEntity); + return jsonDataEntity.getId(); + } + + /* + * Return the JSON structure from the database using the object identifier. + * + * @param jsonStructureId the JSON object identifier. + * + * @return the JSON structure from the database as a string. + */ + @Override + public final String getJsonById(final int jsonStructureId) { + return dataRepository.getOne(jsonStructureId).getJsonStructure(); + } + + /** + * Delete the JSON structure from the database using the object identifier. + * + * @param jsonStructureId the JSON object identifier. + */ + @Override + public void deleteJsonById(int jsonStructureId) { + dataRepository.deleteById(jsonStructureId); + } +} diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistencyServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistencyServiceImpl.java new file mode 100644 index 000000000..01c7a7b53 --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/ModelPersistencyServiceImpl.java @@ -0,0 +1,57 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi.impl; + +import org.onap.cps.spi.ModelPersistencyService; +import org.onap.cps.spi.entities.Dataspace; +import org.onap.cps.spi.entities.ModuleEntity; +import org.onap.cps.spi.repository.DataspaceRepository; +import org.onap.cps.spi.repository.ModuleRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class ModelPersistencyServiceImpl implements ModelPersistencyService { + + + private final ModuleRepository moduleRepository; + + private final DataspaceRepository dataspaceRepository; + + @Autowired + public ModelPersistencyServiceImpl(final ModuleRepository moduleRepository, + final DataspaceRepository dataspaceRepository) { + this.moduleRepository = moduleRepository; + this.dataspaceRepository = dataspaceRepository; + } + + @Override + public void storeModule(final String namespace, final String moduleContent, final String revision, + final String dataspaceName) { + final Dataspace dataspace = new Dataspace(dataspaceName); + if (Boolean.FALSE.equals(dataspaceRepository.existsByName(dataspaceName))) { + dataspaceRepository.save(dataspace); + } + dataspace.setId(dataspaceRepository.findByName(dataspaceName).getId()); + final ModuleEntity moduleEntity = new ModuleEntity(namespace, moduleContent, revision, dataspace); + moduleRepository.save(moduleEntity); + } +} diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/DataRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/DataRepository.java new file mode 100644 index 000000000..f3dd58600 --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/DataRepository.java @@ -0,0 +1,28 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi.repository; + +import org.onap.cps.spi.entities.JsonDataEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface DataRepository extends JpaRepository { +} \ No newline at end of file diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java new file mode 100644 index 000000000..46a526610 --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/DataspaceRepository.java @@ -0,0 +1,32 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Bell Canada. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi.repository; + + +import org.onap.cps.spi.entities.Dataspace; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface DataspaceRepository extends JpaRepository { + Boolean existsByName(String name); //Checks if there are any records by name() + + Dataspace findByName(String name); +} \ No newline at end of file diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/ModuleRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/ModuleRepository.java new file mode 100644 index 000000000..f9078d7c1 --- /dev/null +++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/ModuleRepository.java @@ -0,0 +1,29 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi.repository; + + +import org.onap.cps.spi.entities.ModuleEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ModuleRepository extends JpaRepository { +} \ No newline at end of file diff --git a/cps-ri/src/main/resources/hibernate.properties b/cps-ri/src/main/resources/hibernate.properties new file mode 100644 index 000000000..a22fe63cf --- /dev/null +++ b/cps-ri/src/main/resources/hibernate.properties @@ -0,0 +1 @@ +hibernate.types.print.banner=false \ No newline at end of file diff --git a/cps-ri/src/main/resources/logback-spring.xml b/cps-ri/src/main/resources/logback-spring.xml new file mode 100644 index 000000000..8a4ae07c5 --- /dev/null +++ b/cps-ri/src/main/resources/logback-spring.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + ../log/${logName}.log + + ${logName}.%d{yyyy-MM-dd}.%i.log.zip + + ${maxFileSize} + ${maxHistory} + ${totalSizeCap} + + + ${debugPattern} + + + + + 256 + + true + + + + + + + + + + + + \ No newline at end of file diff --git a/cps-ri/src/main/resources/schema.sql b/cps-ri/src/main/resources/schema.sql new file mode 100644 index 000000000..6a76fbd19 --- /dev/null +++ b/cps-ri/src/main/resources/schema.sql @@ -0,0 +1,63 @@ +CREATE TABLE IF NOT EXISTS RELATION_TYPE +( + RELATION_TYPE TEXT NOT NULL, + ID SERIAL PRIMARY KEY +); + +CREATE TABLE IF NOT EXISTS DATASPACE +( + ID SERIAL PRIMARY KEY, + NAME TEXT NOT NULL, + CONSTRAINT "UQ_NAME" UNIQUE (NAME) +); + +CREATE TABLE IF NOT EXISTS SCHEMA_NODE +( + SCHEMA_NODE_IDENTIFIER TEXT NOT NULL, + ID SERIAL PRIMARY KEY +); + +CREATE TABLE IF NOT EXISTS FRAGMENT +( + ID BIGSERIAL PRIMARY KEY, + XPATH TEXT NOT NULL, + DATASPACE_ID INTEGER NOT NULL REFERENCES DATASPACE(ID), + ATTRIBUTES JSONB, + ANCHOR_ID BIGINT REFERENCES FRAGMENT(ID), + PARENT_ID BIGINT REFERENCES FRAGMENT(ID), + MODULE_SET_ID INTEGER REFERENCES MODULE_SET(ID), + SCHEMA_NODE_ID INTEGER REFERENCES SCHEMA_NODE(ID) +); + +CREATE TABLE IF NOT EXISTS RELATION +( + FROM_FRAGMENT_ID BIGINT NOT NULL REFERENCES FRAGMENT(ID), + TO_FRAGMENT_ID BIGINT NOT NULL REFERENCES FRAGMENT(ID), + RELATION_TYPE_ID INTEGER NOT NULL REFERENCES RELATION_TYPE(ID), + FROM_REL_XPATH TEXT NOT NULL, + TO_REL_XPATH TEXT NOT NULL, + CONSTRAINT RELATION_PKEY PRIMARY KEY (TO_FRAGMENT_ID, FROM_FRAGMENT_ID, RELATION_TYPE_ID) +); + +CREATE TABLE IF NOT EXISTS MODULE +( + NAMESPACE TEXT NOT NULL, + REVISION TEXT NOT NULL, + MODULE_CONTENT TEXT NOT NULL, + DATASPACE_ID BIGINT NOT NULL, + ID SERIAL PRIMARY KEY, + UNIQUE (NAMESPACE, REVISION), + CONSTRAINT module_dataspace FOREIGN KEY (DATASPACE_ID) REFERENCES DATASPACE (id) ON UPDATE CASCADE ON DELETE CASCADE +); + +CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_DATASPACE_ID_FK" ON FRAGMENT USING BTREE(DATASPACE_ID) ; +CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_MODULE_SET_ID_FK" ON FRAGMENT USING BTREE(MODULE_SET_ID) ; +CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_PARENT_ID_FK" ON FRAGMENT USING BTREE(PARENT_ID) ; +CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_ANCHOR_ID_FK" ON FRAGMENT USING BTREE(ANCHOR_ID) ; +CREATE INDEX IF NOT EXISTS "PERF_SCHEMA_NODE_SCHEMA_NODE_ID" ON SCHEMA_NODE USING BTREE(SCHEMA_NODE_IDENTIFIER) ; +CREATE INDEX IF NOT EXISTS "FKI_SCHEMA_NODE_ID_TO_ID" ON FRAGMENT USING BTREE(SCHEMA_NODE_ID) ; +CREATE INDEX IF NOT EXISTS "FKI_RELATION_TYPE_ID_FK" ON RELATION USING BTREE(RELATION_TYPE_ID); +CREATE INDEX IF NOT EXISTS "FKI_RELATIONS_FROM_ID_FK" ON RELATION USING BTREE(FROM_FRAGMENT_ID); +CREATE INDEX IF NOT EXISTS "FKI_RELATIONS_TO_ID_FK" ON RELATION USING BTREE(TO_FRAGMENT_ID); +CREATE INDEX IF NOT EXISTS "PERF_MODULE_SET_MODULE_SET_REFERENCE" ON MODULE_SET USING BTREE(MODULE_SET_REFERENCE) ; +CREATE UNIQUE INDEX IF NOT EXISTS "UQ_FRAGMENT_XPATH"ON FRAGMENT USING btree(xpath COLLATE pg_catalog."default" text_pattern_ops, dataspace_id); \ No newline at end of file -- cgit 1.2.3-korg