Index: main/plugin-web/scripts/derby/jdbc_cache_mon.sql =================================================================== --- main/plugin-web/scripts/derby/jdbc_cache_mon.sql (revision 21258) +++ main/plugin-web/scripts/derby/jdbc_cache_mon.sql (working copy) @@ -14,12 +14,13 @@ -- limitations under the License. -- CREATE TABLE Cache_RA_HTTPServer ( - Unique_Id VARCHAR(31) NOT NULL, + Unique_Id VARCHAR(255) NOT NULL, Site VARCHAR(255) NOT NULL, Request_Date TIMESTAMP NOT NULL, - Method VARCHAR(15) NOT NULL, - Path VARCHAR(255) NOT NULL, - Query_String VARCHAR(255) NOT NULL, + Method VARCHAR(255) NOT NULL, + Path_Hash VARCHAR(255) NOT NULL, + Path VARCHAR(4000) NOT NULL, + Query_String VARCHAR(4000) NOT NULL, Ori_Status_Code CHAR(3) NOT NULL, Ret_Status_Code CHAR(3) NOT NULL, Cache_Hit SMALLINT NOT NULL, @@ -29,10 +30,11 @@ ); CREATE TABLE Cache_RA_Front ( - Unique_Id VARCHAR(31) NOT NULL, - Internal_Uuid VARCHAR(63) NOT NULL, + Unique_Id VARCHAR(255) NOT NULL, + Internal_Uuid VARCHAR(255) NOT NULL, Site VARCHAR(255) NOT NULL, - Ametys_Path VARCHAR(255) NOT NULL, + Ametys_Path_Hash VARCHAR(255) NOT NULL, + Ametys_Path VARCHAR(4000) NOT NULL, Cacheable SMALLINT NOT NULL, Cache_Hit_1 SMALLINT NOT NULL, Cache_Hit_2 SMALLINT NOT NULL, @@ -41,23 +43,24 @@ ); CREATE TABLE Cache_RA_Back ( - Internal_Uuid VARCHAR(63) NOT NULL, - Page_Id VARCHAR(63) NOT NULL, - Page_Path VARCHAR(63) NOT NULL, - Rendering_Context VARCHAR(15) NOT NULL, - Workspace_JCR VARCHAR(15) NOT NULL, + Internal_Uuid VARCHAR(255) NOT NULL, + Page_Id VARCHAR(255) NOT NULL, + Page_Path_Hash VARCHAR(255) NOT NULL, + Page_Path VARCHAR(4000) NOT NULL, + Rendering_Context VARCHAR(255) NOT NULL, + Workspace_JCR VARCHAR(255) NOT NULL, Cacheable SMALLINT NOT NULL, Created_At TIMESTAMP NOT NULL, Processed SMALLINT NOT NULL DEFAULT 0 ); CREATE TABLE Cache_RA_Back_Page_Element ( - Internal_Uuid VARCHAR(63) NOT NULL, - Page_Element_Id VARCHAR(63) NOT NULL, - Page_Element_Type VARCHAR(31) NOT NULL, - Page_Id VARCHAR(63) NOT NULL, - Rendering_Context VARCHAR(15) NOT NULL, - Workspace_JCR VARCHAR(15) NOT NULL, + Internal_Uuid VARCHAR(255) NOT NULL, + Page_Element_Id VARCHAR(255) NOT NULL, + Page_Element_Type VARCHAR(255) NOT NULL, + Page_Id VARCHAR(255) NOT NULL, + Rendering_Context VARCHAR(255) NOT NULL, + Workspace_JCR VARCHAR(255) NOT NULL, Cacheable SMALLINT NOT NULL, Cache_Hit SMALLINT NOT NULL, Created_At TIMESTAMP NOT NULL, @@ -66,11 +69,13 @@ CREATE TABLE Cache_Stats_Front ( Server_Site VARCHAR(255) NOT NULL DEFAULT '-', - Server_Path VARCHAR(255) NOT NULL DEFAULT '-', + Server_Path_Hash VARCHAR(255) NOT NULL DEFAULT '-', + Server_Path VARCHAR(4000), Server_Hits INT NOT NULL DEFAULT 0, Server_Cache_Hits INT NOT NULL DEFAULT 0, Front_Site VARCHAR(255) NOT NULL DEFAULT '-', - Front_Path VARCHAR(255) NOT NULL DEFAULT '-', + Front_Path_Hash VARCHAR(255) NOT NULL DEFAULT '-', + Front_Path VARCHAR(4000), Front_Cacheable SMALLINT NOT NULL DEFAULT 0, Front_Hits INT NOT NULL DEFAULT 0, Front_Cache_Hits_1 INT NOT NULL DEFAULT 0, @@ -81,10 +86,11 @@ ); CREATE TABLE Cache_Stats_Back ( - Page_Id VARCHAR(63) NOT NULL, - Page_Path VARCHAR(63) NOT NULL, - Rendering_Context VARCHAR(15) NOT NULL, - Workspace_JCR VARCHAR(15) NOT NULL, + Page_Id VARCHAR(255) NOT NULL, + Page_Path_Hash VARCHAR(255) NOT NULL, + Page_Path VARCHAR(4000) NOT NULL, + Rendering_Context VARCHAR(255) NOT NULL, + Workspace_JCR VARCHAR(255) NOT NULL, Cacheable SMALLINT NOT NULL, Hits INT NOT NULL, Created_At TIMESTAMP NOT NULL, @@ -93,10 +99,10 @@ ); CREATE TABLE Cache_Stats_Back_Page_Element ( - Page_Element_Id VARCHAR(63) NOT NULL, - Page_Id VARCHAR(63) NOT NULL, - Rendering_Context VARCHAR(15) NOT NULL, - Workspace_JCR VARCHAR(15) NOT NULL, + Page_Element_Id VARCHAR(255) NOT NULL, + Page_Id VARCHAR(255) NOT NULL, + Rendering_Context VARCHAR(255) NOT NULL, + Workspace_JCR VARCHAR(255) NOT NULL, Cacheable SMALLINT NOT NULL, Hits INT NOT NULL, Cache_Hits INT NOT NULL, Index: main/plugin-web/scripts/oracle/jdbc_cache_mon.sql =================================================================== --- main/plugin-web/scripts/oracle/jdbc_cache_mon.sql (revision 21258) +++ main/plugin-web/scripts/oracle/jdbc_cache_mon.sql (working copy) @@ -14,12 +14,13 @@ -- limitations under the License. -- CREATE TABLE Cache_RA_HTTPServer ( - Unique_Id VARCHAR(31) NOT NULL, + Unique_Id VARCHAR(255) NOT NULL, Site VARCHAR(255) NOT NULL, Request_Date TIMESTAMP NOT NULL, - Method VARCHAR(15) NOT NULL, - Path VARCHAR(255) NOT NULL, - Query_String VARCHAR(255) NOT NULL, + Method VARCHAR(255) NOT NULL, + Path_Hash VARCHAR(255) NOT NULL, + Path CLOB NOT NULL, + Query_String CLOB NOT NULL, Ori_Status_Code CHAR(3) NOT NULL, Ret_Status_Code CHAR(3) NOT NULL, Cache_Hit NUMBER(1) NOT NULL, @@ -30,10 +31,11 @@ CREATE TABLE Cache_RA_Front ( - Unique_Id VARCHAR(31) NOT NULL, - Internal_Uuid VARCHAR(63) NOT NULL, + Unique_Id VARCHAR(255) NOT NULL, + Internal_Uuid VARCHAR(255) NOT NULL, Site VARCHAR(255) NOT NULL, - Ametys_Path VARCHAR(255) NOT NULL, + Ametys_Path_Hash VARCHAR(255) NOT NULL, + Ametys_Path CLOB NOT NULL, Cacheable NUMBER(1) NOT NULL, Cache_Hit_1 NUMBER(1) NOT NULL, Cache_Hit_2 NUMBER(1) NOT NULL, @@ -42,23 +44,24 @@ ); CREATE TABLE Cache_RA_Back ( - Internal_Uuid VARCHAR(63) NOT NULL, - Page_Id VARCHAR(63) NOT NULL, - Page_Path VARCHAR(63) NOT NULL, - Rendering_Context VARCHAR(15) NOT NULL, - Workspace_JCR VARCHAR(15) NOT NULL, + Internal_Uuid VARCHAR(255) NOT NULL, + Page_Id VARCHAR(255) NOT NULL, + Page_Path_Hash VARCHAR(255) NOT NULL, + Page_Path CLOB NOT NULL, + Rendering_Context VARCHAR(255) NOT NULL, + Workspace_JCR VARCHAR(255) NOT NULL, Cacheable NUMBER(1) NOT NULL, Created_At TIMESTAMP NOT NULL, Processed NUMBER(1) DEFAULT 0 NOT NULL ); CREATE TABLE Cache_RA_Back_Page_Element ( - Internal_Uuid VARCHAR(63) NOT NULL, - Page_Element_Id VARCHAR(63) NOT NULL, - Page_Element_Type VARCHAR(31) NOT NULL, - Page_Id VARCHAR(63) NOT NULL, - Rendering_Context VARCHAR(15) NOT NULL, - Workspace_JCR VARCHAR(15) NOT NULL, + Internal_Uuid VARCHAR(255) NOT NULL, + Page_Element_Id VARCHAR(255) NOT NULL, + Page_Element_Type VARCHAR(255) NOT NULL, + Page_Id VARCHAR(255) NOT NULL, + Rendering_Context VARCHAR(255) NOT NULL, + Workspace_JCR VARCHAR(255) NOT NULL, Cacheable NUMBER(1) NOT NULL, Cache_Hit NUMBER(1) NOT NULL, Created_At TIMESTAMP NOT NULL, @@ -67,25 +70,28 @@ CREATE TABLE Cache_Stats_Front ( Server_Site VARCHAR(255) DEFAULT '-' NOT NULL, - Server_Path VARCHAR(255) DEFAULT '-' NOT NULL, + Server_Path_Hash VARCHAR(255) DEFAULT '-' NOT NULL, + Server_Path CLOB, Server_Hits INT DEFAULT 0 NOT NULL, Server_Cache_Hits INT DEFAULT 0 NOT NULL, Front_Site VARCHAR(255) DEFAULT '-' NOT NULL, - Front_Path VARCHAR(255) DEFAULT '-' NOT NULL, + Front_Path_Hash VARCHAR(255) DEFAULT '-' NOT NULL, + Front_Path CLOB, Front_Cacheable NUMBER(1) DEFAULT 0 NOT NULL, Front_Hits INT DEFAULT 0 NOT NULL, Front_Cache_Hits_1 INT DEFAULT 0 NOT NULL, Front_Cache_Hits_2 INT DEFAULT 0 NOT NULL, Created_At TIMESTAMP NOT NULL, Updated_At TIMESTAMP NOT NULL, - UNIQUE (Server_Site, Server_Path, Front_Site, Front_Path) + UNIQUE (Server_Site, Server_Path_Hash, Front_Site, Front_Path_Hash) ); CREATE TABLE Cache_Stats_Back ( - Page_Id VARCHAR(63) NOT NULL, - Page_Path VARCHAR(63) NOT NULL, - Rendering_Context VARCHAR(15) NOT NULL, - Workspace_JCR VARCHAR(15) NOT NULL, + Page_Id VARCHAR(255) NOT NULL, + Page_Path_Hash VARCHAR(255) NOT NULL, + Page_Path CLOB NOT NULL, + Rendering_Context VARCHAR(255) NOT NULL, + Workspace_JCR VARCHAR(255) NOT NULL, Cacheable NUMBER(1) NOT NULL, Hits INT NOT NULL, Created_At TIMESTAMP NOT NULL, @@ -94,10 +100,10 @@ ); CREATE TABLE Cache_Stats_Back_Page_Element ( - Page_Element_Id VARCHAR(63) NOT NULL, - Page_Id VARCHAR(63) NOT NULL, - Rendering_Context VARCHAR(15) NOT NULL, - Workspace_JCR VARCHAR(15) NOT NULL, + Page_Element_Id VARCHAR(255) NOT NULL, + Page_Id VARCHAR(255) NOT NULL, + Rendering_Context VARCHAR(255) NOT NULL, + Workspace_JCR VARCHAR(255) NOT NULL, Cacheable NUMBER(1) NOT NULL, Hits INT NOT NULL, Cache_Hits INT NOT NULL, Index: main/plugin-web/scripts/postgresql/jdbc_cache_mon.sql =================================================================== --- main/plugin-web/scripts/postgresql/jdbc_cache_mon.sql (revision 21258) +++ main/plugin-web/scripts/postgresql/jdbc_cache_mon.sql (working copy) @@ -18,16 +18,17 @@ drop table if exists Cache_RA_HTTPServer; CREATE TABLE Cache_RA_HTTPServer ( - Unique_Id VARCHAR(31) NOT NULL, + Unique_Id VARCHAR(255) NOT NULL, Site VARCHAR(255) NOT NULL, Request_Date TIMESTAMP NOT NULL, - Method VARCHAR(15) NOT NULL, - Path VARCHAR(255) NOT NULL, - Query_String VARCHAR(255) NOT NULL, + Method VARCHAR(255) NOT NULL, + Path_Hash VARCHAR(255) NOT NULL, + Path TEXT NOT NULL, + Query_String TEXT NOT NULL, Ori_Status_Code CHAR(3) NOT NULL, Ret_Status_Code CHAR(3) NOT NULL, Cache_Hit SMALLINT NOT NULL, - Created_At TIMESTAMP NOT NULL, -- The DEFAULT clause prevents weird auto update (See Mysql doc) + Created_At TIMESTAMP NOT NULL, Processed SMALLINT NOT NULL DEFAULT 0, PRIMARY KEY (Unique_Id) ); @@ -35,37 +36,39 @@ drop table if exists Cache_RA_Front; CREATE TABLE Cache_RA_Front ( - Unique_Id VARCHAR(31) NOT NULL, - Internal_Uuid VARCHAR(63) NOT NULL, + Unique_Id VARCHAR(255) NOT NULL, + Internal_Uuid VARCHAR(255) NOT NULL, Site VARCHAR(255) NOT NULL, - Ametys_Path VARCHAR(255) NOT NULL, + Ametys_Path_Hash VARCHAR(255) NOT NULL, + Ametys_Path TEXT NOT NULL, Cacheable SMALLINT NOT NULL, Cache_Hit_1 SMALLINT NOT NULL, Cache_Hit_2 SMALLINT NOT NULL, - Created_At TIMESTAMP NOT NULL, -- The DEFAULT clause prevents weird auto update (See Mysql doc) + Created_At TIMESTAMP NOT NULL, Processed SMALLINT NOT NULL DEFAULT 0 ); drop table if exists Cache_RA_Back; CREATE TABLE Cache_RA_Back ( - Internal_Uuid VARCHAR(63) NOT NULL, - Page_Id VARCHAR(63) NOT NULL, - Page_Path VARCHAR(63) NOT NULL, - Rendering_Context VARCHAR(15) NOT NULL, - Workspace_JCR VARCHAR(15) NOT NULL, + Internal_Uuid VARCHAR(255) NOT NULL, + Page_Id VARCHAR(255) NOT NULL, + Page_Path_Hash VARCHAR(255) NOT NULL, + Page_Path TEXT NOT NULL, + Rendering_Context VARCHAR(255) NOT NULL, + Workspace_JCR VARCHAR(255) NOT NULL, Cacheable SMALLINT NOT NULL, - Created_At TIMESTAMP NOT NULL, -- The DEFAULT clause prevents weird auto update (See Mysql doc) + Created_At TIMESTAMP NOT NULL, Processed SMALLINT NOT NULL DEFAULT 0 ); drop table if exists Cache_RA_Back_Page_Element; CREATE TABLE Cache_RA_Back_Page_Element ( - Internal_Uuid VARCHAR(63) NOT NULL, - Page_Element_Id VARCHAR(63) NOT NULL, - Page_Element_Type VARCHAR(31) NOT NULL, - Page_Id VARCHAR(63) NOT NULL, - Rendering_Context VARCHAR(15) NOT NULL, - Workspace_JCR VARCHAR(15) NOT NULL, + Internal_Uuid VARCHAR(255) NOT NULL, + Page_Element_Id VARCHAR(255) NOT NULL, + Page_Element_Type VARCHAR(255) NOT NULL, + Page_Id VARCHAR(255) NOT NULL, + Rendering_Context VARCHAR(255) NOT NULL, + Workspace_JCR VARCHAR(255) NOT NULL, Cacheable SMALLINT NOT NULL, Cache_Hit SMALLINT NOT NULL, Created_At TIMESTAMP NOT NULL, @@ -75,26 +78,29 @@ drop table if exists Cache_Stats_Front; CREATE TABLE Cache_Stats_Front ( Server_Site VARCHAR(255) NOT NULL DEFAULT '-', - Server_Path VARCHAR(255) NOT NULL DEFAULT '-', + Server_Path_Hash VARCHAR(255) NOT NULL DEFAULT '-', + Server_Path TEXT, Server_Hits INT NOT NULL DEFAULT 0, Server_Cache_Hits INT NOT NULL DEFAULT 0, Front_Site VARCHAR(255) NOT NULL DEFAULT '-', - Front_Path VARCHAR(255) NOT NULL DEFAULT '-', + Front_Path_Hash VARCHAR(255) NOT NULL DEFAULT '-', + Front_Path TEXT, Front_Cacheable SMALLINT NOT NULL DEFAULT 0, Front_Hits INT NOT NULL DEFAULT 0, Front_Cache_Hits_1 INT NOT NULL DEFAULT 0, Front_Cache_Hits_2 INT NOT NULL DEFAULT 0, Created_At TIMESTAMP NOT NULL, Updated_At TIMESTAMP NOT NULL, - UNIQUE (Server_Site, Server_Path, Front_Site, Front_Path) + UNIQUE (Server_Site, Server_Path_Hash, Front_Site, Front_Path_Hash) ); drop table if exists Cache_Stats_Back; CREATE TABLE Cache_Stats_Back ( - Page_Id VARCHAR(63) NOT NULL, - Page_Path VARCHAR(63) NOT NULL, - Rendering_Context VARCHAR(15) NOT NULL, - Workspace_JCR VARCHAR(15) NOT NULL, + Page_Id VARCHAR(255) NOT NULL, + Page_Path_Hash VARCHAR(255) NOT NULL, + Page_Path TEXT NOT NULL, + Rendering_Context VARCHAR(255) NOT NULL, + Workspace_JCR VARCHAR(255) NOT NULL, Cacheable SMALLINT NOT NULL, Hits INT NOT NULL, Created_At TIMESTAMP NOT NULL, @@ -104,10 +110,10 @@ drop table if exists Cache_Stats_Back_Page_Element; CREATE TABLE Cache_Stats_Back_Page_Element ( - Page_Element_Id VARCHAR(63) NOT NULL, - Page_Id VARCHAR(63) NOT NULL, - Rendering_Context VARCHAR(15) NOT NULL, - Workspace_JCR VARCHAR(15) NOT NULL, + Page_Element_Id VARCHAR(255) NOT NULL, + Page_Id VARCHAR(255) NOT NULL, + Rendering_Context VARCHAR(255) NOT NULL, + Workspace_JCR VARCHAR(255) NOT NULL, Cacheable SMALLINT NOT NULL, Hits INT NOT NULL, Cache_Hits INT NOT NULL, Index: main/plugin-web/scripts/mysql/jdbc_cache_mon.sql =================================================================== --- main/plugin-web/scripts/mysql/jdbc_cache_mon.sql (revision 21258) +++ main/plugin-web/scripts/mysql/jdbc_cache_mon.sql (working copy) @@ -1,5 +1,5 @@ -- --- Copyright 2012 Anyware Services +-- Copyright 2013 Anyware Services -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. @@ -16,12 +16,13 @@ drop table if exists Cache_RA_HTTPServer; CREATE TABLE Cache_RA_HTTPServer ( - Unique_Id VARCHAR(31) NOT NULL, + Unique_Id VARCHAR(255) NOT NULL, Site VARCHAR(255) NOT NULL, Request_Date TIMESTAMP NOT NULL, - Method VARCHAR(15) NOT NULL, - Path VARCHAR(255) NOT NULL, - Query_String VARCHAR(255) NOT NULL, + Method VARCHAR(255) NOT NULL, + Path_Hash VARCHAR(255) NOT NULL, + Path TEXT NOT NULL, + Query_String TEXT NOT NULL, Ori_Status_Code CHAR(3) NOT NULL, Ret_Status_Code CHAR(3) NOT NULL, Cache_Hit TINYINT(1) NOT NULL, @@ -32,10 +33,11 @@ drop table if exists Cache_RA_Front; CREATE TABLE Cache_RA_Front ( - Unique_Id VARCHAR(31) NOT NULL, - Internal_Uuid VARCHAR(63) NOT NULL, + Unique_Id VARCHAR(255) NOT NULL, + Internal_Uuid VARCHAR(255) NOT NULL, Site VARCHAR(255) NOT NULL, - Ametys_Path VARCHAR(255) NOT NULL, + Ametys_Path_Hash VARCHAR(255) NOT NULL, + Ametys_Path TEXT NOT NULL, Cacheable TINYINT(1) NOT NULL, Cache_Hit_1 TINYINT(1) NOT NULL, Cache_Hit_2 TINYINT(1) NOT NULL, @@ -45,11 +47,12 @@ drop table if exists Cache_RA_Back; CREATE TABLE Cache_RA_Back ( - Internal_Uuid VARCHAR(63) NOT NULL, + Internal_Uuid VARCHAR(255) NOT NULL, Page_Id VARCHAR(255) NOT NULL, - Page_Path VARCHAR(255) NOT NULL, - Rendering_Context VARCHAR(15) NOT NULL, - Workspace_JCR VARCHAR(15) NOT NULL, + Page_Path_Hash VARCHAR(255) NOT NULL, + Page_Path TEXT NOT NULL, + Rendering_Context VARCHAR(255) NOT NULL, + Workspace_JCR VARCHAR(255) NOT NULL, Cacheable TINYINT(1) NOT NULL, Created_At TIMESTAMP NOT NULL DEFAULT 0, -- The DEFAULT clause prevents weird auto update (See Mysql doc) Processed TINYINT(1) NOT NULL DEFAULT 0 @@ -57,12 +60,12 @@ drop table if exists Cache_RA_Back_Page_Element; CREATE TABLE Cache_RA_Back_Page_Element ( - Internal_Uuid VARCHAR(63) NOT NULL, + Internal_Uuid VARCHAR(255) NOT NULL, Page_Element_Id VARCHAR(255) NOT NULL, Page_Element_Type VARCHAR(255) NOT NULL, Page_Id VARCHAR(255) NOT NULL, - Rendering_Context VARCHAR(15) NOT NULL, - Workspace_JCR VARCHAR(15) NOT NULL, + Rendering_Context VARCHAR(255) NOT NULL, + Workspace_JCR VARCHAR(255) NOT NULL, Cacheable TINYINT(1) NOT NULL, Cache_Hit TINYINT(1) NOT NULL, Created_At TIMESTAMP NOT NULL DEFAULT 0, -- The DEFAULT clause prevents weird auto update (See Mysql doc) @@ -72,26 +75,29 @@ drop table if exists Cache_Stats_Front; CREATE TABLE Cache_Stats_Front ( Server_Site VARCHAR(255) NOT NULL DEFAULT '-', - Server_Path VARCHAR(255) NOT NULL DEFAULT '-', + Server_Path_Hash VARCHAR(255) NOT NULL DEFAULT '-', + Server_Path TEXT, Server_Hits INT NOT NULL DEFAULT 0, Server_Cache_Hits INT NOT NULL DEFAULT 0, Front_Site VARCHAR(255) NOT NULL DEFAULT '-', - Front_Path VARCHAR(255) NOT NULL DEFAULT '-', + Front_Path_Hash VARCHAR(255) NOT NULL DEFAULT '-', + Front_Path TEXT, Front_Cacheable TINYINT(1) NOT NULL DEFAULT 0, Front_Hits INT NOT NULL DEFAULT 0, Front_Cache_Hits_1 INT NOT NULL DEFAULT 0, Front_Cache_Hits_2 INT NOT NULL DEFAULT 0, Created_At TIMESTAMP NOT NULL DEFAULT 0, -- The DEFAULT clause prevents weird auto update (See Mysql doc) Updated_At TIMESTAMP NOT NULL DEFAULT 0, -- The DEFAULT clause prevents weird auto update (See Mysql doc) - UNIQUE KEY (Server_Site, Server_Path, Front_Site, Front_Path) + UNIQUE KEY (Server_Site, Server_Path_Hash, Front_Site, Front_Path_Hash) ) ENGINE=InnoDB; drop table if exists Cache_Stats_Back; CREATE TABLE Cache_Stats_Back ( Page_Id VARCHAR(255) NOT NULL, - Page_Path VARCHAR(255) NOT NULL, - Rendering_Context VARCHAR(15) NOT NULL, - Workspace_JCR VARCHAR(15) NOT NULL, + Page_Path_Hash VARCHAR(255) NOT NULL, + Page_Path TEXT NOT NULL, + Rendering_Context VARCHAR(255) NOT NULL, + Workspace_JCR VARCHAR(255) NOT NULL, Cacheable TINYINT(1) NOT NULL, Hits INT NOT NULL, Created_At TIMESTAMP NOT NULL DEFAULT 0, -- The DEFAULT clause prevents weird auto update (See Mysql doc) @@ -101,10 +107,10 @@ drop table if exists Cache_Stats_Back_Page_Element; CREATE TABLE Cache_Stats_Back_Page_Element ( - Page_Element_Id VARCHAR(63) NOT NULL, + Page_Element_Id VARCHAR(255) NOT NULL, Page_Id VARCHAR(255) NOT NULL, - Rendering_Context VARCHAR(15) NOT NULL, - Workspace_JCR VARCHAR(15) NOT NULL, + Rendering_Context VARCHAR(255) NOT NULL, + Workspace_JCR VARCHAR(255) NOT NULL, Cacheable TINYINT(1) NOT NULL, Hits INT NOT NULL, Cache_Hits INT NOT NULL, Index: main/plugin-web/src/org/ametys/web/cache/monitoring/ui/PageElementCacheStatsGenerator.java =================================================================== --- main/plugin-web/src/org/ametys/web/cache/monitoring/ui/PageElementCacheStatsGenerator.java (revision 21258) +++ main/plugin-web/src/org/ametys/web/cache/monitoring/ui/PageElementCacheStatsGenerator.java (working copy) @@ -35,7 +35,6 @@ import org.apache.cocoon.generation.ServiceableGenerator; import org.apache.cocoon.xml.AttributesImpl; import org.apache.cocoon.xml.XMLUtils; -import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; @@ -469,32 +468,6 @@ _hits = __toInt(data.get("P_HITS")); } - private boolean __toBool(Object object) - { - if (object instanceof Boolean) - { - return BooleanUtils.toBoolean((Boolean) object); - } - else if (object instanceof Number) - { - Number i = (Number) object; - return i != null && i.intValue() != 0; - } - - throw new IllegalArgumentException("Not able to convert object to bool : unexpected object type."); - } - - private int __toInt(Object object) - { - if (object instanceof Number) - { - Number n = (Number) object; - return n == null ? 0 : n.intValue(); - } - - throw new IllegalArgumentException("Not able to convert object to int : unexpected object type."); - } - /** * Returns the formatted context name * @return context name @@ -569,31 +542,54 @@ _hits = __toInt(data.get("PE_HITS")); _cacheHits = __toInt(data.get("PE_CACHE_HITS")); } + } + + /** + * Utility method + * Object to boolean + * @param object + * @return the boolean + */ + protected boolean __toBool(Object object) + { + if (object == null) + { + return false; + } - private boolean __toBool(Object object) + if (object instanceof Boolean) { - if (object instanceof Boolean) - { - return BooleanUtils.toBoolean((Boolean) object); - } - else if (object instanceof Number) - { - Number i = (Number) object; - return i != null && i.intValue() != 0; - } + Boolean b = (Boolean) object; + return b.booleanValue(); + } + else if (object instanceof Number) + { + Number i = (Number) object; + return i.intValue() != 0; + } - throw new IllegalArgumentException("Not able to convert object to bool : unexpected object type."); + throw new IllegalArgumentException("Not able to convert object to bool : unexpected object type."); + } + + /** + * Utility method + * Object to int + * @param object + * @return the int + */ + protected int __toInt(Object object) + { + if (object == null) + { + return 0; } - private int __toInt(Object object) + if (object instanceof Number) { - if (object instanceof Number) - { - Number n = (Number) object; - return n == null ? 0 : n.intValue(); - } - - throw new IllegalArgumentException("Not able to convert object to int : unexpected object type."); + Number n = (Number) object; + return n.intValue(); } + + throw new IllegalArgumentException("Not able to convert object to int : unexpected object type."); } } Index: main/plugin-web/src/org/ametys/web/cache/monitoring/ui/ServersCacheStatsGenerator.java =================================================================== --- main/plugin-web/src/org/ametys/web/cache/monitoring/ui/ServersCacheStatsGenerator.java (revision 21258) +++ main/plugin-web/src/org/ametys/web/cache/monitoring/ui/ServersCacheStatsGenerator.java (working copy) @@ -17,6 +17,7 @@ package org.ametys.web.cache.monitoring.ui; import java.io.IOException; +import java.sql.Clob; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -39,7 +40,6 @@ import org.apache.cocoon.generation.ServiceableGenerator; import org.apache.cocoon.xml.AttributesImpl; import org.apache.cocoon.xml.XMLUtils; -import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.StringUtils; import org.joda.time.Duration; import org.joda.time.format.PeriodFormat; @@ -222,7 +222,7 @@ sb.append(" B.Page_Id, B.Page_Path, B.Cacheable, B.Hits"); sb.append(" FROM ").append(Constants.__SQL_TABLE_NAME_HTTPSERVER_AND_FRONT_STATISTICS).append(" F"); sb.append(" LEFT OUTER JOIN ").append(Constants.__SQL_TABLE_NAME_PAGE_STATISTICS).append(" B"); - sb.append(" ON F.Front_Path = B.Page_Path AND B.Rendering_Context = 'front'"); + sb.append(" ON F.Front_Path_Hash = B.Page_Path_Hash AND B.Rendering_Context = 'front'"); sb.append(" WHERE (F.Server_Site = ? OR F.Server_Site = '-' OR F.Front_Site = ? OR F.Front_Site = '-')"); return sb.toString(); @@ -599,9 +599,21 @@ /** * Ctor * @param data map of raw data object. + * @throws SQLException */ - protected RawStatsEntry(Map data) + protected RawStatsEntry(Map data) throws SQLException { + // Mandatory pre-processing of data that contains a Path. + // It must be done while the underlying ResultSet object is not + // closed to correctly handle CLOB to String conversion. + for (String key : data.keySet()) + { + if (key.contains("PATH")) + { + data.put(key, __textToString(data.get(key))); + } + } + _data = data; } @@ -624,6 +636,33 @@ String pageId = (String) _data.get("PAGE_ID"); return pageId != null && !"-".equals(pageId); } + + /** + * Utility method + * Object representing a text to String + * @param object + * @return the boolean + * @throws SQLException + */ + protected String __textToString(Object object) throws SQLException + { + if (object == null) + { + return null; + } + + if (object instanceof String) + { + return (String) object; + } + else if (object instanceof Clob) + { + Clob clob = (Clob) object; + return clob.getSubString(1, (int) clob.length()); + } + + throw new IllegalArgumentException("Not able to convert text object to String : unexpected object type."); + } } /** @@ -788,43 +827,6 @@ _frontCacheHits1 = __toInt(data.get("FRONT_CACHE_HITS_1")); _frontCacheHits2 = __toInt(data.get("FRONT_CACHE_HITS_2")); } - - - /** - * Object to boolean - * @param object - * @return the boolean - */ - protected boolean __toBool(Object object) - { - if (object instanceof Boolean) - { - return BooleanUtils.toBoolean((Boolean) object); - } - else if (object instanceof Number) - { - Number i = (Number) object; - return i != null && i.intValue() != 0; - } - - throw new IllegalArgumentException("Not able to convert object to bool : unexpected object type."); - } - - /** - * Object to int - * @param object - * @return the int - */ - protected int __toInt(Object object) - { - if (object instanceof Number) - { - Number n = (Number) object; - return n == null ? 0 : n.intValue(); - } - - throw new IllegalArgumentException("Not able to convert object to int : unexpected object type."); - } } /** @@ -853,41 +855,54 @@ _cacheable = __toBool(data.get("CACHEABLE")); _hits = __toInt(data.get("HITS")); } - - /** - * Object to boolean - * @param object - * @return the boolean - */ - protected boolean __toBool(Object object) + } + + /** + * Utility method + * Object to boolean + * @param object + * @return the boolean + */ + protected boolean __toBool(Object object) + { + if (object == null) { - if (object instanceof Boolean) - { - return BooleanUtils.toBoolean((Boolean) object); - } - else if (object instanceof Number) - { - Number i = (Number) object; - return i != null && i.intValue() != 0; - } - - throw new IllegalArgumentException("Not able to convert object to bool : unexpected object type."); + return false; } - - /** - * Object to int - * @param object - * @return the int - */ - protected int __toInt(Object object) + + if (object instanceof Boolean) { - if (object instanceof Number) - { - Number n = (Number) object; - return n == null ? 0 : n.intValue(); - } + Boolean b = (Boolean) object; + return b.booleanValue(); + } + else if (object instanceof Number) + { + Number i = (Number) object; + return i.intValue() != 0; + } - throw new IllegalArgumentException("Not able to convert object to int : unexpected object type."); + throw new IllegalArgumentException("Not able to convert object to bool : unexpected object type."); + } + + /** + * Utility method + * Object to int + * @param object + * @return the int + */ + protected int __toInt(Object object) + { + if (object == null) + { + return 0; + } + + if (object instanceof Number) + { + Number n = (Number) object; + return n.intValue(); } + + throw new IllegalArgumentException("Not able to convert object to int : unexpected object type."); } } Index: main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/FrontFromHTTPServerResourceStatistics.java =================================================================== --- main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/FrontFromHTTPServerResourceStatistics.java (revision 21258) +++ main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/FrontFromHTTPServerResourceStatistics.java (working copy) @@ -33,10 +33,12 @@ { private final String _httpserverSite; private final String _httpserverPath; + private final String _httpserverPathHash; private final boolean _httpserverCacheHit; private final String _frontSite; private final String _frontPath; + private final String _frontPathHash; private final boolean _frontCacheable; private final boolean _frontCacheHit1; private final boolean _frontCacheHit2; @@ -46,23 +48,27 @@ /** * Creates a statistic * @param httpserverSite The httpserver site + * @param httpserverPathHash a consistent hash of the httpserver path. * @param httpserverPath The httpserver path * @param httpserverCacheHit The httpserver cache hit * @param frontSite The front site + * @param frontPathHash a consistent hash of the front path. * @param frontPath The front path * @param frontCacheable The front cacheable status * @param frontCacheHit1 The front cache hit 1 status * @param frontCacheHit2 The front cache hit 2 status * @param newHits The hits */ - public FrontFromHTTPServerResourceStatistics(String httpserverSite, String httpserverPath, boolean httpserverCacheHit, String frontSite, String frontPath, boolean frontCacheable, boolean frontCacheHit1, boolean frontCacheHit2, int newHits) + public FrontFromHTTPServerResourceStatistics(String httpserverSite, String httpserverPathHash, String httpserverPath, boolean httpserverCacheHit, String frontSite, String frontPathHash, String frontPath, boolean frontCacheable, boolean frontCacheHit1, boolean frontCacheHit2, int newHits) { _httpserverSite = httpserverSite; _httpserverPath = httpserverPath; + _httpserverPathHash = httpserverPathHash; _httpserverCacheHit = httpserverCacheHit; _frontSite = frontSite; _frontPath = frontPath; + _frontPathHash = frontPathHash; _frontCacheable = frontCacheable; _frontCacheHit1 = frontCacheHit1; _frontCacheHit2 = frontCacheHit2; @@ -73,10 +79,10 @@ @Override public PreparedStatement getFindStatement(Connection connection) throws SQLException { - PreparedStatement stmt = connection.prepareStatement("SELECT count(1) FROM " + Constants.__SQL_TABLE_NAME_HTTPSERVER_AND_FRONT_STATISTICS + " WHERE Server_Site = ? AND Server_Path = ?"); + PreparedStatement stmt = connection.prepareStatement("SELECT count(1) FROM " + Constants.__SQL_TABLE_NAME_HTTPSERVER_AND_FRONT_STATISTICS + " WHERE Server_Site = ? AND Server_Path_Hash = ?"); stmt.setString(1, _httpserverSite); - stmt.setString(2, _httpserverPath); + stmt.setString(2, _httpserverPathHash); return stmt; } @@ -84,23 +90,25 @@ @Override public PreparedStatement getInsertStatement(Connection connection) throws SQLException { - PreparedStatement stmt = connection.prepareStatement("INSERT INTO " + Constants.__SQL_TABLE_NAME_HTTPSERVER_AND_FRONT_STATISTICS + " (Server_Site, Server_Path, Server_Hits, Server_Cache_Hits, Front_Site, Front_Path, Front_Cacheable, Front_Hits, Front_Cache_Hits_1, Front_Cache_Hits_2, Created_At, Updated_At) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + PreparedStatement stmt = connection.prepareStatement("INSERT INTO " + Constants.__SQL_TABLE_NAME_HTTPSERVER_AND_FRONT_STATISTICS + " (Server_Site, Server_Path_Hash, Server_Path, Server_Hits, Server_Cache_Hits, Front_Site, Front_Path_Hash, Front_Path, Front_Cacheable, Front_Hits, Front_Cache_Hits_1, Front_Cache_Hits_2, Created_At, Updated_At) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, _httpserverSite); - stmt.setString(2, _httpserverPath); - stmt.setInt(3, _newHits); - stmt.setInt(4, _getServerCacheHits()); + stmt.setString(2, _httpserverPathHash); + stmt.setString(3, _httpserverPath); + stmt.setInt(4, _newHits); + stmt.setInt(5, _getServerCacheHits()); - stmt.setString(5, _frontSite); - stmt.setString(6, _frontPath); - stmt.setInt(7, BooleanUtils.toInteger(_frontCacheable)); - stmt.setInt(8, _newHits); - stmt.setInt(9, _getFrontCacheHits1()); - stmt.setInt(10, _getFrontCacheHits2()); + stmt.setString(6, _frontSite); + stmt.setString(7, _frontPathHash); + stmt.setString(8, _frontPath); + stmt.setInt(9, BooleanUtils.toInteger(_frontCacheable)); + stmt.setInt(10, _newHits); + stmt.setInt(11, _getFrontCacheHits1()); + stmt.setInt(12, _getFrontCacheHits2()); Timestamp now = new Timestamp(System.currentTimeMillis()); - stmt.setTimestamp(11, now); - stmt.setTimestamp(12, now); + stmt.setTimestamp(13, now); + stmt.setTimestamp(14, now); return stmt; } @@ -108,20 +116,21 @@ @Override public PreparedStatement getUpdateStatement(Connection connection) throws SQLException { - PreparedStatement stmt = connection.prepareStatement("UPDATE " + Constants.__SQL_TABLE_NAME_HTTPSERVER_AND_FRONT_STATISTICS + " SET Server_Hits = Server_Hits + ?, Server_Cache_Hits = Server_Cache_Hits + ?, Front_Site = ?, Front_Path = ?, Front_Cacheable = ?, Front_Hits = Front_Hits + ?, Front_Cache_Hits_1 = Front_Cache_Hits_1 + ?, Front_Cache_Hits_2 = Front_Cache_Hits_2 + ?, Updated_At = ? WHERE Server_Site = ? AND Server_Path = ?"); + PreparedStatement stmt = connection.prepareStatement("UPDATE " + Constants.__SQL_TABLE_NAME_HTTPSERVER_AND_FRONT_STATISTICS + " SET Server_Hits = Server_Hits + ?, Server_Cache_Hits = Server_Cache_Hits + ?, Front_Site = ?, Front_Path_Hash = ?, Front_Path = ?, Front_Cacheable = ?, Front_Hits = Front_Hits + ?, Front_Cache_Hits_1 = Front_Cache_Hits_1 + ?, Front_Cache_Hits_2 = Front_Cache_Hits_2 + ?, Updated_At = ? WHERE Server_Site = ? AND Server_Path_Hash = ?"); stmt.setInt(1, _newHits); stmt.setInt(2, _getServerCacheHits()); stmt.setString(3, _frontSite); - stmt.setString(4, _frontPath); - stmt.setInt(5, BooleanUtils.toInteger(_frontCacheable)); - stmt.setInt(6, _newHits); - stmt.setInt(7, _getFrontCacheHits1()); - stmt.setInt(8, _getFrontCacheHits2()); - stmt.setTimestamp(9, new Timestamp(System.currentTimeMillis())); + stmt.setString(4, _frontPathHash); + stmt.setString(5, _frontPath); + stmt.setInt(6, BooleanUtils.toInteger(_frontCacheable)); + stmt.setInt(7, _newHits); + stmt.setInt(8, _getFrontCacheHits1()); + stmt.setInt(9, _getFrontCacheHits2()); + stmt.setTimestamp(10, new Timestamp(System.currentTimeMillis())); - stmt.setString(10, _httpserverSite); - stmt.setString(11, _httpserverPath); + stmt.setString(11, _httpserverSite); + stmt.setString(12, _httpserverPathHash); return stmt; } Index: main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/HTTPServerOnlyResourceStatistics.java =================================================================== --- main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/HTTPServerOnlyResourceStatistics.java (revision 21258) +++ main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/HTTPServerOnlyResourceStatistics.java (working copy) @@ -32,20 +32,23 @@ { private final String _site; private final String _path; + private final String _hashPath; private final boolean _cacheHit; private final int _newHits; /** * Creates a statistics * @param site The site + * @param hashPath a consistent hash of the path. * @param path The path * @param cacheHit The cache hit status * @param newHits The number of hits */ - public HTTPServerOnlyResourceStatistics(String site, String path, boolean cacheHit, int newHits) + public HTTPServerOnlyResourceStatistics(String site, String hashPath, String path, boolean cacheHit, int newHits) { _site = site; _path = path; + _hashPath = hashPath; _cacheHit = cacheHit; _newHits = newHits; } @@ -53,10 +56,10 @@ @Override public PreparedStatement getFindStatement(Connection connection) throws SQLException { - PreparedStatement stmt = connection.prepareStatement("SELECT count(1) FROM " + Constants.__SQL_TABLE_NAME_HTTPSERVER_AND_FRONT_STATISTICS + " WHERE Server_Site = ? AND Server_Path = ?"); + PreparedStatement stmt = connection.prepareStatement("SELECT count(1) FROM " + Constants.__SQL_TABLE_NAME_HTTPSERVER_AND_FRONT_STATISTICS + " WHERE Server_Site = ? AND Server_Path_Hash = ?"); stmt.setString(1, _site); - stmt.setString(2, _path); + stmt.setString(2, _hashPath); return stmt; } @@ -64,16 +67,17 @@ @Override public PreparedStatement getInsertStatement(Connection connection) throws SQLException { - PreparedStatement stmt = connection.prepareStatement("INSERT INTO " + Constants.__SQL_TABLE_NAME_HTTPSERVER_AND_FRONT_STATISTICS + " (Server_Site, Server_Path, Server_Hits, Server_Cache_Hits, Created_At, Updated_At) values (?, ?, ?, ?, ?, ?)"); + PreparedStatement stmt = connection.prepareStatement("INSERT INTO " + Constants.__SQL_TABLE_NAME_HTTPSERVER_AND_FRONT_STATISTICS + " (Server_Site, Server_Path_Hash, Server_Path, Server_Hits, Server_Cache_Hits, Created_At, Updated_At) values (?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, _site); - stmt.setString(2, _path); - stmt.setInt(3, _newHits); - stmt.setInt(4, _getCacheHits()); + stmt.setString(2, _hashPath); + stmt.setString(3, _path); + stmt.setInt(4, _newHits); + stmt.setInt(5, _getCacheHits()); Timestamp now = new Timestamp(System.currentTimeMillis()); - stmt.setTimestamp(5, now); stmt.setTimestamp(6, now); + stmt.setTimestamp(7, now); return stmt; } @@ -81,14 +85,14 @@ @Override public PreparedStatement getUpdateStatement(Connection connection) throws SQLException { - PreparedStatement stmt = connection.prepareStatement("UPDATE " + Constants.__SQL_TABLE_NAME_HTTPSERVER_AND_FRONT_STATISTICS + " SET Server_Hits = Server_Hits + ?, Server_Cache_Hits = Server_Cache_Hits + ?, Updated_At = ? WHERE Server_Site = ? AND Server_Path = ?"); + PreparedStatement stmt = connection.prepareStatement("UPDATE " + Constants.__SQL_TABLE_NAME_HTTPSERVER_AND_FRONT_STATISTICS + " SET Server_Hits = Server_Hits + ?, Server_Cache_Hits = Server_Cache_Hits + ?, Updated_At = ? WHERE Server_Site = ? AND Server_Path_Hash = ?"); stmt.setInt(1, _newHits); stmt.setInt(2, _getCacheHits()); stmt.setTimestamp(3, new Timestamp(System.currentTimeMillis())); stmt.setString(4, _site); - stmt.setString(5, _path); + stmt.setString(5, _hashPath); return stmt; } Index: main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/HTTPServerOnlyResourceStatisticsFactory.java =================================================================== --- main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/HTTPServerOnlyResourceStatisticsFactory.java (revision 21258) +++ main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/HTTPServerOnlyResourceStatisticsFactory.java (working copy) @@ -22,7 +22,9 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.commons.lang.BooleanUtils; @@ -55,7 +57,13 @@ @Override public List getResourceAccessToProcess() throws SQLException { + // Two queries are necessary in order to retrieve the needed information + // while being compatible with every supported DBMS. + // This raw list holds the data retrieved by the first query. The real + // ResourceStatistics objects will be instantiated during the processing + // of the 2nd query. List resourceStatisticsList = new ArrayList(); + List> rawResourceList = new ArrayList>(); Connection connection = null; PreparedStatement stmt = null; @@ -63,19 +71,55 @@ try { connection = ConnectionHelper.getConnection(Constants.MONITORING_DATASOURCE_POOLNAME); - stmt = connection.prepareStatement("SELECT count(*) AS \"increment\", Site, Path, Cache_Hit FROM " + Constants.__SQL_TABLE_NAME_HTTPSERVER_ACCESS + " WHERE PROCESSED = 0 AND Cache_Hit = 1 AND (Ori_Status_Code = '200' OR Ori_Status_Code = '304') GROUP BY Site, Path, Cache_Hit"); + + // First query. + stmt = connection.prepareStatement("SELECT count(*) AS \"increment\", Site, Path_Hash, Cache_Hit FROM " + Constants.__SQL_TABLE_NAME_HTTPSERVER_ACCESS + " WHERE PROCESSED = 0 AND Cache_Hit = 1 AND (Ori_Status_Code = '200' OR Ori_Status_Code = '304') GROUP BY Site, Path_Hash, Cache_Hit"); resultSet = stmt.executeQuery(); while (resultSet.next()) { - String site = resultSet.getString("Site"); + Map rawResourceData = new HashMap(); + + rawResourceData.put("Site", resultSet.getString("Site")); + rawResourceData.put("Path_Hash", resultSet.getString("Path_Hash")); + rawResourceData.put("Cache_Hit", BooleanUtils.toBoolean(resultSet.getInt("Cache_Hit"))); + rawResourceData.put("increment", resultSet.getInt("increment")); + + rawResourceList.add(rawResourceData); + } + + // Second query. + ConnectionHelper.cleanup(resultSet); + ConnectionHelper.cleanup(stmt); + + stmt = connection.prepareStatement("SELECT Path, Path_Hash FROM " + Constants.__SQL_TABLE_NAME_HTTPSERVER_ACCESS + " WHERE PROCESSED = 0 AND Cache_Hit = 1 AND (Ori_Status_Code = '200' OR Ori_Status_Code = '304') ORDER BY Created_At DESC"); + resultSet = stmt.executeQuery(); + + Map pathMap = new HashMap(); + + while (resultSet.next()) + { + String hash = resultSet.getString("Path_Hash"); String path = resultSet.getString("Path"); - boolean cacheHit = BooleanUtils.toBoolean(resultSet.getInt("Cache_Hit")); - int newHits = resultSet.getInt("increment"); - - resourceStatisticsList.add(new HTTPServerOnlyResourceStatistics(site, path, cacheHit, newHits)); + + if (!pathMap.containsKey(hash)) + { + pathMap.put(hash, path); + } } - + + for (Map rawResourceData : rawResourceList) + { + String hash = (String) rawResourceData.get("Path_Hash"); + + resourceStatisticsList.add(new HTTPServerOnlyResourceStatistics( + (String) rawResourceData.get("Site"), + hash, + pathMap.get(hash), + (Boolean) rawResourceData.get("Cache_Hit"), + (Integer) rawResourceData.get("increment"))); + } + return resourceStatisticsList; } finally Index: main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/PageResourceStatisticsFactory.java =================================================================== --- main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/PageResourceStatisticsFactory.java (revision 21258) +++ main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/PageResourceStatisticsFactory.java (working copy) @@ -22,7 +22,9 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.commons.lang.BooleanUtils; @@ -55,7 +57,13 @@ @Override public List getResourceAccessToProcess() throws SQLException { + // Two queries are necessary in order to retrieve the needed information + // while being compatible with every supported DBMS. + // This raw list holds the data retrieved by the first query. The real + // ResourceStatistics objects will be instantiated during the processing + // of the 2nd query. List resourceStatisticsList = new ArrayList(); + List> rawResourceList = new ArrayList>(); Connection connection = null; PreparedStatement stmt = null; @@ -63,21 +71,61 @@ try { connection = ConnectionHelper.getConnection(Constants.MONITORING_DATASOURCE_POOLNAME); - stmt = connection.prepareStatement("SELECT count(*) AS \"increment\", Page_Id, Page_Path, Rendering_Context, Workspace_JCR, Cacheable FROM " + Constants.__SQL_TABLE_NAME_PAGE_ACCESS + " WHERE PROCESSED = 0 GROUP BY Page_Id, Page_Path, Rendering_Context, Workspace_JCR, Cacheable"); + + // First query. + stmt = connection.prepareStatement("SELECT count(*) AS \"increment\", Page_Id, Rendering_Context, Workspace_JCR, Cacheable FROM " + Constants.__SQL_TABLE_NAME_PAGE_ACCESS + " WHERE PROCESSED = 0 GROUP BY Page_Id, Rendering_Context, Workspace_JCR, Cacheable"); resultSet = stmt.executeQuery(); while (resultSet.next()) { - String pageId = resultSet.getString("Page_Id"); + Map rawResourceData = new HashMap(); + + rawResourceData.put("Page_Id", resultSet.getString("Page_Id")); + rawResourceData.put("Rendering_Context", resultSet.getString("Rendering_Context")); + rawResourceData.put("Workspace_JCR", resultSet.getString("Workspace_JCR")); + rawResourceData.put("Cacheable", BooleanUtils.toBoolean(resultSet.getInt("Cacheable"))); + rawResourceData.put("increment", resultSet.getInt("increment")); + + rawResourceList.add(rawResourceData); + } + + // Second query. + ConnectionHelper.cleanup(resultSet); + ConnectionHelper.cleanup(stmt); + + stmt = connection.prepareStatement("SELECT Page_Path, Page_Path_Hash, Page_Id FROM " + Constants.__SQL_TABLE_NAME_PAGE_ACCESS + " WHERE PROCESSED = 0 ORDER BY Created_At DESC"); + resultSet = stmt.executeQuery(); + + Map pathMap = new HashMap(); + Map hashPathMap = new HashMap(); + + while (resultSet.next()) + { + String id = resultSet.getString("Page_Id"); String path = resultSet.getString("Page_Path"); - String renderingContext = resultSet.getString("Rendering_Context"); - String workspaceJCR = resultSet.getString("Workspace_JCR"); - boolean cacheable = BooleanUtils.toBoolean(resultSet.getInt("Cacheable")); - int increment = resultSet.getInt("increment"); + String hash = resultSet.getString("Page_Path_Hash"); - resourceStatisticsList.add(new PageResourceStatistics(pageId, path, renderingContext, workspaceJCR, cacheable, increment)); + if (!pathMap.containsKey(id)) + { + pathMap.put(id, path); + hashPathMap.put(id, hash); + } } - + + for (Map rawResourceData : rawResourceList) + { + String id = (String) rawResourceData.get("Page_Id"); + + resourceStatisticsList.add(new PageResourceStatistics( + id, + hashPathMap.get(id), + pathMap.get(id), + (String) rawResourceData.get("Rendering_Context"), + (String) rawResourceData.get("Workspace_JCR"), + (Boolean) rawResourceData.get("Cacheable"), + (Integer) rawResourceData.get("increment"))); + } + return resourceStatisticsList; } finally Index: main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/FrontFromHTTPServerResourceStatisticsFactory.java =================================================================== --- main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/FrontFromHTTPServerResourceStatisticsFactory.java (revision 21258) +++ main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/FrontFromHTTPServerResourceStatisticsFactory.java (working copy) @@ -22,7 +22,9 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.avalon.framework.logger.Logger; import org.apache.commons.lang.BooleanUtils; @@ -59,7 +61,13 @@ @Override public List getResourceAccessToProcess() throws SQLException { + // Two queries are necessary in order to retrieve the needed information + // while being compatible with every supported DBMS. + // This raw list holds the data retrieved by the first query. The real + // ResourceStatistics objects will be instantiated during the processing + // of the 2nd query. List resourceStatisticsList = new ArrayList(); + List> rawResourceList = new ArrayList>(); Connection connection = null; PreparedStatement stmt = null; @@ -67,28 +75,83 @@ try { connection = ConnectionHelper.getConnection(Constants.MONITORING_DATASOURCE_POOLNAME); - stmt = connection.prepareStatement("SELECT count(*) AS \"increment\", S.Site AS \"S_Site\", S.Path AS \"S_Path\", S.Cache_Hit AS \"S_Cache_Hit\"," - + " F.Site AS \"F_Site\", F.Ametys_Path AS \"F_Ametys_Path\", F.Cacheable AS \"F_Cacheable\", F.Cache_Hit_1 AS \"F_Cache_Hit_1\", F.Cache_Hit_2 AS \"F_Cache_Hit_2\"" + + // First query. + stmt = connection.prepareStatement("SELECT count(*) AS \"increment\", S.Site AS \"S_Site\", S.Path_Hash AS \"S_Path_Hash\", S.Cache_Hit AS \"S_Cache_Hit\"," + + " F.Site AS \"F_Site\", F.Ametys_Path_Hash AS \"F_Ametys_Path_Hash\", F.Cacheable AS \"F_Cacheable\", F.Cache_Hit_1 AS \"F_Cache_Hit_1\", F.Cache_Hit_2 AS \"F_Cache_Hit_2\"" + " FROM " + Constants.__SQL_TABLE_NAME_FRONT_ACCESS + " F" + " INNER JOIN " + Constants.__SQL_TABLE_NAME_HTTPSERVER_ACCESS + " S ON F.Unique_Id = S.Unique_Id AND F.Processed = 0 AND (S.Ori_Status_Code = '200' OR S.Ori_Status_Code = '304')" - + " GROUP BY S.Site, S.Path, S.Cache_Hit, F.Site, F.Ametys_Path, F.Cacheable, F.Cache_Hit_1, F.Cache_Hit_2"); + + " GROUP BY S.Site, S.Path_Hash, S.Cache_Hit, F.Site, F.Ametys_Path_Hash, F.Cacheable, F.Cache_Hit_1, F.Cache_Hit_2"); resultSet = stmt.executeQuery(); while (resultSet.next()) { - String httpserverSite = resultSet.getString("S_Site"); - String httpserverPath = resultSet.getString("S_Path"); - boolean httpserverCacheHit = BooleanUtils.toBoolean(resultSet.getInt("S_Cache_Hit")); - String frontSite = resultSet.getString("F_Site"); - String frontPath = resultSet.getString("F_Ametys_Path"); - boolean frontCacheable = BooleanUtils.toBoolean(resultSet.getInt("F_Cacheable")); - boolean frontCacheHit1 = BooleanUtils.toBoolean(resultSet.getInt("F_Cache_Hit_1")); - boolean frontCacheHit2 = BooleanUtils.toBoolean(resultSet.getInt("F_Cache_Hit_2")); - int newHits = resultSet.getInt("increment"); - - resourceStatisticsList.add(new FrontFromHTTPServerResourceStatistics(httpserverSite, httpserverPath, httpserverCacheHit, frontSite, frontPath, frontCacheable, frontCacheHit1, frontCacheHit2, newHits)); + Map rawResourceData = new HashMap(); + + rawResourceData.put("S_Site", resultSet.getString("S_Site")); + rawResourceData.put("S_Path_Hash", resultSet.getString("S_Path_Hash")); + rawResourceData.put("S_Cache_Hit", BooleanUtils.toBoolean(resultSet.getInt("S_Cache_Hit"))); + rawResourceData.put("F_Site", resultSet.getString("F_Site")); + rawResourceData.put("F_Ametys_Path_Hash", resultSet.getString("F_Ametys_Path_Hash")); + rawResourceData.put("F_Cacheable", BooleanUtils.toBoolean(resultSet.getInt("F_Cacheable"))); + rawResourceData.put("F_Cache_Hit_1", BooleanUtils.toBoolean(resultSet.getInt("F_Cache_Hit_1"))); + rawResourceData.put("F_Cache_Hit_2", BooleanUtils.toBoolean(resultSet.getInt("F_Cache_Hit_2"))); + rawResourceData.put("increment", resultSet.getInt("increment")); + + rawResourceList.add(rawResourceData); } - + + // Second query. + ConnectionHelper.cleanup(resultSet); + ConnectionHelper.cleanup(stmt); + + stmt = connection.prepareStatement("SELECT S.Path AS \"S_Path\", S.Path_Hash AS \"S_Path_Hash\", F.Ametys_Path AS \"F_Ametys_Path\", F.Ametys_Path_Hash AS \"F_Ametys_Path_Hash\"" + + " FROM " + Constants.__SQL_TABLE_NAME_FRONT_ACCESS + " F" + + " INNER JOIN " + Constants.__SQL_TABLE_NAME_HTTPSERVER_ACCESS + " S ON F.Unique_Id = S.Unique_Id AND F.Processed = 0 AND (S.Ori_Status_Code = '200' OR S.Ori_Status_Code = '304')" + + " ORDER BY S.Request_Date DESC"); + resultSet = stmt.executeQuery(); + + Map sPathMap = new HashMap(); + Map fAmetysPathMap = new HashMap(); + + while (resultSet.next()) + { + String hash = resultSet.getString("S_Path_Hash"); + String path = resultSet.getString("S_Path"); + + if (!sPathMap.containsKey(hash)) + { + sPathMap.put(hash, path); + } + + hash = resultSet.getString("F_Ametys_Path_Hash"); + path = resultSet.getString("F_Ametys_Path"); + + if (!fAmetysPathMap.containsKey(hash)) + { + fAmetysPathMap.put(hash, path); + } + } + + for (Map rawResourceData : rawResourceList) + { + String sHash = (String) rawResourceData.get("S_Path_Hash"); + String fAmetysHash = (String) rawResourceData.get("F_Ametys_Path_Hash"); + + resourceStatisticsList.add(new FrontFromHTTPServerResourceStatistics( + (String) rawResourceData.get("S_Site"), + sHash, + sPathMap.get(sHash), + (Boolean) rawResourceData.get("S_Cache_Hit"), + (String) rawResourceData.get("F_Site"), + fAmetysHash, + fAmetysPathMap.get(fAmetysHash), + (Boolean) rawResourceData.get("F_Cacheable"), + (Boolean) rawResourceData.get("F_Cache_Hit_1"), + (Boolean) rawResourceData.get("F_Cache_Hit_2"), + (Integer) rawResourceData.get("increment"))); + } + return resourceStatisticsList; } finally @@ -110,22 +173,21 @@ connection = ConnectionHelper.getConnection(Constants.MONITORING_DATASOURCE_POOLNAME); StringBuilder sql = new StringBuilder(); - sql.append("UPDATE CACHE_RA_FRONT "); + sql.append("UPDATE ").append(Constants.__SQL_TABLE_NAME_FRONT_ACCESS).append(" "); sql.append("SET Processed = 1 "); sql.append("WHERE Processed = 0 "); sql.append("AND Unique_Id IN "); - sql.append(" (SELECT Unique_Id FROM CACHE_RA_HTTPSERVER WHERE (Ori_Status_Code = '200' OR Ori_Status_Code = '304'))"); + sql.append(" (SELECT Unique_Id FROM ").append(Constants.__SQL_TABLE_NAME_HTTPSERVER_ACCESS).append(" WHERE (Ori_Status_Code = '200' OR Ori_Status_Code = '304'))"); stmt = connection.createStatement(); int processed = stmt.executeUpdate(sql.toString()); - StringBuilder sql2 = new StringBuilder(); - sql2.append("UPDATE CACHE_RA_HTTPSERVER "); + sql2.append("UPDATE ").append(Constants.__SQL_TABLE_NAME_HTTPSERVER_ACCESS).append(" "); sql2.append("SET Processed = 1 "); sql2.append("WHERE Processed = 0 "); sql2.append("AND (Ori_Status_Code = '200' OR Ori_Status_Code = '304') "); sql2.append("AND Unique_Id IN "); - sql2.append(" (SELECT DISTINCT Unique_Id FROM CACHE_RA_FRONT)"); + sql2.append(" (SELECT DISTINCT Unique_Id FROM ").append(Constants.__SQL_TABLE_NAME_FRONT_ACCESS).append(")"); stmt2 = connection.createStatement(); int processed2 = stmt2.executeUpdate(sql2.toString()); Index: main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/FrontOnlyResourceStatistics.java =================================================================== --- main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/FrontOnlyResourceStatistics.java (revision 21258) +++ main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/FrontOnlyResourceStatistics.java (working copy) @@ -33,6 +33,7 @@ { private final String _site; private final String _path; + private final String _hashPath; private final boolean _cacheable; private final boolean _cacheHit1; private final boolean _cacheHit2; @@ -41,16 +42,18 @@ /** * Creates a statistics * @param site The site + * @param hashPath a consistent hash of the path. * @param path The path * @param cacheable The cacheable status * @param cacheHit1 The cache hit 1 status * @param cacheHit2 The cache hit 2 status * @param newHits The number of hits */ - public FrontOnlyResourceStatistics(String site, String path, boolean cacheable, boolean cacheHit1, boolean cacheHit2, int newHits) + public FrontOnlyResourceStatistics(String site, String hashPath, String path, boolean cacheable, boolean cacheHit1, boolean cacheHit2, int newHits) { _site = site; _path = path; + _hashPath = hashPath; _cacheable = cacheable; _cacheHit1 = cacheHit1; _cacheHit2 = cacheHit2; @@ -60,10 +63,10 @@ @Override public PreparedStatement getFindStatement(Connection connection) throws SQLException { - PreparedStatement stmt = connection.prepareStatement("SELECT count(1) FROM " + Constants.__SQL_TABLE_NAME_HTTPSERVER_AND_FRONT_STATISTICS + " WHERE Front_Site = ? AND Front_Path = ? AND Server_Path = '-'"); + PreparedStatement stmt = connection.prepareStatement("SELECT count(1) FROM " + Constants.__SQL_TABLE_NAME_HTTPSERVER_AND_FRONT_STATISTICS + " WHERE Front_Site = ? AND Front_Path_Hash = ? AND Server_Path_Hash = '-'"); stmt.setString(1, _site); - stmt.setString(2, _path); + stmt.setString(2, _hashPath); return stmt; } @@ -71,18 +74,19 @@ @Override public PreparedStatement getInsertStatement(Connection connection) throws SQLException { - PreparedStatement stmt = connection.prepareStatement("INSERT INTO " + Constants.__SQL_TABLE_NAME_HTTPSERVER_AND_FRONT_STATISTICS + " (Front_Site, Front_Path, Front_Cacheable, Front_Hits, Front_Cache_Hits_1, Front_Cache_Hits_2, Created_At, Updated_At) values (?, ?, ?, ?, ?, ?, ?, ?)"); + PreparedStatement stmt = connection.prepareStatement("INSERT INTO " + Constants.__SQL_TABLE_NAME_HTTPSERVER_AND_FRONT_STATISTICS + " (Front_Site, Front_Path_Hash, Front_Path, Front_Cacheable, Front_Hits, Front_Cache_Hits_1, Front_Cache_Hits_2, Created_At, Updated_At) values (?, ?, ?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, _site); - stmt.setString(2, _path); - stmt.setInt(3, BooleanUtils.toInteger(_cacheable)); - stmt.setInt(4, _newHits); - stmt.setInt(5, _getCacheHits1()); - stmt.setInt(6, _getCacheHits2()); + stmt.setString(2, _hashPath); + stmt.setString(3, _path); + stmt.setInt(4, BooleanUtils.toInteger(_cacheable)); + stmt.setInt(5, _newHits); + stmt.setInt(6, _getCacheHits1()); + stmt.setInt(7, _getCacheHits2()); Timestamp now = new Timestamp(System.currentTimeMillis()); - stmt.setTimestamp(7, now); stmt.setTimestamp(8, now); + stmt.setTimestamp(9, now); return stmt; } @@ -90,7 +94,7 @@ @Override public PreparedStatement getUpdateStatement(Connection connection) throws SQLException { - PreparedStatement stmt = connection.prepareStatement("UPDATE " + Constants.__SQL_TABLE_NAME_HTTPSERVER_AND_FRONT_STATISTICS + " SET Front_Cacheable = ?, Front_Hits = Front_Hits + ?, Front_Cache_Hits_1 = Front_Cache_Hits_1 + ?, Front_Cache_Hits_2 = Front_Cache_Hits_2 + ?, Updated_At = ? WHERE Front_Site = ? AND Front_Path = ? AND Server_Path = '-'"); + PreparedStatement stmt = connection.prepareStatement("UPDATE " + Constants.__SQL_TABLE_NAME_HTTPSERVER_AND_FRONT_STATISTICS + " SET Front_Cacheable = ?, Front_Hits = Front_Hits + ?, Front_Cache_Hits_1 = Front_Cache_Hits_1 + ?, Front_Cache_Hits_2 = Front_Cache_Hits_2 + ?, Updated_At = ? WHERE Front_Site = ? AND Front_Path_Hash = ? AND Server_Path_Hash = '-'"); stmt.setInt(1, BooleanUtils.toInteger(_cacheable)); stmt.setInt(2, _newHits); @@ -99,7 +103,7 @@ stmt.setTimestamp(5, new Timestamp(System.currentTimeMillis())); stmt.setString(6, _site); - stmt.setString(7, _path); + stmt.setString(7, _hashPath); return stmt; } Index: main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/FrontOnlyResourceStatisticsFactory.java =================================================================== --- main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/FrontOnlyResourceStatisticsFactory.java (revision 21258) +++ main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/FrontOnlyResourceStatisticsFactory.java (working copy) @@ -22,7 +22,9 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.commons.lang.BooleanUtils; @@ -55,7 +57,13 @@ @Override public List getResourceAccessToProcess() throws SQLException { + // Two queries are necessary in order to retrieve the needed information + // while being compatible with every supported DBMS. + // This raw list holds the data retrieved by the first query. The real + // ResourceStatistics objects will be instantiated during the processing + // of the 2nd query. List resourceStatisticsList = new ArrayList(); + List> rawResourceList = new ArrayList>(); Connection connection = null; PreparedStatement stmt = null; @@ -63,21 +71,59 @@ try { connection = ConnectionHelper.getConnection(Constants.MONITORING_DATASOURCE_POOLNAME); - stmt = connection.prepareStatement("SELECT count(*) AS \"increment\", Site, Ametys_Path, Cacheable, Cache_Hit_1, Cache_Hit_2 FROM " + Constants.__SQL_TABLE_NAME_FRONT_ACCESS + " WHERE PROCESSED = 0 AND Unique_Id = '-' GROUP BY Site, Ametys_Path, Cacheable, Cache_Hit_1, Cache_Hit_2"); + + // First query. + stmt = connection.prepareStatement("SELECT count(*) AS \"increment\", Site, Ametys_Path_Hash, Cacheable, Cache_Hit_1, Cache_Hit_2 FROM " + Constants.__SQL_TABLE_NAME_FRONT_ACCESS + " WHERE PROCESSED = 0 AND Unique_Id = '-' GROUP BY Site, Ametys_Path_Hash, Cacheable, Cache_Hit_1, Cache_Hit_2"); resultSet = stmt.executeQuery(); while (resultSet.next()) { - String site = resultSet.getString("Site"); - String path = resultSet.getString("Ametys_Path"); - boolean cacheable = BooleanUtils.toBoolean(resultSet.getInt("Cacheable")); - boolean cacheHit1 = BooleanUtils.toBoolean(resultSet.getInt("Cache_Hit_1")); - boolean cacheHit2 = BooleanUtils.toBoolean(resultSet.getInt("Cache_Hit_2")); - int newHits = resultSet.getInt("increment"); - - resourceStatisticsList.add(new FrontOnlyResourceStatistics(site, path, cacheable, cacheHit1, cacheHit2, newHits)); + Map rawResourceData = new HashMap(); + + rawResourceData.put("Site", resultSet.getString("Site")); + rawResourceData.put("Ametys_Path_Hash", resultSet.getString("Ametys_Path_Hash")); + rawResourceData.put("Cacheable", BooleanUtils.toBoolean(resultSet.getInt("Cacheable"))); + rawResourceData.put("Cache_Hit_1", BooleanUtils.toBoolean(resultSet.getInt("Cache_Hit_1"))); + rawResourceData.put("Cache_Hit_2", BooleanUtils.toBoolean(resultSet.getInt("Cache_Hit_2"))); + rawResourceData.put("increment", resultSet.getInt("increment")); + + rawResourceList.add(rawResourceData); } + // Second query. + ConnectionHelper.cleanup(resultSet); + ConnectionHelper.cleanup(stmt); + + stmt = connection.prepareStatement("SELECT Ametys_Path, Ametys_Path_Hash FROM " + Constants.__SQL_TABLE_NAME_FRONT_ACCESS + " WHERE PROCESSED = 0 AND Unique_Id = '-' ORDER BY Created_At DESC"); + resultSet = stmt.executeQuery(); + + Map pathMap = new HashMap(); + + while (resultSet.next()) + { + String hash = resultSet.getString("Ametys_Path_Hash"); + String path = resultSet.getString("Ametys_Path"); + + if (!pathMap.containsKey(hash)) + { + pathMap.put(hash, path); + } + } + + for (Map rawResourceData : rawResourceList) + { + String hash = (String) rawResourceData.get("Ametys_Path_Hash"); + + resourceStatisticsList.add(new FrontOnlyResourceStatistics( + (String) rawResourceData.get("Site"), + hash, + pathMap.get(hash), + (Boolean) rawResourceData.get("Cacheable"), + (Boolean) rawResourceData.get("Cache_Hit_1"), + (Boolean) rawResourceData.get("Cache_Hit_2"), + (Integer) rawResourceData.get("increment"))); + } + return resourceStatisticsList; } finally Index: main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/PageResourceStatistics.java =================================================================== --- main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/PageResourceStatistics.java (revision 21258) +++ main/plugin-web/src/org/ametys/web/cache/monitoring/process/statistics/impl/PageResourceStatistics.java (working copy) @@ -34,6 +34,7 @@ { private final String _pageId; private final String _path; + private final String _hashPath; private final String _renderingContext; private final String _workspaceJCR; private final boolean _cacheable; @@ -42,16 +43,18 @@ /** * Creates a page resource statistics * @param pageId The page id + * @param hashPath a consistent hash of the path. * @param path The associated path * @param renderingContext The rendering context * @param jcrWorkspace The jcr workspace * @param cacheable Is the page cacheable ? * @param increment Number of associated hits */ - public PageResourceStatistics(String pageId, String path, String renderingContext, String jcrWorkspace, boolean cacheable, int increment) + public PageResourceStatistics(String pageId, String hashPath, String path, String renderingContext, String jcrWorkspace, boolean cacheable, int increment) { _pageId = pageId; _path = path; + _hashPath = hashPath; _renderingContext = renderingContext; _workspaceJCR = jcrWorkspace; _cacheable = cacheable; @@ -73,18 +76,19 @@ @Override public PreparedStatement getInsertStatement(Connection connection) throws SQLException { - PreparedStatement stmt = connection.prepareStatement("INSERT INTO " + Constants.__SQL_TABLE_NAME_PAGE_STATISTICS + " (Page_Id, Page_Path, Rendering_Context, Workspace_JCR, Cacheable, Hits, Created_At, Updated_At) values (?, ?, ?, ?, ?, ?, ?, ?)"); + PreparedStatement stmt = connection.prepareStatement("INSERT INTO " + Constants.__SQL_TABLE_NAME_PAGE_STATISTICS + " (Page_Id, Page_Path_Hash, Page_Path, Rendering_Context, Workspace_JCR, Cacheable, Hits, Created_At, Updated_At) values (?, ?, ?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, _pageId); - stmt.setString(2, _path); - stmt.setString(3, _renderingContext); - stmt.setString(4, _workspaceJCR); - stmt.setInt(5, BooleanUtils.toInteger(_cacheable)); - stmt.setInt(6, _newHits); + stmt.setString(2, _hashPath); + stmt.setString(3, _path); + stmt.setString(4, _renderingContext); + stmt.setString(5, _workspaceJCR); + stmt.setInt(6, BooleanUtils.toInteger(_cacheable)); + stmt.setInt(7, _newHits); Timestamp now = new Timestamp(System.currentTimeMillis()); - stmt.setTimestamp(7, now); stmt.setTimestamp(8, now); + stmt.setTimestamp(9, now); return stmt; } @@ -92,16 +96,17 @@ @Override public PreparedStatement getUpdateStatement(Connection connection) throws SQLException { - PreparedStatement stmt = connection.prepareStatement("UPDATE " + Constants.__SQL_TABLE_NAME_PAGE_STATISTICS + " SET Page_Path = ?, Cacheable = ?, Hits = Hits + ?, Updated_At = ? WHERE Page_Id = ? AND Rendering_Context = ? AND Workspace_JCR = ?"); + PreparedStatement stmt = connection.prepareStatement("UPDATE " + Constants.__SQL_TABLE_NAME_PAGE_STATISTICS + " SET Page_Path = ?, Page_Path_Hash = ?, Cacheable = ?, Hits = Hits + ?, Updated_At = ? WHERE Page_Id = ? AND Rendering_Context = ? AND Workspace_JCR = ?"); stmt.setString(1, _path); - stmt.setInt(2, BooleanUtils.toInteger(_cacheable)); - stmt.setInt(3, _newHits); - stmt.setTimestamp(4, new Timestamp(System.currentTimeMillis())); + stmt.setString(2, _hashPath); + stmt.setInt(3, BooleanUtils.toInteger(_cacheable)); + stmt.setInt(4, _newHits); + stmt.setTimestamp(5, new Timestamp(System.currentTimeMillis())); - stmt.setString(5, _pageId); - stmt.setString(6, _renderingContext); - stmt.setString(7, _workspaceJCR); + stmt.setString(6, _pageId); + stmt.setString(7, _renderingContext); + stmt.setString(8, _workspaceJCR); return stmt; } Index: main/plugin-web/src/org/ametys/web/cache/monitoring/process/CacheMonitoringScheduler.java =================================================================== --- main/plugin-web/src/org/ametys/web/cache/monitoring/process/CacheMonitoringScheduler.java (revision 21258) +++ main/plugin-web/src/org/ametys/web/cache/monitoring/process/CacheMonitoringScheduler.java (working copy) @@ -87,6 +87,7 @@ calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); + // TODO uncomment after testing // _timer.scheduleAtFixedRate(this, calendar.getTime(), 60 * 60 * 1000); _timer.scheduleAtFixedRate(this, 30 * 1000, 60 * 1000); Index: main/plugin-web/src/org/ametys/web/cache/monitoring/process/access/impl/PageResourceAccess.java =================================================================== --- main/plugin-web/src/org/ametys/web/cache/monitoring/process/access/impl/PageResourceAccess.java (revision 21258) +++ main/plugin-web/src/org/ametys/web/cache/monitoring/process/access/impl/PageResourceAccess.java (working copy) @@ -26,6 +26,7 @@ import org.ametys.web.cache.monitoring.Constants; import org.ametys.web.cache.monitoring.process.access.ResourceAccess; +import org.ametys.web.cache.monitoring.process.access.ResourceAccessUtils; import org.ametys.web.cache.monitoring.process.access.impl.PageElementResourceAccess.PageElementType; import org.ametys.web.renderingcontext.RenderingContext; @@ -37,6 +38,7 @@ private final String _internalUuid; private final String _pageID; private final String _path; + private final String _pathHash; private RenderingContext _renderingContext; private String _workspaceJCR; private boolean _cacheable; @@ -53,13 +55,16 @@ _internalUuid = StringUtils.defaultIfEmpty(internalUuid, "-"); _pageID = pageID; _path = StringUtils.substringBefore(path, "?"); + + // Calculate a hash for the path. + _pathHash = ResourceAccessUtils.toHash(_path); } @Override public PreparedStatement getInsertStatement(Connection connection) throws SQLException { - return connection.prepareStatement("INSERT INTO " + Constants.__SQL_TABLE_NAME_PAGE_ACCESS + " (Internal_Uuid, Page_Id, Page_Path, Rendering_Context, Workspace_JCR, Cacheable, Created_At) values (?, ?, ?, ?, ?, ?, ?)"); + return connection.prepareStatement("INSERT INTO " + Constants.__SQL_TABLE_NAME_PAGE_ACCESS + " (Internal_Uuid, Page_Id, Page_Path_Hash, Page_Path, Rendering_Context, Workspace_JCR, Cacheable, Created_At) values (?, ?, ?, ?, ?, ?, ?, ?)"); } @Override @@ -67,11 +72,12 @@ { stmt.setString(1, _internalUuid); stmt.setString(2, _pageID); - stmt.setString(3, _path); - stmt.setString(4, _renderingContext.toString()); - stmt.setString(5, _workspaceJCR); - stmt.setInt(6, BooleanUtils.toInteger(_cacheable)); - stmt.setTimestamp(7, new Timestamp(System.currentTimeMillis())); + stmt.setString(3, _pathHash); + stmt.setString(4, _path); + stmt.setString(5, _renderingContext.toString()); + stmt.setString(6, _workspaceJCR); + stmt.setInt(7, BooleanUtils.toInteger(_cacheable)); + stmt.setTimestamp(8, new Timestamp(System.currentTimeMillis())); } /** Index: main/plugin-web/src/org/ametys/web/cache/monitoring/process/access/ResourceAccessUtils.java =================================================================== --- main/plugin-web/src/org/ametys/web/cache/monitoring/process/access/ResourceAccessUtils.java (revision 0) +++ main/plugin-web/src/org/ametys/web/cache/monitoring/process/access/ResourceAccessUtils.java (revision 0) @@ -0,0 +1,52 @@ +package org.ametys.web.cache.monitoring.process.access; + +import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import org.apache.avalon.framework.logger.Logger; +import org.apache.commons.codec.binary.Hex; + +import org.ametys.runtime.util.LoggerFactory; + +/** + * Utility methods used when dealing with ResourceAccess object. + */ +public final class ResourceAccessUtils +{ + private static final Logger __LOGGER = LoggerFactory.getLoggerFor(ResourceAccessUtils.class); + + private ResourceAccessUtils() + { + // empty private constructor + } + + /** + * Computes the SHA-256 hash for a string. + * @param str The string to be hashed. + * @return The hashed string. + */ + public static String toHash(String str) + { + MessageDigest md; + byte[] hash; + + try + { + md = MessageDigest.getInstance("SHA-256"); + hash = md.digest(str.getBytes("UTF-8")); + } + catch (NoSuchAlgorithmException e) + { + __LOGGER.error("Cannot get the message digest instance for SHA-256", e); + return null; + } + catch (UnsupportedEncodingException e) + { + __LOGGER.error("UnsupportedEncodingException UTF-8", e); + return null; + } + + return Hex.encodeHexString(hash); + } +}