Switched to Logback. Able to persist to C* and MongoDB.
This commit is contained in:
parent
866ca6abc3
commit
dae5301201
13 changed files with 320 additions and 170 deletions
|
@ -105,7 +105,7 @@ build
|
|||
|
||||
<!-- enhance -->
|
||||
<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>
|
||||
</target>
|
||||
|
||||
|
@ -117,7 +117,7 @@ build
|
|||
|
||||
<schematool classpathref="run.classpath" failonerror="true" verbose="true"
|
||||
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>
|
||||
</target>
|
||||
|
||||
|
@ -129,7 +129,7 @@ build
|
|||
|
||||
<schematool classpathref="run.classpath" failonerror="true" fork="true" verbose="true"
|
||||
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>
|
||||
</target>
|
||||
|
||||
|
@ -141,7 +141,7 @@ build
|
|||
|
||||
<schematool classpathref="run.classpath" failonerror="true" fork="true" verbose="true"
|
||||
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>
|
||||
</target>
|
||||
|
||||
|
|
10
crud.iml
10
crud.iml
|
@ -7,6 +7,7 @@
|
|||
<setting name="provider-name" value="" />
|
||||
<datasource-mapping>
|
||||
<factory-entry name="crud" />
|
||||
<factory-entry name="mongo" />
|
||||
</datasource-mapping>
|
||||
<deploymentDescriptor name="persistence.xml" url="file://$MODULE_DIR$/src/main/resources/META-INF/persistence.xml" />
|
||||
</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-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: 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: 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" />
|
||||
|
@ -36,7 +43,6 @@
|
|||
<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: 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:jffi: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
30
pom.xml
|
@ -32,9 +32,19 @@
|
|||
<version>2.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>[1.2, 1.3)</version>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<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>
|
||||
|
||||
<!-- ENABLE THIS FOR H2 -->
|
||||
|
@ -103,7 +113,7 @@
|
|||
</dependency-->
|
||||
|
||||
<!-- ENABLE THIS FOR MongoDB -->
|
||||
<!--dependency>
|
||||
<dependency>
|
||||
<groupId>org.datanucleus</groupId>
|
||||
<artifactId>datanucleus-mongodb</artifactId>
|
||||
<version>[5.0.0-m1, 5.9)</version>
|
||||
|
@ -111,8 +121,8 @@
|
|||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<artifactId>mongo-java-driver</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency-->
|
||||
<version>3.4.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- ENABLE THIS FOR HBase -->
|
||||
<!--dependency>
|
||||
|
@ -233,7 +243,7 @@
|
|||
<configuration>
|
||||
<api>JPA</api>
|
||||
<persistenceUnitName>crud</persistenceUnitName>
|
||||
<log4jConfiguration>${basedir}/src/main/resources/log4j.properties</log4jConfiguration>
|
||||
<persistenceUnitName>mongo</persistenceUnitName>
|
||||
<verbose>true</verbose>
|
||||
</configuration>
|
||||
<executions>
|
||||
|
@ -252,12 +262,6 @@
|
|||
<version>1.1</version>
|
||||
<configuration>
|
||||
<mainClass>com.example.crud.Main</mainClass>
|
||||
<systemProperties>
|
||||
<systemProperty>
|
||||
<key>log4j.configuration</key>
|
||||
<value>file:${basedir}/src/main/resources/log4j.properties</value>
|
||||
</systemProperty>
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -14,49 +14,51 @@ import javax.persistence.Query;
|
|||
|
||||
import com.example.crud.entities.*;
|
||||
|
||||
import org.datanucleus.enhancer.DataNucleusEnhancer;
|
||||
import org.datanucleus.util.NucleusLogger;
|
||||
|
||||
/**
|
||||
* Controlling application for the DataNucleus Tutorial using JPA.
|
||||
* Uses the "persistence-unit" called "Tutorial".
|
||||
*/
|
||||
public class Main
|
||||
{
|
||||
public static void main(String args[])
|
||||
{
|
||||
public class Main {
|
||||
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"
|
||||
// See the file "META-INF/persistence.xml"
|
||||
EntityManagerFactory emf = Persistence.createEntityManagerFactory("crud");
|
||||
EntityManagerFactory emf_mongo = Persistence.createEntityManagerFactory("mongo");
|
||||
|
||||
// Persistence of a Product and a Book.
|
||||
EntityManager em = emf.createEntityManager();
|
||||
EntityTransaction tx = em.getTransaction();
|
||||
try
|
||||
{
|
||||
try {
|
||||
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);
|
||||
inv.getProducts().add(product);
|
||||
Book book = new Book("Lord of the Rings by Tolkien", "The classic story", 49.99, "JRR Tolkien",
|
||||
"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(magazine);
|
||||
em.persist(inv);
|
||||
|
||||
tx.commit();
|
||||
System.out.println("Product and Book have been persisted");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
catch (Exception e) {
|
||||
NucleusLogger.GENERAL.error(">> Exception persisting data", e);
|
||||
System.err.println("Error persisting data : " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tx.isActive())
|
||||
{
|
||||
} finally {
|
||||
if (tx.isActive()) {
|
||||
tx.rollback();
|
||||
}
|
||||
em.close();
|
||||
|
@ -68,8 +70,7 @@ public class Main
|
|||
em = emf.createEntityManager();
|
||||
tx = em.getTransaction();
|
||||
Inventory inv = null;
|
||||
try
|
||||
{
|
||||
try {
|
||||
tx.begin();
|
||||
|
||||
// Do a find() of the Inventory
|
||||
|
@ -86,61 +87,71 @@ public class Main
|
|||
|
||||
tx.commit();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
catch (Exception e) {
|
||||
NucleusLogger.GENERAL.error(">> Exception performing find() on data", e);
|
||||
System.err.println("Error performing find() on data : " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tx.isActive())
|
||||
{
|
||||
} finally {
|
||||
if (tx.isActive()) {
|
||||
tx.rollback();
|
||||
}
|
||||
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("");
|
||||
|
||||
// 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
|
||||
em = emf.createEntityManager();
|
||||
tx = em.getTransaction();
|
||||
try
|
||||
{
|
||||
try {
|
||||
tx.begin();
|
||||
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");
|
||||
List results = q.getResultList();
|
||||
Iterator iter = results.iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
while (iter.hasNext()) {
|
||||
Object obj = iter.next();
|
||||
System.out.println("> " + obj);
|
||||
|
||||
// Give an example of an update
|
||||
if (obj instanceof Book)
|
||||
{
|
||||
if (obj instanceof Book) {
|
||||
Book b = (Book) obj;
|
||||
b.setDescription(b.getDescription() + " REDUCED");
|
||||
}
|
||||
if (obj instanceof Magazine) {
|
||||
Magazine m = (Magazine) obj;
|
||||
m.setDescription(m.getDescription() + " SPECIAL");
|
||||
}
|
||||
}
|
||||
|
||||
tx.commit();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
catch (Exception e) {
|
||||
NucleusLogger.GENERAL.error(">> Exception querying data", e);
|
||||
System.err.println("Error querying data : " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tx.isActive())
|
||||
{
|
||||
} finally {
|
||||
if (tx.isActive()) {
|
||||
tx.rollback();
|
||||
}
|
||||
em.close();
|
||||
|
@ -150,8 +161,7 @@ public class Main
|
|||
// Clean out the database
|
||||
em = emf.createEntityManager();
|
||||
tx = em.getTransaction();
|
||||
try
|
||||
{
|
||||
try {
|
||||
tx.begin();
|
||||
|
||||
System.out.println("Deleting all products from persistence");
|
||||
|
@ -168,8 +178,7 @@ public class Main
|
|||
Query q = em.createQuery("SELECT p FROM Product p");
|
||||
List<Product> products = q.getResultList();
|
||||
int numDeleted = 0;
|
||||
for (Product prod : products)
|
||||
{
|
||||
for (Product prod : products) {
|
||||
em.remove(prod);
|
||||
numDeleted++;
|
||||
}
|
||||
|
@ -177,16 +186,12 @@ public class Main
|
|||
|
||||
tx.commit();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
catch (Exception e) {
|
||||
NucleusLogger.GENERAL.error(">> Exception in bulk delete of data", e);
|
||||
System.err.println("Error in bulk delete of data : " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tx.isActive())
|
||||
{
|
||||
} finally {
|
||||
if (tx.isActive()) {
|
||||
tx.rollback();
|
||||
}
|
||||
em.close();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.example.crud.entities;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
@ -13,6 +14,7 @@ import javax.persistence.Entity;
|
|||
@Data @Entity
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
@ToString
|
||||
@AllArgsConstructor
|
||||
public class Book extends Product
|
||||
{
|
||||
/** Author of the Book. */
|
||||
|
@ -30,9 +32,7 @@ public class Book extends Product
|
|||
/**
|
||||
* Default Constructor.
|
||||
**/
|
||||
protected Book() {
|
||||
super();
|
||||
}
|
||||
protected Book() { super(); }
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -48,8 +48,10 @@ public class Book extends Product
|
|||
double price,
|
||||
String author,
|
||||
String isbn,
|
||||
String publisher) {
|
||||
String publisher)
|
||||
{
|
||||
super(name,description,price);
|
||||
|
||||
this.author = author;
|
||||
this.isbn = isbn;
|
||||
this.publisher = publisher;
|
||||
|
|
|
@ -6,12 +6,7 @@ import lombok.ToString;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.NamedEntityGraph;
|
||||
import javax.persistence.NamedAttributeNode;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* Definition of an Inventory of products.
|
||||
|
@ -25,9 +20,13 @@ public class Inventory
|
|||
@Id
|
||||
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>();
|
||||
|
||||
@Version
|
||||
long version;
|
||||
|
||||
public Inventory() { }
|
||||
public Inventory(String name)
|
||||
{
|
||||
this.name = name;
|
||||
|
|
62
src/main/java/com/example/crud/entities/Magazine.java
Normal file
62
src/main/java/com/example/crud/entities/Magazine.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,7 @@
|
|||
package com.example.crud.entities;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The Class Person.
|
||||
|
@ -12,8 +10,8 @@ import java.util.Set;
|
|||
@Cacheable
|
||||
@Table( name = "PERSON",
|
||||
indexes = {
|
||||
@Index(name = "last_name_idx", columnList="PERSON_LAST_NAME", unique = true),
|
||||
@Index(name = "email_idx", columnList="EMAIL", unique = false)})
|
||||
@Index(name = "last_name_idx", columnList="PERSON_LAST_NAME", unique = false)
|
||||
/*, @Index(name = "email_idx", columnList="EMAIL", unique = false)*/})
|
||||
public class Person
|
||||
{
|
||||
/** The person id. */
|
||||
|
@ -44,6 +42,8 @@ public class Person
|
|||
private Date updated;
|
||||
*/
|
||||
|
||||
@OneToMany(mappedBy = "seller")
|
||||
private List<Product> products;
|
||||
|
||||
@Column(name = "VERSION")
|
||||
@Version
|
||||
|
|
|
@ -3,12 +3,8 @@ package com.example.crud.entities;
|
|||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.annotation.Generated;
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* Definition of a Product
|
||||
|
@ -21,7 +17,7 @@ public class Product
|
|||
{
|
||||
/** Id for the product. */
|
||||
@Id
|
||||
private long id;
|
||||
private String id;
|
||||
|
||||
/** Name of the Product. */
|
||||
@Basic
|
||||
|
@ -33,9 +29,12 @@ public class Product
|
|||
|
||||
/** Price of the Product. */
|
||||
@Basic
|
||||
@Column (name="THE_PRICE")
|
||||
private double price=0.0;
|
||||
|
||||
/** Seller of this product. */
|
||||
@ManyToOne(optional = false)
|
||||
private Person seller;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
|
|
|
@ -1,20 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
|
||||
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"
|
||||
version="1.0">
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_1.xsd"
|
||||
version="2.1">
|
||||
<description>JPA Mapping for CRUD/JPA</description>
|
||||
<package>com.example.crud.entities</package>
|
||||
|
||||
<!--
|
||||
@Table(indexes = {@Index(columnList="PRICE")})
|
||||
-->
|
||||
<entity class="com.example.crud.entities.Product" name="Product">
|
||||
<table name="JPA_PRODUCTS"/>
|
||||
<table name="PRODUCTS"/>
|
||||
<inheritance strategy="JOINED"/>
|
||||
<attributes>
|
||||
<id name="id">
|
||||
<generated-value strategy="AUTO"/>
|
||||
</id>
|
||||
<basic name="name">
|
||||
<column name="PRODUCT_NAME" length="100"/>
|
||||
<column name="NAME" length="100"/>
|
||||
</basic>
|
||||
<basic name="description">
|
||||
<column length="255"/>
|
||||
|
@ -23,7 +26,9 @@
|
|||
</entity>
|
||||
|
||||
<entity class="com.example.crud.entities.Book" name="Book">
|
||||
<table name="JPA_BOOKS"/>
|
||||
<table name="BOOKS">
|
||||
<index column-list="price" unique="false"/>
|
||||
</table>
|
||||
<attributes>
|
||||
<basic name="isbn">
|
||||
<column name="ISBN" length="20"></column>
|
||||
|
@ -38,17 +43,36 @@
|
|||
</entity>
|
||||
|
||||
<entity class="com.example.crud.entities.Inventory" name="Inventory">
|
||||
<table name="JPA_INVENTORY"/>
|
||||
<table name="INVENTORY"/>
|
||||
<attributes>
|
||||
<id name="name">
|
||||
<column name="NAME" length="40"></column>
|
||||
</id>
|
||||
<version name="version">
|
||||
<column name="VERSION"></column>
|
||||
</version>
|
||||
<one-to-many name="products">
|
||||
<join-table name="JPA_INVENTORY_PRODUCTS">
|
||||
<join-table name="INVENTORY_PRODUCTS">
|
||||
<join-column name="INVENTORY_ID_OID"/>
|
||||
<inverse-join-column name="PRODUCT_ID_EID"/>
|
||||
</join-table>
|
||||
</one-to-many>
|
||||
</attributes>
|
||||
</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>
|
||||
|
|
|
@ -1,56 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
||||
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">
|
||||
<class>com.example.crud.entities.Inventory</class>
|
||||
<class>com.example.crud.entities.Product</class>
|
||||
<class>com.example.crud.entities.Book</class>
|
||||
<class>com.example.crud.entities.Magazine</class>
|
||||
<exclude-unlisted-classes/>
|
||||
|
||||
<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="datanucleus.mapping.Schema" value="kc"/>
|
||||
|
||||
<property name="datanucleus.schema.autoCreateAll" value="true"/>
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
|
|
@ -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
|
96
src/main/resources/logback.xml
Normal file
96
src/main/resources/logback.xml
Normal 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>
|
Loading…
Reference in a new issue