提交 c06ebaa0 编写于 作者: S Serge Rider

Cache model improvement (merge lists)

上级 dd7b8af9
......@@ -61,6 +61,8 @@ public class ResultSetUtils
List<Object[]> rows)
{
DBRProgressMonitor monitor = session.getProgressMonitor();
Map<DBCEntityMetaData, DBSEntity> entityBindingMap = new IdentityHashMap<>();
monitor.beginTask("Discover resultset metadata", 3);
try {
SQLQuery sqlQuery = null;
......@@ -84,6 +86,9 @@ public class ResultSetUtils
}
if (entityMeta != null) {
entity = getEntityFromMetaData(session, entityMeta);
if (entity != null) {
entityBindingMap.put(entityMeta, entity);
}
}
}
}
......@@ -98,13 +103,20 @@ public class ResultSetUtils
// To be editable we need this resultset contain set of columns from the same table
// which construct any unique key
DBSEntity attrEntity = null;
if (attrMeta.getEntityMetaData() != null) {
if (entity != null && entity instanceof DBSTable && ((DBSTable) entity).isView()) {
// If this is a view then don't try to detect entity for each attribute
// MySQL returns rouce table name instead of view name. That's crazy.
attrEntity = entity;
} else {
attrEntity = getEntityFromMetaData(session, attrMeta.getEntityMetaData());
final DBCEntityMetaData attrEntityMeta = attrMeta.getEntityMetaData();
if (attrEntityMeta != null) {
attrEntity = entityBindingMap.get(attrEntityMeta);
if (attrEntity == null) {
if (entity != null && entity instanceof DBSTable && ((DBSTable) entity).isView()) {
// If this is a view then don't try to detect entity for each attribute
// MySQL returns rouce table name instead of view name. That's crazy.
attrEntity = entity;
} else {
attrEntity = getEntityFromMetaData(session, attrEntityMeta);
}
}
if (attrEntity != null) {
entityBindingMap.put(attrEntityMeta, attrEntity);
}
}
if (attrEntity == null) {
......
......@@ -95,13 +95,14 @@ public abstract class AbstractObjectCache<OWNER extends DBSObject, OBJECT extend
{
synchronized (this) {
if (this.objectList == null) {
detectCaseSensitivity(object);
this.objectList.add(object);
if (this.objectMap != null) {
String name = getObjectName(object);
checkDuplicateName(name, object);
this.objectMap.put(name, object);
}
this.objectList = new ArrayList<>();
}
detectCaseSensitivity(object);
this.objectList.add(object);
if (this.objectMap != null) {
String name = getObjectName(object);
checkDuplicateName(name, object);
this.objectMap.put(name, object);
}
}
}
......@@ -152,6 +153,34 @@ public abstract class AbstractObjectCache<OWNER extends DBSObject, OBJECT extend
}
}
/**
* Merges new cache with existing.
* If objects with the same name were already cached - leave them in cache
* (because they might be referenced somewhere).
*/
protected void mergeCache(List<OBJECT> objects)
{
synchronized (this) {
if (this.objectList != null) {
// Merge lists
objects = new ArrayList<>(objects);
for (int i = 0; i < objects.size(); i++) {
OBJECT newObject = objects.get(i);
String newObjectName = getObjectName(newObject);
for (int k = 0; k < objectList.size(); k++) {
OBJECT oldObject = objectList.get(k);
String oldObjectName = getObjectName(oldObject);
if (newObjectName.equals(oldObjectName)) {
objects.set(i, oldObject);
break;
}
}
}
}
}
setCache(objects);
}
private synchronized Map<String, OBJECT> getObjectMap()
{
if (this.objectMap == null) {
......
......@@ -142,7 +142,7 @@ public abstract class JDBCObjectCache<OWNER extends DBSObject, OBJECT extends DB
synchronized (this) {
detectCaseSensitivity(owner);
setCache(tmpObjectList);
mergeCache(tmpObjectList);
this.invalidateObjects(monitor, owner, new CacheIterator());
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册