With the help of Groovy, we can delete a file from a generated project if it meets a condition (for instance if a maven property equals a certain value).

Here is the procedure :
1) Create the archetype. To do that, type the following command from the root of a Maven project : mvn archetype:create-from-project
result ==> [INFO] Archetype project created in E:\eclipse\workspace\celinio\target\generated-sources\archetype

Copy-paste this folder structure into another folder in the workspace and import it as an existing maven project.
By default, I have decided that this archetype will generate a project which contains a file /src/main/resources/META-INF/configuration.xml. This is the file that I do not want to include if the maven property configurable is set to no.

2) Add the following required property to /celinioArchetype/src/main/resources/META-INF/maven/archetype-metadata.xml

To test it in eclipse, you will need to create a project from a run configuration as the groovy script is not executed if you go through the wizard (File > New Maven Project > select archetype etc)
See this link for details :https://bugs.eclipse.org/bugs/show_bug.cgi?id=514993

It is possible to add UML diagrams to the JavaDoc generated during the build phase.

The first thing to do is to install Graphviz which is an open source graph visualization software.
After installation, add the bin folder (D:\Graphviz\bin for instance) to the PATH environment variable.
Then configure the pom.xml :

Here i chose to add the maven-javadoc-plugin to the build maven phase. In the configuration of the plugin, i added the UmlGraphDoc doclet.UMLGraph allows the declarative specification and drawing of UML class and sequence diagrams.

Run mvn install and then check the generated JavaDoc under the folder target/site/apidocs/
Here is a sample :

Modularity and plug-ability features in Servlet 3.0 specification is also called web fragments. The JSR 315 (Java Servlet 3.0 specification) is already 9 years old. The final release dates back to december 10, 2009.
https://jcp.org/en/jsr/detail?id=315
Web fragments are one of the main features of this JSR.
A web fragment is an XML file named web-fragment.xml and located inside the META-INF folder of a jar library.The root element of this file must be :

<web-fragment>

Web fragments are XML files that will have part of the configurations of a web.xml file.

Here is a short and quick demonstration of it. First, create a web app project with the help of the maven-archetype-webapp archetype.

Now create a second project with the help of the maven-archetype-quickstart archetype. Add a resources folder under src/main and then create a META-INF folder under that resources folder. Finally add a new file called web-fragment.xml to that META-INF folder with the following content :

With Tomcat 9, to view the content of the generated web.xml, it is necessary to add the logEffectiveWebXml attribute to the context tag in the context.xml file located under the conf folder and set it to true :

<?xml version="1.0" encoding="UTF-8"?>
<!-- The contents of this file will be loaded for each web application -->
<Context logEffectiveWebXml="true">
<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded. -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
</Context>

During the deployment, the web server scans and treats the various web fragments that it might find.
It will concatenate all the fragments to the main web.xml file.
This is a simple demonstration. You might be wondering what might happen if there is more than one web fragment file and more precisely in which order will they be added to the generated web.xml.
Well, to deal with that, the absolute-ordering tag was added :

So you coded the data layer of your application using JPA (with for instance the Hibernate implementation) and when the application reaches the staging environment, you hear it is too slow !
Too many queries, too long queries, etc.
What do you do ? You try to optimize your data layer !
One possible optimization is to batch insert/update data.
The following properties must be set in persistence.xml :

Java 8 has an interesting feature that I learnt recently.
A variable can become “effectively final”.
Very useful.
For instance, the following class would not compile in Java 1.7.
It would return the following error :
“Cannot refer to the non-final local variable myVocabulary defined in an enclosing scope”.
It would require to add the modifier FINAL to the myVocabulary variable.
In Java 8, there is no need to make it final but make sure you do not change the value once assigned.

Question : how is the cyclomatic complexity of an algorithm calculated ?
Cyclomatic complexity is the number of independent paths through the program.
A program can be seen as a connected graph.
The formula is the following :v(g) = e – n + 2P
where
e = number of edges
n = number of nodes
P = the number of exit points (usually only 1)

An edge connects 2 nodes. It represents non-branching and branching links between nodes.
Nodes are decisions points which may be conditional statements like if, if … else, switch, while, etc.
This metric was developed by Thomas J. McCabe in 1976.

Well, after further investigation and according to this link (checkstyle tool), I have concluded that the McCabe formula is not really applied to calculate the cyclomatic complexity in a Java program.

The complexity is equal to the number of decision points + 1 Decision points: if, while , do, for, ?:, catch , switch, case statements, and operators && and || in the body of target.

