Showing posts with label Java EE. Show all posts
Showing posts with label Java EE. Show all posts

Feb 14, 2014

GUI Design Patterns: MVC, MVP vs. MVVM

There are three famous GUI Design Patterns:
  • MVC: Model - View - Controller (e.g. ASP.NET, Java Swing and JavaFX, JSF)
  • MVP: Model - View - Presenter (e.g. WinForms, Java Swing and JavaFX, see Martin Fowler on GUI Architectures and the Presentation Model)
  • MVVM: Model - View - ViewModel (e.g. .NET WPF, Knockout JavaScript, JavaFX)
These GUI design patterns try to achieve
  • Modularity / Loose Coupling (through "separation of duties/concerns" and dependency injection)
  • Testability (test the different components independently)
  • Maintainability (e.g. changes can be made in one component without touching the others)

What's in common?
  • View: responsible for presentation in GUI (GUI components like buttons, labels etc. and layout & styling)
  • Model: data and behavior (domain objects and logic, services for database interaction)
  • Controller / Presenter / ViewModel: responsible for separation of the latter two (glue logic!)

What's different?

The associations between the three! (see the picture below) First of all, the MVVM pattern is just a specialization of the MVP, that is more loosely coupled through the concept of data binding.
The difference between MVP/MVVM and MVC is, that the View and the Model are completely decoupled - that's a good thing :-)
The black arrows represent a direct association, the red dotted arrows an indirect association (e.g. Observer Pattern/Events/Data Binding)


A good talk explaining this is "MVC,MVP and MVVM: A Comparison of Architectural Patterns" by Joseph Homnick:



Jun 14, 2013

Getting JDBC SQL Connection in JPA with Hibernate

When you need to retrieve the plain Connection from JPA, unfortunately, there is no JPA standard way (unless you get a configured datasource with JNDI). This is needed when you use libraries or legacy applications which use JDBC instead of JPA.


Hibernate 3.x and JPA 1.0

With Hibernate you can get the org.hibernate.session. In pre Hibernate 4.o there was the connection() method which now is removed.
EntityManager em = ...;
Session session = (Session) em.getDelegate();
Connection conn = session.connection();

Hibernate 3.x and JPA 2.0

EntityManager em = ...;
Connection conn = em.unwrap(Session.class).connection();

Hibernate 4.x and JPA 2.0

Session session = em.unwrap(Session.class);
SessionFactoryImplementor sfi = (SessionFactoryImplementor) session.getSessionFactory();
ConnectionProvider cp = sfi.getConnectionProvider();
Connection conn = cp.getConnection();

JNDI-Lookup

If you are running inside a container, you could also perform a JNDI lookup on the configured DataSource.

Jun 13, 2013

Java aktuell: "Lightweight AOP mit CDI und JPA"

Check out my article of the German magazine "Java aktuell – Das iJUG Magazin" (Ausgabe 03/2013) on


Feel free to contact me on questions and suggestions... (mail: hel@'this.domain')


Apr 5, 2013

Hello World and 99 Bottles of Beer

Didn't know that there were so many...

Feb 20, 2013

Usage of em.flush() in JPA

Suppose you have an JPA EntityManager named em. When you call em.persist() / em.merge() / em.remove() the corresponding SQL instructions insert / update / delete are not immediately sent to the database. Instead, they are cached for performance reasons and executed when you commit the transaction on Java-side (when exactly is dependent on the JPA implementation).

This can be a problem in the following scenarios:
  •  if you do something between the em.persist() and the commit that cannot be undone, i.e. is not transactional itself (like sending an email). If possible, do such things after the successful database transaction!
  • you need the result of some side effects, like an autogenerated key, database trigger, etc.
In these cases you may want that the SQLs are executed immediately: You can do this with em.flush(), which empties the internal SQL cache, sends it to the database and also synchronizes the persistence context.

Feb 19, 2013

JUGM Talk: Lightweight AOP with CDI and JPA

Thank you for the great organization with pizza @JUGM, the plenty attendees and the interesting discussions. Here are the slides:

Dec 6, 2012

Getting motivated: Code Hard


Lyrics

In the cubicles representin’ for my JAVA homies… In by nine, out when the deadlines are met, check it.

We code hard in these cubicles. My style’s nerd-chic, I’m a programmin’ freak.
We code hard in these cubicles. Only two hours to your deadline? Don’t sweat my technique.
Sippin’ morning coffee with that JAVA swirl. Born to code; my first words were “Hello World”
Since 95, been JAVA codin’ stayin’ proud. Started on floppy disks, now we take it to the cloud.
On my desktop, JAVA’s what’s bobbin’ and weavin’. We got another winning app before I get to OddEven.
Blazin’ code like a forest fire, climbin’ a tree. Setting standards like I Triple E….
Boot it on up, I use the force like Luke. Got so much love for my homeboy Duke.
GNU Public Licensed, it’s open source. Stop by my desk when you need a crash course
Written once and my script runs anywhere. Straight thuggin’, mean muggin’ in my Aeron chair.
All the best lines of code, you know I wrote ‘em. I’ll run you out of town on your dial-up modem.

‘Cause… We code hard in these cubicles. Me and my crew code hyphy hardcore.
We code hard in these cubicles. It’s been more than 10 years since I’ve seen the 404.
Inheriting a project can make me go beeee-serk. Ain’t got four hours to transfer their Framework.
The cleaners killed the lights, Man, that ain’t nice. Gonna knock this program out, just like Kimbo Slice
I program all night, just like a champ. Look alive under this IKEA lamp.
I code HARDER in the midnight hour, E7 on the vending machine fuels my power.
Ps3 to Smartphones, our code use never ends. JAVA’s there when I beat you in “Words with Friends”.
My developing skills are so fresh please discuss. You better step your game up on that C++.
We know better than to use Dot N-E-T. Even Dan Brown can’t code as hard as me.
You know JAVA’s gettin’ bigger, that’s a promise not a threat. Let me code it on your brain
so you’ll never forget.

We code hard in these cubicles, it’s the core component…of what we implement.
We code hard in these cubicles. Straight to your JAVA Runtime Environment.
We code hard in these cubicles. Keep the syntax light and the algorithm tight.
We code hard in these cubicles. Gotta use JAVA if it’s gonna run right.
We code hard in these cubicles. JAVA keeps adapting, you know it’s built to last.
We code hard in these cubicles. Robust and secure, so our swag’s on blast
CODE HARD

Dec 4, 2012

JayDay 2012

Yesterday on Dec. 3rd the Java conference "JayDay 2012" organized by eppleton took place in Munich. Me and over 90 "angry nerds" attended. Some very interesting talks about
  • Java EE 7/8, 
  • Java EE Cloud, 
  • JavaFX, 
  • NetBeans platform, 
  • Eclipse RCP, 
  • performance tuning, etc.
See the agenda.