Switched to Logback. Able to persist to C* and MongoDB.

This commit is contained in:
Greg Burd 2017-06-20 15:42:24 -04:00
parent 866ca6abc3
commit dae5301201
13 changed files with 320 additions and 170 deletions

View file

@ -105,7 +105,7 @@ build
<!-- enhance --> <!-- enhance -->
<enhancer classpathref="run.classpath" dir="${classes.dir}" verbose="true" api="JPA" persistenceUnit="crud"> <enhancer classpathref="run.classpath" dir="${classes.dir}" verbose="true" api="JPA" persistenceUnit="crud">
<sysproperty key="log4j.configuration" value="file:log4j.properties"/> <sysproperty key="log4j.configuration" value="file:log4j.xml"/>
</enhancer> </enhancer>
</target> </target>
@ -117,7 +117,7 @@ build
<schematool classpathref="run.classpath" failonerror="true" verbose="true" <schematool classpathref="run.classpath" failonerror="true" verbose="true"
mode="create" api="JPA" persistenceUnit="crud"> mode="create" api="JPA" persistenceUnit="crud">
<sysproperty key="log4j.configuration" value="file:${basedir}/log4j.properties"/> <sysproperty key="log4j.configuration" value="file:${basedir}/log4j.xml"/>
</schematool> </schematool>
</target> </target>
@ -129,7 +129,7 @@ build
<schematool classpathref="run.classpath" failonerror="true" fork="true" verbose="true" <schematool classpathref="run.classpath" failonerror="true" fork="true" verbose="true"
mode="delete" api="JPA" persistenceUnit="crud"> mode="delete" api="JPA" persistenceUnit="crud">
<sysproperty key="log4j.configuration" value="file:${basedir}/log4j.properties"/> <sysproperty key="log4j.configuration" value="file:${basedir}/log4j.xml"/>
</schematool> </schematool>
</target> </target>
@ -141,7 +141,7 @@ build
<schematool classpathref="run.classpath" failonerror="true" fork="true" verbose="true" <schematool classpathref="run.classpath" failonerror="true" fork="true" verbose="true"
mode="dbinfo" api="JPA" persistenceUnit="crud"> mode="dbinfo" api="JPA" persistenceUnit="crud">
<sysproperty key="log4j.configuration" value="file:${basedir}/log4j.properties"/> <sysproperty key="log4j.configuration" value="file:${basedir}/log4j.xml"/>
</schematool> </schematool>
</target> </target>

View file

