<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8369030687505463576</id><updated>2026-04-08T02:20:09.185+03:00</updated><category term="java"/><category term="spring framework"/><category term="jaxb"/><category term="rest"/><category term="apache commons"/><category term="applet"/><category term="eclipse"/><category term="freemind"/><category term="hibernate"/><category term="infinispan"/><category term="java web start"/><category term="jnlp"/><category term="maven"/><category term="mindmap"/><title type='text'>Thinking about IT</title><subtitle type='html'>Examples, solutions, recipes and thoughts about IT</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://azagorneanu.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8369030687505463576/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://azagorneanu.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Andrei Zagorneanu</name><uri>http://www.blogger.com/profile/04979424616588139827</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>9</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8369030687505463576.post-1382271819846005040</id><published>2013-06-23T18:37:00.012+03:00</published><updated>2020-06-04T22:47:22.103+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="rest"/><category scheme="http://www.blogger.com/atom/ns#" term="spring framework"/><title type='text'>HATEOAS using Spring Framework</title><content type='html'>&lt;p&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/HATEOAS&quot;&gt;HATEOAS&lt;/a&gt; is a constraint of the &lt;a href=&quot;http://en.wikipedia.org/wiki/Representational_State_Transfer&quot;&gt;REST application architecture&lt;/a&gt; which is very often ignored by developers. In many cases this is caused by the lack of support of frameworks used to build and expose RESTful services. In this post I will show how quickly we can add HATEOAS to RESTful web services using &lt;a href=&quot;http://www.springsource.org/spring-framework&quot;&gt;Spring Framework&lt;/a&gt;. Source code of the demo web application presented below are &lt;a href=&quot;https://azagorneanu.googlecode.com/svn/trunk/blog/zmeu-blog-spring-hateoas.zip&quot;&gt;available for download&lt;/a&gt;, run it using &lt;code&gt;mvn tomcat7:run&lt;/code&gt; command. Also you can read a nice &lt;a href=&quot;http://www.slideshare.net/trilancer/why-hateoas-1547275&quot;&gt;presentation about why HATEOAS is important&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&quot;https://github.com/SpringSource/spring-hateoas&quot;&gt;Spring HATEOAS Library&lt;/a&gt; (currently in Release 0.6) provides API to help creating REST representations that follow the HATEOAS principle. The core problem it tries to address is link creation and representation assembly. Let&amp;#39;s see the main steps required for enabling the HATEOAS for a RESTful web service:&lt;/p&gt;
&lt;a href=&quot;http://azagorneanu.blogspot.com/2013/06/hateoas-using-spring-framework.html#more&quot;&gt;Read More »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://azagorneanu.blogspot.com/feeds/1382271819846005040/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://azagorneanu.blogspot.com/2013/06/hateoas-using-spring-framework.html#comment-form' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8369030687505463576/posts/default/1382271819846005040'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8369030687505463576/posts/default/1382271819846005040'/><link rel='alternate' type='text/html' href='http://azagorneanu.blogspot.com/2013/06/hateoas-using-spring-framework.html' title='HATEOAS using Spring Framework'/><author><name>Andrei Zagorneanu</name><uri>http://www.blogger.com/profile/04979424616588139827</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNLlxaVK8AzDVqwrMYvkQtMbIvGN60wgem_LdJAwPGSxiiac_NWvPV3mvmLq0zutskcLMZGlmDOquEvL6l9vhnb4qYlBLtkPQyt-LyKgTtAiAFGmyIHe94X0ObIDnZ4lEYdMaisY-tNtRa/s72-w640-h546-c/spring-hateoas-json.png" height="72" width="72"/><thr:total>10</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8369030687505463576.post-1313703595160562894</id><published>2013-06-02T23:39:00.008+03:00</published><updated>2020-06-06T11:34:57.302+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="spring framework"/><title type='text'>Transaction synchronization callbacks in Spring Framework</title><content type='html'>&lt;p&gt;Declarative transaction management simplifies considerably the development. Sometimes you want a little more control over transaction but at the same time you don&amp;#39;t want to switch to programmatic transaction management. I&amp;#39;m talking about cases when you want to execute some activities only when transaction was completed successfully. For example: send an email with registration details, update a cache, send a message over network, etc. The tricky part here is that you want to perform these activities from a transactional method (a method marked with &lt;a href=&quot;http://static.springsource.org/spring/docs/3.2.x/javadoc-api/org/springframework/transaction/annotation/Transactional.html&quot; target=&quot;_blank&quot;&gt;&lt;code&gt;@Transactional&lt;/code&gt;&lt;/a&gt; which automatically will start and end the transaction).&lt;/p&gt;
&lt;p&gt;Now let&amp;#39;s see how we can achieve this in Spring Framework. &lt;a href=&quot;http://static.springsource.org/spring/docs/3.2.x/javadoc-api/org/springframework/transaction/support/TransactionSynchronizationManager.html&quot; target=&quot;_blank&quot;&gt;&lt;code&gt;TransactionSynchronizationManager&lt;/code&gt;&lt;/a&gt; is the central helper class that manages resources and transaction synchronizations per thread. It allows to register transaction synchronizations for the current thread if synchronization is active. &lt;a href=&quot;http://static.springsource.org/spring/docs/3.2.x/javadoc-api/org/springframework/transaction/support/TransactionSynchronization.html&quot; target=&quot;_blank&quot;&gt;&lt;code&gt;TransactionSynchronization&lt;/code&gt;&lt;/a&gt; represents the actual transaction synchronization callback with methods like: &lt;code&gt;afterCommit(), afterCompletion(int status), beforeCommit(boolean readOnly), beforeCompletion(),&lt;/code&gt; etc. In order to make things easier for use, we will create an after commit executor which will allow us to execute the code only after a successful commit.&lt;/p&gt;
&lt;a href=&quot;http://azagorneanu.blogspot.com/2013/06/transaction-synchronization-callbacks.html#more&quot;&gt;Read More »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://azagorneanu.blogspot.com/feeds/1313703595160562894/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://azagorneanu.blogspot.com/2013/06/transaction-synchronization-callbacks.html#comment-form' title='15 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8369030687505463576/posts/default/1313703595160562894'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8369030687505463576/posts/default/1313703595160562894'/><link rel='alternate' type='text/html' href='http://azagorneanu.blogspot.com/2013/06/transaction-synchronization-callbacks.html' title='Transaction synchronization callbacks in Spring Framework'/><author><name>Andrei Zagorneanu</name><uri>http://www.blogger.com/profile/04979424616588139827</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>15</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8369030687505463576.post-9117319928499066124</id><published>2011-09-15T22:49:00.006+03:00</published><updated>2020-06-06T12:12:14.964+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="jaxb"/><category scheme="http://www.blogger.com/atom/ns#" term="maven"/><title type='text'>Configure Maven to generate classes from XML Schema using JAXB</title><content type='html'>&lt;p&gt;In my &lt;a href=&quot;http://azagorneanu.blogspot.com/2011/09/crud-restful-services-using-spring.html&quot;&gt;previous post&lt;/a&gt; I showed how to create RESTful services using Spring Framework. For representation of resources in XML I used JAXB and I followed the &lt;a href=&quot;http://en.wikipedia.org/wiki/Top%E2%80%93down_and_bottom%E2%80%93up_design&quot;&gt;bottom-up&lt;/a&gt; approach (I wrote the Java classes and I let to generate XML/XSD from Java classes). In this post I will demonstrate how you can generate the same Java classes (&lt;code&gt;User&lt;/code&gt; and &lt;code&gt;UserList&lt;/code&gt;) from &lt;a href=&quot;http://en.wikipedia.org/wiki/XML_schema&quot;&gt;XML Schema&lt;/a&gt; (XSD) during Maven build, therefore using a &lt;a href=&quot;http://en.wikipedia.org/wiki/Top%E2%80%93down_and_bottom%E2%80%93up_design&quot;&gt;top-down&lt;/a&gt; approach. For generation of Java classes from XML Schema during Maven build I will use &lt;a href=&quot;http://java.net/projects/maven-jaxb2-plugin/pages/Home&quot;&gt;Java.net Maven 2 JAXB 2 Plugin&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Along with the default generation of Java classes from XML Schema using &lt;b&gt;&lt;code&gt;xjc&lt;/code&gt;&lt;/b&gt; tool, I will add the following customizations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Making all the generated classes to implement &lt;code&gt;Serializable&lt;/code&gt; (useful when you want to use classes with some remote services: RMI, EJB, etc).&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;java.util.Calendar&lt;/code&gt; instead of &lt;code&gt;javax.xml.datatype.XMLGregorianCalendar&lt;/code&gt; for fields generated from elements of type &lt;code&gt;xs:dateTime&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Generated classes should also have a generated &lt;code&gt;toString()&lt;/code&gt; method.&lt;/li&gt;
&lt;li&gt;Classes have to be annotated with &lt;code&gt;XmlRootElement&lt;/code&gt; (required by Spring Framework when classes are used to represent state in RESTful services).&lt;/li&gt;
&lt;li&gt;You can further enhance and customize the generation of Java classes using various &lt;a href=&quot;http://confluence.highsource.org/display/J2B/JAXB2+Basics+Plugins&quot;&gt;plugins&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Project sources are available for &lt;a href=&quot;http://azagorneanu.googlecode.com/svn/trunk/blog/zmeu-blog-maven-jaxb.zip&quot;&gt;download&lt;/a&gt;. So let’s start, step by step:&lt;/p&gt;
&lt;a href=&quot;http://azagorneanu.blogspot.com/2011/09/configure-maven-to-generate-classes.html#more&quot;&gt;Read More »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://azagorneanu.blogspot.com/feeds/9117319928499066124/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://azagorneanu.blogspot.com/2011/09/configure-maven-to-generate-classes.html#comment-form' title='30 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8369030687505463576/posts/default/9117319928499066124'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8369030687505463576/posts/default/9117319928499066124'/><link rel='alternate' type='text/html' href='http://azagorneanu.blogspot.com/2011/09/configure-maven-to-generate-classes.html' title='Configure Maven to generate classes from XML Schema using JAXB'/><author><name>Andrei Zagorneanu</name><uri>http://www.blogger.com/profile/04979424616588139827</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>30</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8369030687505463576.post-5759948269151812918</id><published>2011-09-14T23:28:00.004+03:00</published><updated>2020-06-06T12:10:08.843+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="jaxb"/><category scheme="http://www.blogger.com/atom/ns#" term="rest"/><category scheme="http://www.blogger.com/atom/ns#" term="spring framework"/><title type='text'>CRUD RESTful services using Spring Framework</title><content type='html'>&lt;p&gt;In this post I will show how to build &lt;a href=&quot;http://en.wikipedia.org/wiki/Create,_read,_update_and_delete&quot;&gt;CRUD&lt;/a&gt; (&lt;b&gt;C&lt;/b&gt;reate, &lt;b&gt;R&lt;/b&gt;ead, &lt;b&gt;U&lt;/b&gt;pdate, &lt;b&gt;D&lt;/b&gt;elete) &lt;a href=&quot;http://en.wikipedia.org/wiki/Representational_state_transfer&quot;&gt;REST&lt;/a&gt;-ful (&lt;b&gt;Re&lt;/b&gt;presentational &lt;b&gt;S&lt;/b&gt;tate &lt;b&gt;T&lt;/b&gt;ransfer) services using &lt;a href=&quot;http://www.springsource.org/&quot;&gt;Spring Framework&lt;/a&gt;. Spring Framework version used in this example is 3.0.6.RELEASE. &lt;a href=&quot;http://tomcat.apache.org/&quot;&gt;Apache Tomcat&lt;/a&gt; version used for testing the web services is 6.0.29 (default Tomcat version used by &lt;a href=&quot;http://mojo.codehaus.org/tomcat-maven-plugin/&quot;&gt;Tomcat Maven Plugin&lt;/a&gt; of &lt;a href=&quot;http://maven.apache.org/&quot;&gt;Apache Maven&lt;/a&gt; 2.2.1). Project sources are available for &lt;a href=&quot;http://azagorneanu.googlecode.com/svn/trunk/blog/zmeu-blog-spring-rest.zip&quot;&gt;download&lt;/a&gt;. So let’s start, step by step:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;First we have to define the resource on which the CRUD operation will be performed and how this resource will be represented. In our example we will use a resource that represents a User. The resource will be represented using &lt;a href=&quot;http://en.wikipedia.org/wiki/XML&quot;&gt;XML&lt;/a&gt; (E&lt;b&gt;x&lt;/b&gt;tensible &lt;b&gt;M&lt;/b&gt;arkup &lt;b&gt;L&lt;/b&gt;anguage). At the end of the post I will show how you can switch the resource representation to &lt;a href=&quot;http://en.wikipedia.org/wiki/JSON&quot;&gt;JSON&lt;/a&gt; (&lt;b&gt;J&lt;/b&gt;ava&lt;b&gt;S&lt;/b&gt;cript &lt;b&gt;O&lt;/b&gt;bject &lt;b&gt;N&lt;/b&gt;otation) or any other supported form.&lt;/li&gt;
&lt;li&gt;Create a Maven project. We will use Maven for project management and build. Maven POM is shown below:
&lt;/li&gt;&lt;/ol&gt;&lt;a href=&quot;http://azagorneanu.blogspot.com/2011/09/crud-restful-services-using-spring.html#more&quot;&gt;Read More »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://azagorneanu.blogspot.com/feeds/5759948269151812918/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://azagorneanu.blogspot.com/2011/09/crud-restful-services-using-spring.html#comment-form' title='12 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8369030687505463576/posts/default/5759948269151812918'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8369030687505463576/posts/default/5759948269151812918'/><link rel='alternate' type='text/html' href='http://azagorneanu.blogspot.com/2011/09/crud-restful-services-using-spring.html' title='CRUD RESTful services using Spring Framework'/><author><name>Andrei Zagorneanu</name><uri>http://www.blogger.com/profile/04979424616588139827</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGN0pjdu3eZ8MI1kH-ImTG3gMeBXs2Aje7A8aQm2qEd2KQlD2LHGcg1aewnGLYgBeEUXabryxiuyhnTvhwVOVrPGHCKUq4VvhyAJeen-g__CvHumm6PHzRBVvJVoRhkmwXklcao6wKNxvO/s72-c/spring-rest-read-user.png" height="72" width="72"/><thr:total>12</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8369030687505463576.post-7870815597823181378</id><published>2011-08-07T22:51:00.003+03:00</published><updated>2020-06-06T12:26:01.638+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="apache commons"/><category scheme="http://www.blogger.com/atom/ns#" term="eclipse"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><title type='text'>How to generate equals(), hashCode(), toString() and compareTo() using Apache Commons Lang in Eclipse</title><content type='html'>&lt;p&gt;&lt;a href=&quot;http://commons.apache.org/&quot;&gt;Apache Commons&lt;/a&gt; project represents a set of reusable Java components. &lt;a href=&quot;http://commons.apache.org/lang/&quot;&gt;Apache Commons Lang&lt;/a&gt; is one of the Apache Commons components. It provides much needed additions to the standard JDK&amp;#39;s &lt;code&gt;java.lang&lt;/code&gt; package. One of its packages, &lt;a href=&quot;http://commons.apache.org/lang/api-release/org/apache/commons/lang3/builder/package-summary.html&quot;&gt;org.apache.commons.lang3.builder&lt;/a&gt; contains a set of very useful builders that helps in creating consistent &lt;code&gt;equals()&lt;/code&gt;, &lt;code&gt;hashCode()&lt;/code&gt;, &lt;code&gt;toString()&lt;/code&gt; and &lt;code&gt;compareTo()&lt;/code&gt; methods.&lt;/p&gt;
&lt;p&gt;In this post, I will show how to generate &lt;code&gt;equals()&lt;/code&gt;, &lt;code&gt;hashCode()&lt;/code&gt;, &lt;code&gt;toString()&lt;/code&gt; and &lt;code&gt;compareTo()&lt;/code&gt; methods using Apache Commons Lang builders in Eclipse. For demonstrations I will use the latest stable release - &lt;a href=&quot;http://commons.apache.org/lang/api-3.0/index.html&quot;&gt;Apache Commons Lang 3.0&lt;/a&gt;. Note that Lang 3.0 uses a different package (&lt;code&gt;org.apache.commons.lang3&lt;/code&gt;) than its predecessors (&lt;code&gt;org.apache.commons.lang&lt;/code&gt;). All the examples presented in this post will work also with the previous Apache Commons Lang releases; just change the package name from &lt;code&gt;lang3&lt;/code&gt; to &lt;code&gt;lang&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;Native Support&lt;/h3&gt;
&lt;p&gt;Eclipse supports out of the box generation of &lt;code&gt;equals()&lt;/code&gt;, &lt;code&gt;hashCode()&lt;/code&gt; and &lt;code&gt;toString()&lt;/code&gt; methods. But only the generation of &lt;code&gt;toString()&lt;/code&gt; can be configured to use different builders. Below is shown how to configure Eclipse to use &lt;a href=&quot;http://commons.apache.org/lang/api-release/org/apache/commons/lang3/builder/ToStringBuilder.html&quot;&gt;ToStringBuilder&lt;/a&gt; to generate &lt;code&gt;toString()&lt;/code&gt; methods.&lt;/p&gt;&lt;a href=&quot;http://azagorneanu.blogspot.com/2011/08/how-to-generate-equals-hashcode.html#more&quot;&gt;Read More »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://azagorneanu.blogspot.com/feeds/7870815597823181378/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://azagorneanu.blogspot.com/2011/08/how-to-generate-equals-hashcode.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8369030687505463576/posts/default/7870815597823181378'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8369030687505463576/posts/default/7870815597823181378'/><link rel='alternate' type='text/html' href='http://azagorneanu.blogspot.com/2011/08/how-to-generate-equals-hashcode.html' title='How to generate equals(), hashCode(), toString() and compareTo() using Apache Commons Lang in Eclipse'/><author><name>Andrei Zagorneanu</name><uri>http://www.blogger.com/profile/04979424616588139827</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxDKWt2Q_j3CB4AVukR-gndu9k1EXdt-lcwFcFrEtafuBskIJAAGWnkYW6mVKV1j17zeXD3MdKd2kFPZ-23fLSTpVxTgRZju4IEzXMyY9sJ8CSDKsdQ809bGg9h05Dh929qCcPLlRLOXMd/s72-c/eclipse-generate-tostring.png" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8369030687505463576.post-2831315770129971616</id><published>2011-07-31T23:27:00.003+03:00</published><updated>2020-06-06T12:31:15.193+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="hibernate"/><category scheme="http://www.blogger.com/atom/ns#" term="infinispan"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="spring framework"/><title type='text'>How to register Infinispan listeners in Spring when using Infinispan as 2LC for Hibernate</title><content type='html'>In this post I will show how to register &lt;a href=&quot;http://www.jboss.org/infinispan&quot;&gt;Infinispan&lt;/a&gt; listeners in &lt;a href=&quot;http://www.springsource.org/&quot;&gt;Spring&lt;/a&gt; when Infinispan is used as second level cache (2LC) for &lt;a href=&quot;http://hibernate.org/&quot;&gt;Hibernate&lt;/a&gt;. So let’s start:&lt;br&gt;
&lt;ol&gt;
&lt;li&gt;Annotate your entity classes as cacheable. Pay attention to the cache region name (&lt;code&gt;&amp;quot;cache_name&amp;quot;&lt;/code&gt;) specified in the &lt;code&gt;region&lt;/code&gt; attribute of &lt;code&gt;Cache&lt;/code&gt; annotation.
&lt;pre&gt;&lt;code&gt;@Entity
@Cache(region = &amp;quot;cache_name&amp;quot;, usage = CacheConcurrencyStrategy.TRANSACTIONAL)
@Cacheable
@Table(name = &amp;quot;ENTITY_TABLE&amp;quot;)
public class MyEntity implements Serializable {
    // entity fields
}
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;Write your custom &lt;code&gt;InfinispanRegionFactory&lt;/code&gt; as it is shown below. It extends from Hibernate &lt;code&gt;InfinispanRegionFactory&lt;/code&gt; and its logic is very simple. The only thing which it does is to register listeners after its start. Pay attention to the named cache (&lt;code&gt;&amp;quot;cache_name&amp;quot;&lt;/code&gt;) to which listeners are registered. It should be the same as the cache region name used by your entities. &lt;/li&gt;&lt;/ol&gt;&lt;a href=&quot;http://azagorneanu.blogspot.com/2011/07/how-to-register-infinispan-listeners-in.html#more&quot;&gt;Read More »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://azagorneanu.blogspot.com/feeds/2831315770129971616/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://azagorneanu.blogspot.com/2011/07/how-to-register-infinispan-listeners-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8369030687505463576/posts/default/2831315770129971616'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8369030687505463576/posts/default/2831315770129971616'/><link rel='alternate' type='text/html' href='http://azagorneanu.blogspot.com/2011/07/how-to-register-infinispan-listeners-in.html' title='How to register Infinispan listeners in Spring when using Infinispan as 2LC for Hibernate'/><author><name>Andrei Zagorneanu</name><uri>http://www.blogger.com/profile/04979424616588139827</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8369030687505463576.post-8229328232631744318</id><published>2011-07-31T13:53:00.005+03:00</published><updated>2020-06-06T12:34:31.571+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><title type='text'>How to extract type arguments from parameterized (generic) class</title><content type='html'>&lt;p&gt;A nice thing about parameterized classes in Java is that you can extract and access information about class type arguments at runtime (for an explanation about parameters and arguments see &lt;a href=&quot;http://en.wikipedia.org/wiki/Parameter_%28computer_science%29#Parameters_and_arguments&quot;&gt;Parameters and arguments&lt;/a&gt;). Let’s say that we have an abstract parameterized superclass that has a method which provides some common functionality to all its subclasses. And inside that method we wanted to know what is the class type argument specified by the subclass.&lt;p&gt;
&lt;pre&gt;&lt;code&gt;public abstract class GenericAbstractSuperclass&amp;lt;T&amp;gt; {
    public void foo() {
        // here we wanted to know what is the class type argument
    }
}