Anyways, the result number of 22 makes sense.
This method has an awful number of successive if conditions and something should be done about it to improve its maintainability. If we would apply strictly the McCabe formula, the result would be strange. At least according to this plugin for Eclipse : Eclipse Control Flow Graph Generator
The flow chart generated is the following :
And the McCabe result would be 1 !

Here is a complete and short example of asynchronous development using JMS and a Message-Driven Bean (MDB).
First the procedure to configure inside Weblogic Server a JMS server in order to create a queue, then the code for the producer/sender of a message to the queue and then the code for a consumer (MDB).

1) Weblogic configuration
a) Create the JMS server

b) Create a JMS module

c) Create a destination (queue or topic)

d) Create a connection factory

2) Create a producer

For the producer, I got strongly inspired by the code found in this blog. This is a clean example of a producer/sender so no need to reinvent the wheel here.

I found out that it is important to specify the exact version of Oracle in the persistence.xml file. I am currently using EclipseLink as the persistence framework provider.

Oracle hints were introduced to speed up/optimize SQL queries. Starting with Oracle 10, some of them have become almost unecessary because the optimizer was greatly improved. Also, depending on the structure of the queries and the database design (use of primary keys or not, index are where they should be or not, etc), hints can be counterproductive since they slow down queries instead of speeding them up.

I had to find a way to test a method from a stateful session bean (EJB PersonSABean implements PersonSF) defined in a service layer that calls another method from another stateful session bean (EJB HouseSFBean implements HouseSF) defined in a business layer.

To call that method from EJB HouseSFBean, the EJB PersonSABean needs to perform a lookup to get a reference to the EJB HouseSF. In that case, a static method is often created inside a static or final class. For instance :

But unit tests, unlike integration tests, are meant to test a specific method (or class). They are not meant to test the methods that it calls. So in my case, i do not need to make – and should not make – a JNDI lookup to get a reference to the EJB HouseSF . So I have to mockup the EjbUtil.lookup(…) static method.

Fortunately, PowerMockito can mock a static methodso the solution is to use both Mockito and PowerMockito :

It seems to me that the order of execution of the reader, the processor and the writer, inside a step and a chunk, is not always clear in everybody’s mind (included mine when i started with Spring Batch).

So I made the following 2 tables that should help – I hope – clarify things.

1) First scenario : we read, process and write all data at once. There is no commit interval defined.

Here is an excerpt of a job with one step. The reader reads the data from a datasource such as a database.

Then chunk processing will occur in that order (supposing there are 6 items) :

Order of execution with chunk processing

Execution order

Reader

Processor

Writer

Transactions

1

1st item

T1

2

2nd item

3

3rd item

4

4th item

5

1st item

6

2nd item

7

3rd item

8

4th item

9

The first 4 lines, at the same time

10

5th item

T2

11

6th item

12

5th item

13

6th item

14

The last 2 lines, at the same time

There are 2 transactions, one for each chunk.
That means if there is a problem with the 6th item, the first 4 items (1st chunk) will already have been processed and committed.
A rollback will occur for all items of the 2nd chunk (items 5 and 6).

I wrote this small class to illustrate the use of the Async and Await keywords which were added in .NET 4.5.
It should quickly help anyone curious to understand this easier way to write asynchronous programs in C#.

The output below (DOS window) shows clearly the difference between the call of a synchronous method and the call of an asynchronous method.
The message “After calling DisplaySumAsync” (line 25) is called immediately after the call of the DisplaySumAsync() method, whether it is finished or not.
The important thing to note is : the lines written in the same thread used to call the asynchronous method (which runs in another thread) are executed immediately. An asynchronous method does not block the calling function, allowing that function to continue functioning.

Here are the steps to run the super dev mode which is a new feature of GWT 2.5.
The versions i used are GWT 2.5.1-rc1 and Chrome 26.0. That version of Chrome requires the latest version of GWT, otherwise it will not work. I tested it with GWT 2.5 previously and I could not see the source code in Chrome browser.

And do as it says : create 2 bookmarks in Chrome for Dev Mode On and Dev Mode Off, with the help of the bookmarklets. Which I have already done.
Then run the application.
Since I did not use an external server, I ran the application in development mode (gwt:run) so it runs with Jetty. But i could have run it directly under WebLogic for instance.
Then go to the URL of the application :http://127.0.0.1:8888/PlanetEarth.html?gwt.codesvr=127.0.0.1:9997
In fact remove the “?gwt.codesvr=127.0.0.1:9997” part of the URL. It is no longer necessary to install the Google Web Toolkit Developer Plugin for the browser. So the URL to go to is http://127.0.0.1:8888/PlanetEarth.html :