@ -7,6 +7,7 @@
<setting name="provider-name" value="" /> <setting name="provider-name" value="" />
<datasource-mapping> <datasource-mapping>
<factory-entry name="crud" /> <factory-entry name="crud" />
<factory-entry name="mongo" />
</datasource-mapping> </datasource-mapping>
<deploymentDescriptor name="persistence.xml" url="file://$MODULE_DIR$/src/main/resources/META-INF/persistence.xml" /> <deploymentDescriptor name="persistence.xml" url="file://$MODULE_DIR$/src/main/resources/META-INF/persistence.xml" />
</configuration> </configuration>
@ -26,7 +27,13 @@
<orderEntry type="library" name="Maven: org.datanucleus:datanucleus-core:5.1.0-m3" level="project" /> <orderEntry type="library" name="Maven: org.datanucleus:datanucleus-core:5.1.0-m3" level="project" />
<orderEntry type="library" name="Maven: org.datanucleus:datanucleus-api-jpa:5.1.0-m3" level="project" /> <orderEntry type="library" name="Maven: org.datanucleus:datanucleus-api-jpa:5.1.0-m3" level="project" />
<orderEntry type="library" name="Maven: org.datanucleus:javax.persistence:2.1.0" level="project" /> <orderEntry type="library" name="Maven: org.datanucleus:javax.persistence:2.1.0" level="project" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" /> <orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.0.13" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.0.13" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.5" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-access:1.2.3" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:log4j-over-slf4j:1.7.7" level="project" />
<orderEntry type="library" name="Maven: org.datanucleus:datanucleus-mongodb:5.1.0-m3" level="project" />
<orderEntry type="library" name="Maven: org.mongodb:mongo-java-driver:3.4.2" level="project" />
<orderEntry type="library" name="Maven: org.datanucleus:datanucleus-cassandra:5.1.0-m3" level="project" /> <orderEntry type="library" name="Maven: org.datanucleus:datanucleus-cassandra:5.1.0-m3" level="project" />
<orderEntry type="library" name="Maven: com.datastax.cassandra:cassandra-driver-core:3.2.0" level="project" /> <orderEntry type="library" name="Maven: com.datastax.cassandra:cassandra-driver-core:3.2.0" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-handler:4.0.44.Final" level="project" /> <orderEntry type="library" name="Maven: io.netty:netty-handler:4.0.44.Final" level="project" />
@ -36,7 +43,6 @@
<orderEntry type="library" name="Maven: io.netty:netty-codec:4.0.44.Final" level="project" /> <orderEntry type="library" name="Maven: io.netty:netty-codec:4.0.44.Final" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:19.0" level="project" /> <orderEntry type="library" name="Maven: com.google.guava:guava:19.0" level="project" />
<orderEntry type="library" name="Maven: io.dropwizard.metrics:metrics-core:3.1.2" level="project" /> <orderEntry type="library" name="Maven: io.dropwizard.metrics:metrics-core:3.1.2" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.7" level="project" />
<orderEntry type="library" name="Maven: com.github.jnr:jnr-ffi:2.0.7" level="project" /> <orderEntry type="library" name="Maven: com.github.jnr:jnr-ffi:2.0.7" level="project" />
<orderEntry type="library" name="Maven: com.github.jnr:jffi:1.2.10" level="project" /> <orderEntry type="library" name="Maven: com.github.jnr:jffi:1.2.10" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: com.github.jnr:jffi:native:1.2.10" level="project" /> <orderEntry type="library" scope="RUNTIME" name="Maven: com.github.jnr:jffi:native:1.2.10" level="project" />

30
pom.xml
View file

@ -32,9 +32,19 @@
<version>2.1.0</version> <version>2.1.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>log4j</groupId> <groupId>ch.qos.logback</groupId>
<artifactId>log4j</artifactId> <artifactId>logback-classic</artifactId>
<version>[1.2, 1.3)</version> <version>1.0.13</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.7.7</version>
</dependency> </dependency>
<!-- ENABLE THIS FOR H2 --> <!-- ENABLE THIS FOR H2 -->
@ -103,7 +113,7 @@
</dependency--> </dependency-->
<!-- ENABLE THIS FOR MongoDB --> <!-- ENABLE THIS FOR MongoDB -->
<!--dependency> <dependency>
<groupId>org.datanucleus</groupId> <groupId>org.datanucleus</groupId>
<artifactId>datanucleus-mongodb</artifactId> <artifactId>datanucleus-mongodb</artifactId>
<version>[5.0.0-m1, 5.9)</version> <version>[5.0.0-m1, 5.9)</version>
@ -111,8 +121,8 @@
<dependency> <dependency>
<groupId>org.mongodb</groupId> <groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId> <artifactId>mongo-java-driver</artifactId>
<version>3.0.0</version> <version>3.4.2</version>
</dependency--> </dependency>
<!-- ENABLE THIS FOR HBase --> <!-- ENABLE THIS FOR HBase -->
<!--dependency> <!--dependency>
@ -233,7 +243,7 @@
<configuration> <configuration>
<api>JPA</api> <api>JPA</api>
<persistenceUnitName>crud</persistenceUnitName> <persistenceUnitName>crud</persistenceUnitName>
<log4jConfiguration>${basedir}/src/main/resources/log4j.properties</log4jConfiguration> <persistenceUnitName>mongo</persistenceUnitName>
<verbose>true</verbose> <verbose>true</verbose>
</configuration> </configuration>
<executions> <executions>
@ -252,12 +262,6 @@
<version>1.1</version> <version>1.1</version>
<configuration> <configuration>
<mainClass>com.example.crud.Main</mainClass> <mainClass>com.example.crud.Main</mainClass>
<systemProperties>
<systemProperty>
<key>log4j.configuration</key>
<value>file:${basedir}/src/main/resources/log4j.properties</value>
</systemProperty>
</systemProperties>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

