Category Archives: developing

Modelmapper

In clean software development, with clean nice layers, there is one small problem relating entities. Every layer has own, most of the time similar entities. So there is a DB entity, an BusinessObject (BO) and there could be a TransferObject (TO) and so on. And mapping is a pain.

Modelmapper is the solution.

This framework simply mappes to objects and first hands on, this framework is great. Ok my entities where simple… DB Entity -> EntityBO both mainly similar, but with Lists of Objects and actually it worked out of the box. I didnt need any special MapperStrategy.

Love it.

oracle read queue jms data

queues… only triggers are more confusing… ok thats wrong… because i learned stuff about queue_schedulers… pretty scary… but thats something completely different and i actually hope, i dont have to write about these… but back to queues…

queue handling is in my point of view pretty strate forward… define a queue message, write a queue writer to put messages in the queue, write a reader to retrieve the messages from the queue… simple… but checking, whats acutally going on on the queue is difficult…

we have sys_aq$_jms_text_messages in the queue, which is actually shown on the queue_table when you do a select on it… great… so how can i get its content?

select msgid, enq_time, enq_uid, qt.user_data.TEXT_VC from MY_QUEUE_TABLE qt where q_name = ‘my_queue’

where as the qt needs to be written out…

find file in svn

after out switch from cvs to svn all old (not more improved) project where copied to a chaotic seperate lagacy svn… and hurray… i need to find some code in there… so how to search?

svn list -R https://subversion/repository | grep filename

but it takes for ever… so i used:

svn list -R file:///subversion/repository | tee svnlegacy.log

so i see, that it is still working… takes for ever… and if there is a typo in the file, i am looking for, i can search it much fuster in the logfile…

and yeah… still running 🙁

checkstyle and pmd

first of all i think checkstyle and pmd are 2 really cool tools, which can improve java source code… but its kinda hard to fulfill them…

or lets say… an old project is really hard… mainly it should be easy, but due to svn and history reasons, an automated refactoring is crap!

but lets do just the important and simple things:

<plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-checkstyle-plugin</artifactId>
       <configuration>
              <configLocation>[remote file]</configLocation>
       </configuration>
</plugin>
<plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-pmd-plugin</artifactId>
       <version>2.5</version>
 </plugin>

run checkstyle

mvn checkstyle:check

run pmd

mvn pmd:pmd

and with hudson is really cool 🙂

svn and eclipse… and maven

ok one of the problems of eclipse with svn is that no eclipse specific file should be commited to the repository… mainly because they are developers computer specific and kinda crap on others computers… additionally not every one uses eclipse… so that the hell should he be doing with the eclipse files? so goal is to delete and ignore them… simple… but now every body needs to set his project localy correctly…

with maven it is actually a bit more confusing… which folders to add? how to add the Maven Dependencies?

Right Click the Project -> Maven -> Update Project Configuration

Done 🙂

delete files older then X days

who to find and delete files older then X days:

find . -mtime +5 -exec echo rm -rf {} \;

remove the echo to really execute.

@Autowired

after thinking a lot about DIP, it was kinda clear, that we need to refactor some stuff… ok not really the thinking part, more the discusting part… a big beans.xml file sucks… and analysing my beanx.xml showed, that one small component is used everywhere and a lot of injects only where this one class…

first, something about a concept… in my opinion there are two ways for dependency injection… the one where a config file injects classes to others and the one where the class, wishes to get an injection… secondly is @Resource, @Autowired…

and in my project, i thought the one class, which is used almost everywhere should be get by @Autowired… and actually it was an static class, where the key-value configuration out of the db is loaded… so simply refactored it…

and the main problem was: tell spring, that it should autowire!

<context:annotation-config />
<context:component-scan base-package=“[class name]” />

after adding this few lines to the beans.xml, it actually found the [class name] in time and could inject it 🙂

crap config!

powermock

PowerMock is an extension for Mockito or EasyMock, which can mock really special things… static classes, Constructors, partial mocks,…

cool thing…. http://code.google.com/p/powermock/

read from classpath

in our project we have a few templates… so the biggest question is, where to put them… there are a lot of simple answers, but consider this: 4 productive instances, 2 test and 1 dev… these platforms dont know each others… so the solution database, which they share, or localy on each machine… db is not a solution, because the main user has no access to it, and changing templates might happen at the beginning… so file system it is… and we dicided to put them in classpath… easier to roll out for the devs… so how access a file from the classpath?

String filenameOnClasspath = “/myfile.txt” // Located in a directory which is on the classpath
URL url = getClass().getResource(filename);
String fullyQualifiedFilename = url.getFile();

Source

maven create eclipse

Just enter following command:

mvn archetype:create -DgroupId=com.test -DartifactId=mytest

The project will be created… to add it to eclipse it is important to run this command:

mvn eclipse:eclipse

now it can be imported to eclipse