As Liquibase is used, JPA does not manage database definition.
Within Liquibase changelog, only Anchor and Fragment have BIGINT (Long)
IDs. Other entities have INTEGER IDs.
- Change AnchorEntity/AnchorRepository ID type to Long
- Change YangResourceEntity/YangResourceRepository and
ModuleReferenceRepository ID to Integer
- Modify datatypes of foreign key references in liquibase changelog to
use correct types for dataspace_id, schema_set_id, yang_resource_id
- Update test liquibase changelog
Issue-ID: CPS-1676
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: I26de6712b2e74d166fc5a48b1f8149de6a1e5199
Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
- private Integer id;
+ private Long id;
@NotNull
@Column
* @return a collection of FragmentEntities (trees) with descendants.
*/
public static Collection<FragmentEntity> toFragmentEntityTreesAcrossAnchors(
- final Map<Integer, AnchorEntity> anchorEntityPerId, final Collection<FragmentExtract> fragmentExtracts) {
+ final Map<Long, AnchorEntity> anchorEntityPerId, final Collection<FragmentExtract> fragmentExtracts) {
final Map<Long, FragmentEntity> fragmentEntityPerId = new HashMap<>();
for (final FragmentExtract fragmentExtract : fragmentExtracts) {
final AnchorEntity anchorEntity = anchorEntityPerId.get(fragmentExtract.getAnchorId());
Long getId();
- Integer getAnchorId();
+ Long getAnchorId();
String getXpath();
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Pantheon.tech
- * Modifications Copyright (C) 2021-2022 Nordix Foundation
+ * Modifications Copyright (C) 2021-2023 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
- private Long id;
+ private Integer id;
@NotNull
@Column
fragmentRepository.findExtractsWithDescendantsByIds(fragmentEntityIds, fetchDescendantsOption.getDepth());
if (anchorEntity == ALL_ANCHORS) {
- final Collection<Integer> anchorIds = fragmentExtracts.stream()
+ final Collection<Long> anchorIds = fragmentExtracts.stream()
.map(FragmentExtract::getAnchorId).collect(Collectors.toSet());
final List<AnchorEntity> anchorEntities = anchorRepository.findAllById(anchorIds);
- final Map<Integer, AnchorEntity> anchorEntityPerId = anchorEntities.stream()
+ final Map<Long, AnchorEntity> anchorEntityPerId = anchorEntities.stream()
.collect(Collectors.toMap(AnchorEntity::getId, Function.identity()));
return FragmentEntityArranger.toFragmentEntityTreesAcrossAnchors(anchorEntityPerId, fragmentExtracts);
}
final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
final SchemaSetEntity schemaSetEntity =
schemaSetRepository.getByDataspaceAndName(dataspaceEntity, schemaSetName);
- final List<Long> allYangResourceIds =
+ final List<Integer> allYangResourceIds =
yangResourceRepository.getResourceIdsByModuleReferences(allModuleReferences);
yangResourceRepository.insertSchemaSetIdYangResourceId(schemaSetEntity.getId(), allYangResourceIds);
}
import org.springframework.stereotype.Repository;
@Repository
-public interface AnchorRepository extends JpaRepository<AnchorEntity, Integer> {
+public interface AnchorRepository extends JpaRepository<AnchorEntity, Long> {
Optional<AnchorEntity> findByDataspaceAndName(DataspaceEntity dataspaceEntity, String name);
new DataNodeNotFoundException(anchorEntity.getDataspace().getName(), anchorEntity.getName(), xpath));\r
}\r
\r
- List<FragmentEntity> findByAnchorIdAndXpathIn(int anchorId, String[] xpaths);\r
+ List<FragmentEntity> findByAnchorIdAndXpathIn(long anchorId, String[] xpaths);\r
\r
default List<FragmentEntity> findByAnchorAndXpathIn(final AnchorEntity anchorEntity,\r
final Collection<String> xpaths) {\r
return findByDataspaceIdAndXpathIn(dataspaceEntity.getId(), xpaths.toArray(new String[0]));\r
}\r
\r
- boolean existsByAnchorId(int anchorId);\r
+ boolean existsByAnchorId(long anchorId);\r
\r
@Query("SELECT f FROM FragmentEntity f WHERE anchor = :anchor")\r
List<FragmentExtract> findAllExtractsByAnchor(@Param("anchor") AnchorEntity anchorEntity);\r
\r
@Modifying\r
@Query(value = "DELETE FROM fragment WHERE anchor_id = ANY (:anchorIds)", nativeQuery = true)\r
- void deleteByAnchorIdIn(@Param("anchorIds") int[] anchorIds);\r
+ void deleteByAnchorIdIn(@Param("anchorIds") long[] anchorIds);\r
\r
default void deleteByAnchorIn(final Collection<AnchorEntity> anchorEntities) {\r
- deleteByAnchorIdIn(anchorEntities.stream().map(AnchorEntity::getId).mapToInt(id -> id).toArray());\r
+ deleteByAnchorIdIn(anchorEntities.stream().map(AnchorEntity::getId).mapToLong(id -> id).toArray());\r
}\r
\r
@Modifying\r
@Query(value = "DELETE FROM fragment WHERE anchor_id = :anchorId AND xpath = ANY (:xpaths)", nativeQuery = true)\r
- void deleteByAnchorIdAndXpaths(@Param("anchorId") int anchorId, @Param("xpaths") String[] xpaths);\r
+ void deleteByAnchorIdAndXpaths(@Param("anchorId") long anchorId, @Param("xpaths") String[] xpaths);\r
\r
- default void deleteByAnchorIdAndXpaths(final int anchorId, final Collection<String> xpaths) {\r
+ default void deleteByAnchorIdAndXpaths(final long anchorId, final Collection<String> xpaths) {\r
deleteByAnchorIdAndXpaths(anchorId, xpaths.toArray(new String[0]));\r
}\r
\r
@Modifying\r
@Query(value = "DELETE FROM fragment f WHERE anchor_id = :anchorId AND xpath LIKE ANY (:xpathPatterns)",\r
nativeQuery = true)\r
- void deleteByAnchorIdAndXpathLikeAny(@Param("anchorId") int anchorId,\r
+ void deleteByAnchorIdAndXpathLikeAny(@Param("anchorId") long anchorId,\r
@Param("xpathPatterns") String[] xpathPatterns);\r
\r
- default void deleteListsByAnchorIdAndXpaths(int anchorId, Collection<String> xpaths) {\r
+ default void deleteListsByAnchorIdAndXpaths(long anchorId, Collection<String> xpaths) {\r
final String[] listXpathPatterns = xpaths.stream().map(xpath -> xpath + "[%").toArray(String[]::new);\r
deleteByAnchorIdAndXpathLikeAny(anchorId, listXpathPatterns);\r
}\r
\r
@Query(value = "SELECT xpath FROM fragment WHERE anchor_id = :anchorId AND xpath = ANY (:xpaths)",\r
nativeQuery = true)\r
- List<String> findAllXpathByAnchorIdAndXpathIn(@Param("anchorId") int anchorId,\r
+ List<String> findAllXpathByAnchorIdAndXpathIn(@Param("anchorId") long anchorId,\r
@Param("xpaths") String[] xpaths);\r
\r
default List<String> findAllXpathByAnchorAndXpathIn(final AnchorEntity anchorEntity,\r
+ "FROM fragment f INNER JOIN parent_search p ON f.id = p.id",\r
nativeQuery = true\r
)\r
- List<FragmentExtract> findExtractsWithDescendants(@Param("anchorId") int anchorId,\r
+ List<FragmentExtract> findExtractsWithDescendants(@Param("anchorId") long anchorId,\r
@Param("xpaths") String[] xpaths,\r
@Param("maxDepth") int maxDepth);\r
\r
- default List<FragmentExtract> findExtractsWithDescendants(final int anchorId, final Collection<String> xpaths,\r
+ default List<FragmentExtract> findExtractsWithDescendants(final long anchorId, final Collection<String> xpaths,\r
final int maxDepth) {\r
return findExtractsWithDescendants(anchorId, xpaths.toArray(new String[0]), maxDepth);\r
}\r
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.springframework.stereotype.Repository;
@Repository
-public interface ModuleReferenceRepository extends JpaRepository<YangResourceEntity, Long>, ModuleReferenceQuery {}
+public interface ModuleReferenceRepository extends JpaRepository<YangResourceEntity, Integer>, ModuleReferenceQuery {}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
public interface SchemaSetYangResourceRepository {
- void insertSchemaSetIdYangResourceId(final Integer schemaSetId, final List<Long> yangResourceId);
+ void insertSchemaSetIdYangResourceId(final Integer schemaSetId, final List<Integer> yangResourceIds);
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
private EntityManager entityManager;
@Override
- public void insertSchemaSetIdYangResourceId(final Integer schemaSetId, final List<Long> yangResourceIds) {
+ public void insertSchemaSetIdYangResourceId(final Integer schemaSetId, final List<Integer> yangResourceIds) {
final Session session = entityManager.unwrap(Session.class);
session.doWork(connection -> {
try (PreparedStatement preparedStatement = connection.prepareStatement(
"INSERT INTO SCHEMA_SET_YANG_RESOURCES (SCHEMA_SET_ID, YANG_RESOURCE_ID) VALUES ( ?, ?)")) {
int sqlQueryCount = 1;
- for (final long yangResourceId : yangResourceIds) {
+ for (final int yangResourceId : yangResourceIds) {
preparedStatement.setInt(1, schemaSetId);
- preparedStatement.setLong(2, yangResourceId);
+ preparedStatement.setInt(2, yangResourceId);
preparedStatement.addBatch();
if (sqlQueryCount % MAX_INSERT_BATCH_SIZE == 0 || sqlQueryCount == yangResourceIds.size()) {
preparedStatement.executeBatch();
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
public interface YangResourceNativeRepository {
- List<Long> getResourceIdsByModuleReferences(Collection<ModuleReference> moduleReferences);
+ List<Integer> getResourceIdsByModuleReferences(Collection<ModuleReference> moduleReferences);
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@Override
@Transactional
- public List<Long> getResourceIdsByModuleReferences(final Collection<ModuleReference> moduleReferences) {
+ public List<Integer> getResourceIdsByModuleReferences(final Collection<ModuleReference> moduleReferences) {
if (moduleReferences.isEmpty()) {
return Collections.emptyList();
}
final Query query = entityManager.createNativeQuery(getCombinedSelectSqlQuery(moduleReferences))
.unwrap(org.hibernate.query.NativeQuery.class)
- .addScalar("id", StandardBasicTypes.LONG);
- final List<Long> yangResourceIds = query.getResultList();
+ .addScalar("id", StandardBasicTypes.INTEGER);
+ final List<Integer> yangResourceIds = query.getResultList();
if (yangResourceIds.size() != moduleReferences.size()) {
log.warn("ModuleReferences size : {} and QueryResult size : {}", moduleReferences.size(),
yangResourceIds.size());
import org.springframework.stereotype.Repository;
@Repository
-public interface YangResourceRepository extends JpaRepository<YangResourceEntity, Long>,
+public interface YangResourceRepository extends JpaRepository<YangResourceEntity, Integer>,
YangResourceNativeRepository, SchemaSetYangResourceRepository {
List<YangResourceEntity> findAllByChecksumIn(String[] checksums);
final Session session = getSession(sessionId);
final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
final AnchorEntity anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
- final int anchorId = anchorEntity.getId();
+ final long anchorId = anchorEntity.getId();
log.debug("Attempting to lock anchor {} for session {}", anchorName, sessionId);
session.get(AnchorEntity.class, anchorId, LockMode.PESSIMISTIC_WRITE);
log.info("Anchor {} successfully locked", anchorName);
file: changelog/db/changes/18-cascade-delete-fragment-children.yaml
- include:
file: changelog/db/changes/19-delete-not-required-dataspace-id-from-fragment.yaml
+ - include:
+ file: changelog/db/changes/20-change-foreign-key-id-types-to-integer.yaml
--- /dev/null
+# ============LICENSE_START=======================================================
+# Copyright (C) 2023 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=========================================================
+
+databaseChangeLog:
+ - changeSet:
+ author: cps
+ id: 20
+ changes:
+ - modifyDataType:
+ columnName: dataspace_id
+ newDataType: INTEGER
+ tableName: schema_set
+ - modifyDataType:
+ columnName: schema_set_id
+ newDataType: INTEGER
+ tableName: schema_set_yang_resources
+ - modifyDataType:
+ columnName: yang_resource_id
+ newDataType: INTEGER
+ tableName: schema_set_yang_resources
+ rollback:
+ - modifyDataType:
+ columnName: dataspace_id
+ newDataType: BIGINT
+ tableName: schema_set
+ - modifyDataType:
+ columnName: schema_set_id
+ newDataType: BIGINT
+ tableName: schema_set_yang_resources
+ - modifyDataType:
+ columnName: yang_resource_id
+ newDataType: BIGINT
+ tableName: schema_set_yang_resources
constraints:
nullable: false
name: dataspace_id
- type: BIGINT
+ type: INTEGER
tableName: schema_set
- changeSet:
id: 1-6
constraints:
nullable: false
name: schema_set_id
- type: BIGINT
+ type: INTEGER
- column:
constraints:
nullable: false
name: yang_resource_id
- type: BIGINT
+ type: INTEGER
tableName: schema_set_yang_resources
- changeSet:
id: 1-10