View file

@ -14,49 +14,51 @@ import javax.persistence.Query;
import com.example.crud.entities.*; import com.example.crud.entities.*;
import org.datanucleus.enhancer.DataNucleusEnhancer;
import org.datanucleus.util.NucleusLogger; import org.datanucleus.util.NucleusLogger;
/** /**
* Controlling application for the DataNucleus Tutorial using JPA. * Controlling application for the DataNucleus Tutorial using JPA.
* Uses the "persistence-unit" called "Tutorial". * Uses the "persistence-unit" called "Tutorial".
*/ */
public class Main public class Main {
{ public static void main(String args[]) {
public static void main(String args[]) DataNucleusEnhancer enhancer = new DataNucleusEnhancer("JPA", null);
{ enhancer.setVerbose(true);
enhancer.addPersistenceUnit("crud");
enhancer.addPersistenceUnit("mongo");
enhancer.enhance();
// Create an EntityManagerFactory for this "persistence-unit" // Create an EntityManagerFactory for this "persistence-unit"
// See the file "META-INF/persistence.xml" // See the file "META-INF/persistence.xml"
EntityManagerFactory emf = Persistence.createEntityManagerFactory("crud"); EntityManagerFactory emf = Persistence.createEntityManagerFactory("crud");
EntityManagerFactory emf_mongo = Persistence.createEntityManagerFactory("mongo");
// Persistence of a Product and a Book. // Persistence of a Product and a Book.
EntityManager em = emf.createEntityManager(); EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction(); EntityTransaction tx = em.getTransaction();
try try {
{
tx.begin(); tx.begin();
Inventory inv = new Inventory("My Inventory"); Inventory inv = em.merge(new Inventory("My Inventory"));
Product product = new Product("Sony Discman", "A standard discman from Sony", 200.00); Product product = new Product("Sony Discman", "A standard discman from Sony", 200.00);
inv.getProducts().add(product); inv.getProducts().add(product);
Book book = new Book("Lord of the Rings by Tolkien", "The classic story", 49.99, "JRR Tolkien", Book book = new Book("Lord of the Rings by Tolkien", "The classic story", 49.99, "JRR Tolkien",
"12345678", "MyBooks Factory"); "12345678", "MyBooks Factory");
Magazine magazine = new Magazine("Field and Stream", "A hunter's guide to the outdoors.", 3.29, "F&S, Inc.", "23984729347", "F&S, Inc.");
inv.getProducts().add(book); inv.getProducts().add(book);
inv.getProducts().add(magazine);
em.persist(inv); em.persist(inv);
tx.commit(); tx.commit();
System.out.println("Product and Book have been persisted"); System.out.println("Product and Book have been persisted");
} }
catch (Exception e) catch (Exception e) {
{
NucleusLogger.GENERAL.error(">> Exception persisting data", e); NucleusLogger.GENERAL.error(">> Exception persisting data", e);
System.err.println("Error persisting data : " + e.getMessage()); System.err.println("Error persisting data : " + e.getMessage());
return; return;
} } finally {
finally if (tx.isActive()) {
{
if (tx.isActive())
{
tx.rollback(); tx.rollback();
} }
em.close(); em.close();
@ -68,8 +70,7 @@ public class Main
em = emf.createEntityManager(); em = emf.createEntityManager();
tx = em.getTransaction(); tx = em.getTransaction();
Inventory inv = null; Inventory inv = null;
try try {
{
tx.begin(); tx.begin();
// Do a find() of the Inventory // Do a find() of the Inventory
@ -86,61 +87,71 @@ public class Main
tx.commit(); tx.commit();
} }
catch (Exception e) catch (Exception e) {
{
NucleusLogger.GENERAL.error(">> Exception performing find() on data", e); NucleusLogger.GENERAL.error(">> Exception performing find() on data", e);
System.err.println("Error performing find() on data : " + e.getMessage()); System.err.println("Error performing find() on data : " + e.getMessage());
return; return;
} } finally {
finally if (tx.isActive()) {
{
if (tx.isActive())
{
tx.rollback(); tx.rollback();
} }
em.close(); // This will detach all current managed objects em.close(); // This will detach all current managed objects
} }
for (Product prod : inv.getProducts()) for (Product prod : inv.getProducts()) {
{
System.out.println(">> After Detach : Inventory has a product=" + prod); System.out.println(">> After Detach : Inventory has a product=" + prod);
} }
System.out.println(""); System.out.println("");
// Add a person to MongoDB
em = emf_mongo.createEntityManager();
tx = em.getTransaction();
Person person;
try {
tx.begin();
person = new Person();
person.setPersonFirstName("James");
person.setPersonLastName("Bond");
person.setAge(42);
em.merge(person);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close(); // This will detach all current managed objects
}
// Perform some query operations // Perform some query operations
em = emf.createEntityManager(); em = emf.createEntityManager();
tx = em.getTransaction(); tx = em.getTransaction();
try try {
{
tx.begin(); tx.begin();
System.out.println("Executing Query for Products with price below 150.00"); System.out.println("Executing Query for Products with price below 150.00");
Query q = em.createQuery("SELECT p FROM Product p WHERE p.price < 150.00 ORDER BY p.price"); Query q = em.createQuery("SELECT p FROM Product p WHERE p.price < 150.00 ORDER BY p.price");
List results = q.getResultList(); List results = q.getResultList();
Iterator iter = results.iterator(); Iterator iter = results.iterator();
while (iter.hasNext()) while (iter.hasNext()) {
{
Object obj = iter.next(); Object obj = iter.next();
System.out.println("> " + obj); System.out.println("> " + obj);
// Give an example of an update // Give an example of an update
if (obj instanceof Book) if (obj instanceof Book) {
{ Book b = (Book) obj;
Book b = (Book)obj;
b.setDescription(b.getDescription() + " REDUCED"); b.setDescription(b.getDescription() + " REDUCED");
} }
if (obj instanceof Magazine) {
Magazine m = (Magazine) obj;
m.setDescription(m.getDescription() + " SPECIAL");
}
} }
tx.commit(); tx.commit();
} }
catch (Exception e) catch (Exception e) {
{
NucleusLogger.GENERAL.error(">> Exception querying data", e); NucleusLogger.GENERAL.error(">> Exception querying data", e);
System.err.println("Error querying data : " + e.getMessage()); System.err.println("Error querying data : " + e.getMessage());
return; return;
} } finally {
finally if (tx.isActive()) {
{
if (tx.isActive())
{
tx.rollback(); tx.rollback();
} }
em.close(); em.close();
@ -150,12 +161,11 @@ public class Main
// Clean out the database // Clean out the database
em = emf.createEntityManager(); em = emf.createEntityManager();
tx = em.getTransaction(); tx = em.getTransaction();
try try {
{
tx.begin(); tx.begin();
System.out.println("Deleting all products from persistence"); System.out.println("Deleting all products from persistence");
inv = (Inventory)em.find(Inventory.class, "My Inventory"); inv = (Inventory) em.find(Inventory.class, "My Inventory");
System.out.println("Clearing out Inventory"); System.out.println("Clearing out Inventory");
inv.getProducts().clear(); inv.getProducts().clear();
@ -168,8 +178,7 @@ public class Main
Query q = em.createQuery("SELECT p FROM Product p"); Query q = em.createQuery("SELECT p FROM Product p");
List<Product> products = q.getResultList(); List<Product> products = q.getResultList();
int numDeleted = 0; int numDeleted = 0;
for (Product prod : products) for (Product prod : products) {
{
em.remove(prod); em.remove(prod);
numDeleted++; numDeleted++;
} }
@ -177,16 +186,12 @@ public class Main
tx.commit(); tx.commit();
} }
catch (Exception e) catch (Exception e) {
{
NucleusLogger.GENERAL.error(">> Exception in bulk delete of data", e); NucleusLogger.GENERAL.error(">> Exception in bulk delete of data", e);
System.err.println("Error in bulk delete of data : " + e.getMessage()); System.err.println("Error in bulk delete of data : " + e.getMessage());
return; return;
} } finally {
finally if (tx.isActive()) {
{
if (tx.isActive())
{
tx.rollback(); tx.rollback();
} }
em.close(); em.close();

View file

@ -1,5 +1,6 @@
package com.example.crud.entities; package com.example.crud.entities;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
@ -13,6 +14,7 @@ import javax.persistence.Entity;
@Data @Entity @Data @Entity
@EqualsAndHashCode(callSuper=false) @EqualsAndHashCode(callSuper=false)
@ToString @ToString
@AllArgsConstructor
public class Book extends Product public class Book extends Product
{ {
/** Author of the Book. */ /** Author of the Book. */
@ -30,9 +32,7 @@ public class Book extends Product
/** /**
* Default Constructor. * Default Constructor.
**/ **/
protected Book() { protected Book() { super(); }
super();
}
/** /**
* Constructor. * Constructor.
@ -48,8 +48,10 @@ public class Book extends Product
double price, double price,
String author, String author,
String isbn, String isbn,
String publisher) { String publisher)
{
super(name,description,price); super(name,description,price);
this.author = author; this.author = author;
this.isbn = isbn; this.isbn = isbn;
this.publisher = publisher; this.publisher = publisher;

View file

@ -6,12 +6,7 @@ import lombok.ToString;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import javax.persistence.CascadeType; import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedEntityGraph;
import javax.persistence.NamedAttributeNode;
import javax.persistence.OneToMany;
/** /**
* Definition of an Inventory of products. * Definition of an Inventory of products.
@ -25,9 +20,13 @@ public class Inventory
@Id @Id
private String name=null; private String name=null;
@OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH}) @OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH}, fetch=FetchType.EAGER)
public Set<Product> products = new HashSet<Product>(); public Set<Product> products = new HashSet<Product>();
@Version
long version;
public Inventory() { }
public Inventory(String name) public Inventory(String name)
{ {
this.name = name; this.name = name;

View file

@ -0,0 +1,62 @@
package com.example.crud.entities;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;
/**
* Definition of a Book. Extends basic Product class.
**/
@Data @Entity
@EqualsAndHashCode(callSuper=false)
@ToString
@AllArgsConstructor
public class Magazine extends Product
{
/** Author of the Book. */
@Basic
private String author = null;
/** ISBN number of the book. */
@Basic
private String isbn = null;
/** Publisher of the Book. */
@Basic
private String publisher = null;
/**
* Default Constructor.
**/
protected Magazine() {
super();
}
/**
* Constructor.
* @param name name of product
* @param description description of product
* @param price Price
* @param author Author of the book
* @param isbn ISBN number of the book
* @param publisher Name of publisher of the book
**/
public Magazine(String name,
String description,
double price,
String author,
String isbn,
String publisher) {
super(name,description,price);
this.author = author;
this.isbn = isbn;
this.publisher = publisher;
}
}

View file

@ -1,9 +1,7 @@
package com.example.crud.entities; package com.example.crud.entities;
import javax.persistence.*; import javax.persistence.*;
import java.util.Date; import java.util.List;
import java.util.HashSet;
import java.util.Set;
/** /**
* The Class Person. * The Class Person.
@ -12,8 +10,8 @@ import java.util.Set;
@Cacheable @Cacheable
@Table( name = "PERSON", @Table( name = "PERSON",
indexes = { indexes = {
@Index(name = "last_name_idx", columnList="PERSON_LAST_NAME", unique = true), @Index(name = "last_name_idx", columnList="PERSON_LAST_NAME", unique = false)
@Index(name = "email_idx", columnList="EMAIL", unique = false)}) /*, @Index(name = "email_idx", columnList="EMAIL", unique = false)*/})
public class Person public class Person
{ {
/** The person id. */ /** The person id. */
@ -44,6 +42,8 @@ public class Person
private Date updated; private Date updated;
*/ */
@OneToMany(mappedBy = "seller")
private List<Product> products;
@Column(name = "VERSION") @Column(name = "VERSION")
@Version @Version

View file

@ -3,12 +3,8 @@ package com.example.crud.entities;
import lombok.Data; import lombok.Data;
import lombok.ToString; import lombok.ToString;
import javax.persistence.Basic; import javax.annotation.Generated;
import javax.persistence.Column; import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
/** /**
* Definition of a Product * Definition of a Product
@ -21,7 +17,7 @@ public class Product
{ {
/** Id for the product. */ /** Id for the product. */
@Id @Id
private long id; private String id;
/** Name of the Product. */ /** Name of the Product. */
@Basic @Basic
@ -33,9 +29,12 @@ public class Product
/** Price of the Product. */ /** Price of the Product. */
@Basic @Basic
@Column (name="THE_PRICE")
private double price=0.0; private double price=0.0;
/** Seller of this product. */
@ManyToOne(optional = false)
private Person seller;
/** /**
* Default constructor. * Default constructor.
*/ */

View file

@ -1,20 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_1.xsd"
version="1.0"> version="2.1">
<description>JPA Mapping for CRUD/JPA</description> <description>JPA Mapping for CRUD/JPA</description>
<package>com.example.crud.entities</package> <package>com.example.crud.entities</package>
<!--
@Table(indexes = {@Index(columnList="PRICE")})
-->
<entity class="com.example.crud.entities.Product" name="Product"> <entity class="com.example.crud.entities.Product" name="Product">
<table name="JPA_PRODUCTS"/> <table name="PRODUCTS"/>
<inheritance strategy="JOINED"/> <inheritance strategy="JOINED"/>
<attributes> <attributes>
<id name="id"> <id name="id">
<generated-value strategy="AUTO"/> <generated-value strategy="AUTO"/>
</id> </id>
<basic name="name"> <basic name="name">
<column name="PRODUCT_NAME" length="100"/> <column name="NAME" length="100"/>
</basic> </basic>
<basic name="description"> <basic name="description">
<column length="255"/> <column length="255"/>
@ -23,7 +26,9 @@
</entity> </entity>
<entity class="com.example.crud.entities.Book" name="Book"> <entity class="com.example.crud.entities.Book" name="Book">
<table name="JPA_BOOKS"/> <table name="BOOKS">
<index column-list="price" unique="false"/>
</table>
<attributes> <attributes>
<basic name="isbn"> <basic name="isbn">
<column name="ISBN" length="20"></column> <column name="ISBN" length="20"></column>
@ -38,17 +43,36 @@
</entity> </entity>
<entity class="com.example.crud.entities.Inventory" name="Inventory"> <entity class="com.example.crud.entities.Inventory" name="Inventory">
<table name="JPA_INVENTORY"/> <table name="INVENTORY"/>
<attributes> <attributes>
<id name="name"> <id name="name">
<column name="NAME" length="40"></column> <column name="NAME" length="40"></column>
</id> </id>
<version name="version">
<column name="VERSION"></column>
</version>
<one-to-many name="products"> <one-to-many name="products">
<join-table name="JPA_INVENTORY_PRODUCTS"> <join-table name="INVENTORY_PRODUCTS">
<join-column name="INVENTORY_ID_OID"/> <join-column name="INVENTORY_ID_OID"/>
<inverse-join-column name="PRODUCT_ID_EID"/> <inverse-join-column name="PRODUCT_ID_EID"/>
</join-table> </join-table>
</one-to-many> </one-to-many>
</attributes> </attributes>
</entity> </entity>
<entity class="com.example.crud.entities.Magazine" name="Magazine">
<table name="MAGAZINES"/>
<attributes>
<basic name="isbn">
<column name="ISBN" length="20"></column>
</basic>
<basic name="author">
<column name="AUTHOR" length="40"/>
</basic>
<basic name="publisher">
<column name="PUBLISHER" length="40"/>
</basic>
</attributes>
</entity>
</entity-mappings> </entity-mappings>

View file

@ -1,56 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" <persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="mongo">
<class>com.example.crud.entities.Person</class>
<exclude-unlisted-classes/>
<properties>
<!-- ENABLE THESE FOR MONGODB -->
<property name="javax.persistence.jdbc.url" value="mongodb:/crud"/>
<property name="datanucleus.schema.autoCreateAll" value="true"/>
</properties>
</persistence-unit>
<persistence-unit name="crud"> <persistence-unit name="crud">
<class>com.example.crud.entities.Inventory</class> <class>com.example.crud.entities.Inventory</class>
<class>com.example.crud.entities.Product</class> <class>com.example.crud.entities.Product</class>
<class>com.example.crud.entities.Book</class> <class>com.example.crud.entities.Book</class>
<class>com.example.crud.entities.Magazine</class>
<exclude-unlisted-classes/> <exclude-unlisted-classes/>
<properties> <properties>
<!-- ENABLE THESE FOR H2 -->
<!-- <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:nucleus1"/>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="javax.persistence.jdbc.user" value="sa"/>
<property name="javax.persistence.jdbc.password" value=""/> -->
<!-- ENABLE THESE FOR HSQLDB -->
<!--property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:nucleus1"/>
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver"/>
<property name="javax.persistence.jdbc.user" value="sa"/>
<property name="javax.persistence.jdbc.password" value=""/-->
<!-- ENABLE THESE FOR MySQL/MariaDB -->
<!-- Change the "nucleus" to your database name, and the user/password -->
<!--property name="javax.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1/nucleus?useServerPrepStmts=false"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.user" value="mysql" />
<property name="javax.persistence.jdbc.password" value=""/-->
<!-- ENABLE THESE FOR ODF -->
<!-- Change the "tutorial.ods" to include the path to your ODF file -->
<!--property name="javax.persistence.jdbc.url" value="odf:file:tutorial.ods"/-->
<!-- ENABLE THESE FOR EXCEL -->
<!-- Change the "tutorial.xls" to include the path to your Excel file -->
<!--property name="javax.persistence.jdbc.url" value="excel:file:tutorial.xls"/-->
<!-- ENABLE THESE FOR MONGODB -->
<!--property name="javax.persistence.jdbc.url" value="mongodb:/nucleus1"/-->
<!-- ENABLE THESE FOR HBASE -->
<!--property name="javax.persistence.jdbc.url" value="hbase:"/-->
<!-- ENABLE THESE FOR NEO4J -->
<!-- Change the "testDB" to the path to your Neo4j graph DB file -->
<!--property name="javax.persistence.jdbc.url" value="neo4j:testDB"/-->
<!-- ENABLE THESE FOR CASSANDRA -->
<property name="javax.persistence.jdbc.url" value="cassandra:"/> <property name="javax.persistence.jdbc.url" value="cassandra:"/>
<property name="datanucleus.mapping.Schema" value="kc"/> <property name="datanucleus.mapping.Schema" value="kc"/>
<property name="datanucleus.schema.autoCreateAll" value="true"/> <property name="datanucleus.schema.autoCreateAll" value="true"/>
</properties> </properties>
</persistence-unit> </persistence-unit>

View file

@ -1,21 +0,0 @@
# LOG4J Configuration
# ===================
# Basic logging goes to "crud.log"
log4j.appender.A1=org.apache.log4j.FileAppender
log4j.appender.A1.File=crud.log
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss,SSS} (%t) %-5p [%c] - %m%n
#log4j.appender.A1.Threshold=INFO
# Categories
# Each category can be set to a "level", and to direct to an appender
# Default to DEBUG level for all DataNucleus categories
log4j.logger.DataNucleus = DEBUG, A1
log4j.category.com.mchange.v2.c3p0=INFO, A1
log4j.category.com.mchange.v2.resourcepool=INFO, A1
log4j.category.org.logicalcobwebs.proxool=INFO,A1
log4j.category.org.apache.hadoop.conf.Configuration=ERROR

View file

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true">
<!-- ====================================================================== -->
<!-- Changing the pattern requires a change in our logstash parsing module -->
<!-- ====================================================================== -->
<property name="java-pattern" value="%d{ISO8601, UTC} %-5p [%.15t] %c{1}: %m %X{OBJECT_ID}%X{CLIENT_IP}%X{ELEMENT_ID}%X{USER_ID}%X{CONNECTION_ID}%X{REQUEST_ID}%X{CLIENT_ID}%n"/>
<property name="cpp-pattern" value="%d{ISO8601, UTC} %-5p %c{1}: %m %X{OBJECT_ID} %X{ELEMENT_ID}%n"/>
<property name="timer-pattern" value="%d{ISO8601, UTC} %-5p %c: %m \\(%F, line %L\\) %X{OBJECT_ID} %X{ELEMENT_ID}%n"/>
<property name="tree-pattern" value="%d{ISO8601, UTC} %-5p %c: %m%n"/>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${java-pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>TRACE</level>
</filter>
</appender>
<logger name="com.mchange.v2.resourcepool" level="INFO">
<appender-ref ref="console"/>
</logger>
<logger name="com.mchange.v2.c3p0" level="INFO">
<appender-ref ref="console"/>
</logger>
<logger name="org.logicalcobwebs.proxool" level="INFO">
<appender-ref ref="console"/>
</logger>
<logger name="DataNucleus" level="TRACE">
<appender-ref ref="console"/>
</logger>
<logger name="org.springframework" level="TRACE">
<level value="trace" />
<appender-ref ref="console"/>
</logger>
<logger name="org.mongodb.driver" level="TRACE">
<appender-ref ref="console"/>
</logger>
<logger name="org.springdata.cassandra" level="TRACE">
<appender-ref ref="console"/>
</logger>
<logger name="com.datastax.driver.core.Cluster" level="INFO">
<appender-ref ref="console"/>
</logger>
<logger name="com.datastax.driver.core.Session" level="INFO">
<appender-ref ref="console"/>
</logger>
<logger name="com.datastax.driver.core.RequestHandler" level="TRACE">
<appender-ref ref="console"/>
</logger>
<logger name="com.datastax.driver.core.Connection" level="INFO">
<appender-ref ref="console"/>
</logger>
<logger name="com.datastax.driver.core.Message" level="INFO">
<appender-ref ref="console"/>
</logger>
<logger name="com.datastax.driver.core.QueryLogger.SLOW" level="INFO">
<appender-ref ref="console"/>
</logger>
<!--
<logger name="com.datastax.driver.core.QueryLogger.NORMAL" level="TRACE">
<appender-ref ref="console"/>
</logger>
-->
<logger name="com.datastax.driver.core.QueryLogger.FAST" level="INFO">
<appender-ref ref="console"/>
</logger>
<logger name="com.datastax.driver.core.QueryLogger.ERROR" level="INFO">
<appender-ref ref="console"/>
</logger>
<logger name="net.spy.memcached" level="TRACE">
<appender-ref ref="console"/>
</logger>
<!-- Root logger
<root>
<level value="info" />
<appender-ref ref="console" />
</root>
-->
</configuration>