Andrej Koelewijn

8/14/2003

Generating Primary Keys wit Optimalj

Filed under: — andrejk @ 12:03 am

OptimalJ currently doesn’t generate code for database sequences which you can use to create unique values for primary keys in your tables.

So I did some research to see how other people solve this problem. One person suggested counting the number of records in a table, increase that number by one, and use that as your primary key. Brilliant! Should perform really well, and no concurrency problems to be expected.

I found one real solution on the optimalj forum, which was to create a Domain class (this translates into a database table) that holds ‘sequence’ records. One record per sequence, with a name and a value column. Then on the Domain Class you can add a DomainOperation to query the next sequence value, e.g., nextVal. The example on the forum described the situation when using EJBs, but I’m trying to generate DAOs, because i don’t have the memory in my laptop to run an ejb container.

After generating the application model and the code model i have to implement the code for the nextVal operation (get current value from table, add one, etc), but there’s a problem. Where is it? I can’t find the nextval stub anywhere, i must have checked 20 java files…

8/10/2003

Is Andromda really a MDA tool?

Filed under: — andrejk @ 2:25 pm

The Andromda project just released version 2 of their tool. According to their website Andromda is an open source code generation framework that follow the model driver architecture (MDA) paradigm. It’s a nice tool which will generate j2ee code based on xml diagrams saved as xmi files. So you can design your application in an UML tool (e.g., poseidon), save the diagrams, and then use andromda to generate your application.

This is all very usefull ofcourse, but how’s this different than UML tools which generate code? What exactly makes this MDA? As i see it, one of the important characteristics of MDA is that is has models on different levels, and you’ll have tool based support to keep these models in sync. The three levels in MDA are PIM, platform independent model, PSM, platform specific model, and the implementation. Currently the combination of Poseidon (or a similar UML tool) and Andromda seems to be missing the PIM level.

Ofcourse, if you know j2ee and uml, and you just want to be more productive, the combination of a UML tool and Andromda might be exactly what you need.

8/7/2003

MDA problems

Filed under: — andrejk @ 2:40 pm

I did a search on javablogs to see what other people are writing about MDA. Found one interesting entry by Ara, RE Visually Explicit Programming.

He first argues that UML diagrams have no resemblance to the real program and are therefor not useable for programmers. I find this a very strange statement. So why is it that most design patterns are explained by class diagrams? Why is it that if i want to understand an existing program i like to have a look at some class and sequence diagrams to quickly understand how it works? Because UML diagrams actually tell me a lot about the program.

I very much want to use MDA tools, because it avoids me from doing some very boring programming. Normally, for me a project starts by reading some functional designs, translating them into technical designs. I use a lot of UML diagrams in these TDs. Then translating these diagrams into java is for the most part pretty straightforward, so instead of doing that manually i would like to generate the code. To generate it i would first have to enter the requirements into a generator, or be able to generate the code from the UML diagrams, which is what MDA is all about.

Next Ara quotes some statements from SD magazine. The second statement basically says that MDA doesn’t appeal to developers. Now that may be the case for some developers, especially the ones that are doing Java right now. But i also know that there are a lot of developers who right now will not touch java, because it’s too much work, not productive, compared to tools suchs as Oracle Designer.

Ofcourse there are problems with MDA, but not that UML diagrams do not resemble real programs or that programmers do not like MDA. After working with OptimalJ for a week now, i think one of the problems is the complexity. Another problem is that i see right now is that the models used by OptimalJ seem very specific to the tool. Can you export the application model diagrams from OptimalJ, import them into a competing MDA tool and generate the code model using different technology patterns (i.e., instead of using EJB’s, use oracle’s BC4J for example)?

So right now Java developers mostly learn standardized API’s, which are usable in every J2EE server environment, but what happends when you adopt a MDA tool? Your knowledge will probably be more vendor specific.

7/29/2003

TPL - OptimalJ’s templating language

Filed under: — andrejk @ 9:56 pm

As i mentioned yesterday, one of the issues people have with MDA is, how easy it is to modify generated code, and if these changes are maintained when regenerating code from the models.

The code editor in OptimalJ clearly shows you which parts you can modify (white background) and which parts you can’t touch as showed in this screenshot.
optimalj_code_free_block.png Whenever you regenerate the code, the added parts in the free blocks will be untouched.

Optimalj has it’s own templating language TPL. Within the template you can specify which parts are guarded, i.e., generated from the models, and which parts are free code, and should be restored after a regeneration. Free parts have an id so they can be identified when regenerating the code. The resulting code looks like this:

    /**
     * Converts IssueUpdateObject into a IssueDataObject.
     */
    public IssueDataObject(IssueUpdateObject updateObject) { 
        this.setId(updateObject.getId());
        this.setSummary(updateObject.getSummary());
        this.setPriority(updateObject.getPriority());
        this.setIssueType(updateObject.getIssueType());
        this.setDateCreated(updateObject.getDateCreated());
        this.setDescription(updateObject.getDescription());
//GEN-FREE-GEN:toDataObject$$DATAOBJECT$pidf6aef9ffd57bc7d // your code here

//GEN-GUARD:1$$DATAOBJECT$pidf6aef9ffd57bc7d

}

