修改realm事物存储逻辑,解决OOM问题
This commit is contained in:
@@ -39,12 +39,14 @@ public class OMDBReferenceDataSource implements ITileDataSource {
|
||||
int xEnd = (int) ((tile.tileX + 1) << m);
|
||||
int yStart = (int) tile.tileY << m;
|
||||
int yEnd = (int) ((tile.tileY + 1) << m);
|
||||
|
||||
|
||||
if(isUpdate){
|
||||
Realm.getDefaultInstance().refresh();
|
||||
Realm.getInstance(MapParamUtils.getTaskConfig()).refresh();
|
||||
isUpdate = false;
|
||||
}
|
||||
|
||||
String sql = "taskId="+ MapParamUtils.getTaskId() +" and tileX>=" + xStart + " and tileX<=" + xEnd + " and tileY>=" + yStart + " and tileY<=" + yEnd + "";
|
||||
String sql = " tileX>=" + xStart + " and tileX<=" + xEnd + " and tileY>=" + yStart + " and tileY<=" + yEnd + "";
|
||||
|
||||
if(MapParamUtils.getDataLayerEnum()!=null){
|
||||
sql += " and enable" + MapParamUtils.getDataLayerEnum().getSql();
|
||||
@@ -52,7 +54,7 @@ public class OMDBReferenceDataSource implements ITileDataSource {
|
||||
sql += " and 1=1";
|
||||
}
|
||||
|
||||
RealmQuery<ReferenceEntity> realmQuery = Realm.getDefaultInstance().where(ReferenceEntity.class)
|
||||
RealmQuery<ReferenceEntity> realmQuery = Realm.getInstance(MapParamUtils.getTaskConfig()).where(ReferenceEntity.class)
|
||||
.rawPredicate(sql);
|
||||
// 筛选不显示的数据
|
||||
if (Constant.HAD_LAYER_INVISIABLE_ARRAY != null && Constant.HAD_LAYER_INVISIABLE_ARRAY.length > 0) {
|
||||
@@ -67,7 +69,7 @@ public class OMDBReferenceDataSource implements ITileDataSource {
|
||||
mThreadLocalDecoders.get().decode(tile.zoomLevel, tile, mapDataSink, listResult);
|
||||
}
|
||||
mapDataSink.completed(QueryResult.SUCCESS);
|
||||
// Log.d("RealmDBTileDataSource", "tile:"+tile.getBoundingBox().toString());
|
||||
Realm.getInstance(MapParamUtils.getTaskConfig()).close();
|
||||
} else {
|
||||
mapDataSink.completed(QueryResult.SUCCESS);
|
||||
}
|
||||
|
||||
@@ -38,12 +38,13 @@ public class OMDBTileDataSource implements ITileDataSource {
|
||||
int xEnd = (int) ((tile.tileX + 1) << m);
|
||||
int yStart = (int) tile.tileY << m;
|
||||
int yEnd = (int) ((tile.tileY + 1) << m);
|
||||
|
||||
if(isUpdate){
|
||||
Realm.getDefaultInstance().refresh();
|
||||
Realm.getInstance(MapParamUtils.getTaskConfig()).refresh();
|
||||
isUpdate = false;
|
||||
}
|
||||
|
||||
String sql = "taskId="+ MapParamUtils.getTaskId() +" and tileX>=" + xStart + " and tileX<=" + xEnd + " and tileY>=" + yStart + " and tileY<=" + yEnd + "";
|
||||
String sql =" tileX>=" + xStart + " and tileX<=" + xEnd + " and tileY>=" + yStart + " and tileY<=" + yEnd + "";
|
||||
|
||||
if(MapParamUtils.getDataLayerEnum()!=null){
|
||||
sql += " and enable" + MapParamUtils.getDataLayerEnum().getSql();
|
||||
@@ -51,7 +52,7 @@ public class OMDBTileDataSource implements ITileDataSource {
|
||||
sql += " and 1=1";
|
||||
}
|
||||
|
||||
RealmQuery<RenderEntity> realmQuery = Realm.getDefaultInstance().where(RenderEntity.class).rawPredicate(sql);
|
||||
RealmQuery<RenderEntity> realmQuery = Realm.getInstance(MapParamUtils.getTaskConfig()).where(RenderEntity.class).rawPredicate(sql);
|
||||
// 筛选不显示的数据
|
||||
if (Constant.HAD_LAYER_INVISIABLE_ARRAY != null && Constant.HAD_LAYER_INVISIABLE_ARRAY.length > 0) {
|
||||
realmQuery.beginGroup();
|
||||
@@ -65,6 +66,7 @@ public class OMDBTileDataSource implements ITileDataSource {
|
||||
mThreadLocalDecoders.get().decode(tile.zoomLevel, tile, mapDataSink, listResult);
|
||||
}
|
||||
mapDataSink.completed(QueryResult.SUCCESS);
|
||||
Realm.getInstance(MapParamUtils.getTaskConfig()).close();
|
||||
} else {
|
||||
mapDataSink.completed(QueryResult.SUCCESS);
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ public class RealmDBTileDataSource implements ITileDataSource {
|
||||
List<GeometryFeatureEntity> listResult = realmQuery.distinct("id").findAll();
|
||||
mThreadLocalDecoders.get().decode(tile, mapDataSink, listResult);
|
||||
mapDataSink.completed(QueryResult.SUCCESS);
|
||||
Realm.getDefaultInstance().close();
|
||||
// Log.d("RealmDBTileDataSource", "tile:"+tile.getBoundingBox().toString());
|
||||
} else {
|
||||
mapDataSink.completed(QueryResult.SUCCESS);
|
||||
|
||||
@@ -2,20 +2,33 @@ package com.navinfo.collect.library.utils;
|
||||
|
||||
import com.navinfo.collect.library.enums.DataLayerEnum;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import io.realm.RealmConfiguration;
|
||||
|
||||
public class MapParamUtils {
|
||||
|
||||
private static int mtaskId = -1;
|
||||
|
||||
private static RealmConfiguration mTaskConfig = null;
|
||||
|
||||
private static DataLayerEnum dataLayerEnum = DataLayerEnum.ONLY_ENABLE_LAYERS;
|
||||
|
||||
public static int getTaskId() {
|
||||
return mtaskId;
|
||||
}
|
||||
|
||||
public static void setTaskId(int taskId) {
|
||||
mtaskId = taskId;
|
||||
}
|
||||
|
||||
public static RealmConfiguration getTaskConfig() {
|
||||
return mTaskConfig;
|
||||
}
|
||||
|
||||
public static void setTaskConfig(RealmConfiguration taskConfig) {
|
||||
mTaskConfig = taskConfig;
|
||||
}
|
||||
|
||||
public static DataLayerEnum getDataLayerEnum() {
|
||||
return dataLayerEnum;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user