Hi,
sorry for the late reply, let's say i have the following code:
package testpkg.rules
declare Account
balance:Double
currency:String
end
declare Customer
account:Account
end
declare CustomerLimit
account:Account
limit:Double
end
declare SpentLimit
account : Account
spentAmount : Double
end
declare RemainingLimit
account: Account
remainingAmount : Double
end
rule "Calculate customer limit"
dialect "mvel"
when
Customer ( $account : account)
then
CustomerLimit $limit = new CustomerLimit();
$limit.setAccount($account);
$limit.setLimit(50);
insert($limit);
#insert(new CustomerLimit($account, 50));
end
rule "Calculate Remaining Limit"
dialect "mvel"
when
CustomerLimit($account : account, $limit : limit)
SpentLimit(account == $account, $spentAmount : spentAmount)
then
RemainingLimit $remainingLimit = new RemainingLimit();
$remainingLimit.setAccount($account);
$remainingLimit.setRemainingLimit($limit - $spentAmount);
insert($remainingLimit);
#insert(new RemainingLimit($account, $limit - $spentAmount));
end
My facts are of types used only in the rules so only customer and account
will be defined as normal POJOs, the other fact types (
CustomerLimit, SpentLimit, RemainingLimit) will be used only in the drools
rules. So instead of flooding the code of so many POJOs, I decided to use
declared types. I have the following issues:
1) If I use the declared type in one file, everything will be okay, but if I
decide to use it in other rule in another file there happens to be a
problem. So I tried to .package files as you advised. The problem with the
package files is, that the declared type can be used only in one directory.
Does it means that if I use one declared type in more than one directory I
should make it as normal POJO?
2)I am using the drools builder in eclipse to develop my rules, it is very
useful. But it gets puzzled if I use more than one package file to store my
declared types. If I am using one drools.package file and enter all declared
types in it, everything is working. But if I decide to use different file
for every type just to find it easily, the builder cannot find the classes.
But may be I don't understand the purpose of the .package files, can you
send me a little more details about it, or where I can read about it? Also,
please advise how to fix my rules in order eclipse drools builder continue
to work.
3)There is one difference in constructing declared type and normal pojo in
the rules. The java classes can have a constructor defined, and in the
example I have written above, you can see the commented line:
#insert(new RemainingLimit($account, $limit - $spentAmount));
I can't do this with the declared types, since there is no such constructor
defined. I am not sure if this is a valid point, but the commented line
seems a little bit more readable to me than:
RemainingLimit $remainingLimit = new RemainingLimit();
$remainingLimit.setAccount($account);
$remainingLimit.setRemainingLimit($limit - $spentAmount);
insert($remainingLimit);
I just want to doublecheck if there is a more proper way to this.
Thanks and please tell me if you need some more additional information.
Stanka
--
View this message in context:
http://drools-java-rules-engine.46999.n3.nabble.com/Import-of-declared-ty...
Sent from the Drools - Dev mailing list archive at
Nabble.com.