29. August 2009
Aspect-oriented programming (AOP) is a programming paradigm that increases modularity by enabling improved separation of concerns. While object oriented programming paradigms support encapsulation of concerns, some concerns defy these forms of implementation and are called crosscutting concerns because they “cut across” multiple abstractions in a program. Logging is a common example of a crosscutting concern because a logging strategy necessarily affects every single logged part of the system.
For introducing AspectJ based AOP within the well-known Spring Framework, we just need a few lines of Spring Configuration
<!-- Activating AspectJ in Spring Config -->
<aop:aspectj-autoproxy/>
<!-- Configuring the Bean declaring the Aspect -->
<bean id="testAspect" class="spring.demo.TestAspect"/>
<!-- Some Test Bean to demonstrate the Aspect Execution -->
<bean id="test" class="spring.demo.Test"/>
plus: the Class declaring the Aspect, of course
@Aspect
public class TestAspect {
@Pointcut("execution(* *(..))")
public void methodExecution() {}
@Around("spring.demo.AspectJTest.TestAspect.methodExecution()")
public Object doTrace(ProceedingJoinPoint pjp) throws Throwable {
Log log = LogFactory.getLog(pjp.getSignature().getDeclaringType());
Object retVal;
log.info("Starting method " + pjp.getSignature().toLongString());
retVal = pjp.proceed();
log.info("Ending method " + pjp.getSignature().toLongString());
log.info("Method returned " + retVal);
return retVal;
}
}
As this Aspect triggers the @Around method on every method execution invoking the method boolean doSomething(boolean) on our Test Class
public class Test {
public boolean doSomething(boolean param) {
LogFactory.getLog(getClass()).info("About to return " + param);
return param;
}
}
will lead to something like the following sample output proving the execution of the TestAspect.doTrace(...) method:
Starting method public boolean spring.demo.Test.doSomething(boolean)
About to return true
Ending method public boolean spring.demo.Test.doSomething(boolean)
Method returned true
which is nice, actually. The Full Spring Guide on this can be found here
- Leave a comment
28. August 2009
Most of the time, Mac OS X programs do not use environment variables like the “PATH”. However, sometimes I use tools that require such Variables. Contrary to well known places to put this kind of information in a Unix Environment (like /etc/profile, /etc/bashrc, ~/.profile, or ~/.bashrc files) the recommended way of doing this is the following:
- Add the following File to your User Directory, if it does not already exist:
~/.MacOSX/environment.plist
- Open it with some Text Editor and add the following XML Code
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
- Open the File in the Finder and add beneath “Root” an Environment Variable with the Mac OSX Plist Editor.
- Log off and on again.
- Enjoy.
- Leave a comment
22. August 2009
The field of field of Business Process Execution is rising in importance and will make a fully web service oriented software development strategy of today really shining tomorrow.
What must one think of when it comes to “integrating” such an Engine with a Framework of Components primarily targeted at developing stand-alone “applications” for specified Business Purposes? Well, nothing stands alone anymore in these days and everthing is a process, isn’t it? Therefore, I think it would be nice to have in place
- A Web Service Oriented Architecture of the Application itself in order to allow the Business Process Execution Engine to automatically trigger any Task one could think of
- In addition to that a Task Management which is fully integrated into the Application in order to allow the User of the Application to go through all the Tasks which concern the Application and need Human Intervention by a User just like the one which happens to sit in front of the Application.
Such a Task Management will probably
- Provide a small layer of interface code which abstracts away the main aspects of typical Business Process Task Managements (should as a starting point work with jBPM and Intalio Task Management)
- Filter out and present only Tasks which concern Human Intervention in this Application itself.
- Provide useful mechanisms of linking such Tasks to Target Screens of the Application and maybe even prepopulate forms presented to the user with data needed for this task
- Such “Data needed for the Task” could be Data already available in the Process Instance and somehow transfered to the Application via the Task – but an even better Idea could be to prepare User Screens which need Human Confirmation directly by the Process Instance (via a Web Service) and after that Create the Task which links to this prepared “Screen”. (When thinking about it, what’s happening here is very similar to the approach of “Second Set of Eyes”. The Idea is in my mind that a Process could act just like a User which is not allowed to activate changes and prepare some “not-yet-activated” Data, while a Human User who is allowed to activate such changes could just confirm them when going through the Task List linking to such Screens of Prepared and Not-Yet-Activated Data).
(This post is part of my thoughts about A portfolio for Enterprise Web Applications)
- Leave a comment
22. August 2009
Still astonishing when working in the arena of Java based so called “Enterprise level” Web Applications for some years is the fact how little effort regularly is invested into smooth deploying and upgrading of such applications. Let’s therefore shortly consider the main requirement aspects one has to keep in mind when developing software which doesn’t cause too many headaches at deployment time.
- There has to be some thoughtful Management of Configuration Data manipulable by the User of the Software Package in a way that makes sure that existing Configuration Data isn’t lost when deploying a new version of the software.
- This Configuration Management therefore also has to provide a mechanism which is able to migrate the User Configuration itself into some new Configuration Structure complying to what’s needed by the new Version of the Software.
- Of course, the Configuration Management has to work for all Configuration Data of the System including the Connection Parameters to other systems such as Databases.
- We need a Database Upgrade Mechanism which is able to automatically detect the Software version of a Database and to applying all Migration Processes needed to upgrade to the currently needed Version.
- In an ideal world, there would also be a Downgrade Path which allows to Downgrade to a previous Software Version without loosing the Data added to the System in the meantime. Well.
- We need some security which makes sure that Databases with Production Data are never migrated “by accident”.
- We have to take into account that for “Migrating a Database” we typically need more administrative database rights than for regular usage, e.g. when it comes to extending the Schema (applying DDL statements).
- There should also be some mechanism which takes care of transition with a working Test Environment to a Production Environment.
(This post is part of my thoughts about A portfolio for Enterprise Web Applications)
- Leave a comment
21. August 2009
Provided you are already working with some JPA/Hibernate mapped Database, it would be very useful to have a generic and out-of-the-box working Database Import/Export mechanism at hand, which in the most generic case solely works on the JPA configuration/mapping already in place, for more sophisticated cases with some additional configuration. Such a mechanism should in my mind probably allow
- To export the whole Database in a Vendor Unspecific, Java centric way and serialize it to some appropriate (probably XML-based) Data Format
- To recover the whole Database to exactly the State represented in the Export.
- To limit the Export to some Tables/Entities to be exported.
- To make use of different Import Strategies when it comes to importing Entities into a non-empty Database. I think here of applying different Deletion Strategies – probably configurable per Entity Class – whenever importing instances of any given Class found in the Dump, cause I already stumbled upon practically applicable Use Cases for all of them:
- Deleting all (mapped) Entities in the Database.
- Deleting all Entities of the Hierarchy of the Class found in the Dump.
- Deleting all Entities of the Class found in the Dump.
- Deleting just the Entity found in the Dump itself.
- Not deleting anything, but just populating an eventually preexisting Entity found in the Database with the Properties found in the dumped Entity.
- To alternatively base the “Identity” of a Dumped Entity not on it’s Database Primary Key, but on some configurable “natural” Key Values which can be found among its Properties.
- To be aware of whether the Database Schema matches the Dump, and potentially also whether the Version of the Software working with the Data represented in the Database matches the Dump, and throw appropriate warnings and/or errors if not. (Maybe the desirable behaviour will depend on the requested Import Strategies for the Entities in the Dump.)
- To be able to import Dumps produced with older versions of the Import/Export Tool itself.
A bit more investigation needed. It could turn out, that the basic features can be relatively easily achieved based on Hibernates XML serialisation format. Surely, we remember: nothing is as easy as espected. (On the other hand: exactly because of this truth we should also be wise enough not to expect everything to be difficult. Provided the statement “nothing is as easy as espected” is true, our expectations will influence how hard our time with an issue will turn out to be in the end. Won’t they?
(This post is part of my thoughts about A portfolio for Enterprise Web Applications)
- Leave a comment
21. August 2009
In my last project I ran into an “actually” quite obvious trouble I want to resolve properly once and for all times, because I expect it to be a regular requirement when working with something like JPA/Hibernate persistence layer and something like the Spring Framework Bean Instantiation mechanism.
When I persist some JPA mapped Entity into my database, I’d later on very much like to be able to recover it exactly in the state when it was persisted. This is what persistence is all about anyway, isn’t it? It is, but troubles arise when this persisted Entity originally was instantiated based on some Spring Prototype Bean Configuration. Typically, Parts of the Properties of such a prepopulated Beans are just for Configuration Purposes and to persist those Properties to the Database is either obsolete and causing a lot of redundant and performance burdening data (in case of e.g. simple configuration values or beans), but can also turn out to be difficult or impossible to achieve in case the injected Data (e.g. some Configuration carrying Singleton Bean) is just not made to be persistent.
However, later on, when recovering such an Entity from the Database it will have lost all it (non-persistent) configuration data. Of course: JPA/Hibernate constructs the Java Objects via the Default Constructor of the Class and populates it with the Property Values persisted in the Database. That’s it, basically. The solution for my issue should be easy and some instructions and/or even ready code should be obtainable via the Internet: I just have to “teach” Hibernate to construct the Java Objects derived as Database Entities not via the default Class Constructur but via the Spring Bean Instantiation. I “just” have to do some research about this…
Once having this in place, I expect such an approach to turn out to make very good sense for almost all persistent Entities, also for the simple cases, because it allows
- To externalize the configuration of transient-only Property values with default (prepopulated) values becoming persistent later on and to have all this transparent in one place within the Spring Prototype Bean Configuration.
- Domain specific Object Models to carry some (e.g. DAO aware) lookup or logic methods in case applicable and useful.
I’m eager to see it working soon!
(This post is part of my thoughts about A portfolio for Enterprise Web Applications)
- Leave a comment
21. August 2009
When developing Database centric Applications you regularly stumble upon the “actually stupid” trouble that the User naturally wants to sort Data Tables presented to him “by every column available”. And the sort order should of course be the “naturally expected one”. Actually not a big deal? Sure not, however some troubles will unavoidably come along your road if you don’t take care of all the typical involved scenarios in advance (meaning: when designing the application).
Basically these issues boil down to the fact that something in a table column is presented to the user that is somehow different to what is directly stored in the underlying database. Typically
- Some key value is stored in the database, but on the UI the key is replaced with some display string. The User wants to see the Column sorted by Display Strings not by the underlying Keys.
- Some default language value is stored in the database, but for display the string is presented in some other language selected by the User. The User wants to see the column sorted in the displayed language not in some other one.
- A numeric value is for some reason (eventually for no wise reason…) stored in a string typed column of the database. The User wants to see such columns sorted numerically (and not “alphabetically”, meaning here sorted by the Character Codes of the displayed Numbers).
- A numeric value is somehow a systematic part of strings stored in a column of the underlying database, like in a column called “Reference”, holding values like “Issue #13, Page 24″. The User wants to see the mentioned Reference showing up after “Issue #2, Page 30″ and before “Issue #13, Page 101″. Unfortunately, when sorting “alphabetically”, it will show up exactly the other way round: after “Issue #13, Page 101″ and before “Issue #2, Page 30″…
- A column displays a string concatenated of several (arbitrarily typed) columns, eventually mixed with some fixed strings, like in “Maier Alfred, Austria, born Feb. 19, 1958″. The User wants to see such a Mr. Maier sorted before this other Austrian Mr. Alfred Maier born in December 1981, “of course”. Will he? Well, it probably depends on how all this stuff is implemented…
In order to be able to sort all this stuff in a consistent, performing (database centric) way and in a way the user will naturally expect it to be, we will need an equally consistent and problem aware approach for
- Maintaining, loading and storing I18n aware display labels in the database.
- Taking care of numerical characters stored inside string typed database columns.
- Systematically generating concatenated Columns consisting of the contents of several database columns.
- Internally representing Data Tables aware of the Database Sort Column(s) for each Display Column.
Yep, I’d definitely like to spend some more thoughts on such a consistent approach and develop everything needed (and not yet available) in code.
(This post is part of my thoughts about A portfolio for Enterprise Web Applications)
- Leave a comment
21. August 2009
Connected to my thoughts about A portfolio for Enterprise Web Applications I am thinking about developing (= providing a well tested, bundled and documented software feature with minimal coding effort) a mechanism which is capable of the following
- Log all persisted states of an Entity inside the Database – always including Information about Action Type, Time and User/Process
- Allow also forthcoming states to be saved as such an “inactive” Entity state (meaning “to be activated later”).
- Allow for Action Types the Database Operations (C)reate, (R)ead, (U)pdate, (D)elete *and* (A)ctivate (the right to activate a Database changing Operation) to be defined as Rights a User/Process may have on a Class of Entities.
- Allow each such User Right on an Entity Class to be restricted by a (custom) Right Condition.
- Provide Out of The Box a Right Condition allowing a User to (A)ctivate only if the Operation to be activated was not done by the activating User himself (”Second Set of Eyes” Feature)
- Allow for Ability to activate not just forthcoming, but also every old “inactive” Entity State. (”Entity Rollback” Feature)
I want to do this based on Java while making use of JPA/Hibernate simply because these ideas are about leveraging preexisting project experience and knowledge. To be further investigated is the Usage of
- Hibernate Interceptors for Logging Entity State change
- Hibernate XML API also for Logging
- (Hibernate) Bean Validator Framework for CRUD and Activation Rights and mentioned Custom Conditions
- Leave a comment
20. August 2009
Thinking about “developing” a technology portfolio for Enterprise enabled Web Applications actually means:
- Researching, selecting, glueing and maintaining a set of Software Technology Components
- Adding some interesting code for the typical requirements of Mission Critical Applications
- Integration testing and proving everything in order to be able to concentrate on “the Application itself” later on.
The main aspects I’d like to focus on here and already came to my mind are roughly summed up in a series of small Articles written lately, as they are
Some smaller and more technical aspects that are in my minds pipeline:
- Leave a comment