Predicate & hash key

Posts   
 
    
Fabrice
User
Posts: 180
Joined: 25-May-2004
# Posted on: 12-Mar-2007 12:47:55   

Hi all

In short: I need to get an hash key from a predicate, so I call ".GetHashCode()" But each different predicate but with the same filter return different hashkey. Do you have an idea on how to have a unique hashkey from the predicate content ? For example if I build 2 predicate object with a filter like "WHERE myId=1", how to have a method that return the same hashkey for both predicate object ?

Now a bit more explanation on why I need it. I've a process that fetch a lot of data from the database (sql server), make its job and then save the results. Now, I need some unit test and a garantee that changes done to this process will not break customer cases, but we get maybe 20 or 30 databases on customer location, sometime with customer specific configuration. Right now we've an nunit db set and we need to input a lot of data to recreate a real customer case in order to test it each night. So it take a lot of time and (of course) nobody do it, so we have maybe 100 nunit where we should have about 1000 to cover all the cases. I think anybody know this sort of problem simple_smile

So now ... I'm creating a tool that will generate in a file - all data (from the customer db) needed for the process - the results of the process And then run the process from the data in the file, and then comparing the results

The process before: Process -----> llblgen -----> db The process after Process -----> dataprovider ------> llblgen ------> db

I've 2 dataprovider right now: - the normal one, that works as before and it only fetch data from llblgen - the file dataprovider, that provide functionality to (un)serialize from/to file

the file dataprovider works in both way: - serialization : fetch from the db, then serialize the result in the file - deserialization: unserialize from the file and return this data (db is not needed anymore)

Ok now the heart of the problem: In serialize mode, the dataprovider compute an hash key from the method name and from all parameters to get an unique key, then it serialize the data with this unique key. In unserialize mode, it compute the same key and use it to retrieve data from the file and return it

Code example:


public CodeGetCode(int codId)
{
    Code    code = null;
    string  key = this.getUniqueHash(methodName(), codId);
    switch (this.SerializeDirection)
    {
case ComputeSerialization.Serialize:
{
    code = this.dbCddProvider.Cache.GetCode(codId);
    //serialize
    this.ComputeFileManager.Serialize( code, key );
    break;
}
case ComputeSerialization.Deserialize:
{
    code = new Code();
    this.ComputeFileManager.UnSerialize( code, key );
    break;
}
    }

    if (code != null && code.Fields.State == EntityState.OutOfSync)
code = null;
    return code;

The getHashKey method:

private string getUniqueHash(params object[] objList)   
{
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    System.Diagnostics.Debug.Write("getUniqueHash: ");

    string hashCode;
    foreach (object o in objList)
    {
    hashCode = o.GetType().FullName.GetHashCode().ToString() + o.GetHashCode().ToString();
System.Diagnostics.Debug.Write(string.Format("{0} ({1}) ||| ", o.ToString(), hashCode));
sb.Append(hashCode);
    }
    System.Diagnostics.Debug.WriteLine(" ----------> " + sb.ToString());

    return sb.ToString();
}

My problem is that for predicate this key change for each object instance, even if the sql output from the predicate is the same.

Any idea? Thank you for your help.

Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 12-Mar-2007 14:55:16   

Hi,

I think you must create a specific case if the object type is Predicate and call


myPredicate.ToQueryText(0);

and then call .GetHashCode() on the string returned witch is a string representation of the predicate like "myId=1"

cheers,

Aurélien

Fabrice
User
Posts: 180
Joined: 25-May-2004
# Posted on: 15-Mar-2007 10:43:34   

Hum Thank you I didn't see this method I'll test it today

It seem I'll have the same problem with the PrefetchPath2, do you have any other idea ? I think it'll be harder for this object type :s

Fabrice
User
Posts: 180
Joined: 25-May-2004
# Posted on: 15-Mar-2007 13:42:53   

Ok so I've tested the ToQueryText method. First, this method need that the DatabaseSpecificCreator isset on the predicate. I don't have any connection to the database (when unserializing), so I'm creating a new Sql creator, I've changed my code and now it's:

predicate.PredicateExpression.DatabaseSpecificCreator = new SD.LLBLGen.Pro.DQE.SqlServer.SqlServerSpecificCreator();
string query = predicate.PredicateExpression.ToQueryText(ref counter);
if (query != null)
    hashCode = query.GetHashCode().ToString();

In fact, when I do that I don't have anymore the error asking the DatabaseSpecificCreator, instead I've an "Object reference not set" exception. Does this method need anything else to be put on the predicate?

Stack trace:

Exception report - Thursday, March 15, 2007 1:48:26 PM
Object reference not set to an instance of an object.

Source : 
SD.LLBLGen.Pro.DQE.SqlServer.NET11

StackTrace : 
   at SD.LLBLGen.Pro.DQE.SqlServer.SqlServerSpecificCreator.CreateParameter(IEntityFieldCore field, IFieldPersistenceInfo persistenceInfo, ParameterDirection direction, Object valueToSet)
   at SD.LLBLGen.Pro.ORMSupportClasses.FieldCompareValuePredicate.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause)
   at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker, Boolean inHavingClause)
   at SD.LLBLGen.Pro.ORMSupportClasses.PredicateExpression.ToQueryText(Int32& uniqueMarker)
   at HRAccent.BusinessLayer.Process.Db2FileComputeDayDataProvider.getUniqueHash(Object[] objList) in c:\hraccentdevtree\src\trunk\hraccentserver.root\hraccentserver\hrabusinesslayer\process\db2filedataprovider.cs:line 1621
bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 16-Mar-2007 01:45:28   

http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=1159&HighLight=1 This thread looks to address that issue toward the end.

Fabrice
User
Posts: 180
Joined: 25-May-2004
# Posted on: 19-Mar-2007 13:22:05   

It works nice, thank you for the link !