Page 1 of 1

Code to process information indepentantly of datasource

PostPosted: Thu Jun 23, 2005 6:02 pm
by neilg
This contribution involves some code to seperate business logic from JDBC (which is ugly). A very simple object-relational mapping , I guess.

The business logic is completely seperated from the sourcing of the data.

We call it like this:

Code: Select all
sql="select * from c_bpartner a where a.ad_client_id=" +
            org.compiere.util.Env.getAD_Client_ID(ctx);
Processor processor=new CompiereSQLProcessor(sql);
LogicUnit unit=new BusinessPartnerLogicUnitTest();
processor.setLogicUnit(unit);
//
processor.process();

PostPosted: Sat Jun 25, 2005 4:12 am
by neilg
Here is a preview of the LogicUnit code:

Code: Select all
public void execute() {       
        String name;
        //
        name=getColumnValueAsString("NAME");
        setShowMessage(true);
        setMessage("Business Partner Name='" + name + "'");
        setRowOk(true);
               
    }


What this does is prints out a list of all the business partners to a console window.

Now, you could get your data from any JDBC data source, Compiere, or CSV, whatever, but the logic will remain consistent. I looked at the 'Command' design pattern and it seemed to be similiar so I adopted some of the code.

Also its written purely in Poseidon UML community edition and generated from there and works, I'm trying not to make any changes outside of the UML, and this is a first for me , works quite well... you're working mostly in the visual world and dumping some code into the methods... reminds me a bit of VB6 :!:

I think is similiar to what people are trying to achieve with object-relational mapping tools, but this has alot less overhead (like learning, etc)

PostPosted: Sun Jun 26, 2005 5:19 am
by neilg
The completed package is here:

http://www.knowledgesuccess.com/contrib/genericProcessor/genericProcessor.zip

Source code and Poseidon UML document included. The source is generated from the UML document.

Example on how to use the GenericProcessor..

PostPosted: Sun Jun 26, 2005 5:27 am
by neilg
You define a class that extends AbstractLogicUnit, such:

Code: Select all
package za.co.ntier.genericProcessor;

/**
* <p></p>
*
*/
public class DemoShowPartnerInfo extends za.co.ntier.genericProcessor.AbstractLogicUnit {

/**
* <p>Does ...</p>
*
*
*
*/
    public void execute() {       
        String name;
               
                    name=getColumnValueAsString("NAME");
                    setShowMessage(true);
                    setMessage("Business Partner Name='" + name + "'");
                    setRowOk(true);
               
                 
               
    }
}



Now you call it (Invoke it) with another class, such:

Code: Select all

public class DemoCompiereAsDataSource {

    public static void main(String[] args) {       
                java.util.Properties ctx;
        String sql;
        za.co.ntier.genericProcessor.Console console;
        //
        //Setup the compiere runtime environment
        //
        org.compiere.Compiere.startupClient();
        ctx = org.compiere.util.Env.getCtx();
        org.compiere.util.Env.setContext(ctx, "#AD_Client_ID", 1000000);
        org.compiere.util.Env.setContext(ctx, "#AD_Org_ID", 0);
        org.compiere.util.Env.setContext(ctx, "#AD_Role_ID", 0);
        //
        //Do the test
        //
        console=Console.getConsole("Testing");
        console.clear();
        console.printHeader("Just a list of business partners");
        //
        sql="select * from c_bpartner a where a.ad_client_id=" +
            org.compiere.util.Env.getAD_Client_ID(ctx);
        Processor processor=new CompiereSQLProcessor(sql);
        LogicUnit unit=new BusinessPartnerLogicUnitTest();
        processor.setLogicUnit(unit);
        //
        processor.process();
        //
        console.printFooter("Completed");
        console.printSummary(processor);
                       
    }
}


What this does is print a list of business partners from client 1,000,000 (usually the first live client) out to the console.

If you replaced CompiereSQLProcessor with CSVProcessor then the data could just as easily come from a .csv file. You would then need to download the csv JDBC driver from sourceforge and reference it from your project for this to work.

It is a very simple example.

The other advantage of this package is the Console class. Using it you can display a window which will show output from anywhere in your code. So your process can now be more diagnostic.

You use the Console class as follows:

Code: Select all
Console.getConsole().println("test");


The way the code is coupled to the Console is of course not optimum but that is all that I need at the moment :twisted:

new release - 2005-06-28

PostPosted: Wed Jun 29, 2005 12:27 am
by neilg
- Added the csv / jdbc source code from relique
- Added a csv importer example
- Added more docs
- Added an export of the class diagram from Poseidon as a jpg
- Improved the demo class names
- Fixed a bug - wasn't increasing the failed count if the row failed

So things should be simpler

PostPosted: Wed Jun 29, 2005 8:09 am
by red1
Just downloaded your liteweit compiere OR tool. Made it 252d compliant by changing a line to compiere.startupEnvironment(true). It sits in Eclipse error free.

Will give it a try and tell u if it breaks my keyboard or my fingers.

(3 mins later)
Hmm... it really works! And i use only one finger to tap the fingerpad to the RUN icon and clickclick. The BPartner list do show up.
My only complain is that u did not pen the authorship lineage into the codings. For the record these codes come from Neil Gordon, the character from Flash! (emailto neilg@knowledgesuccess.com).
(fingers loosening up now)
Thanks again Neil for yet other devilish tool.

PostPosted: Wed Jun 29, 2005 2:26 pm
by neilg
Thanks for the test drive, Red1!

Will implement your suggestion ASAP.

PostPosted: Sun Jul 17, 2005 9:26 pm
by neilg
I have just posted the latest version of genericProcessor at the address above.

- bugfixes
- author recognition (ie. written by Neil Gordon)
- support for Timestamps

I'm using this code quite extensively so there will be more changes! Watch this spot

spring framework

PostPosted: Mon Nov 07, 2005 8:46 pm
by neilg
this code would have benefitted from the spring framework jdbc components