User Guide - logitopia/jmortar-core-persistence GitHub Wiki

A guide on implementing the JMortar persistence in your software project!

Prerequisite

Adding the dependency

In order to make use of this library you should import the JAR using your favourite dependency manager.

Note: All JMortar artefacts are stored in our open source Bintray (JMortar Release).

Using Gradle

Add the Bintray repository

repositories {
     maven {
         url  "https://dl.bintray.com/logitopia/jmortar-release"
     }
 }

Add the dependency

compile 'com.logitopia:jmortar-core-persistence:1.0.0'

Using Maven

Add the bintray repository

<profiles>
 	<profile>
 		<repositories>
 			<repository>
 				<snapshots>
 					<enabled>false</enabled>
 				</snapshots>
 				<id>bintray-logitopia-maven</id>
 				<name>bintray</name>
 				<url>https://dl.bintray.com/logitopia/maven</url>
 			</repository>
 		</repositories>
 		<pluginRepositories>
 			<pluginRepository>
 				<snapshots>
 					<enabled>false</enabled>
 				</snapshots>
 				<id>bintray-logitopia-maven</id>
 				<name>bintray-plugins</name>
 				<url>https://dl.bintray.com/logitopia/maven</url>
 			</pluginRepository>
 		</pluginRepositories>
 		<id>bintray</id>
 	</profile>
 </profiles>

Add the dependency

<dependency>
  <groupId>com.logitopia</groupId>
  <artifactId>jmortar-core-persistence</artifactId>
  <version>1.0.0</version>
  <type>pom</type>
</dependency>

The Easy Way

This fits pretty much everyone's purposes. All you need to do is annotate your model, add in the builder setup and configure your database connection. Job done! If that sounds like your thing … read on!

Prerequisites

This tutorial assumes you are setting up your beans using Spring.

Step One - Annotate your model

Simply add the relevant persistent implementation annotation to your model class.

@DynamoDBPersistent
public class Car {

@Key
private String vin;

private String make;
}

Note: If the persistence method you want to use requires annotations, then you should add them on top of the persistent model ones.

Step Two - Add in builder setup

Add the following component scan to your spring context. This will scan for the annotation scanner and persistent builder components you need to create your Data Access Objects.

<!-- Scan for  builder components -->
<context:component-scan
            base-package="
com.logitopia.jmortar.core.persistence.dao.builder, com.logitopia.jmortar.core.object.annotation"/>

Step Three - Configure Database Connection

Just need to add the relevant database resources to allow your Data Access Objects to perform persistence operations.

IMPORTANT: Check the API for the default bean names for your database resources if you don’t plan on overriding them with the annotation parameters.

The Detailed Way

So, this approach isn't as quick as the one above. It requires you manually configuring your DAO and DAC beans. Why would I want to do this? Well maybe you don't want to annotate your POJO or maybe you are doing debugging and you want to test a fixed configuration. Either way, here is how you get the job done.

Prerequisite

Ensure that you have setup the dependency as detailed in the section above.

Step One

The first step is to manually add the data access components you want to use for your model. This guide assumes that you are using Spring IO to setup your dependencies. Here is an example configuration in a Spring XML context.

   <!--
      Readable Data Access Controller
    -->
    <bean id="reportReadable"       class="com.logitopia.platform.core.persistence.dao.component.impl.ReadableDynamoDBDataAccessComponentImpl">
        <constructor-arg>
            <list>
                <value>reportId</value>
            </list>
        </constructor-arg>
        <constructor-arg ref="queryFactory"/>
        <constructor-arg ref="resource"/>
    </bean>

Fig 1: Create the readable DAC

<!--
      Writable Data Access Controller
    -->
    <bean id="reportWriteable"
          class="com.logitopia.platform.core.persistence.dao.component.impl.WritableDynamoDBDataAccessComponentImpl">
        <constructor-arg ref="resource"/>
    </bean>

Fig 2: Create the writable DAC

Step Two

The next step is to add the data access object and calibrate it to reference the desired data access components.

<!--
      Report Data Access Object
    -->
    <bean id="reportDAO" class="com.logitopia.platform.core.persistence.dao.impl.DataAccessObjectImpl">
        <constructor-arg>
            <null/>
        </constructor-arg>
        <constructor-arg ref="reportReadable"/>
        <constructor-arg ref="reportWriteable"/>
        <constructor-arg type="java.lang.Class"
                         value="com.logitopia.platform.core.persistence.dao.component.model.Report"></constructor-arg>
    </bean>

Fig3: Create the data access object

Step Three

As with the easy step, setup your persistence beans and wire them up to your data access controllers.

Done

All done! You can now use your data access object to read and write data.

⚠️ **GitHub.com Fallback** ⚠️