Skip to content

Commit

Permalink
Add internal entity link query
Browse files Browse the repository at this point in the history
  • Loading branch information
filiphr committed May 11, 2024
1 parent 82337ee commit 7154a2e
Show file tree
Hide file tree
Showing 19 changed files with 506 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void testStartToEnd() {
assertDatabaseSelects("StartProcessInstanceCmd",
"selectLatestProcessDefinitionByKey", 1L,
"selectVariablesByQuery", 1L,
"selectEntityLinksByRootScopeIdAndRootScopeType", 1L);
"selectEntityLinksByQuery", 1L);

assertDatabaseInserts("StartProcessInstanceCmd",
"HistoricActivityInstanceEntityImpl-bulk-with-3", 1L,
Expand All @@ -168,7 +168,7 @@ public void testVariablesAndPassthrough() {
assertDatabaseSelects("StartProcessInstanceCmd",
"selectLatestProcessDefinitionByKey", 1L,
"selectVariablesByQuery", 1L,
"selectEntityLinksByRootScopeIdAndRootScopeType", 1L);
"selectEntityLinksByQuery", 1L);
assertDatabaseInserts("StartProcessInstanceCmd",
"HistoricVariableInstanceEntityImpl-bulk-with-4", 1L,
"HistoricProcessInstanceEntityImpl", 1L,
Expand All @@ -188,7 +188,7 @@ public void testManyVariablesViaServiceTaskAndPassthroughs() {
assertDatabaseSelects("StartProcessInstanceCmd",
"selectLatestProcessDefinitionByKey", 1L,
"selectVariablesByQuery", 1L,
"selectEntityLinksByRootScopeIdAndRootScopeType", 1L);
"selectEntityLinksByQuery", 1L);
assertDatabaseInserts("StartProcessInstanceCmd",
"HistoricVariableInstanceEntityImpl-bulk-with-50", 1L,
"HistoricProcessInstanceEntityImpl", 1L,
Expand All @@ -208,7 +208,7 @@ public void testOnlyPassThroughs() {
assertDatabaseSelects("StartProcessInstanceCmd",
"selectLatestProcessDefinitionByKey", 1L,
"selectVariablesByQuery", 1L,
"selectEntityLinksByRootScopeIdAndRootScopeType", 1L);
"selectEntityLinksByQuery", 1L);
assertDatabaseInserts("StartProcessInstanceCmd",
"HistoricActivityInstanceEntityImpl-bulk-with-17", 1L,
"HistoricProcessInstanceEntityImpl", 1L);
Expand All @@ -227,7 +227,7 @@ public void testParallelForkAndJoin() {
assertDatabaseSelects("StartProcessInstanceCmd",
"selectLatestProcessDefinitionByKey", 1L,
"selectVariablesByQuery", 1L,
"selectEntityLinksByRootScopeIdAndRootScopeType", 1L);
"selectEntityLinksByQuery", 1L);
assertDatabaseInserts("StartProcessInstanceCmd",
"HistoricActivityInstanceEntityImpl-bulk-with-13", 1L,
"HistoricProcessInstanceEntityImpl", 1L);
Expand Down Expand Up @@ -288,7 +288,7 @@ public void testParallelForkAndJoinWithAsyncJobs() {
"selectById org.flowable.job.service.impl.persistence.entity.JobEntityImpl", 1L,
// Almost all selectXXXByExecutionId are needed when the process instance is deleted
"selectDeadLetterJobsByExecutionId", 1L,
"selectEntityLinksByRootScopeIdAndRootScopeType", 1L,
"selectEntityLinksByQuery", 1L,
"selectEventSubscriptionsByExecution", 1L,
"selectExecutionsWithSameRootProcessInstanceId", 1L,
"selectExternalWorkerJobsByExecutionId", 1L,
Expand Down Expand Up @@ -327,7 +327,7 @@ public void testNestedParallelForkAndJoin() {
assertDatabaseSelects("StartProcessInstanceCmd",
"selectLatestProcessDefinitionByKey", 1L,
"selectVariablesByQuery", 1L,
"selectEntityLinksByRootScopeIdAndRootScopeType", 1L);
"selectEntityLinksByQuery", 1L);

assertDatabaseInserts("StartProcessInstanceCmd",
"HistoricActivityInstanceEntityImpl-bulk-with-41", 1L,
Expand All @@ -347,7 +347,7 @@ public void testExclusiveGateway() {
assertDatabaseSelects("StartProcessInstanceCmd",
"selectLatestProcessDefinitionByKey", 1L,
"selectVariablesByQuery", 1L,
"selectEntityLinksByRootScopeIdAndRootScopeType", 1L);
"selectEntityLinksByQuery", 1L);
assertDatabaseInserts("StartProcessInstanceCmd",
"HistoricActivityInstanceEntityImpl-bulk-with-9", 1L,
"HistoricProcessInstanceEntityImpl", 1L,
Expand Down Expand Up @@ -407,7 +407,7 @@ public void testOneTaskProcess() {
// Start process instance
assertDatabaseSelects("StartProcessInstanceCmd",
"selectLatestProcessDefinitionByKey", 1L,
"selectEntityLinksByReferenceScopeIdAndType", 1L);
"selectEntityLinksByQuery", 1L);
assertDatabaseInserts("StartProcessInstanceCmd",
"ExecutionEntityImpl-bulk-with-2", 1L,
"TaskEntityImpl", 1L,
Expand Down Expand Up @@ -439,7 +439,7 @@ public void testOneTaskProcess() {
"selectTasksByExecutionId", 2L,
"selectVariablesByQuery", 2L,
"selectIdentityLinksByProcessInstance", 1L,
"selectEntityLinksByRootScopeIdAndRootScopeType", 1L,
"selectEntityLinksByQuery", 1L,
"selectEventSubscriptionsByExecution", 1L,
"selectTimerJobsByExecutionId", 1L,
"selectSuspendedJobsByExecutionId", 1L,
Expand Down Expand Up @@ -479,7 +479,7 @@ public void testOneTaskWithBoundaryTimerProcess() {
// Start process instance
assertDatabaseSelects("StartProcessInstanceCmd",
"selectLatestProcessDefinitionByKey", 1L,
"selectEntityLinksByReferenceScopeIdAndType", 1L);
"selectEntityLinksByQuery", 1L);

assertDatabaseInserts("StartProcessInstanceCmd",
"ExecutionEntityImpl-bulk-with-3", 1L,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,32 @@
*/
public interface EntityLinkService {

List<EntityLink> findEntityLinksByScopeIdAndType(String scopeId, String scopeType, String linkType);
default List<EntityLink> findEntityLinksByScopeIdAndType(String scopeId, String scopeType, String linkType) {
return createInternalEntityLinkQuery()
.scopeId(scopeId)
.scopeType(scopeType)
.linkType(linkType)
.list();
}

List<EntityLink> findEntityLinksByRootScopeIdAndRootType(String scopeId, String scopeType);
default List<EntityLink> findEntityLinksByRootScopeIdAndRootType(String scopeId, String scopeType) {
return createInternalEntityLinkQuery()
.rootScopeId(scopeId)
.rootScopeType(scopeType)
.list();
}

List<EntityLink> findEntityLinksWithSameRootScopeForScopeIdAndScopeType(String scopeId, String scopeType, String linkType);

List<EntityLink> findEntityLinksByReferenceScopeIdAndType(String referenceScopeId, String scopeType, String linkType);
default List<EntityLink> findEntityLinksByReferenceScopeIdAndType(String referenceScopeId, String scopeType, String linkType) {
return createInternalEntityLinkQuery()
.referenceScopeId(referenceScopeId)
.referenceScopeType(scopeType)
.linkType(linkType)
.list();
}

InternalEntityLinkQuery<EntityLink> createInternalEntityLinkQuery();

EntityLink createEntityLink();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* 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.
*/
package org.flowable.entitylink.api;

import java.util.List;

/**
* @author Filip Hrisafov
*/
public interface InternalEntityLinkQuery<E extends EntityLinkInfo> {

/**
* Query entity links with the given scope id.
*/
InternalEntityLinkQuery<E> scopeId(String scopeId);

/**
* Query entity links with the given scope definition id.
*/
InternalEntityLinkQuery<E> scopeDefinitionId(String scopeDefinitionId);

/**
* Query entity links with the given scope type.
*/
InternalEntityLinkQuery<E> scopeType(String scopeType);

/**
* Query entity links with the given reference scope id.
*/
InternalEntityLinkQuery<E> referenceScopeId(String referenceScopeId);

/**
* Query entity links with the given reference scope definition id.
*/
InternalEntityLinkQuery<E> referenceScopeDefinitionId(String referenceScopeDefinitionId);

/**
* Query entity links with the given reference scope type.
*/
InternalEntityLinkQuery<E> referenceScopeType(String referenceScopeType);

/**
* Query entity links with the given root scope id.
*/
InternalEntityLinkQuery<E> rootScopeId(String rootScopeId);

/**
* Query entity links with the given root scope type.
*/
InternalEntityLinkQuery<E> rootScopeType(String rootScopeType);

/**
* Query entity links with the given link type.
*/
InternalEntityLinkQuery<E> linkType(String linkType);

/**
* Query entity links with the given hierarchy type.
*/
InternalEntityLinkQuery<E> hierarchyType(String hierarchyType);

List<E> list();

E singleResult();

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.util.Collection;
import java.util.List;

import org.flowable.entitylink.api.InternalEntityLinkQuery;

/**
* Service which provides access to historic entity links.
*
Expand All @@ -24,15 +26,35 @@ public interface HistoricEntityLinkService {

HistoricEntityLink getHistoricEntityLink(String id);

List<HistoricEntityLink> findHistoricEntityLinksByScopeIdAndScopeType(String scopeId, String scopeType, String linkType);
default List<HistoricEntityLink> findHistoricEntityLinksByScopeIdAndScopeType(String scopeId, String scopeType, String linkType) {
return createInternalHistoricEntityLinkQuery()
.scopeId(scopeId)
.scopeType(scopeType)
.linkType(linkType)
.list();
}

List<HistoricEntityLink> findHistoricEntityLinksWithSameRootScopeForScopeIdAndScopeType(String scopeId, String scopeType, String linkType);

List<HistoricEntityLink> findHistoricEntityLinksWithSameRootScopeForScopeIdsAndScopeType(Collection<String> scopeIds, String scopeType, String linkType);

List<HistoricEntityLink> findHistoricEntityLinksByReferenceScopeIdAndType(String referenceScopeId, String scopeType, String linkType);
default List<HistoricEntityLink> findHistoricEntityLinksByReferenceScopeIdAndType(String referenceScopeId, String scopeType, String linkType) {
return createInternalHistoricEntityLinkQuery()
.referenceScopeId(referenceScopeId)
.referenceScopeType(scopeType)
.linkType(linkType)
.list();
}

default List<HistoricEntityLink> findHistoricEntityLinksByScopeDefinitionIdAndScopeType(String scopeDefinitionId, String scopeType, String linkType) {
return createInternalHistoricEntityLinkQuery()
.scopeDefinitionId(scopeDefinitionId)
.scopeType(scopeType)
.linkType(linkType)
.list();
}

List<HistoricEntityLink> findHistoricEntityLinksByScopeDefinitionIdAndScopeType(String scopeDefinitionId, String scopeType, String linkType);
InternalEntityLinkQuery<HistoricEntityLink> createInternalHistoricEntityLinkQuery();

HistoricEntityLink createHistoricEntityLink();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.flowable.common.engine.impl.service.CommonServiceImpl;
import org.flowable.entitylink.api.EntityLink;
import org.flowable.entitylink.api.EntityLinkService;
import org.flowable.entitylink.api.InternalEntityLinkQuery;
import org.flowable.entitylink.service.EntityLinkServiceConfiguration;
import org.flowable.entitylink.service.impl.persistence.entity.EntityLinkEntity;
import org.flowable.entitylink.service.impl.persistence.entity.EntityLinkEntityManager;
Expand All @@ -30,24 +31,15 @@ public EntityLinkServiceImpl(EntityLinkServiceConfiguration entityLinkServiceCon
super(entityLinkServiceConfiguration);
}

@Override
public List<EntityLink> findEntityLinksByScopeIdAndType(String scopeId, String scopeType, String linkType) {
return getEntityLinkEntityManager().findEntityLinksByScopeIdAndType(scopeId, scopeType, linkType);
}

@Override
public List<EntityLink> findEntityLinksByRootScopeIdAndRootType(String scopeId, String scopeType) {
return getEntityLinkEntityManager().findEntityLinksByRootScopeIdAndRootType(scopeId, scopeType);
}

@Override
public List<EntityLink> findEntityLinksWithSameRootScopeForScopeIdAndScopeType(String scopeId, String scopeType, String linkType) {
return getEntityLinkEntityManager().findEntityLinksWithSameRootScopeForScopeIdAndScopeType(scopeId, scopeType, linkType);
}

@Override
public List<EntityLink> findEntityLinksByReferenceScopeIdAndType(String referenceScopeId, String referenceScopeType, String linkType) {
return getEntityLinkEntityManager().findEntityLinksByReferenceScopeIdAndType(referenceScopeId, referenceScopeType, linkType);
@SuppressWarnings("unchecked")
public InternalEntityLinkQuery<EntityLink> createInternalEntityLinkQuery() {
return (InternalEntityLinkQuery) getEntityLinkEntityManager().createInternalEntityLinkQuery();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.List;

import org.flowable.common.engine.impl.service.CommonServiceImpl;
import org.flowable.entitylink.api.InternalEntityLinkQuery;
import org.flowable.entitylink.api.history.HistoricEntityLink;
import org.flowable.entitylink.api.history.HistoricEntityLinkService;
import org.flowable.entitylink.service.EntityLinkServiceConfiguration;
Expand All @@ -36,11 +37,6 @@ public HistoricEntityLink getHistoricEntityLink(String id) {
return getHistoricEntityLinkEntityManager().findById(id);
}

@Override
public List<HistoricEntityLink> findHistoricEntityLinksByScopeIdAndScopeType(String scopeId, String scopeType, String linkType) {
return getHistoricEntityLinkEntityManager().findHistoricEntityLinksByScopeIdAndScopeType(scopeId, scopeType, linkType);
}

@Override
public List<HistoricEntityLink> findHistoricEntityLinksWithSameRootScopeForScopeIdAndScopeType(String scopeId, String scopeType, String linkType) {
return getHistoricEntityLinkEntityManager().findHistoricEntityLinksWithSameRootScopeForScopeIdAndScopeType(scopeId, scopeType, linkType);
Expand All @@ -52,13 +48,9 @@ public List<HistoricEntityLink> findHistoricEntityLinksWithSameRootScopeForScope
}

@Override
public List<HistoricEntityLink> findHistoricEntityLinksByReferenceScopeIdAndType(String referenceScopeId, String scopeType, String linkType) {
return getHistoricEntityLinkEntityManager().findHistoricEntityLinksByReferenceScopeIdAndType(referenceScopeId, scopeType, linkType);
}

@Override
public List<HistoricEntityLink> findHistoricEntityLinksByScopeDefinitionIdAndScopeType(String scopeDefinitionId, String scopeType, String linkType) {
return getHistoricEntityLinkEntityManager().findHistoricEntityLinksByScopeDefinitionIdAndScopeType(scopeDefinitionId, scopeType, linkType);
@SuppressWarnings("unchecked")
public InternalEntityLinkQuery<HistoricEntityLink> createInternalHistoricEntityLinkQuery() {
return (InternalEntityLinkQuery) getHistoricEntityLinkEntityManager().createInternalHistoricEntityLinkQuery();
}

@Override
Expand Down

0 comments on commit 7154a2e

Please sign in to comment.