What are the f***ing system requirements for GOS 3 ?
According to the link above it's x86 1GHZ , 256Mb Ram . But I tried installing this on a laptop that is 2GHz with 256Mb Ram and on the first step of the installer on the live cd (where you select the language) , everything just froze :-(
If anybody else has had this problem and knows what to do, please leave a comment!
Thursday 27 November 2008
Wednesday 29 October 2008
SQL Server Cascade Delete
Just came across one of the most useful scripts ever! It can be a real pain in the arse when you need to delete some data from a table , then find out that some data somewhere else depends upon what you want to delete, and some data somewhere else relies on that, and so on and so on.
Well this script from Tim Young, creates a stored procedure that does everything for you. You just pass it the name of your table and some criteria (like user='bob') and it will delete all the referencing data and also print out the DELETE statements it created.
See the link below for a full example and explanation
http://www.sqlteam.com/article/performing-a-cascade-delete-in-sql-server-7
But if you can't wait and just want to see the store procedure, here you go
P.S. I got this to work on SQLServer 2005.
Well this script from Tim Young, creates a stored procedure that does everything for you. You just pass it the name of your table and some criteria (like user='bob') and it will delete all the referencing data and also print out the DELETE statements it created.
See the link below for a full example and explanation
http://www.sqlteam.com/article/performing-a-cascade-delete-in-sql-server-7
But if you can't wait and just want to see the store procedure, here you go
P.S. I got this to work on SQLServer 2005.
Here’s the code for the procedure:
CREATE Procedure spDeleteRows
/*
Recursive row delete procedure.
It deletes all rows in the table specified that conform to the criteria selected,
while also deleting any child/grandchild records and so on. This is designed to do the
same sort of thing as Access's cascade delete function. It first reads the sysforeignkeys
table to find any child tables, then deletes the soon-to-be orphan records from them using
recursive calls to this procedure. Once all child records are gone, the rows are deleted
from the selected table. It is designed at this time to be run at the command line. It could
also be used in code, but the printed output will not be available.
*/
(
@cTableName varchar(50), /* name of the table where rows are to be deleted */
@cCriteria nvarchar(1000), /* criteria used to delete the rows required */
@iRowsAffected int OUTPUT /* number of records affected by the delete */
)
As
set nocount on
declare @cTab varchar(255), /* name of the child table */
@cCol varchar(255), /* name of the linking field on the child table */
@cRefTab varchar(255), /* name of the parent table */
@cRefCol varchar(255), /* name of the linking field in the parent table */
@cFKName varchar(255), /* name of the foreign key */
@cSQL nvarchar(1000), /* query string passed to the sp_ExecuteSQL procedure */
@cChildCriteria nvarchar(1000), /* criteria to be used to delete
records from the child table */
@iChildRows int /* number of rows deleted from the child table */
/* declare the cursor containing the foreign key constraint information */
DECLARE cFKey CURSOR LOCAL FOR
SELECT SO1.name AS Tab,
SC1.name AS Col,
SO2.name AS RefTab,
SC2.name AS RefCol,
FO.name AS FKName
FROM dbo.sysforeignkeys FK
INNER JOIN dbo.syscolumns SC1 ON FK.fkeyid = SC1.id
AND FK.fkey = SC1.colid
INNER JOIN dbo.syscolumns SC2 ON FK.rkeyid = SC2.id
AND FK.rkey = SC2.colid
INNER JOIN dbo.sysobjects SO1 ON FK.fkeyid = SO1.id
INNER JOIN dbo.sysobjects SO2 ON FK.rkeyid = SO2.id
INNER JOIN dbo.sysobjects FO ON FK.constid = FO.id
WHERE SO2.Name = @cTableName
OPEN cFKey
FETCH NEXT FROM cFKey INTO @cTab, @cCol, @cRefTab, @cRefCol, @cFKName
WHILE @@FETCH_STATUS = 0
BEGIN
/* build the criteria to delete rows from the child table. As it uses the
criteria passed to this procedure, it gets progressively larger with
recursive calls */
SET @cChildCriteria = @cCol + ' in (SELECT [' + @cRefCol + '] FROM [' +
@cRefTab +'] WHERE ' + @cCriteria + ')'
print 'Deleting records from table ' + @cTab
/* call this procedure to delete the child rows */
EXEC spDeleteRows @cTab, @cChildCriteria, @iChildRows OUTPUT
FETCH NEXT FROM cFKey INTO @cTab, @cCol, @cRefTab, @cRefCol, @cFKName
END
Close cFKey
DeAllocate cFKey
/* finally delete the rows from this table and display the rows affected */
SET @cSQL = 'DELETE FROM [' + @cTableName + '] WHERE ' + @cCriteria
print @cSQL
EXEC sp_ExecuteSQL @cSQL
print 'Deleted ' + CONVERT(varchar, @@ROWCOUNT) + ' records from table ' + @cTableName
In the above scenario, we were trying to perform the following :
DELETE FROM X WHERE field1 = '234'
Using this procedure, we would use the following command:
exec spDeleteRows 'X', 'field1 = ''234''', 0
Monday 28 July 2008
Not so warm for cuil
The top technology story on the bbc today was a new search "rival" to google. I was going to dismiss it, but I caught the line where it said it is developed by former employees from the big G.
The name of this new search engine Cuil , pronounced Cool means knowledge in Gaelic, but who cares, is it any better than good ol' google?
First thing I noticed when I entered the site, was the blackness, in contrast to googles white nothingness. Also it took a few moments to come up, I think it may have come up with a loading screen for a second.
I searched for this blog randomconsultant and it didn't have it listed. That was slightly disapointing, as their crawler technology is suppose to be better than google's. But hey it's their first day and this is an little known blog.
But Cuil does claim that it searches more pages on the web than anyone else - three times as many as google and ten times as many as microsoft.
I then searched for something more likely, like the firm I work for. That did come up and the thing that stands out is that the search results were in two columns and each had a little thumbnail. Some of the thumbnails didn't really match the result and there were too many results for pages from the same site.
On the right it had some categories.. but pratically speaking one wants their search engine to contain what they want in the first 3 hits, who cares about other categories. I remember dogpile.com(use to collect google,yahoo and other searches) had a similar thing but I never used it then.
The results didn't come up that quickly too, which maybe because the whole web wants to check out a possible google killer. In fact Cuil and cuil.com are number one and two respectively in the hottest Google Trends list (i.e. the most searched for keywords right now) . I am sure google love that.
The search technology cuil uses is suppose to be a lot more sophicticated than google. Instead of just looking at which pages link to what like google does, it also looks at the context of the page and probably other stuff.
I will reserve complete judgement for now, until cuil has a bit of time to crawl the web, but I can't see anything now that will really trouble or make me and others want to switch their homepage.
Maybe in the future, when I am searching for some obscure things and google is firing blanks, and cuil comes up trumps maybe I will switch, but right now I don't think anybody will be in line to jump out of the windows at google hq.
STOP PRESS:
Just tried going to cuil.com and I got this message
The name of this new search engine Cuil , pronounced Cool means knowledge in Gaelic, but who cares, is it any better than good ol' google?
First thing I noticed when I entered the site, was the blackness, in contrast to googles white nothingness. Also it took a few moments to come up, I think it may have come up with a loading screen for a second.
I searched for this blog randomconsultant and it didn't have it listed. That was slightly disapointing, as their crawler technology is suppose to be better than google's. But hey it's their first day and this is an little known blog.
But Cuil does claim that it searches more pages on the web than anyone else - three times as many as google and ten times as many as microsoft.
I then searched for something more likely, like the firm I work for. That did come up and the thing that stands out is that the search results were in two columns and each had a little thumbnail. Some of the thumbnails didn't really match the result and there were too many results for pages from the same site.
On the right it had some categories.. but pratically speaking one wants their search engine to contain what they want in the first 3 hits, who cares about other categories. I remember dogpile.com(use to collect google,yahoo and other searches) had a similar thing but I never used it then.
The results didn't come up that quickly too, which maybe because the whole web wants to check out a possible google killer. In fact Cuil and cuil.com are number one and two respectively in the hottest Google Trends list (i.e. the most searched for keywords right now) . I am sure google love that.
The search technology cuil uses is suppose to be a lot more sophicticated than google. Instead of just looking at which pages link to what like google does, it also looks at the context of the page and probably other stuff.
I will reserve complete judgement for now, until cuil has a bit of time to crawl the web, but I can't see anything now that will really trouble or make me and others want to switch their homepage.
Maybe in the future, when I am searching for some obscure things and google is firing blanks, and cuil comes up trumps maybe I will switch, but right now I don't think anybody will be in line to jump out of the windows at google hq.
STOP PRESS:
Just tried going to cuil.com and I got this message
"We’ll be back soon...
Due to overwhelming interest, our Cuil servers are running a bit hot right now. The search engine is momentarily unavailable as we add more capacity.
Thanks for your patience."
As the US starts waking up looks like they are on overload.... wonder how long people will use it... maybe for the novelty factor... or mayber it will be just "cuiler" (ok that's bad) than googling!
IBM buy ILOG!
Just heard that IBM have swallowed up another product! Apparently this will provide ILOG customers with
This basically means RSA will probably come bundled with JRules and projects will probably be encouraged (forced) to go with websphere if they choose to go with JRules.
I just find this quite funny, as for the last couple of years on my project, ILOG have complained websphere is no good, the IBM jdk is no good, and the rule studio plugin doesn't play well with RSA. IBM have complained that JRules has a ton of peformance issues and a whole load of other stuff.
I wonder what the guys at JBoss think. Before this they were the only ones who could provide a complete suite of application server and rules etc.
So this will probably bring ILOG into the mainstream, so nowhere is safe from the bpm and brms!
Futher reading:
First thoughts on the IBM/ILOG announcement by James Taylor - more of an in depth serious look at it than me.
IBM Puts the Rules Down - OnStrategies.
ILOG Press release
IBM throws arms around ILOG - The Register
"a full set of rule management tools for complete information and application lifecycle management across a comprehensive platform including IBM's leading WebSphere application development and management platform."
This basically means RSA will probably come bundled with JRules and projects will probably be encouraged (forced) to go with websphere if they choose to go with JRules.
I just find this quite funny, as for the last couple of years on my project, ILOG have complained websphere is no good, the IBM jdk is no good, and the rule studio plugin doesn't play well with RSA. IBM have complained that JRules has a ton of peformance issues and a whole load of other stuff.
I wonder what the guys at JBoss think. Before this they were the only ones who could provide a complete suite of application server and rules etc.
So this will probably bring ILOG into the mainstream, so nowhere is safe from the bpm and brms!
Futher reading:
First thoughts on the IBM/ILOG announcement by James Taylor - more of an in depth serious look at it than me.
IBM Puts the Rules Down - OnStrategies.
ILOG Press release
IBM throws arms around ILOG - The Register
Monday 21 July 2008
Creating a J2ME app with EclipseME and Sony Ericsson SDK
I wanted to try out creating a little J2ME application which could be deployed onto my Sony Ericsson K850i phone. Sony do provide an SDK, and there seems to be a lot of documentation on their developer site , but there wasn't much in the way of a "Hello World" example.
So this is my example of creating a J2ME application using the EclipseME plugin.
This example should work on similar Sony Ericsson phones.
Prerequisites
You need to have the following installed before doing anything else:
Next you will need to install the EclipseME plugin to Eclipse
Now create a new Midlet class following the instructions from here and replace the template code with this:
Now you can run in debug mode in the phones emulator
You should see the date pop up for a moment in the emulator.
Now that we know we have a working app, we can try deploying it onto our phone. You have to create a package that will create a jad and jar file:
The jad and jar file will be dropped into the deployed folder within your project.
Now connect your phone via the usb cable or using bluetooth and copy the jad and jar file to somewhere on your phone.
Disconnect your phone from your pc, and open file manager on your phone ( Menu > Organizer > File Manager on my K850i) and select the jad file you copied over. Click on it and it will ask you where you would like to install the jad file (i.e. in applications or games).
Now your application can be selected from which ever menu you added it to (applications or games) and you will be able to run it!
For all my source code you can download it from here.
Leave a comment if you can't get this working or need a hand.
So this is my example of creating a J2ME application using the EclipseME plugin.
This example should work on similar Sony Ericsson phones.
Prerequisites
You need to have the following installed before doing anything else:
- JDK 6
- Eclipse 3.2 or above
- A Sony Ericsson phone with a USB or bluetooth connection
- Sony Ericsson PC Suite (this should have come on a cd with your phone too)
Next you will need to install the EclipseME plugin to Eclipse
- Follow the install instructions from here.
- After you have restarted Eclipse ,you will need to configure EclipseME with Eclipse. Follow the instructions from here and in step 4 use the location you noted down above(i.e. C:\SonyEricsson\JavaME_SDK_CLDC\)
Now create a new Midlet class following the instructions from here and replace the template code with this:
package com.randomconsultant.test;
import java.util.Date;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class MyMidlet extends MIDlet {
Alert timeAlert;
public MyMidlet() {
timeAlert = new Alert("Alert!");
timeAlert.setString(new Date().toString());
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
Display.getDisplay(this).setCurrent(timeAlert);
}
}
Now you can run in debug mode in the phones emulator
You should see the date pop up for a moment in the emulator.
Now that we know we have a working app, we can try deploying it onto our phone. You have to create a package that will create a jad and jar file:
The jad and jar file will be dropped into the deployed folder within your project.
Now connect your phone via the usb cable or using bluetooth and copy the jad and jar file to somewhere on your phone.
Disconnect your phone from your pc, and open file manager on your phone ( Menu > Organizer > File Manager on my K850i) and select the jad file you copied over. Click on it and it will ask you where you would like to install the jad file (i.e. in applications or games).
Now your application can be selected from which ever menu you added it to (applications or games) and you will be able to run it!
For all my source code you can download it from here.
Leave a comment if you can't get this working or need a hand.
Saturday 12 July 2008
Working with Drools from a JRules perspective
I had heard a few good things about drools , so I had a play with it over the last few days. I decided to create a small project in JRules 6.7 and keeping the same object model port it to drools 4.07 and see what happens. I specifically wanted to test out porting the following:
The rule project
I created a simple JRules project to process a train ticket. Given a journey start point (zone) and a journey destination, the rules would work out the cost of the journey and deduct it from the user's credit on their prepaid card(Oyster card). The price would also be influenced by the type of user (i.e. train staff, student, senior) . I have tried to keep a one-to-one mapping between rules I have created in JRules and rules I created in Drools.
Download the report of the jrules project from here.
The editors
JRules and Drools both provide an editor which is a plugin to eclipse. Actually, using eclipse is the only way to build the rules too. Even if you need to build from the command line , it runs in eclipse headless mode. However in Drools you are not tied to the editor, you can write all you rules in notepad or vi if you want then use the libraries to build them. That said, I would recommend using the eclipse plugin for Drools.
Verbalising the object model
Firstly if you are unclear about what an object model is in relation to rules, read Dan Serner's useful entry on his ILOG blog.
Ok, JRules , creates your object mapping for free, and creates default verbalisations for your object model. This is great so you can start writing rules right away. However some rules can end up with some convoluted verbalisations as you would have verbalised your object model without thinking about how each one will be used in the rules. You will probably have to go through a verbalisation refactoring stage to sort this out.
However in Drools, you need to create a dsl (domain specific language) file which maps expressions and actions to some given text. So you first think of your rule, then think of the verbalisation, then you add the mapping to your dsl file. This can lead to rules with greater readability, but you have to add each verbalisation yourself.
Here's a shot of my dsl file. (btw all the source code can be downloaded from a link at the bottom)
Writing business rules
Ok in Drools you can write rules directly in DRL (equivalent of IRL in JRules) or you can write rules in dslr which use verbalisations (equivalent of BRLs I guess).
Ok the first thing that threw me, was that you can't use an
Decision Tables
In JRules, you create decision tables within the eclipse editor. I have always found the Jrules decision table editor a bit flaky and pretty slow to open an existing decision table.
In Drools, you create decision tables in excel spreadsheets, csv or openoffice spreadsheets. You do not get autocomplete like the JRules editor, and auto static analysis and some other wizzy stuff, but it is very flexible. And given that while I have been working with JRules, I end up importing and exporting everything I do with decision tables to spreadsheets, I found this pretty useful.
Ruleflows
The ruleflow functionality is pretty similar between JRules and Drools. The major exception though is probably that a rule or decision table in Drools points to the rule group(ruleflow task in jrules) it belongs to, rather than in Jrules where a ruleflow task only knows which rules it contains, and a rule can end up in many tasks.
Actually one of our complaints about JRules was that it was difficult to find out which ruleflows a rule is referenced in. But in Drools as it is the other way round, it is a bit of a hassle to search for all the rules that belong to a group, hopefully in a newer release the editor will automatically show all the rules that belong to a group.
Another thing about decision tables in Drools is that individual rows can belong to different rule groups. In JRules the whole table goes in the task.
Local variables
Ok this is where I found the most pain in drools. The equivalent of local variables in drools are global variables. I just couldn't get these damn things to work properly, so I created a local variable class, and a local variable object was passed into the ruleset as a parameter to provide the same functionality. It was also a pain , because I wanted to use a global with a primitive type and drools just didn't like it, and I ended up with some weird errors.
Building and executing
As I mentioned earlier drools is a bit more flexible as you do not need to use eclipse to build your rules in the same way JRules forces you to do. But in drools you need to add each rule or rule package to your ruleset or Rulebase , in your code. In JRules you just build your jar , and you have all your rules neatly packaged up. The code to execute the rules in drools is slightly easier than jrules i would say. Look at the code in
The verdict
I like Drools, but if I was choosing a rules engine at the moment for my project I would stick with JRules. I know Drools is free, but I think it still needs to mature a bit. All the features are there, and it has a web based BRMS too. I have never used JRules Rule Team Server so I didn't compare it to Drools' equivalent.
In a couple of years though I expect Drools to be a real challenger in this space and as it is opensource I expect a lot more expertise to be out there. So if you have been working with JRules I encourage to try out Drools, but don't expect it to be a replacement just as yet. But if you are going throught the decision process now of picking a rules engine, do not discount Drools, it maybe exactly what you need.
Download my comparision projects from here.
Related blogs:
Drools Rules - useful examples on using Drools and benchmarking
ILOG Blogs - the official blog from the company behind JRules
Drools - the blog from the guys who produce Drools
- verbalisations
- a ruleflow , with a subflow
- business rules (brl rules)
- decision tables
- local variables
The rule project
I created a simple JRules project to process a train ticket. Given a journey start point (zone) and a journey destination, the rules would work out the cost of the journey and deduct it from the user's credit on their prepaid card(Oyster card). The price would also be influenced by the type of user (i.e. train staff, student, senior) . I have tried to keep a one-to-one mapping between rules I have created in JRules and rules I created in Drools.
Download the report of the jrules project from here.
The editors
JRules and Drools both provide an editor which is a plugin to eclipse. Actually, using eclipse is the only way to build the rules too. Even if you need to build from the command line , it runs in eclipse headless mode. However in Drools you are not tied to the editor, you can write all you rules in notepad or vi if you want then use the libraries to build them. That said, I would recommend using the eclipse plugin for Drools.
Verbalising the object model
Firstly if you are unclear about what an object model is in relation to rules, read Dan Serner's useful entry on his ILOG blog.
Ok, JRules , creates your object mapping for free, and creates default verbalisations for your object model. This is great so you can start writing rules right away. However some rules can end up with some convoluted verbalisations as you would have verbalised your object model without thinking about how each one will be used in the rules. You will probably have to go through a verbalisation refactoring stage to sort this out.
However in Drools, you need to create a dsl (domain specific language) file which maps expressions and actions to some given text. So you first think of your rule, then think of the verbalisation, then you add the mapping to your dsl file. This can lead to rules with greater readability, but you have to add each verbalisation yourself.
Here's a shot of my dsl file. (btw all the source code can be downloaded from a link at the bottom)
Writing business rules
Ok in Drools you can write rules directly in DRL (equivalent of IRL in JRules) or you can write rules in dslr which use verbalisations (equivalent of BRLs I guess).
Ok the first thing that threw me, was that you can't use an
else
in a rule. Weird huh? But there is probably a good reason for it. The other thing was, that I found myself getting into an infinite loop in a rule. You need to set the no-loop
property on the rule otherwise it will keep evaluating if the when condition is true. Otherwise no other great surprises here.Decision Tables
In JRules, you create decision tables within the eclipse editor. I have always found the Jrules decision table editor a bit flaky and pretty slow to open an existing decision table.
In Drools, you create decision tables in excel spreadsheets, csv or openoffice spreadsheets. You do not get autocomplete like the JRules editor, and auto static analysis and some other wizzy stuff, but it is very flexible. And given that while I have been working with JRules, I end up importing and exporting everything I do with decision tables to spreadsheets, I found this pretty useful.
Ruleflows
The ruleflow functionality is pretty similar between JRules and Drools. The major exception though is probably that a rule or decision table in Drools points to the rule group(ruleflow task in jrules) it belongs to, rather than in Jrules where a ruleflow task only knows which rules it contains, and a rule can end up in many tasks.
Actually one of our complaints about JRules was that it was difficult to find out which ruleflows a rule is referenced in. But in Drools as it is the other way round, it is a bit of a hassle to search for all the rules that belong to a group, hopefully in a newer release the editor will automatically show all the rules that belong to a group.
Another thing about decision tables in Drools is that individual rows can belong to different rule groups. In JRules the whole table goes in the task.
Local variables
Ok this is where I found the most pain in drools. The equivalent of local variables in drools are global variables. I just couldn't get these damn things to work properly, so I created a local variable class, and a local variable object was passed into the ruleset as a parameter to provide the same functionality. It was also a pain , because I wanted to use a global with a primitive type and drools just didn't like it, and I ended up with some weird errors.
Building and executing
As I mentioned earlier drools is a bit more flexible as you do not need to use eclipse to build your rules in the same way JRules forces you to do. But in drools you need to add each rule or rule package to your ruleset or Rulebase , in your code. In JRules you just build your jar , and you have all your rules neatly packaged up. The code to execute the rules in drools is slightly easier than jrules i would say. Look at the code in
com.transport.ticketFeeRules.jrules.RuleEngineRunner
and com.transport.OysterCardRules.droolsrulerunner.DroolsRuleRunner
, and you will see the difference.The verdict
I like Drools, but if I was choosing a rules engine at the moment for my project I would stick with JRules. I know Drools is free, but I think it still needs to mature a bit. All the features are there, and it has a web based BRMS too. I have never used JRules Rule Team Server so I didn't compare it to Drools' equivalent.
In a couple of years though I expect Drools to be a real challenger in this space and as it is opensource I expect a lot more expertise to be out there. So if you have been working with JRules I encourage to try out Drools, but don't expect it to be a replacement just as yet. But if you are going throught the decision process now of picking a rules engine, do not discount Drools, it maybe exactly what you need.
Download my comparision projects from here.
Related blogs:
Drools Rules - useful examples on using Drools and benchmarking
ILOG Blogs - the official blog from the company behind JRules
Drools - the blog from the guys who produce Drools
Tuesday 8 July 2008
Building from command line in JRules 6.7
In my post last week [2 years of JRules] I had a bit of a moan that JRules didn't have out of the box functionality to build a ruleset from outside of eclipse. Ironically a couple of days after I posted that up I was trying out JRules 6.7 and it appears ILOG have pulled their finger out and provided a way of building a ruleset from outside the eclipse rule studio.
It works by running eclipse in headless mode and providing a script location as one of the command line arguments. The given script is written in javascript and calls the JRules API.
For those of you who just want to dive straight into the code here are the downloads:
rule-builder-script.xml - this is an ant build file to run eclipse in headless mode and invoke the script
RulesBuild.js - this is the script that builds and extracts a ruleset by calling the JRules API.
I won't go through the ant script in detail, but if you are new to ant, have a look at the ant user manual.
The target "BuildSomething" is a dummy target for you to change. Here are the parameters that need to be updated:
projectName - This is the name of the project which contains the main rule flow.
extractorName - Name of extractor to use
archiveFile - path of where to save the ruleset jar
workspace.dir - path to the eclipse workspace which contains your rule projects
The other target "buildAndExtractRuleset" which BuildSomething calls, calls the macrodef task "headless.appication" which actually fires up eclipse in headless mode. The variables in here that need to be updated are:
script.location - path to RulesBuild.js
eclipse.home - the install path to eclipse
Once you update these variables you can just run the task BuildSomething (command line:
The script will take a bit of time to run depending on the number of rules in your projects, and once you see
Now let's look at the script. Firstly get to know the global variables that are accessible in the script:
The function main() is the entry point to the script. This reads in the arguments , turns off auto-building , calls the build functions, calls the generate archive action and then prints a report of all the projects built.
I'll skip to the function build in ArchiveBuilder (line 166):
First all the projects in the workspace are cleaned and refreshed:
You could add some code before this to open projects that are closed in the workspace.
Then a full build is called and for each project, a report is generated:
That's the build complete, i.e. the ilr has been created for all your business rules, decision tables, ruleflows, etc.
Now all this ilr has to be packaged up into a jar.
The generate function(line 192) is called to to this.
The extractorHelper is called to extract the jar. If you don't have an extractor, the extract method is overloaded to also generate a ruleset just with a RuleProject and a path location.
That's about it. I really advise you to go through the RulesBuild.js and look at the JRules API documentation. If you have any questions post me a comment.
It works by running eclipse in headless mode and providing a script location as one of the command line arguments. The given script is written in javascript and calls the JRules API.
For those of you who just want to dive straight into the code here are the downloads:
rule-builder-script.xml - this is an ant build file to run eclipse in headless mode and invoke the script
RulesBuild.js - this is the script that builds and extracts a ruleset by calling the JRules API.
I won't go through the ant script in detail, but if you are new to ant, have a look at the ant user manual.
The target "BuildSomething" is a dummy target for you to change. Here are the parameters that need to be updated:
projectName - This is the name of the project which contains the main rule flow.
extractorName - Name of extractor to use
archiveFile - path of where to save the ruleset jar
workspace.dir - path to the eclipse workspace which contains your rule projects
The other target "buildAndExtractRuleset" which BuildSomething calls, calls the macrodef task "headless.appication" which actually fires up eclipse in headless mode. The variables in here that need to be updated are:
script.location - path to RulesBuild.js
eclipse.home - the install path to eclipse
Once you update these variables you can just run the task BuildSomething (command line:
ant -f rule-builder-script.xml BuildSomething
) .The script will take a bit of time to run depending on the number of rules in your projects, and once you see
RulesBuild.js ENDED
, your ruleset jar should be in the location of archiveFile.Now let's look at the script. Firstly get to know the global variables that are accessible in the script:
Global Variable Name | Java Type | Description |
---|---|---|
workspace | org.eclipse.core.resources.IWorkspace | Provides access to the projects |
ruleModel | ilog.rules.studio.model.IlrRuleModel | Provides access to the Rule Studio Model |
modelHelper | ilog.rules.studio.javascript.dom.IlrModelHelper | Modifies to Rule Studio rule model |
importHelper | ilog.rules.studio.javascript.dom.IlrImportHelper | Imports projects into the workspace |
buildHelper | ilog.rules.studio.javascript.dom.IlrBuildHelper | Builds the projects of the workspace |
extractorHelper | ilog.rules.studio.javascript.dom.IlrExtractorHelper | Extracts the ruleset archives from the rule projects |
The function main() is the entry point to the script. This reads in the arguments , turns off auto-building , calls the build functions, calls the generate archive action and then prints a report of all the projects built.
I'll skip to the function build in ArchiveBuilder (line 166):
First all the projects in the workspace are cleaned and refreshed:
Utilities.println("Begin Clean...");
buildHelper.clean ();
Utilities.println("End Clean...");
Utilities.println("Begin Refresh...");
for each( project in workspace.getRoot().getProjects() ) {
project.refreshLocal(2, null);
}
Utilities.println("End Refresh.");
You could add some code before this to open projects that are closed in the workspace.
Then a full build is called and for each project, a report is generated:
Utilities.println("Begin Full Build...");
buildHelper.fullBuild();
Utilities.println("End Full Build");
for each( project in workspace.getRoot().getProjects() ) {
var report = new BuildReport (project,buildHelper.getBuildErrors(project, buildHelper.SEVERITY_ERROR));
this.reports.push (report);
}
That's the build complete, i.e. the ilr has been created for all your business rules, decision tables, ruleflows, etc.
Now all this ilr has to be packaged up into a jar.
The generate function(line 192) is called to to this.
var rp = ruleModel.getRuleProject(ruleprojectName) ;
var jarfile = archivePath;
Utilities.println("Extracting ruleset archive " + rp.getName() + " with extractor '" + extractor + "'");
extractorHelper.extract(rp,jarfile,extractor);
Utilities.println("Successfully extracted in " + (new java.io.File (jarfile)).getAbsolutePath());
The extractorHelper is called to extract the jar. If you don't have an extractor, the extract method is overloaded to also generate a ruleset just with a RuleProject and a path location.
That's about it. I really advise you to go through the RulesBuild.js and look at the JRules API documentation. If you have any questions post me a comment.
Wednesday 2 July 2008
Using ClearQuest API from VB 6 or VBA
On my current project, I found myself exporting my team's list of activities from clearquest to excel over and over again. This made me look at what clearquest offers in terms of an API. Luckily enough, there was an API available, however whatever documentation that google threw at me, was pants.
I created an excel VBA macro to connect to clearquest and pull whatever data I wanted. Another useful use of the API is wto create some kind of integration tool thing between subversion and clearquest. I haven't had time to do this though.
You can download the excel workbook which contains my vba macro from here. You need access to a clearquest database and have the clearquest client installed for this to work.
Here's an explanation of the code which is contained in the "ThisWorkbook" object if you open the Visual Basic editor ( Tools > Macro > Visual Basic Editor) .
I would recommend that you have the Rational ClearQuest API Reference open while you're going through this.
The first thing to do is to import the module clearquest.bas from C:\Program Files\Rational\Clearquest or wherever cq is installed. This module contains a whole load of useful contstants that you may need later on.
Next open Tools>References and look in the Available references list and make sure "ClearQuestOLEServer" is selected.
Now for some code. You need to create a Session object to connect to clearquest. You need to supply a username, password and name of the clearquest database you are connecting to
displayFields is simly an array of strings where each string is a name of a field.
Next the filters for the query need to be added.
This creates an AND operator (the constant
This creates and populats a ResultSet object from the query
Now you can iterate through
At the end call
That's it. Looking at the example in the workbook you should be able to create and execute your own queries. This will work in VB 6 too.
The source code for everything here can be downloaded from here.
If you just want the code without downloading the excel workbook , download from here.
Further reading:
Rational ClearQuest API Reference
I created an excel VBA macro to connect to clearquest and pull whatever data I wanted. Another useful use of the API is wto create some kind of integration tool thing between subversion and clearquest. I haven't had time to do this though.
You can download the excel workbook which contains my vba macro from here. You need access to a clearquest database and have the clearquest client installed for this to work.
Here's an explanation of the code which is contained in the "ThisWorkbook" object if you open the Visual Basic editor ( Tools > Macro > Visual Basic Editor) .
I would recommend that you have the Rational ClearQuest API Reference open while you're going through this.
The first thing to do is to import the module clearquest.bas from C:\Program Files\Rational\Clearquest or wherever cq is installed. This module contains a whole load of useful contstants that you may need later on.
Next open Tools>References and look in the Available references list and make sure "ClearQuestOLEServer" is selected.
Now for some code. You need to create a Session object to connect to clearquest. You need to supply a username, password and name of the clearquest database you are connecting to
'LOGIN - Create CQ Session
'==========================
Dim cqsession As Session
Set cqsession = New Session
Call cqsession.UserLogon(strUsername, strPassword, strCQDB, AD_SHARED_SESSION, "")
'Create Query
'===============
Set querydef = cqsession.BuildQuery(strRecordType)
'Fields to display
For Each displayField In displayFields
querydef.BuildField (displayField)
Next displayField
displayFields is simly an array of strings where each string is a name of a field.
Next the filters for the query need to be added.
This creates an AND operator (the constant
AD_BOOL_OP_AND
is from the module that was imported)Set Operator = querydef.BuildFilterOperator(AD_BOOL_OP_AND)
This filter added below specifies that the value of the given field (strFieldFilterName) must be one of the values in the array filterValuesCall Operator.BuildFilter(strFilterFieldName, AD_COMP_OP_IN, filterValues)
Now you can execute your query and get back some resultsThis creates and populats a ResultSet object from the query
Dim rsltset As Object
Set rsltset = cqsession.BuildResultSet(querydef)
Call rsltset.Execute
Now you can iterate through
rsltset
using rsltset.MoveNext
and calling rsltset.GetColumnValue(Column)
to get the values.At the end call
cqsession.SignOff
so it closes the clearquest session cleanly.That's it. Looking at the example in the workbook you should be able to create and execute your own queries. This will work in VB 6 too.
The source code for everything here can be downloaded from here.
If you just want the code without downloading the excel workbook , download from here.
Further reading:
Rational ClearQuest API Reference
Monday 30 June 2008
2 years of JRules
Recently I came across the an an article on the register "ILOG launches JRules 6.0" which was written around the same time I first started working with the product. This was around a couple of years ago, so I thought I'd share my thoughts about the product , ILOG and rules engines in general.
What and why?
Firstly, what on earth is a rules engine and why would anybody bother using one?The wikipedia definition says "A business rules engine is a software system that executes one or more business rules in a runtime production environment".
The way I see it , a rules engine is a bit of software which contains the business logic for a system , instead of it existing in source code. These rules can be viewed and maybe manipulated by business users .The users should not need to understand the technical implementation (i.e. be able to understand java code), but should be able to view and change the business rules through the rules engine interface.
The example in the JRules documentation is of some kind of retail/sales application where certain customers receive discounts dependant on various details. A business analyst for example can come in and create a new rule to give a 10% discount to a customer who orders over $100 worth of goods. They can do this through the interface and it gets deployed , without the business analyst touching a line of code or the entire application being rebuilt and deployed.
This is one of the main selling points of a rules engine, it makes things a lot cheaper to change an applications behavior. Also the business is not totally dependent on some developer who knows all the intricacies of the code.
My Project
So before I joined the project, some bright sparks decided a rules engine fitted the bill for what they were doing and they chose ILOG JRules over a rival product from Fair Isaac. I think they went with ILOG because of better performance stats when they did a crappy POC.
As I was on a "rules developer" , I used the rules studio which was a plugin to eclipse. As we were the first project to use version 6.0, which really should have been a beta version, the product was riddled with bugs. Also the ILOG consultants on the engagement had little or no experience with version 6 which was significantly different to the previous version which was a standalone application.
So my first impressions of the product and the ILOG guys weren't great. A lot of the problems were ironed out over time, but the ILOG guys were pretty rubbish in communicting any problems back to hq and we had to repetively badger them to get anything done.
Some bugs still haven't been fixed , and we're now on version 6.7 and we have had a whole suite of helper tools as workarounds. Also some features are pretty shit. The reports that can be generated from JRules are almost useless. They are basically screen dumps of the rules and there are no links between rules and where they are referenced in the flow of the rules. We actually developed our own application to produce some really useful reports, which to be honest should be out of the box functionality.
When working on any business application, it is vital that the the requirements are good. Also it is pretty important to have people around who really understand the business domain. These two things are even more important when using a rules engine. Actually I would go as far to say, that if the requirements are pants and you don't have the business users around, who in the end will be defining and analysing the rules, then don't bother going with a rules engine.
On our project we had neither. In the article from the register mentioned earlier, David Norfolk says "Rules processing systems need configuration management and testing just like any other automated system; applying the wrong rules, or the wrong set of overlapping rules with a combined behaviour you didn't anticipate, can become very expensive very quickly." This is pretty much what happened on our project.
Also ILOG provided no recommendations on config management, source control, or build and deployment setups. We have ended up with unique setup. For example JRules out of the box doesn't let you build a ruleset (the collection of rules pacakged up as a zip) from a script or in any automated way. We had to have a custom built plugin to run eclipse in headless mode to create rulesets from an ant script ( See my post "Building from the command line in JRules 6.7").
Performance became a big issue with JRules. But with a few tweaks we were able to push things to an acceptable level. I post up some of the things we did later on.
Rule Engines
Whatever my gripes are with JRules, I think rule engines are more than just a passing fad. The technology is relatively immature and as more people in the industry gain experience in using these products we will see some really good implementations. Rules engines also do seem to be a natural progression from high level languages as they bridge some of the gap between the techie and business user. I have heard good things about Drools and it could be one of those projects the open source community will take to. Also there are companies like Pegasystems who have been primarily working on business process managment solutions, but now their products are crossing over into the business rules space.
Some things to look out for if you go for JRules or any rules engine
Further reading:
ILOG Lauches JRules 6 - The Register
ILOG White papers
Drools Documentation
What and why?
Firstly, what on earth is a rules engine and why would anybody bother using one?The wikipedia definition says "A business rules engine is a software system that executes one or more business rules in a runtime production environment".
The way I see it , a rules engine is a bit of software which contains the business logic for a system , instead of it existing in source code. These rules can be viewed and maybe manipulated by business users .The users should not need to understand the technical implementation (i.e. be able to understand java code), but should be able to view and change the business rules through the rules engine interface.
The example in the JRules documentation is of some kind of retail/sales application where certain customers receive discounts dependant on various details. A business analyst for example can come in and create a new rule to give a 10% discount to a customer who orders over $100 worth of goods. They can do this through the interface and it gets deployed , without the business analyst touching a line of code or the entire application being rebuilt and deployed.
This is one of the main selling points of a rules engine, it makes things a lot cheaper to change an applications behavior. Also the business is not totally dependent on some developer who knows all the intricacies of the code.
My Project
So before I joined the project, some bright sparks decided a rules engine fitted the bill for what they were doing and they chose ILOG JRules over a rival product from Fair Isaac. I think they went with ILOG because of better performance stats when they did a crappy POC.
As I was on a "rules developer" , I used the rules studio which was a plugin to eclipse. As we were the first project to use version 6.0, which really should have been a beta version, the product was riddled with bugs. Also the ILOG consultants on the engagement had little or no experience with version 6 which was significantly different to the previous version which was a standalone application.
So my first impressions of the product and the ILOG guys weren't great. A lot of the problems were ironed out over time, but the ILOG guys were pretty rubbish in communicting any problems back to hq and we had to repetively badger them to get anything done.
Some bugs still haven't been fixed , and we're now on version 6.7 and we have had a whole suite of helper tools as workarounds. Also some features are pretty shit. The reports that can be generated from JRules are almost useless. They are basically screen dumps of the rules and there are no links between rules and where they are referenced in the flow of the rules. We actually developed our own application to produce some really useful reports, which to be honest should be out of the box functionality.
When working on any business application, it is vital that the the requirements are good. Also it is pretty important to have people around who really understand the business domain. These two things are even more important when using a rules engine. Actually I would go as far to say, that if the requirements are pants and you don't have the business users around, who in the end will be defining and analysing the rules, then don't bother going with a rules engine.
On our project we had neither. In the article from the register mentioned earlier, David Norfolk says "Rules processing systems need configuration management and testing just like any other automated system; applying the wrong rules, or the wrong set of overlapping rules with a combined behaviour you didn't anticipate, can become very expensive very quickly." This is pretty much what happened on our project.
Also ILOG provided no recommendations on config management, source control, or build and deployment setups. We have ended up with unique setup. For example JRules out of the box doesn't let you build a ruleset (the collection of rules pacakged up as a zip) from a script or in any automated way. We had to have a custom built plugin to run eclipse in headless mode to create rulesets from an ant script ( See my post "Building from the command line in JRules 6.7").
Performance became a big issue with JRules. But with a few tweaks we were able to push things to an acceptable level. I post up some of the things we did later on.
Rule Engines
Whatever my gripes are with JRules, I think rule engines are more than just a passing fad. The technology is relatively immature and as more people in the industry gain experience in using these products we will see some really good implementations. Rules engines also do seem to be a natural progression from high level languages as they bridge some of the gap between the techie and business user. I have heard good things about Drools and it could be one of those projects the open source community will take to. Also there are companies like Pegasystems who have been primarily working on business process managment solutions, but now their products are crossing over into the business rules space.
Some things to look out for if you go for JRules or any rules engine
- Requirements , requirements , requirements - make sure the requirements have been nailed and you have people around who actually understand them
- Spend time with the business analysts to develop a good business object model and good verbalisations for the model. This will make your rules readable, understanble, maintainable, and you will end up with an overall better result. One of the most frequent complaints by the business analysts was the the verbalisations were rubbish.
- Spend time on design - just because you're using a rules engine doesn't mean you can chuck everything in and expect it to do what you want
- If the ILOG consultants aren't playing ball, get them replaced early
- Setup a process to build, unit and component test early on
- Plan time for refactoring
- Make sure the business users are involved - they will be the ones who will need to work with what you develop
- Rules engines can't do everything, you still need good code built around it.
Further reading:
ILOG Lauches JRules 6 - The Register
ILOG White papers
Drools Documentation
Setting up Ubuntu on VirtualBox Windows XP Host
The geeky side of me got the better of myself this weekend and I thought I'd try out Ubuntu using VirtualBox. And I have to be honest, it was a pretty painless experience and now I have ubuntu running inside xp on my laptop!
Ubuntu is a great operating system in it's own right, but if you are new to unix, but want to try it out, it is definitely for you! Also with VirtualBox it's a no risk way of setting it up on Windows.
VirtualBox from Sun is a machine emulation thing like vmware or Microsoft's VirtualPC. Basically it lets you run a virtual(emulated) pc as an application on your desktop. It's free and has a pretty small memory footprint and I found it a lot easier to use than vmware which I am sick of using at work.
Here are the instructions I followed. I installed Ubuntu 8.04(Hardy Heron) , but these instructions should work for older versions too.
Installation
I followed the steps on the website below to install virtualbox and ubuntu.
http://www.psychocats.net/ubuntu/virtualbox
Install Linux guest additions:
You need to do this to get ubuntu in fullscreen mode and (i.e. a better screen resolution thatn 640x480). This is from the VirtualBox's help.
4.3.1. Installing the Linux Guest Additions
The VirtualBox Guest Additions for Linux are provided on the same ISO CD-ROM as the Additions for Windows described above. They also come with an installation program guiding you through the setup process, although, due to the significant differences between Linux distributions, installation may be slightly more complex.
Installation involves the following steps:
Before installing the Guest Additions, you will have to prepare your guest system for building external kernel modules. This is exactly the same process as described in Section 2.3.2, The VirtualBox kernel module, except that this step must now be performed in your Linux guest instead of on a Linux host system, as described there.
Mount the VBoxGuestAdditions.iso file as your Linux guest's virtual CD-ROM drive, exactly the same way as described for a Windows guest in Section 4.2.1.1, Mounting the Additions ISO file.
Change to the directory where your CD-ROM drive is mounted and execute as root:
sh ./VBoxLinuxAdditions.run
The VirtualBox Guest Additions contain several different drivers. If for any reason you do not wish to install them all, you can specify the ones which you wish on the command line - for example
sh ./VBoxAdditions.run x11 to install the X Window graphic drivers. Type in the command
sh ./VBoxAdditions.run help
Setup Shared folders:
Shared folders let you share any folder on your host pc (im my case my xp laptop) and your guest machine (in my case ubuntu)
http://ozz314.wordpress.com/2008/05/08/virtualbox-shared-folders-between-ubuntu-guest-and-mac-host/
With VirtualBox I shared the "My Documents" folder on my host machine so then I could execute the command below in ubuntu to see this folder :
sudo mount -t vboxsf "My Documents" /home/sm/Documents/host_docs
Setting up Internet connectivity in ubuntu:
This is probably the trickiest step, but if you follow what it says on this link you should be fine.
http://forums.virtualbox.org/viewtopic.php?t=2430&highlight=network+proxy
Other random things
- I gave the ubuntu guest 256MB of memory and it was fine.
- I installed the virtualdisk , on my portable usb harddrive and everything worked fine, even though I was afraid it might be a bit slow.
- If you want to listen to mp3s and watch movie files and things, ubuntu needs to download a whole load of codecs, so make sure your intetnet connection is working before you do this.
- I haven't tried out the usb support, but I think I read somewhere that your usb device will only be accessible from your host or guest, not both at the same time.
- In VirtualBox before running your Ubuntu guest, remember to set the Audio to your soundcard so you can get sound in ubuntu
- Ubuntu takes is a 700mb download, so set the download off now before your do anything else
- Make sure you install the linux additions, so you get a proper fullscreen , VirtualBox's seamless mouse integration(you will know what this is when it works) and copying/pasting works between the guest and host machines.
- Check out the Top 10 Ubuntu apps and tweaks from Lifehacker, for a few things you can install.
- If you are new to unix, look at Learn Unix in 10 minutes to familiarize yourself with some commands.
Welcome
Hello,
I needed a place to publish my random thoughts and useful things I come across. These things could be about stuff in the consulting world or anything and everything. So I thought a blog like this would be perfect.
Keep checking back and there might be some useful stuff on here soon.
I needed a place to publish my random thoughts and useful things I come across. These things could be about stuff in the consulting world or anything and everything. So I thought a blog like this would be perfect.
Keep checking back and there might be some useful stuff on here soon.
Subscribe to:
Posts (Atom)