public class GenericClass1 extends GenericAbstractSuperclass&amp;lt;Integer&amp;gt; {
    // subclass methods
}

public class GenericClass2 extends GenericAbstractSuperclass&amp;lt;String&amp;gt; {
    // subclass methods
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In above example, method &lt;code&gt;foo()&lt;/code&gt; has to access class type argument. In case of &lt;code&gt;GenericClass1&lt;/code&gt; it has to get &lt;code&gt;Integer&lt;/code&gt; and in case of &lt;code&gt;GenericClass2&lt;/code&gt; it has to get &lt;code&gt;String&lt;/code&gt;. Below is listed a utility class that can accomplish this.&lt;/p&gt;&lt;/p&gt;&lt;/p&gt;&lt;a href=&quot;http://azagorneanu.blogspot.com/2011/07/how-to-extract-type-arguments-from.html#more&quot;&gt;Read More »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://azagorneanu.blogspot.com/feeds/8229328232631744318/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://azagorneanu.blogspot.com/2011/07/how-to-extract-type-arguments-from.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8369030687505463576/posts/default/8229328232631744318'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8369030687505463576/posts/default/8229328232631744318'/><link rel='alternate' type='text/html' href='http://azagorneanu.blogspot.com/2011/07/how-to-extract-type-arguments-from.html' title='How to extract type arguments from parameterized (generic) class'/><author><name>Andrei Zagorneanu</name><uri>http://www.blogger.com/profile/04979424616588139827</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8369030687505463576.post-7376413346567023452</id><published>2011-07-25T21:35:00.003+03:00</published><updated>2020-06-06T12:36:07.969+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="java"/><title type='text'>java.math.BigDecimal performance</title><content type='html'>&lt;p&gt;These days I had to do some monetary calculations in Java. This reminded me again about primitive &lt;code&gt;double&lt;/code&gt; type and that it is absolutely the worst thing you can use when dealing with money. As you know, primitive &lt;code&gt;double&lt;/code&gt; don&amp;#39;t necessarily give you the right value, only the value that can be stored in a binary number format (any decimal number is represented by an approximated value). Whilst, &lt;code&gt;java.math.BigDecimal&lt;/code&gt; gives you the required precision, its performance is very poor comparable to primitive types.&lt;/p&gt;
&lt;p&gt;Below are few simple tests that are measuring &lt;code&gt;BigDecimal&lt;/code&gt; performance based on a simple computation &lt;code&gt;x&lt;sup&gt;2&lt;/sup&gt; + y&lt;sup&gt;2&lt;/sup&gt;&lt;/code&gt; which is performed in a loop 250000 times. In order to exclude the JVM warm-up cost, each test was executed 10 times. The execution time was calculated as average of all executions except first execution &lt;code&gt;(exec&lt;sub&gt;2&lt;/sub&gt; + exec&lt;sub&gt;3&lt;/sub&gt; + … + exec&lt;sub&gt;10&lt;/sub&gt;) / 9&lt;/code&gt;.&lt;/p&gt;&lt;a href=&quot;http://azagorneanu.blogspot.com/2011/07/javamathbigdecimal-performance.html#more&quot;&gt;Read More »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://azagorneanu.blogspot.com/feeds/7376413346567023452/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://azagorneanu.blogspot.com/2011/07/javamathbigdecimal-performance.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8369030687505463576/posts/default/7376413346567023452'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8369030687505463576/posts/default/7376413346567023452'/><link rel='alternate' type='text/html' href='http://azagorneanu.blogspot.com/2011/07/javamathbigdecimal-performance.html' title='java.math.BigDecimal performance'/><author><name>Andrei Zagorneanu</name><uri>http://www.blogger.com/profile/04979424616588139827</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8369030687505463576.post-7467673837539248762</id><published>2011-06-19T12:33:00.025+03:00</published><updated>2020-06-06T12:41:20.007+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="applet"/><category scheme="http://www.blogger.com/atom/ns#" term="freemind"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="java web start"/><category scheme="http://www.blogger.com/atom/ns#" term="jnlp"/><category scheme="http://www.blogger.com/atom/ns#" term="mindmap"/><title type='text'>Export FreeMind mind map as Java Applet</title><content type='html'>&lt;p&gt;&lt;a href=&quot;http://freemind.sourceforge.net/&quot;&gt;FreeMind&lt;/a&gt; is a free &lt;a href=&quot;http://en.wikipedia.org/wiki/Mind_map&quot;&gt;mind-mapping&lt;/a&gt; software written in Java. In this post I will show how to export FreeMind mind maps as Java Applet, describe issues which you can encounter during this process and give some hints on a how to better package exported mind maps.&lt;/p&gt;
&lt;p&gt;Let’s start with creating a test mind map. Suppose we have the following mind map:&lt;/p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgplfXriZmVtDqHSKu_EuhDca6lCD0c77d2IpfrsnKUm3mbAJq89RsJTz17pN3QH-3EVntZ7RRsO7JImsQWg40NXcpnDYJl1KBjNFaRQ9WpKZmmpmP99n_-mNnpPkBB6-0J8LrKoMPGadoT/s1600/test-partial-mm.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;336&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgplfXriZmVtDqHSKu_EuhDca6lCD0c77d2IpfrsnKUm3mbAJq89RsJTz17pN3QH-3EVntZ7RRsO7JImsQWg40NXcpnDYJl1KBjNFaRQ9WpKZmmpmP99n_-mNnpPkBB6-0J8LrKoMPGadoT/s640/test-partial-mm.png&quot; width=&quot;640&quot; title=&quot;Test Mind Map&quot; alt=&quot;Test Mind Map&quot;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;FreeMind has plenty of options for exporting mind maps. For example the image which you see above was created using Export as PNG option (&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;File -&amp;gt; Export -&amp;gt; As PNG…&lt;/span&gt;). Your next question might be: Why to export mind maps as Java Applet if there are so many other options? Here is the answer. Even if FreeMind has many options for exporting mind maps, most of them are not suitable for publishing on the Internet (especially for big mind maps). Starting with FreeMind 0.9.0 two new export options were added: &lt;b&gt;Flash&lt;/b&gt; and &lt;b&gt;Java Applet&lt;/b&gt;. These two options can be used to bring mind maps into the Internet.&lt;/p&gt;
&lt;a href=&quot;http://azagorneanu.blogspot.com/2011/06/export-freemind-mind-map-as-java-applet.html#more&quot;&gt;Read More »&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://azagorneanu.blogspot.com/feeds/7467673837539248762/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://azagorneanu.blogspot.com/2011/06/export-freemind-mind-map-as-java-applet.html#comment-form' title='17 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8369030687505463576/posts/default/7467673837539248762'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8369030687505463576/posts/default/7467673837539248762'/><link rel='alternate' type='text/html' href='http://azagorneanu.blogspot.com/2011/06/export-freemind-mind-map-as-java-applet.html' title='Export FreeMind mind map as Java Applet'/><author><name>Andrei Zagorneanu</name><uri>http://www.blogger.com/profile/04979424616588139827</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgplfXriZmVtDqHSKu_EuhDca6lCD0c77d2IpfrsnKUm3mbAJq89RsJTz17pN3QH-3EVntZ7RRsO7JImsQWg40NXcpnDYJl1KBjNFaRQ9WpKZmmpmP99n_-mNnpPkBB6-0J8LrKoMPGadoT/s72-c/test-partial-mm.png" height="72" width="72"/><thr:total>17</thr:total></entry></feed>