Custom Predicate and PersistenceInfo

Posts   
 
    
StampedeXV
User
Posts: 20
Joined: 06-Apr-2009
# Posted on: 26-Feb-2010 13:00:17   

Hi,

I wrote my own custom Predicate. So far so good. As given in other threads I overrode OnInsertPersistenceObjects in DataAccessAdapter.

Now I want to use the Predicate in many different LLBLGen Projects. If I'm not mistaken I'd have to override the OnInsertPersistenceObjects in the DataAccessAdapter of each project.

Is there a way to circumvent this? ( Maybe provide the PersistenceInfo to the Predicate at an earlier stage?)

Regards

Markus

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 27-Feb-2010 18:00:27   

Hi Markus. What does your custom predicate do? Most of the time the best option is inherit from an existen predicate class. What code do you have so far?

David Elizondo | LLBLGen Support Team
StampedeXV
User
Posts: 20
Joined: 06-Apr-2009
# Posted on: 01-Mar-2010 08:34:58   

Hi,

it takes an xpath string as input and a list of values, creates an exist query from it.

What would I gain from inheriting from an existing predicate? Wouldn't it be necessary to overwrite the method in DataAccessAdapter then?

The code from ToQueryText:


            
            uniqueMarker++;
            
            string fieldName = this.DatabaseSpecificCreator.CreateFieldName(field, persistenceInfo, field.Name, this.ObjectAlias, ref uniqueMarker, inHavingClause);
            
            StringBuilder newPath = new StringBuilder(256);
            newPath.AppendFormat("({0}).exist('(",fieldName).Append(xPath);

            if (this.values != null && this.values.Count > 0)
            {
                newPath.Append("[");
                bool first = false;
                int counter = 1;
                foreach (string val in this.values)
                {
                    if (!first)
                    {
                        first = true;
                    }
                    else
                    {
                        newPath.Append(" or ");
                    }
                    newPath.Append("contains(.,sql:variable(\"{{").Append(counter).Append("}}\"))");
                    counter++;
                }
                newPath.Append("]");
            }
            newPath.Append(")')=");


            if (base.Negate)
            {
                newPath.Append("0");
            }
            else
            {
                newPath.Append("1");
            }
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 01-Mar-2010 11:38:24   

the method in the dataaccessadapter has logic for existing predicates. So if your predicate always works on a single field or a field and an expression, you can derive from those predicates and the persistence info is inserted for you. It's unlikely your code has requirements differently from what's already there.

For example, if you want to compare a field's value with some expression, it's logical to use a fieldcompareexpression predicate and your custom code is then formed by an expression.

Your predicate suggests that it transforms the whole query sent to the db, correct? Or just the where clause? (as that's unclear). persistence info is only needed for elements which refer to tables/views etc. e.g. fields.

Frans Bouma | Lead developer LLBLGen Pro
StampedeXV
User
Posts: 20
Joined: 06-Apr-2009
# Posted on: 01-Mar-2010 17:42:04   

Hi,

the predicate should only modify the where clause. I thought that was the main or even sole purpose of a predicate.

I'll try with The FieldCompareExpression. As you describe it, it should work fine.

Thank you.

Markus