Skip to content

Commit

Permalink
clear cache after modification schema
Browse files Browse the repository at this point in the history
  • Loading branch information
vzakharchenko committed Mar 25, 2020
1 parent 5287729 commit d300483
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void registerQ(Map<String, QDynamicTable> qDynamicTableMap,
for (QDynamicTable qDynamicTable : qDynamicTables) {
qDynamicTableMap.put(StringUtils.upperCase(
qDynamicTable.getTableName()), qDynamicTable);
qDynamicTable.reInit();
}
updateCache(qDynamicTableMap, cacheName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ public List<ForeignKey<?>> deletedForeignKeys() {
return this.removedForeignKeys;
}

protected abstract void init();

public void reInit() {
deletedColumns().clear();
deletedForeignKeys().clear();
init();
}

public void removeForeignKey(List<Path<?>> localColumns) {
List<ForeignKey<?>> foreignKeys = getForeignKeys().stream().filter(
(Predicate<ForeignKey<?>>) foreignKey ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ protected QDynamicTable(String tableName) {
super(StringUtils.upperCase(tableName));
}

@Override
protected void init() {
removedIndexList.clear();
}

// CHECKSTYLE:OFF
@Override
public boolean equals(Object o) { //NOPMD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.github.vzakharchenko.dynamic.orm.core.dynamic.structure.DynamicStructureSaver;
import com.github.vzakharchenko.dynamic.orm.core.dynamic.structure.DynamicStructureUpdater;
import com.github.vzakharchenko.dynamic.orm.core.dynamic.structure.LiquibaseHolder;
import com.github.vzakharchenko.dynamic.orm.core.helper.CacheHelper;
import liquibase.database.Database;
import liquibase.database.DatabaseFactory;
import liquibase.database.jvm.JdbcConnection;
Expand Down Expand Up @@ -150,6 +151,9 @@ public void clear() {
sequenceModelMap.clear();
dynamicTableMap.clear();
viewModelMap.clear();
removedTables.clear();
removedSequences.clear();
CacheHelper.getAccessQueryContext(ormQueryFactory).clearCache();
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.vzakharchenko.dynamic.orm.core.helper;

import com.github.vzakharchenko.dynamic.orm.core.AccessQueryContext;
import com.github.vzakharchenko.dynamic.orm.core.DMLModel;
import com.github.vzakharchenko.dynamic.orm.core.OrmQueryFactory;
import com.github.vzakharchenko.dynamic.orm.core.cache.CachedAllData;
import com.github.vzakharchenko.dynamic.orm.core.cache.CachedColumn;
import com.github.vzakharchenko.dynamic.orm.core.cache.CachedColumnWithValue;
Expand All @@ -11,6 +13,7 @@
import com.querydsl.sql.RelationalPath;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.util.Assert;

import java.io.Serializable;
import java.util.Collections;
Expand All @@ -31,6 +34,11 @@ public abstract class CacheHelper {
// }
// }

public static AccessQueryContext getAccessQueryContext(OrmQueryFactory ormQueryFactory) {
Assert.notNull(ormQueryFactory, ormQueryFactory + " is null");
return (AccessQueryContext) ormQueryFactory;
}


public static CachedAllData buildAllDataCache(RelationalPath<?> qTable) {
return new CachedAllData(qTable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public void dropSchema() {
for (DbStructureService dbStructureService : dbStructureServices) {
dbStructureService.clear();
}
qDynamicTableFactory.clear();
checkConnectionLeaks();

}
Expand Down

0 comments on commit d300483

Please sign in to comment.