|
From: <sv...@de...> - 2005-05-30 03:15:34
|
Author: marijn
Date: 2005-05-29 23:15:08 -0400 (Sun, 29 May 2005)
New Revision: 1195
Added:
humano2/branches/caching/components/viewTools/viewCache.cs
Modified:
humano2/branches/caching/components/viewTools/ViewTools.cs
humano2/branches/caching/components/webTools/Adapter.cs
humano2/branches/caching/core/db/absCrud.cs
humano2/branches/caching/web/portal/site/instance.aspx.cs
Log:
* Adding simple caching system for viewTools.
* Removing some excessive logger verbosity.
Modified: humano2/branches/caching/components/viewTools/ViewTools.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/branches/caching/components/viewTools/ViewTools.cs 2005-05-30=
01:11:31 UTC (rev 1194)
+++ humano2/branches/caching/components/viewTools/ViewTools.cs 2005-05-30=
03:15:08 UTC (rev 1195)
@@ -319,6 +319,11 @@
=20
public DataTable GetSQLDataTable(DataTable parametros)
{
+ return GetSQLDataTable(parametros, true);
+ }
+
+ private DataTable GetSQLDataTable(DataTable parametros, bool retry)
+ {
string sql =3D ParseQuery(parametros);
DataTable res =3D new DataTable();
int find =3D sql.IndexOf("tempTable");
@@ -363,8 +368,29 @@
// throw new Exception("Error realizando paginado de la consulta.\n"=
+ex.Message,ex.InnerException);
//}
}
- res =3D Complex.doSelect(sql);
=20
+ try=20
+ {
+ res =3D Complex.doSelect(sql);
+ }=20
+ catch (Exception ex)
+ { // We got an error executing the request!
+ if(retry)
+ {
+ Logger.Log("We got an exception executing SQL, Will flush cache!", =
LogLevel.Error);
+ Logger.Log("Statement was: " + sql, LogLevel.Error);
+ ViewCache.Instance().FlushAll();
+ GetSQLDataTable(parametros, false);
+ }
+ else
+ {
+ Logger.Log("We got an exception executing SQL again, Raising Error!=
", LogLevel.Error);
+ Logger.Log("Final Statement was: " + sql, LogLevel.Error); =09
+ throw ex;
+ }
+ =09
+ }
+
if(find > -1) {
Complex.doCommand(dropTable);
}
@@ -447,9 +473,9 @@
foreach(DisplayOrder var2 in disp)
{
vars.Add(var2.Text + "," + var2.Type);
- Logger.Log("ViewTools: vars[]=3D" + var2.Text + "," =
+ var2.Type,LogLevel.Trace);
+ //Logger.Log("ViewTools: vars[]=3D" + var2.Text + ",=
" + var2.Type,LogLevel.Trace);
}
- Logger.Log("ViewTools: call of BuildTempTable",LogLevel.=
Trace);
+ //Logger.Log("ViewTools: call of BuildTempTable",LogLeve=
l.Trace);
Query.Append(Complex.BuildTempTable((string[])vars.ToArray(typeof(st=
ring)),ref tableName));
TempTable =3D tableName;
}
@@ -461,7 +487,7 @@
=20
Query.Remove(Query.Length-2,2);
Query.Append(" ");
- Logger.Log("Select Query: " + Query.ToString() ,LogLevel.Tra=
ce);
+ //Logger.Log("Select Query: " + Query.ToString() ,LogLevel.T=
race);
return Query.ToString();
}
=20
@@ -636,10 +662,17 @@
{
DataRow objRow;
object[] objArray;
- StringBuilder Query =3D new StringBuilder();
- =09
+
objRow =3D Params.Rows[0];
+
+ string res =3D ViewCache.Instance().GetCachedStatement(objRow) ;
+ if( res !=3D null )
+ { // We got the cached datatable result. lets return that and not con=
struct a new one again.
+ return res;
+ }
+
objArray =3D objRow.ItemArray;
+ StringBuilder Query =3D new StringBuilder();
=09
string[] dataRowColumns =3D new string [objArray.Length];
=20
@@ -703,8 +736,12 @@
Query.Append(";\n");
Query.Append("SELECT * FROM " + TempTable + " where row between "+ i=
nicio.ToString() + " and " + limite.ToString());
}
- //Logger.Log("Query=3D" + Query.ToString(),LogLevel.Trace);
- return Query.ToString();
+
+ res =3D Query.ToString();
+ //Logger.Log("Query=3D" + res,LogLevel.Trace);
+ ViewCache.Instance().AddStatement(objRow, res);
+
+ return res;
}
=09
private string GetGroupingFilters(string[] strParams)
Added: humano2/branches/caching/components/viewTools/viewCache.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/branches/caching/components/viewTools/viewCache.cs 2005-05-30=
01:11:31 UTC (rev 1194)
+++ humano2/branches/caching/components/viewTools/viewCache.cs 2005-05-30=
03:15:08 UTC (rev 1195)
@@ -0,0 +1,90 @@
+//
+// The Humano2 Business solution.
+// Copyright (C) 2004,5 Humano2 Chile S.A. (http://www.humano2.com)
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// $Id: /humano2/local/core/db/cache.cs 119 2005-03-27T08:59:44.479824Z =
marijn $
+//
+
+using System;
+using System.Text;
+using System.Data;
+
+using Humano2.Core;
+
+namespace Humano2.Components.ViewTools=20
+{
+ public class ViewCache
+ {
+ /// <summary>
+ /// Constructor
+ /// </summary>
+ protected ViewCache() {
+ databaseStatementCache =3D new CacheDictionary();
+ =09
+ }
+ private CacheDictionary databaseStatementCache =3D null;
+
+ private static ViewCache instance =3D null;
+
+ /// <summary>
+ /// Get an instance of the viewCache
+ /// </summary>
+ /// <returns>the viewCache</returns>
+ public static ViewCache Instance() {
+ // Uses "Lazy initialization"
+ if( instance =3D=3D null ) {
+ instance =3D new ViewCache();
+ }
+ return instance;
+ }
+
+ public string GetCachedStatement(DataRow dr)
+ {
+ int rowHash =3D genStableHashKey(dr);
+ string res =3D (string) databaseStatementCache[rowHash];
+ /* if(res =3D=3D null)=20
+ {
+ Logger.Log("GetCachedStatement: MISS!", LogLevel.Trace);
+ }
+ else=20
+ {
+ Logger.Log("GetCachedStatement: HIT!", LogLevel.Trace);
+ } */
+ return res;
+ }
+
+ public void AddStatement(DataRow dr, string statement)
+ {
+ int rowHash =3D genStableHashKey(dr);
+ databaseStatementCache.Add(rowHash, statement);
+ }
+
+ private int genStableHashKey(DataRow dr)
+ {
+ StringBuilder res =3D new StringBuilder();
+ int colCount =3D dr.Table.Columns.Count;
+ for(int c =3D 0; c < colCount; c++)
+ {
+ res.Append(Convert.ToString(dr[c]));
+ }
+ string str =3D res.ToString();
+ int code =3D str.GetHashCode();
+
+ //Logger.Log("genStableHashKey: " + str + " =3D " + code, LogLevel.Tr=
ace);
+
+ return code;
+ }
+
+ ///<summary>Clean the cache. Resetting it to Empty.</summary>
+ public void FlushAll()=20
+ {
+ databaseStatementCache =3D new CacheDictionary(); =09
+ }
+
+ }
+}
Property changes on: humano2/branches/caching/components/viewTools/viewCa=
che.cs
___________________________________________________________________
Name: svn:mime-type
+ text/cpp
Modified: humano2/branches/caching/components/webTools/Adapter.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/branches/caching/components/webTools/Adapter.cs 2005-05-30 01=
:11:31 UTC (rev 1194)
+++ humano2/branches/caching/components/webTools/Adapter.cs 2005-05-30 03=
:15:08 UTC (rev 1195)
@@ -1037,6 +1037,8 @@
/// </summary>
/// <param name=3D"classId">The id of the class</param>
/// <returns>The name of class</returns>
+ /// <param name=3D"classId">The id of the class</param>
+ /// <returns>The name of class</returns>
public string GetClassNameById(int classId)
{
=20
Modified: humano2/branches/caching/core/db/absCrud.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/branches/caching/core/db/absCrud.cs 2005-05-30 01:11:31 UTC (=
rev 1194)
+++ humano2/branches/caching/core/db/absCrud.cs 2005-05-30 03:15:08 UTC (=
rev 1195)
@@ -59,7 +59,6 @@
virtual public string AttributeTypeMapping(string name)
{
string res =3D "";
- Logger.Log("AttributeTypeMapping. name=3D " + name, LogLevel=
.Trace);
if(attMap[name] =3D=3D null) //This is not a basic type
{
res =3D findSqlTypeForAttribute(attMap,name);
@@ -68,6 +67,7 @@
{
res =3D attMap[name]; =20
}
+ //Logger.Log("AttributeTypeMapping. name=3D " + name + " res=
=3D " + res, LogLevel.Trace);
return res;
}
=09
Modified: humano2/branches/caching/web/portal/site/instance.aspx.cs
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- humano2/branches/caching/web/portal/site/instance.aspx.cs 2005-05-30 =
01:11:31 UTC (rev 1194)
+++ humano2/branches/caching/web/portal/site/instance.aspx.cs 2005-05-30 =
03:15:08 UTC (rev 1195)
@@ -113,7 +113,7 @@
=20
=20
=20
- Logger.Log("createXmlASP: BEGIN",LogLevel.Trace);
+ //Logger.Log("createXmlASP: BEGIN",LogLevel.Trace);
=20
//Generamos el XML con la informacion de la entidad pedida=20
=09
@@ -228,7 +228,7 @@
data +=3D "</data>\n";
}
=20
- Logger.Log("createXmlASP: data(before)=3D" + data,Lo=
gLevel.Trace);
+ //Logger.Log("createXmlASP: data(before)=3D" + data,=
LogLevel.Trace);
//Construimos el Xml
string swXml =3D "";
swXml +=3D "<?xml version=3D\"1.0\" encoding=3D\"UTF=
-8\"?>";
@@ -249,8 +249,8 @@
swXml +=3D "</page>";
=20
//Logger.Log("createXmlASP: structure=3D" + structur=
e,LogLevel.Trace);
- Logger.Log("createXmlASP: clearDateTime(data)=3D" + =
clearDateTimeData(data),LogLevel.Trace);
- Logger.Log("swXml: " + swXml ,LogLevel.Trace);
+ //Logger.Log("createXmlASP: clearDateTime(data)=3D" =
+ clearDateTimeData(data),LogLevel.Trace);
+ //Logger.Log("swXml: " + swXml ,LogLevel.Trace);
return swXml;
=20
}
@@ -274,7 +274,7 @@
dateClearedData =3D dateClearedData.Replace("]",">"); =
=20
// NO SACAR: Ensucia los campos TEXT!! dateClearedData =3D=
dateClearedData.Replace(" ",""); //trim
dateClearedData =3D dateClearedData.Trim();
- Logger.Log("\n\n[clearDateTimeData ]: " + dateClearedDat=
a, LogLevel.Trace);
+ //Logger.Log("\n\n[clearDateTimeData ]: " + dateClearedD=
ata, LogLevel.Trace);
return dateClearedData;
}
=20
|