In this post I will show you how to setup two or more data sources in a Spring application where the access to the database is done via JPA. It will be a XML-based Spring configuration. To highlight the setup I will use a showcase that builds on an existing demo example I have committed on GitHub, that covers other two posts of mine

Don’t worry! You don’t have to understand what’s going on in those if you just want to see how the setup for multiple data sources looks like – I’ll do a quick introduction in the first part of the post.

Continue Reading ...

One thing I immediately needed when using GIT/EGit instead of Subversion/Subversive in Eclipse,  was the possibility to quickly revert the changes I made to a file. The good news is that with EGit it goes just as fast…

Revert changes:

  • Subversive  right click on file > Team > Revert…
  • EGitright click on file > Replace With > File in Git Index
Replace with file from Git index

Replace with file from Git index

There are quite often situations, when you’d need to add or substract a time period to a date when you are accessing the database via Java Persistence API(JPA). Now

  • the bad news is that Java Persistence Query Language(JPQL) does not support such operations on dates yet.
  • the good news is that it is possible by using a native query or doing the computation on the Java side. I prefer the second option as it provides database independence.
  • <head>
        <title>Hoisting example reloaded</title>
    </head>
    &lt;body&gt;
        &lt;h1&gt;Hoisting in action&lt;/h1&gt;
        &lt;script type="application/javascript"&gt;
            var hoisting = "global variable";
            alert("global 'hoisting' var =&gt; " + hoisting);
            (function(){
                alert("local 'hoisting' var (BEFORE declaration WILL NOT PICK its global 'shadow' -&gt; undefined !) =&gt; " + hoisting);
                var hoisting = "local variable";
                alert("local 'hoisting' var (AFTER declaration WILL HIDE its global 'shadow' -&gt; assigned value !) =&gt; " + hoisting);
                // block
                {
                    var hoisting = "block variable";
                    alert("block 'hoisting' var (AFTER declaration WILL OVERRIDE its local 'shadow' -&gt; assigned value !) =&gt; " + hoisting);
                }
                // after block
                alert("local 'hoisting' var REPLACED AFTER BLOCK with its block 'shadow' =&gt; " + hoisting);
                // THE moral
                alert("The Hoisting MORAL: ALL local variables (even from blocks) are pre-defined/hoisted by JavaScript Runtime in front of the method body !\nDYI to make it clear !");
            })(); //self-executing function
        &lt;/script&gt;
    &lt;/body&gt;
    

    Thank you Dev{eloper} Stonez (@devstonez) for the tip.

    1. References of used class/method in code

    This is a very quick and useful way to find out where a class or method is used throughout the workspace/project. How to do it – select class/method > right click > References > Workspace (Ctrl+Shift+G) || Project

    Once you’ve done that, the results will be displayed in the Search view:

    Show-References

    Show references

    Another alternative for that is by selecting the class/method > start Java Search (Ctrl+H) > select your search criteria (in this case Type) and limit to References:

    show references - java search

    Show References via Java Search

    Continue Reading ...