[rules-users] Type Declaration upgrade

Edson Tirelli ed.tirelli at gmail.com
Mon Feb 14 13:10:53 EST 2011


   The current version of Drools does not support dynamic changes in "type
declarations" and I don't see this changing anytime soon. The reason is that
not only the actual fact would require changes, but the actual knowledge
base would require changes as several nodes might be referencing the old
class.

   So, to update a fact type you need to recreate the knowledge base. This
is the same, BTW, than changing one of your fact classes in your application
jars... you need to recompile the knowledge base or you will end up with
class cast exceptions, sooner or later.

    Edson

2011/2/14 delete <boyun.yuriy at gmail.com>

>
> Hi.
> I have such declaration of type
> declare Contact
>  firstName : String
> end
>
> then I want to add new property to this type. so the  next version is
> declare Contact
>  firstName : String
>  newField : String
> end
>
> this type declaration is in separate drl file.
> then I add this new type to current KnowledgeBase.
> but when I execute knowledgeBase.getFactType("test.package", "Contact");
> I get old version of Contact.
>
> During debugging I found the place where is should be upgraded in the
> KnowledgeBase.
> org.drools.common.AbstractRuleBase.mergePackage
> there is
> // merge the type declarations
>        if ( newPkg.getTypeDeclarations() != null ) {
>            // add type declarations
>            for ( TypeDeclaration type :
> newPkg.getTypeDeclarations().values() ) {
>                // @TODO should we allow overrides? only if the class is not
> in use.
>                if ( !pkg.getTypeDeclarations().containsKey(
> type.getTypeName() ) ) {
>                    // add to package list of type declarations
>                    pkg.addTypeDeclaration( type );
>                }
>            }
>        }
>
> so according this comments it's not possible to upgrade Type on the fly.
>
> Am I missing something?
> Does someone had such problems or know the workaround.
>
> Thanks in advance,
> Yuriy
>
> --
> View this message in context:
> http://drools-java-rules-engine.46999.n3.nabble.com/Type-Declaration-upgrade-tp2491975p2491975.html
> Sent from the Drools - User mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
  Edson Tirelli
  JBoss Drools Core Development
  JBoss by Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110214/b99a6aa9/attachment.html 


More information about the rules-users mailing list