From 3905c61a4f4041f196c54819b6a8cc1562cbde9b Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Mon, 6 Apr 2015 12:19:02 +0000 Subject: [PATCH] NotSerializableException: QueryResultsManager #PL-4353 --- .../app/queryresults/QueryResultsManager.java | 32 ++------------- .../haulmont/cuba/core/sys/QueryHolder.java | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+), 28 deletions(-) create mode 100644 modules/global/src/com/haulmont/cuba/core/sys/QueryHolder.java diff --git a/modules/core/src/com/haulmont/cuba/core/app/queryresults/QueryResultsManager.java b/modules/core/src/com/haulmont/cuba/core/app/queryresults/QueryResultsManager.java index 53348837ac..32da6c00aa 100644 --- a/modules/core/src/com/haulmont/cuba/core/app/queryresults/QueryResultsManager.java +++ b/modules/core/src/com/haulmont/cuba/core/app/queryresults/QueryResultsManager.java @@ -14,16 +14,15 @@ import com.haulmont.cuba.core.app.ClusterManagerAPI; import com.haulmont.cuba.core.app.DataServiceQueryBuilder; import com.haulmont.cuba.core.global.*; import com.haulmont.cuba.core.sys.AppContext; +import com.haulmont.cuba.core.sys.QueryHolder; import com.haulmont.cuba.core.sys.persistence.DbTypeConverter; import com.haulmont.cuba.security.app.UserSessionsAPI; import com.haulmont.cuba.security.entity.UserSessionEntity; -import org.apache.commons.lang.ObjectUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import javax.annotation.ManagedBean; import javax.inject.Inject; -import java.io.Serializable; import java.sql.SQLException; import java.sql.Types; import java.util.*; @@ -127,7 +126,9 @@ public class QueryResultsManager implements QueryResultsManagerAPI { QueryHolder queryHolder = new QueryHolder(query); QueryHolder oldQueryHolder = recentQueries.put(queryKey, queryHolder); - userSessionSource.getUserSession().setAttribute("_recentQueries", recentQueries); + // do not set to session attribute recentQueries directly, it contains reference to QueryResultsManager class + // copy data to new LinkedHashMap + userSessionSource.getUserSession().setAttribute("_recentQueries", new LinkedHashMap<>(recentQueries)); return queryHolder.equals(oldQueryHolder); } @@ -226,29 +227,4 @@ public class QueryResultsManager implements QueryResultsManagerAPI { throw new RuntimeException(e); } } - - private static class QueryHolder implements Serializable { - - private static final long serialVersionUID = -6055610488135337366L; - - public final LoadContext.Query query; - - public QueryHolder(LoadContext.Query query) { - this.query = query; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - QueryHolder that = (QueryHolder) o; - - if (query == null || that.query == null) return false; - if (!ObjectUtils.equals(query.getQueryString(), that.query.getQueryString())) return false; - if (!ObjectUtils.equals(query.getParameters(), that.query.getParameters())) return false; - - return true; - } - } } \ No newline at end of file diff --git a/modules/global/src/com/haulmont/cuba/core/sys/QueryHolder.java b/modules/global/src/com/haulmont/cuba/core/sys/QueryHolder.java new file mode 100644 index 0000000000..dd8b2b9590 --- /dev/null +++ b/modules/global/src/com/haulmont/cuba/core/sys/QueryHolder.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2008-2015 Haulmont. All rights reserved. + * Use is subject to license terms, see http://www.cuba-platform.com/license for details. + */ + +package com.haulmont.cuba.core.sys; + +import com.haulmont.cuba.core.global.LoadContext; +import org.apache.commons.lang.ObjectUtils; + +import java.io.Serializable; + +/** + * @author artamonov + * @version $Id$ + */ +public class QueryHolder implements Serializable { + + private static final long serialVersionUID = -6055610488135337366L; + + public final LoadContext.Query query; + + public QueryHolder(LoadContext.Query query) { + this.query = query; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + QueryHolder that = (QueryHolder) o; + + if (query == null || that.query == null) return false; + if (!ObjectUtils.equals(query.getQueryString(), that.query.getQueryString())) return false; + if (!ObjectUtils.equals(query.getParameters(), that.query.getParameters())) return false; + + return true; + } +} \ No newline at end of file