Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #3817 Bulk delete Operations with custom Entities are not executed by DbSqlSession #3818

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -880,11 +880,16 @@ protected void flushDeletes() {
for (Class<? extends Entity> entityClass : deletedObjects.keySet()) {
flushDeleteEntities(entityClass,
deletedObjects.get(entityClass).values());
}
}
if (bulkDeleteOperations.size() > 0) {
for (Class<? extends Entity> entityClass : bulkDeleteOperations.keySet()) {
flushBulkDeletes(entityClass);
}
}

deletedObjects.clear();
bulkDeleteOperations.clear();
}

protected void flushBulkDeletes(Class<? extends Entity> entityClass) {
Expand All @@ -893,6 +898,7 @@ protected void flushBulkDeletes(Class<? extends Entity> entityClass) {
for (BulkDeleteOperation bulkDeleteOperation : bulkDeleteOperations.get(entityClass)) {
bulkDeleteOperation.execute(sqlSession);
}
bulkDeleteOperations.remove(entityClass);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.activiti.engine.impl.db;

import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;

import org.activiti.engine.impl.persistence.entity.AbstractEntity;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class DbSqlSessionTest
{
@Mock
private DbSqlSessionFactory dbSqlSessionFactoryMock;

@Mock
private SqlSessionFactory sqlSessionFactoryMock;

@Mock
private SqlSession sqlSessionMock;

private DbSqlSession dbSqlSession;

@Before
public void constructDbSqlSession()
{
when(dbSqlSessionFactoryMock.getSqlSessionFactory()).thenReturn(sqlSessionFactoryMock);
when(sqlSessionFactoryMock.openSession()).thenReturn(sqlSessionMock);
when(dbSqlSessionFactoryMock.mapStatement("someStatement")).thenReturn("someMappedStatement");

dbSqlSession = new DbSqlSession(dbSqlSessionFactoryMock, null);
}

@Test
public void testFlushDeletesWithCustomEntityBulkDeletion()
{
dbSqlSession.delete("someStatement", "myParam", CustomEntity.class);

// act
dbSqlSession.flushDeletes();

// assert
verify(sqlSessionMock).delete("someMappedStatement", "myParam");
}

private static class CustomEntity extends AbstractEntity
{
@Override
public Object getPersistentState()
{
return null;
}
}
}