Do what you think is interesting, do something that you think is fun and worthwhile, because otherwise you won't do it well anyway.
                                - Brian Kernighan
 
Поиск
Поиск

 
 
Меню навигации
Меню навигации
 
 
Проекты
Проекты
 
 
 
 
Size_box_tl   Size_box_tr
 
Unfortunately, there is no translation for this page. We have redirected you to the english version of the site. We are sorry for any inconvenience caused...

GeDA documentation has moved to http://www.inspire-software.com/confluence/display/GeDA/GeDA+-+Generic+DTO+Assembler now. This page may be outdated



What the heck is DTOHelper?

 

Recently, I received a letter from one of the users of GeDA. He was asking for a new feature - populating DTO from an array. I will be honest and at first I though that this was not a very good idea. I mean why would anybody what to do that? Later I have came back to this, and the reason was that I saw a whole new dimention of use.

One of the cool features that java lacks is ability to easy iterate over fields extract them to an array and so forth. Of course you can do a little bit of trickery through reflection (which is what DTOHelper is doing) but why not just take it for granted with GeDA.

They say that a picture is worth 1000 words, well I think a snippet is like a picture in this sense.

So check this out:

 

	public void groovyPropertyIteration() {
		
		final TestDto2Class dto = new TestDto2Class();
		dto.setMyBoolean(true);
		dto.setMyDouble(new Double(2));
		dto.setMyLong(3L);
		dto.setMyString("test");
		
		Map values = DTOHelper.unloadMap(dto);
		
		// Iterate over field with two lines of code
		for (String field : values.keySet()) {
			
			System.out.println("Iterating over field: " + field);
			
		}
		
		// Iterate over field values with two lines of code
		for (Object value : values.values()) {
			
			System.out.println("Iterating over value: " + value);
			
		}
		
	}

 

Java is very hard on syntax, but hopefully this groovy new feature will lessen the burden. Enjoy!

P.S. By the way check out the JUnits for more examples on loading/unloading from/to Map/Array

Эта страница была обновлена: 29/11/2010 08:40


© Inspire Software, Denys Pavlov, 2005-2012
© Inspire Software, Denys Pavlov, 2005-2012
 
Size_box_bl   Size_box_br