Step 5 :

While on that page, click on the “Dev Mode On” bookmark. A popup asking to compile the module will show up :

Click on Compile. This will recompile the application.
Then in Chrome go to Tools > Developers Tools > Settings and check the checkbox “Enable source maps” :

Refresh the page and you should see the Java code in the “Sources” tab :

Just want to signal something that a lot of Java developers seem not to be aware of :
a few of the upcoming features of the JDK 8 have been available in C# for some time now.

.NET / C#

Java

Lambda expressions (closures)

.NET 3.5 - C# 3 - 2007

JDK 8 - 2013

Virtual extension methods

.NET 3.5 - C# 3 - 2007

JDK 8 - 2013

...

...

...

C# was inspired by Java and C++ and now it kind of feels like Java 8 is catching up with C# !
But it is a good thing when the languages influence each other.
That is the case with C# and Java but that is also the case with Windows Forms / WPF + XAML and JavaFX 2 / GWT or ASP.NET MVC and Java MVC-based frameworks, etc.

WebLogic 10.3.5 is JAVA EE 5 certified. However JPA 2 is not part of the JAVA EE 5 (2006) specifications, it is part of the JAVA EE 6 (2009) specifications.
So since WebLogic Server implements the Java EE 5 specification, it is not required to support JPA 2. However it is possible to add support to WebLogic 10.3.5 for JPA 2. Look no further, the answer is of course on Oracle WebLogic website: Using Oracle TopLink with Oracle WebLogic Server

So if you make the choice to configure things manually then you do not need to install a patch.
It is just a matter of declaring a PRE_CLASSPATH environment variable in the file commEnv.cmd (Windows) or commEnv.sh (Linux) located in the WL_HOME/common/bin/ folder.

If you do not configure WebLogic 10.3.5 to support JPA 2 you will get an error message like this one :

nested exception is:
javax.ejb.EJBException: what do i do: seems an odd quirk of the EJB spec.
The exception is:java.lang.NoSuchMethodError: javax.persistence.EntityManager.createQuery(Ljava/lang/String;Ljava/lang/Class;)Ljavax/persistence/TypedQuery;;
nested exception is: javax.ejb.EJBException: what do i do: seems an odd quirk of the EJB spec.
The exception is:java.lang.NoSuchMethodError: javax.persistence.EntityManager.createQuery(Ljava/lang/String;Ljava/lang/Class;)Ljavax/persistence/TypedQuery;
javax.ejb.EJBException: what do i do: seems an odd quirk of the EJB spec.
The exception is:java.lang.NoSuchMethodError: javax.persistence.EntityManager.createQuery(Ljava/lang/String;Ljava/lang/Class;)Ljavax/persistence/TypedQuery;

There is no need to edit the file weblogic-application.xml and to add some additional prefered application package. That one for instance works :

I want to mention the Criteria API, a very cool API which in my opinion is not used as much as it should be. The developers who implement the specification (JSR 317: Java Persistence 2.0) do an impressive work. Thanks to them we have an API that makes it possible to write type safe queries in an object oriented way.
Usually Java developers write queries using JPQL or they write native queries. The fact is that the API Criteria has a (small) learning curve : you have to explore the API and study some basic queries examples before writing your own queries. The first time you use it, it does not seem as intuitive as JPQL.

The Criteria API is particularly convenient when writing queries which do not have a static where clause. For instance in the case of a web page where the user can make a research based on optional criterias. Then the generated query is not always the same.

The Criteria API has its advantages and its disadvantages : it produces typesafe queries that can be checked at compile time but on the other hand queries can be a bit hard to read (apparently unlike QueryDSL or EasyCriteria).
Another advantage is that it can help to avoid SQL injection since the user input is validated or escaped by the JDBC driver (which is not the case with native queries).

To create typesafe queries, one uses the canonical metamodel class associated to an entity (an idea originally proposed by Gavin King, as far as i know). A possible definition of a metamodel class could be that one : it is a class that provides meta information about a managed entity. By default, it has the same name as the entity plus an underscore. For instance if an entity is called Employee then the metamodel class is called Employee_. It is annotated with the annotation javax.persistence.StaticMetamodel.
Fortunately you do not have to write them, you can generate them using an annotation processor, through Eclipse or a Maven plugin for instance.
I chose to generate the metamodel classes with the help of the Hibernate Metamodel Generator (an annotation processor) and the maven-processor-plugin maven plugin, at each build so that they are updated whenever the entities are modified. It is a good way to keep the metamodel classes up to date.