OptimalJ - some screenshots

Filed under: — andrejk @ 1:00 am

Here are some screenshots of OptimalJ.

The first image shows the Domain model, containing two conceptual classes, Sales order and Order line. It also show their attributes. These classes are created using wizard. For this simple example no services are included.
Domain Model

The second image shows the Domain Class Diagram. Here you can draw associations between classes, define the multiplicity of the association, and specify the type of the association, for example composite aggregation.
Class Diagram

The next picture shows the application model explorer. I’ve created three application models based on the Domain model created previously. The three application models are: ejb model, database model and web model. These models are generated in three steps.
Application Model

Now the code model can be generated, the result of this is displayed in the next picture, which shows the code model explorer. This requires one action, and all code will be generated. The code is put into 2 different directories, one for the model and services, and one for the web code.
Code Model

Finally, i’ve added a picture of some generated code in this last picture. This picture shows part of the jsp generated for browsing Order lines. As you can see it contains pretty straightforward html using the struts tags.
Jsp code

7/28/2003

OptimalJ - part 1

Filed under: — andrejk @ 10:33 pm

I picked up a demo version of optimalj professional editional from the post office last thursday, and installed it yesterday. When i talked to one of the compuware representatives they said i needed to mail them to get a key for the evaluation, but optimalj seems to work for 30 days without installing a key, which is nice.

I started by following the ‘your first optimalj application’ tutorial in the documentation. The default help window is a modal window, which you can’t minimize and which is closed automatically when you press finish in one of the wizard. Weird, and irritating. Then i discovered that the documentation is also provided as a pdf, which works a lot nicer, as i can now alt tab between the documentation and optimalj.

The basic process in optimalj is as follows:
1) You define your application, independently of the technology it will use. You do this in the domain model. The domain model contains classes and services.
2) Now you can generate the implementation models, for example, an ejb model, an database (ER) model, and a web model (which can be 3 tier using ejb’s, or 2 tier using DOA’s)
3) Finally you can generate the code model based on the implementation models.

Once you have the code you can compile and deploy.

I saw some blog entries (e.g., MDA rant) which question the use of MDA. The biggest problem seems to be that code generators will not easily be able to merge generated code with hand written code. I don’t know yet how optimalj solves this problem, but in Oracle Designer you just enter the code that needs to be added to the generated code in Oracle Designer itself. Then, upon generating the code, Oracle Designer will mix the entered code with the generated code.

Oracle Designer does not eliminate the need to write code, but the code that needs to be written is a lot less and a lot easier than the code that the developer would have need to write when doing everything manual. And the developer doesn’t have to think about the application framework, or the architecture. Just the domain model (conceptual entities) and business rules (written using a normal programming language, pl/sql) and the rest is generated. And this work for at least 90% of all data entry applications. I don’t see why this wouldn’t work for most java/j2ee applications. Most j2ee applications i have worked on so far have been data entry applications, and most of that code could have been generated.

7/22/2003

Improving productivity using MDA

Filed under: — andrejk @ 1:40 pm

Some intersting reads on theserverside and the register about improving productivity using MDA with OptimalJ.

I don’t have any experience yet with optimalj, but my evaluation kit is waiting for me in the post-office. I’m quite curious to see how i’ll like it.

I noticed some scepticism when reading the thread on the serverside, but i’m sure that MDA will improve productivity, especially for standard problems. In the company i work for, it-eye, we use Oracle Designer a lot for generating back-office data entry applications, reports, database pl/sql code and database schema’s. Designer is quite good at this, and most application can be generated for 100%. You see that a lot of our customers aim for this, as it makes upgrading to newer versions of Oracle Forms, Oracle Reports, and the Oracle RDBMS easier. The more i read about MDA, the more it looks like Oracle Designer, but vendor and platform neutral, based on an open standard.

The problem with Oracle Designer, one customer mentioned, is that it requires a lot of knowledge of the user. He actually wittnessed one developer trying a lot of properties, which took a full day, before the correct application was generated. Using Oracle Developer (oracle’s 4gl gui application tool), this would have taken 10 minutes. Sometimes Designer gets kind of fuzzy and it is not very clear which property to change to change something in the generated application.

So don’t think that you need less knowledgeable developers on your project just because the code is generated. But MDA tools can improve the productivity of skilled developers when creating certain kinds of applications.

Powered by WordPress