Skip to content

Commit

Permalink
Do not compute persistent state for immutable entities and do not do …
Browse files Browse the repository at this point in the history
…dirty check
  • Loading branch information
filiphr committed Nov 1, 2024
1 parent baba466 commit e4eb8bf
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ public InputStream getMyBatisXmlConfigurationStream() {

@Override
protected void initDbSqlSessionFactoryEntitySettings() {
defaultInitDbSqlSessionFactoryEntitySettings(EntityDependencyOrder.INSERT_ORDER, EntityDependencyOrder.DELETE_ORDER);
defaultInitDbSqlSessionFactoryEntitySettings(EntityDependencyOrder.INSERT_ORDER, EntityDependencyOrder.DELETE_ORDER, EntityDependencyOrder.IMMUTABLE_ENTITIES);

// Oracle doesn't support bulk inserting for historic task log entries
if (isBulkInsertEnabled && "oracle".equals(databaseType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.flowable.cmmn.engine.impl.db;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -59,6 +60,7 @@ public class EntityDependencyOrder {

public static List<Class<? extends Entity>> DELETE_ORDER = new ArrayList<>();
public static List<Class<? extends Entity>> INSERT_ORDER;
public static Collection<Class<? extends Entity>> IMMUTABLE_ENTITIES = new ArrayList<>();

static {

Expand Down Expand Up @@ -100,6 +102,10 @@ public class EntityDependencyOrder {
INSERT_ORDER = new ArrayList<>(DELETE_ORDER);
Collections.reverse(INSERT_ORDER);

IMMUTABLE_ENTITIES.add(EntityLinkEntityImpl.class);
IMMUTABLE_ENTITIES.add(HistoricEntityLinkEntityImpl.class);
IMMUTABLE_ENTITIES.add(HistoricIdentityLinkEntityImpl.class);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,10 @@ public DbSqlSessionFactory createDbSqlSessionFactory() {
protected abstract void initDbSqlSessionFactoryEntitySettings();

protected void defaultInitDbSqlSessionFactoryEntitySettings(List<Class<? extends Entity>> insertOrder, List<Class<? extends Entity>> deleteOrder) {
defaultInitDbSqlSessionFactoryEntitySettings(insertOrder, deleteOrder, Collections.emptyList());
}

protected void defaultInitDbSqlSessionFactoryEntitySettings(List<Class<? extends Entity>> insertOrder, List<Class<? extends Entity>> deleteOrder, Collection<Class<? extends Entity>> immutableEntities) {
if (insertOrder != null) {
for (Class<? extends Entity> clazz : insertOrder) {
dbSqlSessionFactory.getInsertionOrder().add(clazz);
Expand All @@ -767,6 +771,10 @@ protected void defaultInitDbSqlSessionFactoryEntitySettings(List<Class<? extends
dbSqlSessionFactory.getDeletionOrder().add(clazz);
}
}

if (immutableEntities != null && !immutableEntities.isEmpty()) {
dbSqlSessionFactory.getImmutableEntities().addAll(immutableEntities);
}
}

public void initTransactionFactory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,15 @@ protected void removeUnnecessaryOperations() {
public void determineUpdatedObjects() {
updatedObjects = new ArrayList<>();
Map<Class<?>, Map<String, CachedEntity>> cachedObjects = entityCache.getAllCachedEntities();
if (cachedObjects.isEmpty()) {
return;
}

Collection<Class<? extends Entity>> immutableEntities = dbSqlSessionFactory.getImmutableEntities();
for (Class<?> clazz : cachedObjects.keySet()) {
if (immutableEntities.contains(clazz)) {
continue;
}

Map<String, CachedEntity> classCache = cachedObjects.get(clazz);
for (CachedEntity cachedObject : classCache.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -55,6 +56,7 @@ public class DbSqlSessionFactory implements SessionFactory {

protected List<Class<? extends Entity>> insertionOrder = new ArrayList<>();
protected List<Class<? extends Entity>> deletionOrder = new ArrayList<>();
protected Collection<Class<? extends Entity>> immutableEntities = new HashSet<>();

protected boolean isDbHistoryUsed = true;

Expand Down Expand Up @@ -327,6 +329,15 @@ public List<Class<? extends Entity>> getDeletionOrder() {
public void setDeletionOrder(List<Class<? extends Entity>> deletionOrder) {
this.deletionOrder = deletionOrder;
}

public Collection<Class<? extends Entity>> getImmutableEntities() {
return immutableEntities;
}

public void setImmutableEntities(Collection<Class<? extends Entity>> immutableEntities) {
this.immutableEntities = immutableEntities;
}

public void addLogicalEntityClassMapping(String logicalName, Class<?> entityClass) {
logicalNameToClassMapping.put(logicalName, entityClass);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ public void initSessionFactories() {

@Override
protected void initDbSqlSessionFactoryEntitySettings() {
defaultInitDbSqlSessionFactoryEntitySettings(EntityDependencyOrder.INSERT_ORDER, EntityDependencyOrder.DELETE_ORDER);
defaultInitDbSqlSessionFactoryEntitySettings(EntityDependencyOrder.INSERT_ORDER, EntityDependencyOrder.DELETE_ORDER, EntityDependencyOrder.IMMUTABLE_ENTITIES);

// Oracle doesn't support bulk inserting for event log entries and historic task log entries
if (isBulkInsertEnabled && "oracle".equals(databaseType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.flowable.engine.impl.db;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -66,6 +67,7 @@ public class EntityDependencyOrder {

public static List<Class<? extends Entity>> DELETE_ORDER = new ArrayList<>();
public static List<Class<? extends Entity>> INSERT_ORDER;
public static Collection<Class<? extends Entity>> IMMUTABLE_ENTITIES = new ArrayList<>();

static {

Expand Down Expand Up @@ -222,6 +224,10 @@ public class EntityDependencyOrder {
INSERT_ORDER = new ArrayList<>(DELETE_ORDER);
Collections.reverse(INSERT_ORDER);

IMMUTABLE_ENTITIES.add(EntityLinkEntityImpl.class);
IMMUTABLE_ENTITIES.add(HistoricEntityLinkEntityImpl.class);
IMMUTABLE_ENTITIES.add(HistoricIdentityLinkEntityImpl.class);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
* @author Tijs Rademakers
Expand Down Expand Up @@ -44,21 +42,8 @@ public EntityLinkEntityImpl() {

@Override
public Object getPersistentState() {
Map<String, Object> persistentState = new HashMap<>();
persistentState.put("linkType", this.linkType);
persistentState.put("scopeId", this.scopeId);
persistentState.put("subScopeId", this.subScopeId);
persistentState.put("scopeType", this.scopeType);
persistentState.put("scopeDefinitionId", this.scopeDefinitionId);
persistentState.put("parentElementId", this.parentElementId);
persistentState.put("referenceScopeId", this.referenceScopeId);
persistentState.put("referenceScopeType", this.referenceScopeType);
persistentState.put("referenceScopeDefinitionId", this.referenceScopeDefinitionId);
persistentState.put("rootScopeId", this.rootScopeId);
persistentState.put("rootScopeType", this.rootScopeType);
persistentState.put("hierarchyType", this.hierarchyType);

return persistentState;
// Entity link is immutable
return EntityLinkEntityImpl.class;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
* @author Tijs Rademakers
Expand Down Expand Up @@ -44,23 +42,8 @@ public HistoricEntityLinkEntityImpl() {

@Override
public Object getPersistentState() {
Map<String, Object> persistentState = new HashMap<>();
persistentState.put("id", this.id);
persistentState.put("linkType", this.linkType);
persistentState.put("scopeId", this.scopeId);
persistentState.put("subScopeId", this.subScopeId);
persistentState.put("scopeType", this.scopeType);
persistentState.put("scopeDefinitionId", this.scopeDefinitionId);
persistentState.put("parentElementId", this.parentElementId);
persistentState.put("referenceScopeId", this.referenceScopeId);
persistentState.put("referenceScopeType", this.referenceScopeType);
persistentState.put("referenceScopeDefinitionId", this.referenceScopeDefinitionId);
persistentState.put("rootScopeId", this.rootScopeId);
persistentState.put("rootScopeType", this.rootScopeType);
persistentState.put("hierarchyType", this.hierarchyType);
persistentState.put("createTime", this.createTime);

return persistentState;
// Historic entity link is immutable
return HistoricEntityLinkEntityImpl.class;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.flowable.common.engine.api.FlowableException;

Expand Down Expand Up @@ -43,47 +41,8 @@ public HistoricIdentityLinkEntityImpl() {

@Override
public Object getPersistentState() {
Map<String, Object> persistentState = new HashMap<>();
persistentState.put("id", this.id);
persistentState.put("type", this.type);

if (this.userId != null) {
persistentState.put("userId", this.userId);
}

if (this.groupId != null) {
persistentState.put("groupId", this.groupId);
}

if (this.taskId != null) {
persistentState.put("taskId", this.taskId);
}

if (this.processInstanceId != null) {
persistentState.put("processInstanceId", this.processInstanceId);
}

if (this.scopeId != null) {
persistentState.put("scopeId", this.scopeId);
}

if (this.subScopeId != null) {
persistentState.put("subScopeId", this.subScopeId);
}

if (this.scopeType!= null) {
persistentState.put("scopeType", this.scopeType);
}

if (this.scopeDefinitionId != null) {
persistentState.put("scopeDefinitionId", this.scopeDefinitionId);
}

if (this.createTime != null) {
persistentState.put("createTime", this.createTime);
}

return persistentState;
// Historic identity link is immutable
return HistoricIdentityLinkEntityImpl.class;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public DbSqlSessionFactory createDbSqlSessionFactory() {

@Override
protected void initDbSqlSessionFactoryEntitySettings() {
defaultInitDbSqlSessionFactoryEntitySettings(EntityDependencyOrder.INSERT_ORDER, EntityDependencyOrder.DELETE_ORDER);
defaultInitDbSqlSessionFactoryEntitySettings(EntityDependencyOrder.INSERT_ORDER, EntityDependencyOrder.DELETE_ORDER, EntityDependencyOrder.IMMUTABLE_ENTITIES);
}

public void initPasswordEncoder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.flowable.idm.engine.impl.db;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

Expand All @@ -32,6 +33,7 @@ public class EntityDependencyOrder {

public static List<Class<? extends Entity>> DELETE_ORDER = new ArrayList<>();
public static List<Class<? extends Entity>> INSERT_ORDER = new ArrayList<>();
public static Collection<Class<? extends Entity>> IMMUTABLE_ENTITIES = new ArrayList<>();

static {

Expand All @@ -49,6 +51,10 @@ public class EntityDependencyOrder {
INSERT_ORDER = new ArrayList<>(DELETE_ORDER);
Collections.reverse(INSERT_ORDER);

IMMUTABLE_ENTITIES.add(MembershipEntityImpl.class);
IMMUTABLE_ENTITIES.add(PrivilegeEntityImpl.class);
IMMUTABLE_ENTITIES.add(PrivilegeMappingEntityImpl.class);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,14 @@
*/
package org.flowable.idm.engine.impl.persistence.entity;

import java.util.HashMap;
import java.util.Map;

public class PrivilegeEntityImpl extends AbstractIdmEngineEntity implements PrivilegeEntity {

protected String name;

@Override
public Object getPersistentState() {
Map<String, String> state = new HashMap<>();
state.put("id", id);
state.put("name", name);
return state;
// Privilege is immutable
return PrivilegeEntityImpl.class;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ public class PrivilegeMappingEntityImpl extends AbstractIdmEngineEntity implemen

@Override
public Object getPersistentState() {
Map<String, String> state = new HashMap<>();
state.put("id", id);
state.put("privilegeId", privilegeId);
state.put("userId", userId);
state.put("groupId", groupId);
return state;
// Privilege mapping is immutable
return PrivilegeMappingEntityImpl.class;
}

@Override
Expand Down

0 comments on commit e4eb8bf

Please sign in to comment.