Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, after a bit of reading and diving into the world of design patterns I decided to do the following and share my experiences (please see my first post for resolving the references).</p> <p>For the persistence layer ([5], [6], [7], etc.) I used the Strategy-Pattern, but you can also call it <a href="http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html" rel="nofollow">DAOFactory-Pattern</a> if you want to google it. In connection with that I used the <a href="https://community.jboss.org/wiki/GenericDataAccessObjects" rel="nofollow">GenericDAO-Pattern</a>, which is very good explained in the book "Java Persistence with Hibernate".</p> <p>The Strategy-Pattern basically consists of an interface, in my case called <em>PersistenceStrategy</em> abstracting the actual persistence implementation. Further I have a service <em>PersistenceService</em> which wraps that Persistency Strategy.</p> <pre><code>public interface PersistenceStrategy { public void persist(BaseEntity object); ... } </code></pre> <p>The PersistenceService:</p> <pre><code>public class PersistenceService { private PersistenceStrategy persistenceStrategy; public void setPersistenceStrategy(PersistenceStrategy strategy) { this.persistenceStrategy = strategy; } public PersistenceStrategy getPersistenceStrategy() { return this.persistenceStrategy; } } </code></pre> <p>The actual persistence classes [6] and [7] (e.g. PersistenceStrategyHibernate) etc. implement this interface and I declared them as a Spring bean. Also I declared the PersistenceService as a bean. The actual PersistenceStrategy is them injected to the PersistenceService. Please note that this bean definition is in the actual persistence implementation in [5] and [6] for instance, not in the webapp project [4].</p> <pre><code>&lt;bean id="hibernatePersistenceStrategy" class="org.myProject.persistence.relational.HibernatePersistenceStrategy" /&gt; &lt;!-- PersistenceService is instantiated here with the actual persistence strategy implementation --&gt; &lt;bean id="persistenceService" class="org.myProject.persistence.PersistenceService"&gt; &lt;property name="persistenceStrategy" ref="hibernatePersistenceStrategy"&gt;&lt;/property&gt; &lt;/bean&gt; </code></pre> <p>In my webapp maven project [4] I do a reference to the actual persistence implementation, e.g. [5] or [6]. </p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;org.myProject&lt;/groupId&gt; &lt;!-- this is where the persistence module is referenced. if you want to change the type of persistence you can do it here. --&gt; &lt;artifactId&gt;persistence-relational&lt;/artifactId&gt; &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>In my controller classes I can then reference the PersistenceService and the PersistenceStrategy.</p> <pre><code>@Controller public class NewDatasetController { @Autowired PersistenceStrategy persistenceStrategy; @RequestMapping("/") public String landing() { ... } } </code></pre> <p>These pattern are quite nice in my opinion. If you want to add something to this post please feel free.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload