From: <jbo...@li...> - 2006-04-19 02:41:54
|
Author: woolfel Date: 2006-04-18 22:41:48 -0400 (Tue, 18 Apr 2006) New Revision: 3780 Added: labs/jbossrules/trunk/drools-examples/src/java/com/sample/benchmark/ labs/jbossrules/trunk/drools-examples/src/java/com/sample/benchmark/GenerateRuleSet.java labs/jbossrules/trunk/drools-examples/src/java/com/sample/benchmark/models/ labs/jbossrules/trunk/drools-examples/src/java/com/sample/benchmark/models/Account.java Log: added a simple ruleset generator and test class used in the rules. peter Added: labs/jbossrules/trunk/drools-examples/src/java/com/sample/benchmark/GenerateRuleSet.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/java/com/sample/benchmark/GenerateRuleSet.java 2006-04-19 02:19:52 UTC (rev 3779) +++ labs/jbossrules/trunk/drools-examples/src/java/com/sample/benchmark/GenerateRuleSet.java 2006-04-19 02:41:48 UTC (rev 3780) @@ -0,0 +1,57 @@ +package com.sample.benchmark; + +import java.io.FileWriter; + +public class GenerateRuleSet { + + /** + * + */ + public GenerateRuleSet() { + super(); + } + + public static void main(String[] args) { + // the number of rules + int count = 100; + String objectName = "Account"; + String outputFile = count + "_rules.drl"; + if (args == null || args.length < 1) { + // print out a message of the options + System.out.println("No parameters were set. Please provide a rule count"); + System.out.println("and filename."); + System.out.println(""); + System.out.println("example: GenerateRuleSet 1000 1000rules.drl"); + } else { + if (args[0] != null) { + count = Integer.parseInt(args[0]); + outputFile = args[1]; + } + String linebreak = System.getProperty("line.separator"); + String tab = " "; + try { + FileWriter writer = new FileWriter(outputFile); + StringBuffer buf = new StringBuffer(); + // delcare the package + buf.append("package org.drools.samples" + linebreak); + buf.append("import com.sample.benchmark.models.Account;" + linebreak + linebreak); + // now loop + for (int idx=0; idx < count; idx++) { + buf.append("rule rule" + idx + "" + linebreak); + buf.append(" when" + linebreak); + buf.append(" $acc : Account(status == \"standard\", title == \"mr\")" + + linebreak); + buf.append(" then" + linebreak); + buf.append(" System.out.println(\"rule" + idx + " fired\");" + linebreak); + buf.append("end" + linebreak + linebreak); + } + writer.write(buf.toString()); + writer.close(); + System.out.println("Generated " + count + " rules to " + outputFile); + } catch (Exception e) { + + } + } + + } +} Added: labs/jbossrules/trunk/drools-examples/src/java/com/sample/benchmark/models/Account.java =================================================================== --- labs/jbossrules/trunk/drools-examples/src/java/com/sample/benchmark/models/Account.java 2006-04-19 02:19:52 UTC (rev 3779) +++ labs/jbossrules/trunk/drools-examples/src/java/com/sample/benchmark/models/Account.java 2006-04-19 02:41:48 UTC (rev 3780) @@ -0,0 +1,241 @@ +package com.sample.benchmark.models; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeEvent; +import java.io.Serializable; +import java.util.ArrayList; + +/** + * @author Peter Lin + * + * A simple test bean that represents a generic account. It could be + * a bank account, shopping card account, or any type of membership + * account with a nationwide company. + */ +public class Account implements Serializable { + + protected String first = null; + protected String middle = null; + protected String last = null; + /** + * mr, mrs, ms, junior, etc + */ + protected String title = null; + protected String accountId = null; + protected String accountType = null; + protected String status = null; + protected String username = null; + /** + * this would represent the region of the office the account + * was opened at. + */ + protected String regionCode = null; + /** + * the code for the office where the account was opened. + */ + protected String officeCode = null; + protected String areaCode = null; + protected String exchange = null; + protected String number = null; + protected String ext = null; + + protected ArrayList listeners = new ArrayList(); + + /** + * + */ + public Account() { + super(); + } + + public void setTitle(String val){ + if (!val.equals(this.title)){ + String old = this.title; + this.title = val; + notifyListener("title",old,this.title); + } + } + + public String getTitle(){ + return this.title; + } + + public void setFirst(String val){ + if (!val.equals(this.first)){ + String old = this.first; + this.first = val; + notifyListener("first",old,this.first); + } + } + + public String getFirst(){ + return this.first; + } + + public void setLast(String val){ + if (!val.equals(this.last)){ + String old = this.last; + this.last = val; + notifyListener("last",old,this.last); + } + } + + public String getLast(){ + return this.last; + } + + public void setMiddle(String val){ + if (!val.equals(this.middle)){ + String old = this.middle; + this.middle = val; + notifyListener("middle",old,this.middle); + } + } + + public String getMiddle(){ + return this.middle; + } + + public void setOfficeCode(String val){ + if (!val.equals(this.officeCode)){ + String old = this.officeCode; + this.officeCode = val; + notifyListener("officeCode",old,this.officeCode); + } + } + + public String getOfficeCode(){ + return this.officeCode; + } + + public void setRegionCode(String val){ + if (!val.equals(this.regionCode)){ + String old = this.regionCode; + this.regionCode = val; + notifyListener("regionCode",old,this.regionCode); + } + } + + public String getRegionCode(){ + return this.regionCode; + } + + public void setStatus(String val){ + if (!val.equals(this.status)){ + String old = this.status; + this.status = val; + notifyListener("status",old,this.status); + } + } + + public String getStatus(){ + return this.status; + } + + public void setAccountId(String val){ + if (!val.equals(this.accountId)){ + String old = this.accountId; + this.accountId = val; + notifyListener("accountId",old,this.accountId); + } + } + + public String getAccountId(){ + return this.accountId; + } + + public void setAccountType(String val){ + if (!val.equals(this.accountType)){ + String old = this.accountType; + this.accountType = val; + notifyListener("accountType",old,this.accountType); + } + } + + public String getAccountType(){ + return this.accountType; + } + + public void setUsername(String val){ + if (!val.equals(this.username)){ + String old = this.username; + this.username = val; + notifyListener("username",old,this.username); + } + } + + public String getUsername(){ + return this.username; + } + + public String getAreaCode() { + return this.areaCode; + } + + public void setAreaCode(String val) { + if (!val.equals(this.areaCode)){ + String old = this.areaCode; + this.areaCode = val; + notifyListener("areaCode",old,this.areaCode); + } + } + + public String getExchange() { + return this.exchange; + } + + public void setExchange(String val) { + if (!val.equals(this.exchange)){ + String old = this.exchange; + this.exchange = val; + notifyListener("exchange",old,this.exchange); + } + } + + public String getNumber() { + return this.number; + } + + public void setNumber(String val) { + if (!val.equals(this.number)){ + String old = this.number; + this.number = val; + notifyListener("number",old,this.number); + } + } + + public String getExt() { + return this.ext; + } + + public void setExt(String val) { + if (!val.equals(this.ext)){ + String old = this.ext; + this.ext = val; + notifyListener("ext",old,this.ext); + } + } + + public void addPropertyChangeListener(PropertyChangeListener listener){ + this.listeners.add(listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener){ + this.listeners.remove(listener); + } + + protected void notifyListener(String field, Object oldValue, Object newValue){ + if (listeners == null || listeners.size() == 0) { + return; + } else { + PropertyChangeEvent event = new PropertyChangeEvent(this, field, + oldValue, newValue); + + for (int i = 0; i < listeners.size(); i++) { + ((java.beans.PropertyChangeListener) listeners.get(i)) + .propertyChange(event); + } + } + + } +} |