This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<plugin> | |
<groupId>org.apache.openjpa</groupId> | |
<artifactId>openjpa-maven-plugin</artifactId> | |
<version>2.2.0</version> | |
<configuration> | |
<includes>**/entities/*.class</includes> | |
<excludes>**/entities/XML*.class</excludes> | |
<addDefaultConstructor>true</addDefaultConstructor> | |
<enforcePropertyRestrictions>true</enforcePropertyRestrictions> | |
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.apache.openjpa</groupId> | |
<artifactId>openjpa-all</artifactId> | |
<version>2.1.1</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<profiles> | |
<profile> | |
<id>dev</id> | |
<activation> | |
<activeByDefault>true</activeByDefault> | |
</activation> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.liquibase</groupId> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestClientManagement { | |
@Test | |
public void should_persist_a_customer() { | |
Customer customer = new Customer("John", "Doe", "123456", 36); | |
long id=new CustomerManagementService().createCustomer(customer); | |
Assert.assertEquals("Id is not was expected",5,id); | |
} | |
@Test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
public class Customer extends BaseEntity{ | |
private String name; | |
private String surname; | |
private String identity_number; | |
private int age; | |
public Customer(String name, String surname, String identity_number, int age) { | |
this.name = name; | |
this.surname = surname; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@MappedSuperclass | |
public class BaseEntity implements Identifier{ | |
@Id | |
@GeneratedValue(strategy= GenerationType.SEQUENCE, generator="id_sequence_gen") | |
@SequenceGenerator(name="id_sequence_gen", sequenceName="id_sequence") | |
private long id; | |
public long getId() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<persistence xmlns="http://java.sun.com/xml/ns/persistence" | |
version="1.0"> | |
<persistence-unit name="JPAIntroduction" transaction-type="RESOURCE_LOCAL"> | |
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> | |
<class>com.craigew.entity.Customer</class> | |
<class>com.craigew.entity.BaseEntity</class> | |
<properties> | |
<property name="openjpa.ConnectionURL" value="jdbc:oracle:thin:@192.168.0.9:1521/xe"/> | |
<property name="openjpa.ConnectionDriverName" value="oracle.jdbc.driver.OracleDriver"/> | |
<property name="openjpa.ConnectionUserName" value="dev"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DataAccess<T extends BaseEntity> { | |
private Class<T> entityClass; | |
protected long add(T object){ | |
EntityManagerFactory factory = Persistence.createEntityManagerFactory("JPAIntroduction"); | |
EntityManager em = factory.createEntityManager(); | |
em.getTransaction().begin(); | |
em.persist(object); | |
em.getTransaction().commit(); | |
long id=object.getId(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomerManagementService extends DataAccess<Customer> { | |
public long createCustomer(Customer customer) { | |
return add(customer); | |
} | |
public boolean updateCustomer(Customer customer) { | |
update(customer); | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.craigew.entity; | |
import javax.persistence.Entity; | |
@Entity | |
public class Address extends BaseEntity{ | |
private String addressLine1; | |
private String addressLine2; | |
private String suburb; | |
private String postalCode; |
OlderNewer